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

Input-only GPIO wrapper intended for push-buttons. More...

#include <button.hpp>

Inheritance diagram for c7222::Button:
Inheritance graph
Collaboration diagram for c7222::Button:
Collaboration graph

Public Member Functions

 Button (uint32_t pin, GpioPullMode pull=GpioPullMode::PullUp)
 Construct a button pin in input mode.
 
virtual ~Button ()=default
 Destructor unregisters the button from the platform map.
 
void Configure (const Config &config)=delete
 Disallow generic reconfiguration.
 
void Reconfigure (GpioPullMode pull=GpioPullMode::PullUp)
 Reconfigure the button pull mode.
 
bool IsPressed () const
 Return true if the button is currently pressed (active-low).
 
- Public Member Functions inherited from c7222::GpioIn
 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
 

Additional Inherited Members

- Protected Member Functions inherited from c7222::GpioIn
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 inherited from c7222::GpioIn
uint32_t pin_
 GPIO pin number managed by this instance.
 
Config config_
 Cached configuration used to (re)apply platform settings.
 

Detailed Description

Input-only GPIO wrapper intended for push-buttons.

Design intent:

  • Input-only: derives from GpioIn and deletes Configure() to prevent reconfiguration into output mode.
  • Simple polling: IsPressed() provides a clear, easy-to-read API for beginners. IRQ support is still available through the inherited GpioIn API when more advanced usage is needed.

Wiring assumption (C7222 Pico W board):

  • Buttons are wired active-low with a pull-up, so a press produces a HIGH->LOW transition.
  • IsPressed() returns true when the logical state indicates a press and abstracts the active-low wiring from callers.

Reconfiguration note:

  • If the button pin was temporarily used for PWM, call Reconfigure() after releasing PWM ownership to restore input configuration.

Constructor & Destructor Documentation

◆ Button()

c7222::Button::Button ( uint32_t  pin,
GpioPullMode  pull = GpioPullMode::PullUp 
)
explicit

Construct a button pin in input mode.

Parameters
pinGPIO number.
pullPull configuration (default: PullUp).

◆ ~Button()

virtual c7222::Button::~Button ( )
virtualdefault

Destructor unregisters the button from the platform map.

Member Function Documentation

◆ Configure()

void c7222::Button::Configure ( const Config config)
delete

Disallow generic reconfiguration.

◆ IsPressed()

bool c7222::Button::IsPressed ( ) const

Return true if the button is currently pressed (active-low).

Here is the caller graph for this function:

◆ Reconfigure()

void c7222::Button::Reconfigure ( GpioPullMode  pull = GpioPullMode::PullUp)

Reconfigure the button pull mode.

This is intended for cases where the pin was temporarily used for PWM and then returned to GPIO input control.

Parameters
pullPull configuration (default: PullUp).

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