Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
14 changes: 9 additions & 5 deletions components/led/led_indicator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
set(srcs "src/led_ledc.c"
set(srcs "src/led_indicator_ledc.c"
"src/led_gamma.c"
"src/led_gpio.c"
"src/led_indicator_gpio.c"
"src/led_indicator.c"
"src/led_indicator_blink_default.c"
"src/led_rgb.c"
"src/led_strips.c"
"src/led_indicator_rgb.c"
"src/led_indicator_strips.c"
"src/led_convert.c"
)
if(CONFIG_USE_MI_BLINK_DEFAULT)
list(APPEND srcs "src/mi_led_indicator_blink_default.c")
else()
list(APPEND srcs "src/led_indicator_blink_default.c")
endif()

idf_component_register( SRCS ${srcs}
INCLUDE_DIRS "include"
Expand Down
4 changes: 4 additions & 0 deletions components/led/led_indicator/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ menu "LED Indicator"
bool "Enable gamma correction"
default "y"

config USE_MI_BLINK_DEFAULT
bool "Use Xiaomi blink default"
default "n"

menu "LEDC Config"

choice LEDC_SPEED_MODE
Expand Down
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.

59 changes: 0 additions & 59 deletions components/led/led_indicator/include/led_gpio.h

This file was deleted.

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
26 changes: 24 additions & 2 deletions components/led/led_indicator/include/led_indicator_blink_default.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* 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 "led_indicator.h"
#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -14,6 +14,27 @@ extern "C" {
* @brief The blink type with smaller index has the higher priority
* eg. BLINK_FACTORY_RESET priority is higher than BLINK_UPDATING
*/
#ifdef CONFIG_USE_MI_BLINK_DEFAULT
enum {
BLINK_MI_WAIT_CONNECT, /*!< Device waiting for connection */
BLINK_MI_CONNECTING, /*!< Connecting to network */
BLINK_MI_ONLINE, /*!< Device online */
BLINK_MI_FAULT, /*!< Device fault (connection failed/network error/disconnected) */
BLINK_MI_RECONNECTING, /*!< Reconnecting to network */
BLINK_MI_OTA_UPDATING, /*!< OTA updating */
BLINK_MI_WIFI_PROVISION_OFF, /*!< Wi-Fi provision function off */
BLINK_MI_WORKING, /*!< Device working normally */
BLINK_MI_WORK_ABNORMAL, /*!< Device abnormal or high-risk alarm */
BLINK_MI_ENV_GOOD, /*!< Environment status good */
BLINK_MI_ENV_MODERATE, /*!< Environment moderate pollution or call action */
BLINK_MI_ENV_SEVERE, /*!< Environment severe pollution or device fault */
BLINK_MI_SETTING, /*!< Device in setting mode */
BLINK_MI_LOW_BATTERY, /*!< Low battery */
BLINK_MI_CHARGING, /*!< Charging */
BLINK_MI_CHARGED, /*!< Fully charged */
BLINK_MAX, /*!< INVALID type */
};
#else
enum {
BLINK_FACTORY_RESET, /*!< restoring factory settings */
BLINK_UPDATING, /*!< updating software */
Expand All @@ -24,6 +45,7 @@ enum {
BLINK_PROVISIONING, /*!< provisioning */
BLINK_MAX, /*!< INVALID type */
};
#endif

extern const int DEFAULT_BLINK_LIST_NUM;
extern blink_step_t const *default_led_indicator_blink_lists[];
Expand Down
40 changes: 40 additions & 0 deletions components/led/led_indicator/include/led_indicator_gpio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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" {
#endif

/**
* @brief LED GPIO configuration
*
*/
typedef struct {
bool is_active_level_high; /*!< Set true if GPIO level is high when light is ON, otherwise false. */
int32_t gpio_num; /*!< num of GPIO */
} led_indicator_gpio_config_t;

/**
* @brief Create a new LED indicator device using a GPIO pin.
*
*
* @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_FAIL Delete fail
*/
esp_err_t led_indicator_new_gpio_device(const led_indicator_config_t *led_config, const led_indicator_gpio_config_t *gpio_cfg, led_indicator_handle_t *handle);
#ifdef __cplusplus
}
#endif
Loading