Debian Codegraph @

bindings/cxx/gpiodcxx/line.hpp

raw symbols SCIP
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /* SPDX-FileCopyrightText: 2021-2022 Bartosz Golaszewski <[email protected]> */
3
4 /**
5 * @file line.hpp
6 */
7
8 #ifndef __LIBGPIOD_CXX_LINE_HPP__
9 #define __LIBGPIOD_CXX_LINE_HPP__
10
11 #if !defined(__LIBGPIOD_GPIOD_CXX_INSIDE__)
12 #error "Only gpiod.hpp can be included directly."
13 #endif
14
15 #include <ostream>
16 #include <utility>
17 #include <vector>
18
19 namespace gpiod {
20
21 /**
22 * @brief Namespace containing various type definitions for GPIO lines.
23 */
24 namespace line {
25
26 /**
27 * @brief Wrapper around unsigned int for representing line offsets.
28 */
29 class offset
30 {
31 public:
32 /**
33 * @brief Constructor with implicit conversion from unsigned int.
34 * @param off Line offset.
35 */
36 offset(unsigned int off = 0) : _m_offset(off) { }
37
38 /**
39 * @brief Copy constructor.
40 * @param other Object to copy.
41 */
42 offset(const offset& other) = default;
43
44 /**
45 * @brief Move constructor.
46 * @param other Object to move.
47 */
48 offset(offset&& other) = default;
49
50 ~offset() = default;
51
52 /**
53 * @brief Assignment operator.
54 * @param other Object to copy.
55 * @return Reference to self.
56 */
57 offset& operator=(const offset& other) = default;
58
59 /**
60 * @brief Move assignment operator.
61 * @param other Object to move.
62 * @return Reference to self.
63 */
64 offset& operator=(offset&& other) noexcept = default;
65
66 /**
67 * @brief Conversion operator to `unsigned int`.
68 */
69 operator unsigned int() const noexcept
70 {
71 return this->_m_offset;
72 }
73
74 private:
75 unsigned int _m_offset;
76 };
77
78 /**
79 * @brief Logical line states.
80 */
81 enum class value
82 {
83 INACTIVE = 0,
84 /**< Line is inactive. */
85 ACTIVE = 1,
86 /**< Line is active. */
87 };
88
89 /**
90 * @brief Direction settings.
91 */
92 enum class direction
93 {
94 AS_IS = 1,
95 /**< Request the line(s), but don't change current direction. */
96 INPUT,
97 /**< Direction is input - we're reading the state of a GPIO line. */
98 OUTPUT,
99 /**< Direction is output - we're driving the GPIO line. */
100 };
101
102 /**
103 * @brief Edge detection settings.
104 */
105 enum class edge
106 {
107 NONE = 1,
108 /**< Line edge detection is disabled. */
109 RISING,
110 /**< Line detects rising edge events. */
111 FALLING,
112 /**< Line detect falling edge events. */
113 BOTH,
114 /**< Line detects both rising and falling edge events. */
115 };
116
117 /**
118 * @brief Internal bias settings.
119 */
120 enum class bias
121 {
122 AS_IS = 1,
123 /**< Don't change the bias setting when applying line config. */
124 UNKNOWN,
125 /**< The internal bias state is unknown. */
126 DISABLED,
127 /**< The internal bias is disabled. */
128 PULL_UP,
129 /**< The internal pull-up bias is enabled. */
130 PULL_DOWN,
131 /**< The internal pull-down bias is enabled. */
132 };
133
134 /**
135 * @brief Drive settings.
136 */
137 enum class drive
138 {
139 PUSH_PULL = 1,
140 /**< Drive setting is push-pull. */
141 OPEN_DRAIN,
142 /**< Line output is open-drain. */
143 OPEN_SOURCE,
144 /**< Line output is open-source. */
145 };
146
147 /**
148 * @brief Event clock settings.
149 */
150 enum class clock
151 {
152 MONOTONIC = 1,
153 /**< Line uses the monotonic clock for edge event timestamps. */
154 REALTIME,
155 /**< Line uses the realtime clock for edge event timestamps. */
156 HTE,
157 /*<< Line uses the hardware timestamp engine for event timestamps. */
158 };
159
160 /**
161 * @brief Vector of line offsets.
162 */
163 using offsets = ::std::vector<offset>;
164
165 /**
166 * @brief Vector of line values.
167 */
168 using values = ::std::vector<value>;
169
170 /**
171 * @brief Represents a mapping of a line offset to line logical state.
172 */
173 using value_mapping = ::std::pair<offset, value>;
174
175 /**
176 * @brief Vector of offset->value mappings. Each mapping is defined as a pair
177 * of an unsigned and signed integers.
178 */
179 using value_mappings = ::std::vector<value_mapping>;
180
181 /**
182 * @brief Stream insertion operator for logical line values.
183 * @param out Output stream.
184 * @param val Value to insert into the output stream in a human-readable form.
185 * @return Reference to out.
186 */
187 ::std::ostream& operator<<(::std::ostream& out, value val);
188
189 /**
190 * @brief Stream insertion operator for direction values.
191 * @param out Output stream.
192 * @param dir Value to insert into the output stream in a human-readable form.
193 * @return Reference to out.
194 */
195 ::std::ostream& operator<<(::std::ostream& out, direction dir);
196
197 /**
198 * @brief Stream insertion operator for edge detection values.
199 * @param out Output stream.
200 * @param edge Value to insert into the output stream in a human-readable form.
201 * @return Reference to out.
202 */
203 ::std::ostream& operator<<(::std::ostream& out, edge edge);
204
205 /**
206 * @brief Stream insertion operator for bias values.
207 * @param out Output stream.
208 * @param bias Value to insert into the output stream in a human-readable form.
209 * @return Reference to out.
210 */
211 ::std::ostream& operator<<(::std::ostream& out, bias bias);
212
213 /**
214 * @brief Stream insertion operator for drive values.
215 * @param out Output stream.
216 * @param drive Value to insert into the output stream in a human-readable form.
217 * @return Reference to out.
218 */
219 ::std::ostream& operator<<(::std::ostream& out, drive drive);
220
221 /**
222 * @brief Stream insertion operator for event clock values.
223 * @param out Output stream.
224 * @param clock Value to insert into the output stream in a human-readable form.
225 * @return Reference to out.
226 */
227 ::std::ostream& operator<<(::std::ostream& out, clock clock);
228
229 /**
230 * @brief Stream insertion operator for the list of output values.
231 * @param out Output stream.
232 * @param vals Object to insert into the output stream in a human-readable form.
233 * @return Reference to out.
234 */
235 ::std::ostream& operator<<(::std::ostream& out, const values& vals);
236
237 /**
238 * @brief Stream insertion operator for the list of line offsets.
239 * @param out Output stream.
240 * @param offs Object to insert into the output stream in a human-readable form.
241 * @return Reference to out.
242 */
243 ::std::ostream& operator<<(::std::ostream& out, const offsets& offs);
244
245 /**
246 * @brief Stream insertion operator for the offset-to-value mapping.
247 * @param out Output stream.
248 * @param mapping Value to insert into the output stream in a human-readable
249 * form.
250 * @return Reference to out.
251 */
252 ::std::ostream& operator<<(::std::ostream& out, const value_mapping& mapping);
253
254 /**
255 * @brief Stream insertion operator for the list of offset-to-value mappings.
256 * @param out Output stream.
257 * @param mappings Object to insert into the output stream in a human-readable
258 * form.
259 * @return Reference to out.
260 */
261 ::std::ostream& operator<<(::std::ostream& out, const value_mappings& mappings);
262
263 } /* namespace line */
264
265 } /* namespace gpiod */
266
267 #endif /* __LIBGPIOD_CXX_LINE_HPP__ */