Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Gpio.hxx
Go to the documentation of this file.
1
35#ifndef _OS_GPIO_HXX_
36#define _OS_GPIO_HXX_
37
38#include "utils/macros.h"
39
42class Gpio
43{
44public:
48 constexpr Gpio()
49 {
50 }
51
52 /* It is important that there be no destructor declared here, not even with
53 * empty and inlined and non-virtual body. The Gpio objects are never
54 * deleted through their base class; the specific implementations must live
55 * in HwInit.cxx with global scope. If there is a destructor here, that
56 * will prevent the compiler from creating the Gpio instance variables in
57 * the flash, and they will all start using RAM instead. That's a big
58 * difference. */
59
61 enum Value : bool
62 {
63 CLR = false,
64 SET = true,
65 VLOW = CLR,
66 VHIGH = SET
67 };
68
72 enum class Direction
73 {
74 DINPUT,
75 DOUTPUT,
76 };
77
81 virtual void write(Value new_state) const = 0;
82
92 void write(bool new_state) const
93 {
94 write((Value)new_state);
95 }
96
100 virtual Value read() const = 0;
101
105 bool is_set() const
106 {
107 return read() == SET;
108 }
109
113 bool is_clr()const
114 {
115 return read() == CLR;
116 }
117
120 virtual void set() const = 0;
121
124 virtual void clr() const = 0;
125
129 virtual void set_direction(Direction dir) const = 0;
130
134 virtual Direction direction() const = 0;
135};
136
137#endif /* _FREERTOS_DRIVERS_COMMON_GPIOGENERIC_HXX_ */
OS-independent abstraction for GPIO.
Definition Gpio.hxx:43
virtual void write(Value new_state) const =0
Writes a GPIO output pin (set or clear to a specific state).
virtual Direction direction() const =0
Gets the GPIO direction.
bool is_set() const
Tests the GPIO input pin to see if it is set.
Definition Gpio.hxx:105
virtual void clr() const =0
Clears the GPIO output pin to low.
Value
Defines the options for GPIO level.
Definition Gpio.hxx:62
virtual void set_direction(Direction dir) const =0
Sets the GPIO direction.
void write(bool new_state) const
Writes a GPIO output pin (set or clear to a specific state).
Definition Gpio.hxx:92
bool is_clr() const
Tests the GPIO input pin to see if it is clear.
Definition Gpio.hxx:113
constexpr Gpio()
Constructor.
Definition Gpio.hxx:48
virtual void set() const =0
Sets the GPIO output pin to high.
Direction
Defines the options for GPIO direction.
Definition Gpio.hxx:73
virtual Value read() const =0
Retrieves the current Value of a GPIO input pin.