Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/led/led_indicator/include/led_convert.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down
58 changes: 0 additions & 58 deletions components/led/led_indicator/include/led_custom.h

This file was deleted.

37 changes: 9 additions & 28 deletions components/led/led_indicator/include/led_gpio.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "driver/gpio.h"
#include "led_indicator.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -22,38 +23,18 @@ typedef struct {
} led_indicator_gpio_config_t;

/**
* @brief Initialize the specific GPIO to work as a LED indicator
* @brief Create a new LED indicator device using a GPIO pin.
*
* @param param led_indicator_gpio_config_t
* @param ret_handle gpio_handle
* @return esp_err_t
* - ESP_OK success
* - ESP_ERR_INVALID_ARG Parameter error
*/
esp_err_t led_indicator_gpio_init(void *param, void **ret_handle);

/**
* @brief Deinitialize the specific GPIO that works as a LED indicator
*
* @param handle GPIO handle
* @return esp_err_t
* - ESP_OK success
*/
esp_err_t led_indicator_gpio_deinit(void *handle);

/**
* @brief Set the specific GPIO's level to make the LED indicator ON or OFF
*
* @param handle GPIO handle
* @param on_off Set number to control the GPIO's level. If the LED's positive side is connected to this GPIO, then setting number greater than 0 will make the LED OFF,
* and setting 0 will make the LED ON. If the LED's negative side is connected to this GPIO, then setting 0 will make the LED OFF, and
* setting number greater than 0 will make the LED ON.
* @param led_config Pointer to the LED configuration structure.
* @param gpio_cfg Pointer to the GPIO configuration structure for the LED.
* @param handle pointer to LED indicator handle
* @return esp_err_t
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG GPIO number error
* - ESP_FAIL Delete fail
*/
esp_err_t led_indicator_gpio_set_on_off(void *handle, bool on_off);

led_indicator_handle_t iot_led_new_gpio_device(const led_config_t *led_config, const led_indicator_gpio_config_t *gpio_cfg);
#ifdef __cplusplus
}
#endif
96 changes: 25 additions & 71 deletions components/led/led_indicator/include/led_indicator.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -12,90 +12,44 @@ extern "C" {

#include <stdint.h>
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "freertos/timers.h"
#include "freertos/semphr.h"
#include "esp_err.h"
#include "led_gpio.h"
#include "led_ledc.h"
#include "led_rgb.h"
#include "led_strips.h"
#include "led_convert.h"
#include "led_custom.h"
#include "led_types.h"

/**
* @brief LED state: 0-100, only hardware that supports to set brightness can adjust brightness.
*
*/
enum {
LED_STATE_OFF = 0, /*!< turn off the LED */
LED_STATE_25_PERCENT = 64, /*!< 25% brightness, must support to set brightness */
LED_STATE_50_PERCENT = 128, /*!< 50% brightness, must support to set brightness */
LED_STATE_75_PERCENT = 191, /*!< 75% brightness, must support to set brightness */
LED_STATE_ON = UINT8_MAX, /*!< turn on the LED */
};
#define LED_INDICATOR_CHECK(a, str, action) if(!(a)) { \
ESP_LOGE(TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \
action; \
}

/**
* @brief actions in this type
*
*/
typedef enum {
LED_BLINK_STOP = -1, /*!< stop the blink */
LED_BLINK_HOLD, /*!< hold the on-off state */
LED_BLINK_BREATHE, /*!< breathe state */
LED_BLINK_BRIGHTNESS, /*!< set the brightness, it will transition from the old brightness to the new brightness */
LED_BLINK_RGB, /*!< color change with R(0-255) G(0-255) B(0-255) */
LED_BLINK_RGB_RING, /*!< Gradual color transition from old color to new color in a color ring */
LED_BLINK_HSV, /*!< color change with H(0-360) S(0-255) V(0-255) */
LED_BLINK_HSV_RING, /*!< Gradual color transition from old color to new color in a color ring */
LED_BLINK_LOOP, /*!< loop from first step */
} blink_step_type_t;
#define LED_INDICATOR_CHECK_WARNING(a, str, action) if(!(a)) { \
ESP_LOGW(TAG,"%s:%d (%s):%s", __FILE__, __LINE__, __FUNCTION__, str); \
action; \
}

/**
* @brief one blink step, a meaningful signal consists of a group of steps
* @brief Creates a new LED indicator instance with the specified configuration.
*
*/
typedef struct {
blink_step_type_t type; /*!< action type in this step */
uint32_t value; /*!< hold on or off, set 0 if LED_BLINK_STOP() or LED_BLINK_LOOP */
uint32_t hold_time_ms; /*!< hold time(ms), set 0 if not LED_BLINK_HOLD */
} blink_step_t;

/**
* @brief LED indicator blink mode, as a member of led_indicator_config_t
* @param cfg Pointer to a configuration structure of type _led_indicator_com_config_t
* containing initialization parameters for the LED indicator.
*
* @return Pointer to the created _led_indicator_t instance on success, or NULL on failure.
*/
typedef enum {
LED_GPIO_MODE, /*!< blink with max brightness */
LED_LEDC_MODE, /*!< blink with LEDC driver */
LED_RGB_MODE, /*!< blink with RGB driver */
LED_STRIPS_MODE, /*!< blink with LEDC strips driver */
LED_CUSTOM_MODE, /*!< blink with custom driver */
} led_indicator_mode_t;
_led_indicator_t *_led_indicator_create_com(_led_indicator_com_config_t *cfg);

/**
* @brief LED indicator specified configurations, as a arg when create a new indicator
* @brief Add a new node to the LED indicator instance.
*
*/
typedef struct {
led_indicator_mode_t mode; /*!< LED work mode, eg. GPIO or pwm mode */
union {
led_indicator_gpio_config_t *led_indicator_gpio_config; /*!< LED GPIO configuration */
led_indicator_ledc_config_t *led_indicator_ledc_config; /*!< LED LEDC configuration */
led_indicator_rgb_config_t *led_indicator_rgb_config; /*!< LED RGB configuration */
led_indicator_strips_config_t *led_indicator_strips_config; /*!< LED LEDC rgb configuration */
led_indicator_custom_config_t *led_indicator_custom_config; /*!< LED custom configuration */
}; /**< LED configuration */
blink_step_t const **blink_lists; /*!< user defined LED blink lists */
uint16_t blink_list_num; /*!< number of blink lists */
} led_indicator_config_t;

typedef void *led_indicator_handle_t; /*!< LED indicator operation handle */

/**
* @brief create a LED indicator instance with GPIO number and configuration
* @param[in,out] p_led_indicator Pointer to the LED indicator instance to which the node will be added.
*
* @param config configuration of the LED, eg. GPIO level when LED off
* @return led_indicator_handle_t handle of the LED indicator, NULL if create failed.
* @return esp_err_t
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_ERR_NOT_FOUND no predefined blink_type found
* - ESP_OK Success
*/
led_indicator_handle_t led_indicator_create(const led_indicator_config_t *config);
esp_err_t _led_indicator_add_node(_led_indicator_t *p_led_indicator);

/**
* @brief delete the LED indicator and release resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

#pragma once

#include "led_indicator.h"
#ifdef __cplusplus
extern "C" {
#endif
Expand Down
48 changes: 9 additions & 39 deletions components/led/led_indicator/include/led_ledc.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include "driver/ledc.h"
#include "led_indicator.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -21,49 +22,18 @@ typedef struct {
} led_indicator_ledc_config_t;

/**
* @brief Initialize LEDC-related configurations for this LED indicator.
* @brief Create a new LED indicator device using the LEDC (LED Controller) peripheral.
*
* @param param LEDC config: ledc_timer_config & ledc_channel_config
* @return esp_err_t
* - ESP_OK Success
* - ESP_FAIL Deinit fail
* - ESP_ERR_NO_MEM failed to request memory
*/
esp_err_t led_indicator_ledc_init(void *param);

/**
* @brief Deinitialize LEDC which is used by the LED indicator.
*
* @param ledc_handle LED indicator LEDC operation handle
* @return esp_err_t
* - ESP_OK Success
* - ESP_FAIL Deinit fail
*/
esp_err_t led_indicator_ledc_deinit(void *ledc_handle);

/**
* @brief Set the specific LEDC's level to make the LED indicator ON or OFF
*
* @param ledc_handle LED indicator LEDC operation handle
* @param on_off Set 0 to control the LEDC's output level low, while values greater than 0 set the LEDC's output level high..
* @return esp_err_t
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_FAIL LEDC channel doesn't init
*/
esp_err_t led_indicator_ledc_set_on_off(void *ledc_handle, bool on_off);

/**
* @brief Set LEDC duty cycle
*
* @param ledc_handle LED indicator LEDC operation handle
* @param brightness duty cycle of LEDC [0-255]
* @param led_config Pointer to the general LED configuration structure.
* @param ledc_cfg Pointer to the LEDC-specific configuration structure.
* @param handle pointer to LED indicator handle
* @return esp_err_t
* - ESP_ERR_INVALID_ARG if parameter is invalid
* - ESP_OK Success
* - ESP_ERR_INVALID_ARG Parameter error
* - ESP_FAIL Set brightness fail
* - ESP_FAIL Delete fail
*/
esp_err_t led_indicator_ledc_set_brightness(void *ledc_handle, uint32_t brightness);
led_indicator_handle_t iot_led_new_ledc_device(const led_config_t *led_config, const led_indicator_ledc_config_t *ledc_cfg);

#ifdef __cplusplus
}
Expand Down
Loading