| 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 | /* SPDX-FileCopyrightText: 2022 Bartosz Golaszewski <[email protected]> */ |
| 3 | |
| 4 | #ifndef __GPIOD_CXX_GPIOSIM_HPP__ |
| 5 | #define __GPIOD_CXX_GPIOSIM_HPP__ |
| 6 | |
| 7 | #include <filesystem> |
| 8 | #include <memory> |
| 9 | |
| 10 | namespace gpiosim { |
| 11 | |
| 12 | class chip_builder; |
| 13 | |
| 14 | class chip |
| 15 | { |
| 16 | public: |
| 17 | enum class pull { |
| 18 | PULL_UP = 1, |
| 19 | PULL_DOWN, |
| 20 | }; |
| 21 | |
| 22 | enum class value { |
| 23 | INACTIVE = 0, |
| 24 | ACTIVE = 1, |
| 25 | }; |
| 26 | |
| 27 | chip(const chip& other) = delete; |
| 28 | chip(chip&& other); |
| 29 | ~chip(); |
| 30 | |
| 31 | chip& operator=(const chip& other) = delete; |
| 32 | chip& operator=(chip&& other); |
| 33 | |
| 34 | ::std::filesystem::path dev_path() const; |
| 35 | ::std::string name() const; |
| 36 | |
| 37 | value get_value(unsigned int offset); |
| 38 | void set_pull(unsigned int offset, pull pull); |
| 39 | |
| 40 | private: |
| 41 | |
| 42 | chip(); |
| 43 | |
| 44 | struct impl; |
| 45 | |
| 46 | ::std::unique_ptr<impl> _m_priv; |
| 47 | |
| 48 | friend chip_builder; |
| 49 | }; |
| 50 | |
| 51 | class chip_builder |
| 52 | { |
| 53 | public: |
| 54 | enum class direction { |
| 55 | INPUT = 1, |
| 56 | OUTPUT_HIGH, |
| 57 | OUTPUT_LOW, |
| 58 | }; |
| 59 | |
| 60 | chip_builder(); |
| 61 | chip_builder(const chip_builder& other) = delete; |
| 62 | chip_builder(chip_builder&& other); |
| 63 | ~chip_builder(); |
| 64 | |
| 65 | chip_builder& operator=(const chip_builder& other) = delete; |
| 66 | chip_builder& operator=(chip_builder&& other); |
| 67 | |
| 68 | chip_builder& set_num_lines(::std::size_t num_lines); |
| 69 | chip_builder& set_label(const ::std::string& label); |
| 70 | chip_builder& set_line_name(unsigned int offset, const ::std::string& name); |
| 71 | chip_builder& set_hog(unsigned int offset, const ::std::string& name, direction direction); |
| 72 | |
| 73 | chip build(); |
| 74 | |
| 75 | private: |
| 76 | |
| 77 | struct impl; |
| 78 | |
| 79 | ::std::unique_ptr<impl> _m_priv; |
| 80 | }; |
| 81 | |
| 82 | chip_builder make_sim(); |
| 83 | |
| 84 | } /* namespace gpiosim */ |
| 85 | |
| 86 | #endif /* __GPIOD_CXX_GPIOSIM_HPP__ */ |