objc

led.h
Go to the documentation of this file.
1 
11 #pragma once
12 #include "pwm.h"
13 #include <stdbool.h>
14 #include <stdint.h>
15 
17 // TYPES
18 
19 #define HW_LED_CTX_SIZE 64
20 
21 
30 typedef struct {
31  uint8_t gpio;
33  uint8_t ctx[HW_LED_CTX_SIZE];
34 } hw_led_t;
35 
43 typedef enum {
45  HW_LED_CAP_BINARY = (1 << 0),
46  HW_LED_CAP_LINEAR = (1 << 1),
47  HW_LED_CAP_GPIO = (1 << 2),
48 } hw_led_cap_t;
49 
51 // LIFECYCLE
52 
69 hw_led_t hw_led_init(uint8_t gpio, hw_pwm_t *pwm);
70 
78 uint8_t hw_led_status_gpio();
79 
89 void hw_led_finalize(hw_led_t *led);
90 
92 // METHODS
93 
101 bool hw_led_valid(hw_led_t *led);
102 
116 
127 bool hw_led_set_state(hw_led_t *led, bool on);
128 
141 bool hw_led_set_brightness(hw_led_t *led, uint8_t brightness);
142 
157 bool hw_led_blink(hw_led_t *led, uint32_t period_ms, bool repeats);
158 
174 bool hw_led_fade(hw_led_t *led, uint32_t period_ms, bool repeats);
#define HW_LED_CTX_SIZE
Size of the LED context buffer.
Definition: led.h:19
Pulse Width Modulation (PWM) interface.
No capabilities.
Definition: led.h:44
hw_led_cap_t
LED capabilities flags.
Definition: led.h:43
hw_led_t hw_led_init(uint8_t gpio, hw_pwm_t *pwm)
Initialize an LED unit.
void hw_led_finalize(hw_led_t *led)
Finalize and release an LED.
uint8_t hw_led_status_gpio()
Return the GPIO pin number for the on-board status LED.
GPIO pin control.
Definition: led.h:47
Supports linear brightness control via PWM.
Definition: led.h:46
uint8_t gpio
GPIO pin number for the LED.
Definition: led.h:31
PWM structure representing a PWM instance.
Definition: pwm.h:56
hw_pwm_t * pwm
Optional pointer to a PWM structure for linear control.
Definition: led.h:32
bool hw_led_set_brightness(hw_led_t *led, uint8_t brightness)
Set the LED brightness (linear LEDs only).
bool hw_led_blink(hw_led_t *led, uint32_t period_ms, bool repeats)
Blink the LED (toggle full on/off).
hw_led_cap_t hw_led_capabilities(hw_led_t *led)
Return LED capabilities.
bool hw_led_fade(hw_led_t *led, uint32_t period_ms, bool repeats)
Fade (breathe) the LED (PWM LEDs only).
Supports binary on/off control.
Definition: led.h:45
bool hw_led_valid(hw_led_t *led)
Check if an LED handle is valid and initialized.
bool hw_led_set_state(hw_led_t *led, bool on)
Set the LED binary state (full on or off).
LED structure definition for hardware control.
Definition: led.h:30