Veethree D7 SDK
Loading...
Searching...
No Matches
digital_common.h
Go to the documentation of this file.
1
5#ifndef DIGITAL_COMMON_H
6#define DIGITAL_COMMON_H
7
8#include <cstdint>
9#include <memory>
10
11namespace vsdk::io::digout {
12
19enum class channel : uint8_t {
27};
28
35enum class pwm : uint8_t {
39};
40
47enum class mode : uint8_t {
51};
52
53} // namespace vsdk::io::digout
54
55namespace vsdk::io::digin {
56
63enum class channel : uint8_t {
70};
71
78enum class pwm : uint8_t {
82};
83
90enum class mode : uint8_t {
94};
95
96} // namespace vsdk::io::digin
97
98namespace vsdk::io {
99
110template<typename T>
111int channel_cast(T /* ch */)
112{
113 static_assert(false, "must be specialised");
114 return -1;
115}
116
126template<>
128{
129 return ch == digin::channel::none ? -1 : static_cast<int>(ch) - 1;
130}
131
141template<>
143{
144 return ch == digout::channel::none ? -1 : static_cast<int>(ch) - 1;
145}
146
156template<>
158{
159 return ch == digout::pwm::none ? -1 : static_cast<int>(ch) - 1;
160}
161
171template<>
173{
174 return ch == digin::pwm::none ? -1 : static_cast<int>(ch) - 1;
175}
176
187
198
209
210// TODO: pwm_in_descriptor - needs to evaluate what pwm input implementation does.
211
222
223class digital_context_interface;
231std::shared_ptr<digital_context_interface> digital_context_instance();
232
233} // namespace vsdk::io
234
235#ifndef DOXYGEN_SKIP_THIS
236
237// Note: these are convenience formatters for our types
238
239#include <utils/fmt_wrapper.h>
240
241template<>
242struct fmt::formatter<vsdk::io::digin::channel> : fmt::formatter<std::string> {
243 auto format(vsdk::io::digin::channel ch, format_context& ctx) const -> format_context::iterator
244 {
245 return formatter<std::string>::format(fmt::format("digin:ch:{:02d}",
247 ctx);
248 }
249};
250
251template<>
252struct fmt::formatter<vsdk::io::digin::pwm> : fmt::formatter<std::string> {
253 auto format(vsdk::io::digin::pwm ch, format_context& ctx) const -> format_context::iterator
254 {
255 return formatter<std::string>::format(fmt::format("digin:pwm:{:02d}",
257 ctx);
258 }
259};
260
261template<>
262struct fmt::formatter<vsdk::io::digout::channel> : fmt::formatter<std::string> {
263 auto format(vsdk::io::digout::channel ch, format_context& ctx) const -> format_context::iterator
264 {
265 return formatter<std::string>::format(fmt::format("digout:ch:{:02d}",
267 ctx);
268 }
269};
270
271template<>
272struct fmt::formatter<vsdk::io::digout::pwm> : fmt::formatter<std::string> {
273 auto format(vsdk::io::digout::pwm ch, format_context& ctx) const -> format_context::iterator
274 {
275 return formatter<std::string>::format(fmt::format("digout:pwm:{:02d}",
277 ctx);
278 }
279};
280
281template<>
282struct fmt::formatter<vsdk::io::digout::mode> : fmt::formatter<std::string> {
283 auto format(vsdk::io::digout::mode mode, format_context& ctx) const -> format_context::iterator
284 {
285 std::string s;
286 switch (mode) {
288 s = "active-high";
289 break;
291 s = "active-low";
292 break;
294 s = "none";
295 break;
296 }
297 return formatter<std::string>::format(fmt::format("digout:mode:{}", s), ctx);
298 }
299};
300
301#endif // DOXYGEN_SKIP_THIS
302
303#endif // DIGITAL_COMMON_H
Include this file to your file so you have access to fmtlib header-only implementation.
channel
Digital input channels.
Definition digital_common.h:63
channel
Digital output channels.
Definition digital_common.h:19
mode
Digital input channel mode.
Definition digital_common.h:90
mode
Digital output channel mode.
Definition digital_common.h:47
@ none
no channel set (default value)
Definition digital_common.h:64
@ ch2
channel 2
Definition digital_common.h:67
@ ch4
channel 4
Definition digital_common.h:69
@ ch0
channel 0
Definition digital_common.h:65
@ ch3
channel 3
Definition digital_common.h:68
@ ch1
channel 1
Definition digital_common.h:66
@ none
no channel set (default value)
Definition digital_common.h:20
@ ch5
channel 5
Definition digital_common.h:26
@ ch2
channel 2
Definition digital_common.h:23
@ ch4
channel 4
Definition digital_common.h:25
@ ch0
channel 0
Definition digital_common.h:21
@ ch3
channel 3
Definition digital_common.h:24
@ ch1
channel 1
Definition digital_common.h:22
@ active_high
active high mode
Definition digital_common.h:92
@ active_low
active low mode
Definition digital_common.h:93
@ none
no digital output channel mode set (default value)
Definition digital_common.h:48
@ active_high
active high mode
Definition digital_common.h:49
@ active_low
active low mode
Definition digital_common.h:50
pwm
PWM output channels.
Definition digital_common.h:35
pwm
PWM input channels.
Definition digital_common.h:78
@ none
no pwm channel set (default value)
Definition digital_common.h:36
@ pwm1
pwm channel 1
Definition digital_common.h:38
@ pwm0
pwm channel 0
Definition digital_common.h:37
@ none
no pwm channel set (default value)
Definition digital_common.h:79
@ pwm1
pwm channel 1
Definition digital_common.h:81
@ pwm0
pwm channel 0
Definition digital_common.h:80
Any types used for digital and PWM input.
Any types used for digital and PWM output.
Any entities that belong to the IO library.
int channel_cast(T)
Channel enumeration cast to integer.
Definition digital_common.h:111
std::shared_ptr< digital_context_interface > digital_context_instance()
Returns a single instance for the digital context object.
Any entities that belong to the Veethree SDK libraries.
Definition can_adapter.h:11
The digital_in_descriptor class.
Definition digital_common.h:194
digin::mode mode
The mode the channel should be configured. See digin::mode.
Definition digital_common.h:196
digin::channel channel
The selected channel. See digin::channel.
Definition digital_common.h:195
The digital_out_descriptor class.
Definition digital_common.h:183
digout::channel channel
The selected channel. See digout::channel.
Definition digital_common.h:184
digout::mode mode
The selected mode for the channel. See digout::mode.
Definition digital_common.h:185
The pwm_in_descriptor class.
Definition digital_common.h:218
uint32_t frequency
The update rate of the PWM signal in ms.
Definition digital_common.h:220
digin::pwm channel
The selected PWM channel. See digin::pwm.
Definition digital_common.h:219
The pwm_out_descriptor classHolds the configuration for a pwm_out_channel.
Definition digital_common.h:204
digout::pwm channel
The selected PWM channel. See digout::pwm.
Definition digital_common.h:205
double frequency
The frequency generated in the selected channel. The period is 1/frequency. The value is in Hertz (Hz...
Definition digital_common.h:206
double duty_cycle
The duty cycle applied to the period. This represents the percentage of the period,...
Definition digital_common.h:207