Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
MmapGpioTemplate< STORAGE > Class Template Reference

Gpio wrapper for a single bit in memory. More...

#include <MmapGpio.hxx>

Inheritance diagram for MmapGpioTemplate< STORAGE >:
Gpio

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...
 

Detailed Description

template<typename STORAGE>
class MmapGpioTemplate< STORAGE >

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.

Constructor & Destructor Documentation

◆ MmapGpioTemplate()

template<typename STORAGE >
constexpr MmapGpioTemplate< STORAGE >::MmapGpioTemplate ( STORAGE *const  ptr,
const unsigned  bit_ofs,
const bool  is_output 
)
inlineconstexpr

Constructor.

Constexpr allowing storage in flash for these objects.

Parameters
ptris a base pointer for a bit array. It must be aligned to word boundary.
bit_ofsis 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_outputtrue if we want to simulate an output gpio, false if an input gpio.

Definition at line 63 of file MmapGpio.hxx.

Member Function Documentation

◆ clr()

template<typename STORAGE >
void MmapGpioTemplate< STORAGE >::clr ( ) const
inlinevirtual

Clears the GPIO output pin to low.

Implements Gpio.

Definition at line 85 of file MmapGpio.hxx.

◆ direction()

template<typename STORAGE >
Direction MmapGpioTemplate< STORAGE >::direction ( ) const
inlinevirtual

Gets the GPIO direction.

Returns
INPUT or OUTPUT

Implements Gpio.

Definition at line 101 of file MmapGpio.hxx.

◆ read()

template<typename STORAGE >
Value MmapGpioTemplate< STORAGE >::read ( ) const
inlinevirtual

Retrieves the current Value of a GPIO input pin.

Returns
SET if currently high, CLR if currently low.

Implements Gpio.

Definition at line 90 of file MmapGpio.hxx.

◆ set()

template<typename STORAGE >
void MmapGpioTemplate< STORAGE >::set ( ) const
inlinevirtual

Sets the GPIO output pin to high.

Implements Gpio.

Definition at line 80 of file MmapGpio.hxx.

◆ set_direction()

template<typename STORAGE >
void MmapGpioTemplate< STORAGE >::set_direction ( Direction  dir) const
inlinevirtual

Sets the GPIO direction.

Parameters
dirINPUT or OUTPUT

Implements Gpio.

Definition at line 95 of file MmapGpio.hxx.

◆ write()

template<typename STORAGE >
void MmapGpioTemplate< STORAGE >::write ( Value  new_state) const
inlinevirtual

Writes a GPIO output pin (set or clear to a specific state).

Parameters
new_statethe desired output state. See Value.

Implements Gpio.

Definition at line 71 of file MmapGpio.hxx.

Member Data Documentation

◆ bit_

template<typename STORAGE >
const unsigned MmapGpioTemplate< STORAGE >::bit_
private

Which bit. 0 == LSB, from there it goes up towards MSB.

Definition at line 110 of file MmapGpio.hxx.

◆ isOutput_

template<typename STORAGE >
const unsigned MmapGpioTemplate< STORAGE >::isOutput_
private

1 if this GPIO is an output, 0 if it's an input.

Definition at line 112 of file MmapGpio.hxx.

◆ ptr_

template<typename STORAGE >
STORAGE* const MmapGpioTemplate< STORAGE >::ptr_
private

Pointer to storage.

Definition at line 108 of file MmapGpio.hxx.


The documentation for this class was generated from the following file: