LED control interface for hardware platforms. More...
![]() |
Data Structures | |
struct | hw_led_t |
LED structure definition for hardware control. More... | |
Enumerations | |
enum | hw_led_cap_t { HW_LED_CAP_NONE = 0, HW_LED_CAP_BINARY = (1 << 0), HW_LED_CAP_LINEAR = (1 << 1), HW_LED_CAP_GPIO = (1 << 2) } |
LED capabilities flags. More... | |
Functions | |
hw_led_t | hw_led_init (uint8_t gpio, hw_pwm_t *pwm) |
Initialize an LED unit. More... | |
uint8_t | hw_led_status_gpio () |
Return the GPIO pin number for the on-board status LED. More... | |
void | hw_led_finalize (hw_led_t *led) |
Finalize and release an LED. More... | |
bool | hw_led_valid (hw_led_t *led) |
Check if an LED handle is valid and initialized. More... | |
hw_led_cap_t | hw_led_capabilities (hw_led_t *led) |
Return LED capabilities. More... | |
bool | hw_led_set_state (hw_led_t *led, bool on) |
Set the LED binary state (full on or off). More... | |
bool | hw_led_set_brightness (hw_led_t *led, uint8_t brightness) |
Set the LED brightness (linear LEDs only). More... | |
bool | hw_led_blink (hw_led_t *led, uint32_t period_ms, bool repeats) |
Blink the LED (toggle full on/off). More... | |
bool | hw_led_fade (hw_led_t *led, uint32_t period_ms, bool repeats) |
Fade (breathe) the LED (PWM LEDs only). More... | |
LED control interface for hardware platforms.
enum hw_led_cap_t |
LED capabilities flags.
This enum defines the capabilities of an LED unit, such as whether it supports binary on/off control or linear brightness control via PWM.
Enumerator | |
---|---|
HW_LED_CAP_NONE | No capabilities. |
HW_LED_CAP_BINARY | Supports binary on/off control. |
HW_LED_CAP_LINEAR | Supports linear brightness control via PWM. |
HW_LED_CAP_GPIO | GPIO pin control. |
Definition at line 43 of file led.h.
bool hw_led_blink | ( | hw_led_t * | led, |
uint32_t | period_ms, | ||
bool | repeats | ||
) |
Blink the LED (toggle full on/off).
led | Pointer to the LED structure. |
period_ms | Full ON+OFF cycle period in milliseconds. |
repeats | True to continue indefinitely, false to perform a single full cycle (ending in OFF). |
hw_led_cap_t hw_led_capabilities | ( | hw_led_t * | led | ) |
Return LED capabilities.
led | Pointer to the LED structure to check. |
Notes:
bool hw_led_fade | ( | hw_led_t * | led, |
uint32_t | period_ms, | ||
bool | repeats | ||
) |
Fade (breathe) the LED (PWM LEDs only).
led | Pointer to the LED structure. |
period_ms | Full up+down brightness cycle period in milliseconds. |
repeats | True to continue indefinitely, false to perform one full cycle. |
void hw_led_finalize | ( | hw_led_t * | led | ) |
Initialize an LED unit.
gpio | The GPIO pin number for the LED. |
pwm | Optional pointer to a PWM structure for linear control. |
This function initializes an LED unit. If linear control is supported (non-NULL PWM pointer associated with the GPIO pin), it will set up the PWM channel for the LED.
If the pin number is 0xFF then it assumes the platform on-board status LED is being initialized (which may be implemented via a Wi‑Fi / radio module rather than a raw GPIO). If the PWM structure is NULL, the LED will be controlled in a simple on/off manner (binary) without PWM.
bool hw_led_set_brightness | ( | hw_led_t * | led, |
uint8_t | brightness | ||
) |
Set the LED brightness (linear LEDs only).
led | Pointer to the LED structure. |
brightness | Desired brightness (0 = off, 255 = full on). |
Cancels any ongoing blink or fade before applying the new brightness. For non-PWM LEDs this degenerates to binary on/off; intermediate values are coerced to 0 or 255.
bool hw_led_set_state | ( | hw_led_t * | led, |
bool | on | ||
) |
Set the LED binary state (full on or off).
led | Pointer to the LED structure. |
on | True to turn on the LED to full brightness, false to turn it off. |
Cancels any ongoing blink or fade before applying the new state. For a linear (PWM) LED, "on" maps to brightness 255 and "off" maps to 0.
uint8_t hw_led_status_gpio | ( | ) |
bool hw_led_valid | ( | hw_led_t * | led | ) |
Check if an LED handle is valid and initialized.
led | Pointer to the LED structure to check. |