|
Open Model Railroad Network (OpenMRN)
|
Gpio wrapper for a single bit in memory. More...
#include <MmapGpio.hxx>
Public Member Functions | |
| constexpr | MmapGpioTemplate (STORAGE *const ptr, const unsigned bit_ofs, const bool is_output) |
| Constructor. | |
| void | write (Value new_state) const OVERRIDE |
| Writes a GPIO output pin (set or clear to a specific state). | |
| void | set () const OVERRIDE |
| Sets the GPIO output pin to high. | |
| void | clr () const OVERRIDE |
| Clears the GPIO output pin to low. | |
| Value | read () const OVERRIDE |
| Retrieves the current Value of a GPIO input pin. | |
| void | set_direction (Direction dir) const OVERRIDE |
| Sets the GPIO direction. | |
| Direction | direction () const OVERRIDE |
| Gets the GPIO direction. | |
Public Member Functions inherited from Gpio | |
| constexpr | Gpio () |
| Constructor. | |
| void | write (bool new_state) const |
| Writes a GPIO output pin (set or clear to a specific state). | |
| bool | is_set () const |
| Tests the GPIO input pin to see if it is set. | |
| bool | is_clr () const |
| Tests the GPIO input pin to see if it is clear. | |
Private Attributes | |
| STORAGE *const | ptr_ |
| Pointer to storage. | |
| const unsigned | bit_: 5 |
| Which bit. 0 == LSB, from there it goes up towards MSB. | |
| const unsigned | isOutput_: 1 |
| 1 if this GPIO is an output, 0 if it's an input. | |
Additional Inherited Members | |
Public Types inherited from Gpio | |
| enum | Value : bool { CLR = false , SET = true , VLOW = CLR , VHIGH = SET } |
| Defines the options for GPIO level. More... | |
| enum class | Direction { DINPUT , DOUTPUT } |
| Defines the options for GPIO direction. More... | |
Gpio wrapper for a single bit in memory.
This may be in a peripheral or in SRAM. Access width will be defined by the template parameter. These objects can be allocated in flash, not needing any SRAM or initialization. Use the following syntax:
uint32_t output_register[1] = {0}; // in RAM
constexpr const MmapGpio PORTD_LINE1(output_register, 7, true);
Definition at line 52 of file MmapGpio.hxx.
|
inlineconstexpr |
Constructor.
Constexpr allowing storage in flash for these objects.
| ptr | is a base pointer for a bit array. It must be aligned to word boundary. |
| bit_ofs | is the offset of the interesting bit from the beginning of the array. 0 == LSB of the first byte, 31 == MSB of byte 3. May be 32 or more and ptr will be auto adjusted. |
| is_output | true if we want to simulate an output gpio, false if an input gpio. |
Definition at line 63 of file MmapGpio.hxx.
|
inlinevirtual |
|
inlinevirtual |
Gets the GPIO direction.
Implements Gpio.
Definition at line 101 of file MmapGpio.hxx.
|
inlinevirtual |
Retrieves the current Value of a GPIO input pin.
Implements Gpio.
Definition at line 90 of file MmapGpio.hxx.
|
inlinevirtual |
|
inlinevirtual |
Sets the GPIO direction.
| dir | INPUT or OUTPUT |
Implements Gpio.
Definition at line 95 of file MmapGpio.hxx.
|
inlinevirtual |
Writes a GPIO output pin (set or clear to a specific state).
| new_state | the desired output state. See Value. |
Implements Gpio.
Definition at line 71 of file MmapGpio.hxx.
|
private |
Which bit. 0 == LSB, from there it goes up towards MSB.
Definition at line 110 of file MmapGpio.hxx.
|
private |
1 if this GPIO is an output, 0 if it's an input.
Definition at line 112 of file MmapGpio.hxx.
|
private |
Pointer to storage.
Definition at line 108 of file MmapGpio.hxx.