|
|
ChaosDMX
Open-Source DMX-Interface
|
Implementation of LEDC-driven status LED with dynamic generator. More...
#include "led.h"Go to the source code of this file.
Macros | |
| #define | LOG_TAG "LED" |
| Logging tag for the LED component. | |
| #define | LED_GPIO_PIN 7 |
| GPIO pin number for the status LED. | |
| #define | LED_SPEED_MODE LEDC_LOW_SPEED_MODE |
| LEDC speed mode (Low Speed). | |
| #define | LED_TIMER LEDC_TIMER_0 |
| LEDC timer index. | |
| #define | LED_CHANNEL LEDC_CHANNEL_0 |
| LEDC channel index. | |
| #define | LED_DUTY_RES LEDC_TIMER_8_BIT |
| LEDC duty resolution (8-bit). | |
| #define | LED_FREQUENCY 5000 |
| PWM frequency in Hz. | |
| #define | M_PI 3.14159265358979323846 |
| Mathematical constant PI. | |
Functions | |
| static void | set_pwm_duty (uint8_t duty) |
| Updates the physical LEDC duty cycle. | |
| static void | led_generator_task (void *pvParameters) |
| Generic asynchronous generator for LED effects. | |
| static void | update_led_generator_unsafe (uint32_t period_ms, bool breathing) |
| Configures effect parameters and ensures the generator task is running. | |
| esp_err_t | led_init (void) |
| Initializes the LEDC peripheral for the status LED. | |
| void | led_set_mode (led_mode_t mode) |
| Sets the current operational mode of the LED. | |
| void | led_set_brightness (uint8_t brightness) |
| Dynamically updates the LED maximum brightness. | |
Variables | |
| static uint8_t | s_config_brightness |
| User defined brightness (0-255) in RAM. | |
| static uint8_t | s_active_max_brightness |
| Active peak duty cycle for current mode (0-255). | |
| static led_mode_t | s_current_mode |
| Current operational mode. | |
| static SemaphoreHandle_t | s_led_mutex |
| Guard for thread-safe access to LED state. | |
| static TaskHandle_t | s_generator_task_handle |
| Handle for the effect generator task. | |
| static uint32_t | s_param_period_ms = 1000 |
| Cycle duration for effects. | |
| static bool | s_param_breathing |
| True for sine-fade, False for square-blink. | |
Implementation of LEDC-driven status LED with dynamic generator.
Definition in file led.c.
| #define LED_CHANNEL LEDC_CHANNEL_0 |
LEDC channel index.
Definition at line 13 of file led.c.
Referenced by led_init(), and set_pwm_duty().
| #define LED_DUTY_RES LEDC_TIMER_8_BIT |
| #define LED_FREQUENCY 5000 |
| #define LED_GPIO_PIN 7 |
| #define LED_SPEED_MODE LEDC_LOW_SPEED_MODE |
LEDC speed mode (Low Speed).
Definition at line 11 of file led.c.
Referenced by led_init(), and set_pwm_duty().
| #define LED_TIMER LEDC_TIMER_0 |
| #define M_PI 3.14159265358979323846 |
|
static |
Generic asynchronous generator for LED effects.
Runs in its own task and calculates the duty cycle based on mode parameters. Deletes itself when mode is set to LED_MODE_NORMAL.
| [in] | pvParameters | Unused. |
Definition at line 56 of file led.c.
References LED_MODE_NORMAL, M_PI, s_active_max_brightness, s_current_mode, s_generator_task_handle, s_led_mutex, s_param_breathing, s_param_period_ms, and set_pwm_duty().
Referenced by update_led_generator_unsafe().
| esp_err_t led_init | ( | void | ) |
Initializes the LEDC peripheral for the status LED.
Sets up the timer and channel configuration for the LED GPIO.
Definition at line 117 of file led.c.
References LED_CHANNEL, LED_DUTY_RES, LED_FREQUENCY, LED_GPIO_PIN, LED_SPEED_MODE, LED_TIMER, s_active_max_brightness, s_led_mutex, and set_pwm_duty().
Referenced by app_main().
| void led_set_brightness | ( | uint8_t | brightness | ) |
Dynamically updates the LED maximum brightness.
| [in] | brightness | Value from 0 (off) to 255 (max). |
Definition at line 188 of file led.c.
References LED_MODE_NORMAL, LED_MODE_WARN, s_active_max_brightness, s_config_brightness, s_current_mode, s_led_mutex, and set_pwm_duty().
Referenced by app_main(), and config_set_led_brightness().
| void led_set_mode | ( | led_mode_t | mode | ) |
Sets the current operational mode of the LED.
Modes include static, blinking, and breathing effects.
| [in] | mode | The desired led_mode_t to activate. |
Definition at line 141 of file led.c.
References LED_MODE_BOOT_BREATHING, LED_MODE_ERROR, LED_MODE_NORMAL, LED_MODE_OFF, LED_MODE_RESET, LED_MODE_WARN, s_active_max_brightness, s_config_brightness, s_current_mode, s_led_mutex, set_pwm_duty(), and update_led_generator_unsafe().
Referenced by app_main().
|
static |
Updates the physical LEDC duty cycle.
| [in] | duty | 8-bit duty cycle value (0-255). |
Definition at line 43 of file led.c.
References LED_CHANNEL, and LED_SPEED_MODE.
Referenced by led_generator_task(), led_init(), led_set_brightness(), and led_set_mode().
|
static |
Configures effect parameters and ensures the generator task is running.
| [in] | period_ms | Effect cycle time. |
| [in] | breathing | True for sine-pulse, false for blink. |
Definition at line 101 of file led.c.
References led_generator_task(), LOGE, s_generator_task_handle, s_param_breathing, and s_param_period_ms.
Referenced by led_set_mode().
|
static |
Active peak duty cycle for current mode (0-255).
Definition at line 20 of file led.c.
Referenced by led_generator_task(), led_init(), led_set_brightness(), and led_set_mode().
|
static |
User defined brightness (0-255) in RAM.
Definition at line 18 of file led.c.
Referenced by led_set_brightness(), and led_set_mode().
|
static |
Current operational mode.
Definition at line 22 of file led.c.
Referenced by led_generator_task(), led_set_brightness(), and led_set_mode().
|
static |
Handle for the effect generator task.
Definition at line 26 of file led.c.
Referenced by led_generator_task(), and update_led_generator_unsafe().
|
static |
Guard for thread-safe access to LED state.
Definition at line 24 of file led.c.
Referenced by led_generator_task(), led_init(), led_set_brightness(), and led_set_mode().
|
static |
True for sine-fade, False for square-blink.
Definition at line 31 of file led.c.
Referenced by led_generator_task(), and update_led_generator_unsafe().
|
static |
Cycle duration for effects.
Definition at line 30 of file led.c.
Referenced by led_generator_task(), and update_led_generator_unsafe().