ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
c7222::GpioIn Class Reference

GPIO input-only wrapper with pull configuration and optional IRQ. More...

#include <gpio.hpp>

Inheritance diagram for c7222::GpioIn:
Inheritance graph
Collaboration diagram for c7222::GpioIn:
Collaboration graph

Classes

struct  Config
 Configuration structure for input GPIO setup. More...
 

Public Member Functions

 GpioIn (uint32_t pin)
 Create a GPIO input with default configuration.
 
 GpioIn (uint32_t pin, const Config &config)
 Create a GPIO input with the given configuration.
 
virtual ~GpioIn ()
 Destructor.
 
void EnableIrq (GpioInputEvent events, std::function< void(uint32_t)> handler)
 Enable GPIO IRQs for the given event set and handler.
 
void DisableIrq ()
 Disable any IRQs configured for this input.
 
void Configure (const Config &config)
 Apply a new configuration.
 
bool Read () const
 Read the current GPIO level.
 
uint32_t GetPin () const
 Return the GPIO number.
 
Config GetConfig () const
 Return the cached configuration.
 
bool HasHandler () const
 Return true if an IRQ handler is currently registered.
 
void CallIrqHandler (uint32_t events) const
 Invoke the registered IRQ handler (if any).
 
- Public Member Functions inherited from c7222::NonCopyable
 NonCopyable (const NonCopyable &)=delete
 
NonCopyableoperator= (const NonCopyable &)=delete
 
 NonCopyable (NonCopyable &&)=default
 
NonCopyableoperator= (NonCopyable &&)=default
 
- Public Member Functions inherited from c7222::NonMovable
 NonMovable (const NonMovable &)=default
 
NonMovableoperator= (const NonMovable &)=default
 
 NonMovable (NonMovable &&)=delete
 
NonMovableoperator= (NonMovable &&)=delete
 

Protected Member Functions

void ApplyConfig ()
 Apply internal configuration to the hardware.
 
- Protected Member Functions inherited from c7222::NonCopyableNonMovable
 NonCopyableNonMovable ()=default
 
 ~NonCopyableNonMovable ()=default
 
- Protected Member Functions inherited from c7222::NonCopyable
 NonCopyable ()=default
 
 ~NonCopyable ()=default
 
- Protected Member Functions inherited from c7222::NonMovable
 NonMovable ()=default
 
 ~NonMovable ()=default
 

Protected Attributes

uint32_t pin_
 GPIO pin number managed by this instance.
 
Config config_
 Cached configuration used to (re)apply platform settings.
 

Detailed Description

GPIO input-only wrapper with pull configuration and optional IRQ.

This class owns an input pin configuration and exposes Read() plus IRQ enable/disable helpers. Only pull mode and input events are configurable.

IRQ behavior:

  • EnableIrq(events, handler) registers a callback and enables GPIO IRQs on the platform backend.
  • The events argument is a bitmask of GpioInputEvent values. Multiple events can be OR-ed together to enable several triggers at once.
  • The backend passes the raw event bitmask to handler whenever an IRQ fires, so the handler can inspect which edge/level caused the interrupt.

Event masking:

  • GpioInputEvent values are bit flags (LevelLow, LevelHigh, FallingEdge, RisingEdge). The platform maps these directly to the underlying Pico SDK IRQ masks.
  • Example: EnableIrq(GpioInputEvent::FallingEdge | GpioInputEvent::RisingEdge, cb) enables both edges on the same pin.

Constructor & Destructor Documentation

◆ GpioIn() [1/2]

c7222::GpioIn::GpioIn ( uint32_t  pin)
inlineexplicit

Create a GPIO input with default configuration.

◆ GpioIn() [2/2]

c7222::GpioIn::GpioIn ( uint32_t  pin,
const Config config 
)
explicit

Create a GPIO input with the given configuration.

Parameters
pinGPIO number.
configInitial configuration.

◆ ~GpioIn()

virtual c7222::GpioIn::~GpioIn ( )
virtual

Destructor.

Platform backends may use this to unregister the pin from internal maps.

Member Function Documentation

◆ ApplyConfig()

void c7222::GpioIn::ApplyConfig ( )
protected

Apply internal configuration to the hardware.

Implemented by the platform backend.

◆ CallIrqHandler()

void c7222::GpioIn::CallIrqHandler ( uint32_t  events) const

Invoke the registered IRQ handler (if any).

Used by platform IRQ dispatchers.

◆ Configure()

void c7222::GpioIn::Configure ( const Config config)

Apply a new configuration.

Parameters
configNew configuration.

◆ DisableIrq()

void c7222::GpioIn::DisableIrq ( )

Disable any IRQs configured for this input.

Here is the caller graph for this function:

◆ EnableIrq()

void c7222::GpioIn::EnableIrq ( GpioInputEvent  events,
std::function< void(uint32_t)>  handler 
)

Enable GPIO IRQs for the given event set and handler.

Parameters
eventsBitmask of input events to enable.
handlerCallback invoked from IRQ context.
Here is the caller graph for this function:

◆ GetConfig()

Config c7222::GpioIn::GetConfig ( ) const
inline

Return the cached configuration.

◆ GetPin()

uint32_t c7222::GpioIn::GetPin ( ) const
inline

Return the GPIO number.

◆ HasHandler()

bool c7222::GpioIn::HasHandler ( ) const
inline

Return true if an IRQ handler is currently registered.

◆ Read()

bool c7222::GpioIn::Read ( ) const

Read the current GPIO level.

Returns
Current logic level.

Member Data Documentation

◆ config_

Config c7222::GpioIn::config_
protected

Cached configuration used to (re)apply platform settings.

◆ pin_

uint32_t c7222::GpioIn::pin_
protected

GPIO pin number managed by this instance.


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