Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TivaGpio< GPIO_BASE, GPIO_PIN > Class Template Reference

Generic GPIO class implementation. More...

#include <TivaGPIO.hxx>

Inheritance diagram for TivaGpio< GPIO_BASE, GPIO_PIN >:
Gpio Gpio

Public Member Functions

constexpr TivaGpio ()
 This constructor is constexpr which ensures that the object can be initialized in the data section.
 
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.
 
 TivaGpio (unsigned number, Mode mode, Value safe=CLR)
 Constructor.
 
 ~TivaGpio ()
 Destructor.
 
bool is_set () OVERRIDE
 Test the GPIO pin to see if it is set.
 
bool is_clr () OVERRIDE
 Test the GPIO pin to see if it is clear.
 
void set () OVERRIDE
 Set the GPIO to a '1'.
 
void clr () OVERRIDE
 Clear the GPIO to a '0'.
 
void direction (Mode mode) OVERRIDE
 Set the GPIO direction.
 
Mode direction () OVERRIDE
 Get 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 Member Functions

constexpr volatile uint8_t * pin_address () const
 Computes the memory address where the bit referring to this pin can be accessed.
 
 DISALLOW_COPY_AND_ASSIGN (TivaGpio)
 

Private Attributes

uint32_t base
 BASE address of the GPIO.
 

Static Private Attributes

static const TivaGpio instance_
 Static instance variable that can be used for libraries expectiong a generic Gpio pointer.
 

Friends

template<class Defs >
struct GpioShared
 

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<unsigned GPIO_BASE, unsigned GPIO_PIN>
class TivaGpio< GPIO_BASE, GPIO_PIN >

Generic GPIO class implementation.

Tiva specific implementation of GPIO.

For the Tiva devices, the GPIO number mapping can be found in the GpioMapping enumeration.

Definition at line 72 of file TivaGPIO.hxx.

Constructor & Destructor Documentation

◆ TivaGpio() [1/2]

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
constexpr TivaGpio< GPIO_BASE, GPIO_PIN >::TivaGpio ( )
inlineconstexpr

This constructor is constexpr which ensures that the object can be initialized in the data section.

Definition at line 77 of file TivaGPIO.hxx.

◆ TivaGpio() [2/2]

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
TivaGpio< GPIO_BASE, GPIO_PIN >::TivaGpio ( unsigned  number,
Mode  mode,
Value  safe = CLR 
)

Constructor.

Parameters
numberGPIO number
modeGPIO mode settings
safedefault "safe" value, may go unused for input only pins
GPIOnumber
modeGPIO mode settings
safedefault "safe" value, may go unused for input only pins

Definition at line 46 of file TivaGPIOGeneric.cxx.

◆ ~TivaGpio()

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
TivaGpio< GPIO_BASE, GPIO_PIN >::~TivaGpio ( )
inline

Destructor.

Definition at line 65 of file TivaGPIOGeneric.hxx.

Member Function Documentation

◆ clr() [1/2]

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
void TivaGpio< GPIO_BASE, GPIO_PIN >::clr ( ) const
inlinevirtual

Clears the GPIO output pin to low.

Implements Gpio.

Definition at line 91 of file TivaGPIO.hxx.

◆ clr() [2/2]

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
void TivaGpio< GPIO_BASE, GPIO_PIN >::clr ( )
inline

Clear the GPIO to a '0'.

Note: if the GPIO is inverted, this has have the opposite effect of setting the GPIO to a value of '1'.

Definition at line 102 of file TivaGPIOGeneric.hxx.

◆ direction() [1/3]

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
Direction TivaGpio< GPIO_BASE, GPIO_PIN >::direction ( ) const
inlinevirtual

Gets the GPIO direction.

Returns
INPUT or OUTPUT

Implements Gpio.

Definition at line 113 of file TivaGPIO.hxx.

◆ direction() [2/3]

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
Gpio::Mode TivaGpio< GPIO_BASE, GPIO_PIN >::direction ( )

Get the GPIO direction.

Returns
INPUT or OUTPUT

Definition at line 195 of file TivaGPIOGeneric.cxx.

◆ direction() [3/3]

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
void TivaGpio< GPIO_BASE, GPIO_PIN >::direction ( Mode  mode)

Set the GPIO direction.

Parameters
modeINPUT or OUTPUT

Definition at line 185 of file TivaGPIOGeneric.cxx.

◆ is_clr()

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
bool TivaGpio< GPIO_BASE, GPIO_PIN >::is_clr ( )
inline

Test the GPIO pin to see if it is clear.

Returns
true if currently a '0', false CLR if currently a '1'. Note: if the GPIO is inverted, this has the effect of returning the opposite value

Definition at line 85 of file TivaGPIOGeneric.hxx.

◆ is_set()

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
bool TivaGpio< GPIO_BASE, GPIO_PIN >::is_set ( )
inline

Test the GPIO pin to see if it is set.

Returns
true if currently a '1', false CLR if currently a '0'. Note: if the GPIO is inverted, this has the effect of returning the opposite value

Definition at line 74 of file TivaGPIOGeneric.hxx.

◆ pin_address()

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
constexpr volatile uint8_t * TivaGpio< GPIO_BASE, GPIO_PIN >::pin_address ( ) const
inlineconstexprprivate

Computes the memory address where the bit referring to this pin can be accessed.

This address is bit-masked to the single individual pin, so only ever one bit can be read to be non-zero, and setting any other bit than the desired has no effect. This allows write with 0xff and 0x00 to set/clear and read != 0 to test.

Returns
magic address.

Definition at line 142 of file TivaGPIO.hxx.

◆ read()

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
Value TivaGpio< GPIO_BASE, GPIO_PIN >::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 96 of file TivaGPIO.hxx.

◆ set() [1/2]

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
void TivaGpio< GPIO_BASE, GPIO_PIN >::set ( ) const
inlinevirtual

Sets the GPIO output pin to high.

Implements Gpio.

Definition at line 86 of file TivaGPIO.hxx.

◆ set() [2/2]

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
void TivaGpio< GPIO_BASE, GPIO_PIN >::set ( )
inline

Set the GPIO to a '1'.

Note: if the GPIO is inverted, this could have the opposite effect of clearing the GPIO to a value of '0'.

Definition at line 94 of file TivaGPIOGeneric.hxx.

◆ set_direction()

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
void TivaGpio< GPIO_BASE, GPIO_PIN >::set_direction ( Direction  dir) const
inlinevirtual

Sets the GPIO direction.

Parameters
dirINPUT or OUTPUT

Implements Gpio.

Definition at line 101 of file TivaGPIO.hxx.

◆ write()

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
void TivaGpio< GPIO_BASE, GPIO_PIN >::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 81 of file TivaGPIO.hxx.

Friends And Related Symbol Documentation

◆ GpioShared

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
template<class Defs >
friend struct GpioShared
friend

Definition at line 128 of file TivaGPIO.hxx.

Member Data Documentation

◆ base

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
uint32_t TivaGpio< GPIO_BASE, GPIO_PIN >::base
private

BASE address of the GPIO.

Definition at line 119 of file TivaGPIOGeneric.hxx.

◆ instance_

template<unsigned GPIO_BASE, unsigned GPIO_PIN>
const TivaGpio< GPIO_BASE, GPIO_PIN > TivaGpio< GPIO_BASE, GPIO_PIN >::instance_
staticprivate

Static instance variable that can be used for libraries expectiong a generic Gpio pointer.

Defines the linker symbol for the wrapped Gpio instance.

This instance variable will be initialized by the linker and (assuming the application developer initialized the hardware pins in hw_preinit) is accessible, including virtual methods at static constructor time.

Definition at line 134 of file TivaGPIO.hxx.


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