Zephyr C++ Toolkit
Loading...
Searching...
No Matches
zct::GpioReal Class Reference

#include <GpioReal.hpp>

Inheritance diagram for zct::GpioReal:
Collaboration diagram for zct::GpioReal:

Public Member Functions

 GpioReal (const char *name, const struct gpio_dt_spec *spec, Direction direction=Direction::Input, LogicMode logicMode=LogicMode::ActiveHigh)
 Create a new real GPIO pin.
 
 ~GpioReal ()
 Destroy the GPIO. Does nothing.
 
void setPhysical (bool value) override
 
bool getPhysical () const override
 
void configureInterrupt (InterruptMode interruptMode, std::function< void()> callback) override
 
- Public Member Functions inherited from zct::IGpio
 IGpio (const char *name, Direction direction=Direction::Input, LogicMode logicMode=LogicMode::ActiveHigh, PullMode pullMode=PullMode::None)
 Create a new GPIO.
 
virtual ~IGpio ()=default
 Destroy the GPIO.
 
virtual void set (bool value)
 
virtual bool get () const
 
virtual void setDirection (Direction direction)
 
virtual void setLogicMode (LogicMode logicMode)
 
virtual void setPullMode (PullMode pullMode)
 

Protected Member Functions

void configurePinBasedOnSettings () override
 

Static Protected Member Functions

static void interruptCallback (const struct device *dev, struct gpio_callback *cb, gpio_port_pins_t pins)
 

Protected Attributes

const struct gpio_dt_specm_spec
 
GpioCallbackDataAndObject m_gpioCallbackDataAndObject
 
- Protected Attributes inherited from zct::IGpio
const charm_name
 
Direction m_direction
 
LogicMode m_logicMode
 
PullMode m_pullMode
 
InterruptMode m_interruptMode
 
std::function< void()> m_interruptUserCallback
 

Additional Inherited Members

- Public Types inherited from zct::IGpio
enum class  Direction { Input , Output }
 
enum class  LogicMode { ActiveHigh , ActiveLow }
 
enum class  PullMode { None , PullUp , PullDown }
 
enum class  InterruptMode {
  Disable , EdgeRising , EdgeFalling , EdgeBoth ,
  LevelLow , LevelHigh , LevelToInactive , LevelToActive ,
  LevelInactive , LevelActive
}
 

Detailed Description

Implements a real Zephyr GPIO pin. Implements the IGpio interface.

Create these in your real application code.

See also
GpioMock

Constructor & Destructor Documentation

◆ GpioReal()

zct::GpioReal::GpioReal ( const char name,
const struct gpio_dt_spec spec,
Direction  direction = Direction::Input,
LogicMode  logicMode = LogicMode::ActiveHigh 
)

Create a new real GPIO pin.

Parameters
nameThe name of the GPIO. Used for logging purposes.
specThe Zephyr GPIO DT spec struct.
directionThe direction of the GPIO.
logicModeThe logic mode of the GPIO. LogicMode::ActiveHigh is the default (0V is inactive, +VCC is active).

◆ ~GpioReal()

zct::GpioReal::~GpioReal ( )

Destroy the GPIO. Does nothing.

Member Function Documentation

◆ configureInterrupt()

void zct::GpioReal::configureInterrupt ( InterruptMode  interruptMode,
std::function< void()>  callback 
)
overridevirtual

Configure an interrupt on the GPIO.

Parameters
interruptModeThe interrupt mode to set.
callbackThe callback to call when the interrupt occurs. This will be called in a interrupt context.

Implements zct::IGpio.

◆ configurePinBasedOnSettings()

void zct::GpioReal::configurePinBasedOnSettings ( )
overrideprotectedvirtual

Configure the pin based on the current settings. The real GPIO will call the Zephyr gpio_pin_configure_dt() function. The mock GPIO will do nothing.

Implements zct::IGpio.

◆ getPhysical()

bool zct::GpioReal::getPhysical ( ) const
overridevirtual

Get the physical value of the GPIO.

This ignores the logic mode of the GPIO and returns the physical value directly.

Returns
The physical value of the GPIO.

Implements zct::IGpio.

◆ interruptCallback()

void zct::GpioReal::interruptCallback ( const struct device dev,
struct gpio_callback cb,
gpio_port_pins_t  pins 
)
staticprotected

Static callback handler function which has the correct signature so that it can be passed to Zephyr's gpio_init_callback() function.

This in turn calls the user provided callback function in configureInterrupt().

Parameters
devThe device that triggered the interrupt.
cbThe callback structure.
pinsThe pins that triggered the interrupt.

◆ setPhysical()

void zct::GpioReal::setPhysical ( bool  value)
overridevirtual

Set the physical value of the GPIO.

This ignores the logic mode of the GPIO and sets the physical value directly.

Parameters
valueThe physical value to set.

Implements zct::IGpio.

Member Data Documentation

◆ m_gpioCallbackDataAndObject

GpioCallbackDataAndObject zct::GpioReal::m_gpioCallbackDataAndObject
protected

Structure for holding callback info, if used.

Needs to be a pointer to a member of the class.

◆ m_spec

const struct gpio_dt_spec* zct::GpioReal::m_spec
protected

The Zephyr GPIO DT spec struct.


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