11#define LED_SPEED_MODE LEDC_LOW_SPEED_MODE
12#define LED_TIMER LEDC_TIMER_0
13#define LED_CHANNEL LEDC_CHANNEL_0
14#define LED_DUTY_RES LEDC_TIMER_8_BIT
15#define LED_FREQUENCY 5000
35#define M_PI 3.14159265358979323846
57 const uint32_t step_interval_ms = 20;
58 uint32_t elapsed_time_ms = 0;
77 (sinf(((
float)elapsed_time_ms / period) * 2.0f * (
float)
M_PI -
78 ((
float)
M_PI / 2.0f)) +
83 bool upper_half = elapsed_time_ms < (period / 2);
87 vTaskDelay(pdMS_TO_TICKS(step_interval_ms));
88 elapsed_time_ms = (elapsed_time_ms + step_interval_ms) % period;
109 LOGE(
"Failed to create LED generator task");
120 return ESP_ERR_NO_MEM;
126 .clk_cfg = LEDC_AUTO_CLK};
127 ESP_ERROR_CHECK(ledc_timer_config(&ledc_timer));
129 ledc_channel_config_t ledc_channel = {.speed_mode =
LED_SPEED_MODE,
135 ESP_ERROR_CHECK(ledc_channel_config(&ledc_channel));
void led_set_brightness(uint8_t brightness)
Dynamically updates the LED maximum brightness.
static void update_led_generator_unsafe(uint32_t period_ms, bool breathing)
Configures effect parameters and ensures the generator task is running.
static uint8_t s_config_brightness
User defined brightness (0-255) in RAM.
#define LED_DUTY_RES
LEDC duty resolution (8-bit).
#define LED_FREQUENCY
PWM frequency in Hz.
static bool s_param_breathing
True for sine-fade, False for square-blink.
#define LED_SPEED_MODE
LEDC speed mode (Low Speed).
static void led_generator_task(void *pvParameters)
Generic asynchronous generator for LED effects.
static uint32_t s_param_period_ms
Cycle duration for effects.
void led_set_mode(led_mode_t mode)
Sets the current operational mode of the LED.
#define LED_CHANNEL
LEDC channel index.
esp_err_t led_init(void)
Initializes the LEDC peripheral for the status LED.
static TaskHandle_t s_generator_task_handle
Handle for the effect generator task.
static SemaphoreHandle_t s_led_mutex
Guard for thread-safe access to LED state.
static uint8_t s_active_max_brightness
Active peak duty cycle for current mode (0-255).
#define LED_TIMER
LEDC timer index.
static led_mode_t s_current_mode
Current operational mode.
#define M_PI
Mathematical constant PI.
#define LED_GPIO_PIN
GPIO pin number for the status LED.
static void set_pwm_duty(uint8_t duty)
Updates the physical LEDC duty cycle.
LED control component with flexible blinking and breathing modes.
led_mode_t
Available operational modes for the status LED.
@ LED_MODE_BOOT_BREATHING
#define LOGE(...)
Log a message at Error level.