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

Output-only GPIO wrapper intended for LEDs. More...

#include <led.hpp>

Inheritance diagram for c7222::Led:
Inheritance graph
Collaboration diagram for c7222::Led:
Collaboration graph

Public Member Functions

 Led (uint32_t pin, bool initial_on=false, GpioDriveStrength drive=GpioDriveStrength::mA4, bool active_low=false)
 Construct an LED output pin.
 
void Configure (const Config &config)=delete
 Disallow generic reconfiguration.
 
void Reconfigure (bool initial_on=false, GpioDriveStrength drive=GpioDriveStrength::mA4, bool active_low=false)
 Reconfigure LED output settings.
 
void Set (bool on)
 Set the LED state.
 
void On ()
 Turn the LED on.
 
void Off ()
 Turn the LED off.
 
void Toggle ()
 Toggle the LED state.
 
- Public Member Functions inherited from c7222::GpioOut
 GpioOut (uint32_t pin)
 Create a GPIO output with default configuration.
 
virtual ~GpioOut ()
 Destructor.
 
 GpioOut (uint32_t pin, const Config &config)
 Create a GPIO output with the given configuration.
 
void Configure (const Config &config)
 Apply a new configuration.
 
void Write (bool value)
 Write an output value.
 
void Toggle ()
 Toggle the pin output.
 
uint32_t GetPin () const
 Return the GPIO number.
 
Config GetConfig () const
 Return the cached configuration.
 
- 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::GpioOut
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::GpioOut
uint32_t pin_
 GPIO pin number managed by this instance.
 
Config config_
 Cached configuration used to (re)apply platform settings.
 

Detailed Description

Output-only GPIO wrapper intended for LEDs.

Design intent:

  • Output-only: derives from GpioOut and deletes Configure() to prevent accidental reconfiguration into input mode.
  • LED-friendly API: exposes On(), Off(), Set(), and Toggle() instead of raw GPIO writes.

Default configuration:

  • OutputType::PushPull
  • PullMode::None
  • Drive strength configurable (default 4 mA)

Active-low support:

  • Some boards (including the C7222 Pico W board LEDs) are wired active-low so a GPIO low turns the LED on.
  • The active_low flag controls the logical-to-physical mapping so callers can use On()/Off() without worrying about wiring.

Reconfiguration note:

  • If the LED pin was temporarily used for PWM, call Reconfigure() after releasing PWM ownership to restore LED-safe GPIO settings.

Constructor & Destructor Documentation

◆ Led()

c7222::Led::Led ( uint32_t  pin,
bool  initial_on = false,
GpioDriveStrength  drive = GpioDriveStrength::mA4,
bool  active_low = false 
)
explicit

Construct an LED output pin.

Parameters
pinGPIO number.
initial_onInitial LED state (default: false/off).
drivePad drive strength (default: 4 mA).
active_lowIf true, LED is active-low (GPIO low = on).

Member Function Documentation

◆ Configure()

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

Disallow generic reconfiguration.

This prevents accidentally switching the LED pin into input mode.

◆ Off()

void c7222::Led::Off ( )

Turn the LED off.

Here is the caller graph for this function:

◆ On()

void c7222::Led::On ( )

Turn the LED on.

Here is the caller graph for this function:

◆ Reconfigure()

void c7222::Led::Reconfigure ( bool  initial_on = false,
GpioDriveStrength  drive = GpioDriveStrength::mA4,
bool  active_low = false 
)

Reconfigure LED output settings.

This is intended for cases where the pin was temporarily used for PWM and then returned to GPIO control. It only exposes LED-safe settings.

Parameters
initial_onInitial LED state (default: false/off).
drivePad drive strength (default: 4 mA).
active_lowIf true, LED is active-low (GPIO low = on).

◆ Set()

void c7222::Led::Set ( bool  on)

Set the LED state.

Parameters
ontrue = on, false = off.
Here is the caller graph for this function:

◆ Toggle()

void c7222::Led::Toggle ( )

Toggle the LED state.

Note: For active-low LEDs, toggling the GPIO level still toggles the LED.

Here is the caller graph for this function:

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