-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/add_led_for_ot_device' into 'master'
feat(openthread): add different led color for openthread devices Closes TZ-597 See merge request espressif/esp-idf!28779
- Loading branch information
Showing
9 changed files
with
186 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
examples/openthread/ot_common_components/ot_led/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
if(CONFIG_OPENTHREAD_STATE_INDICATOR_ENABLE) | ||
set(srcs "ot_led_strip.c") | ||
endif() | ||
|
||
idf_component_register(SRCS "${srcs}" | ||
INCLUDE_DIRS "include" | ||
PRIV_REQUIRES led_strip openthread) |
24 changes: 24 additions & 0 deletions
24
examples/openthread/ot_common_components/ot_led/Kconfig.projbuild
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
menu "OpenThread Device Role LED" | ||
|
||
orsource "$IDF_PATH/examples/common_components/env_caps/$IDF_TARGET/Kconfig.env_caps" | ||
|
||
config OPENTHREAD_STATE_INDICATOR_ENABLE | ||
depends on SOC_RMT_SUPPORTED | ||
bool 'Enable the LED for openthread deivce' | ||
default False | ||
help | ||
If enabled, the LED of ESP Openthread Device will display different colors based on the current role. | ||
|
||
config OPENTHREAD_STATE_INDICATOR_GPIO | ||
depends on OPENTHREAD_STATE_INDICATOR_ENABLE | ||
int "Blink GPIO number" | ||
range ENV_GPIO_RANGE_MIN ENV_GPIO_OUT_RANGE_MAX | ||
default 5 if IDF_TARGET_ESP32 | ||
default 18 if IDF_TARGET_ESP32S2 | ||
default 48 if IDF_TARGET_ESP32S3 | ||
default 8 | ||
help | ||
GPIO number (IOxx) to blink on and off the LED. | ||
Some GPIOs are used for other purposes (flash connections, etc.) and cannot be used to blink. | ||
|
||
endmenu |
2 changes: 2 additions & 0 deletions
2
examples/openthread/ot_common_components/ot_led/idf_component.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dependencies: | ||
espressif/led_strip: "^2.4.1" |
53 changes: 53 additions & 0 deletions
53
examples/openthread/ot_common_components/ot_led/include/ot_led_strip.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: CC0-1.0 | ||
* | ||
* OpenThread Command Line Example | ||
* | ||
* This example code is in the Public Domain (or CC0 licensed, at your option.) | ||
* | ||
* Unless required by applicable law or agreed to in writing, this | ||
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. | ||
*/ | ||
|
||
#include "esp_err.h" | ||
#include "esp_openthread.h" | ||
|
||
/** | ||
* @brief Initilize the LED of OpenThread device. | ||
* | ||
* @return | ||
* - ESP_OK on success | ||
* - ESP_FAIL on failure | ||
* | ||
*/ | ||
esp_err_t esp_openthread_state_indicator_init(otInstance *instance); | ||
|
||
/** | ||
* @brief Set the LED color of OpenThread device. | ||
* | ||
* @param[in] index index of pixel to set | ||
* @param[in] red red part of color | ||
* @param[in] green green part of color | ||
* @param[in] blue blue part of color | ||
* | ||
* @return | ||
* - ESP_OK on success | ||
* - ESP_ERR_INVALID_ARG: Set LED color failed because of invalid parameters | ||
* - ESP_FAIL on other failure | ||
* | ||
*/ | ||
esp_err_t esp_openthread_state_indicator_set(uint32_t index, uint32_t red, uint32_t green, uint32_t blue); | ||
|
||
/** | ||
* @brief Clear the LED color of OpenThread device. | ||
* | ||
* @return | ||
* - ESP_OK on success | ||
* - ESP_ERR_INVALID_ARG: Clear LED color failed because of invalid parameters | ||
* - ESP_FAIL on other failure | ||
* | ||
*/ | ||
esp_err_t esp_openthread_state_indicator_clear(void); |
77 changes: 77 additions & 0 deletions
77
examples/openthread/ot_common_components/ot_led/ot_led_strip.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: CC0-1.0 | ||
* | ||
* OpenThread Command Line Example | ||
* | ||
* This example code is in the Public Domain (or CC0 licensed, at your option.) | ||
* | ||
* Unless required by applicable law or agreed to in writing, this | ||
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. | ||
*/ | ||
|
||
#include "ot_led_strip.h" | ||
#include "esp_check.h" | ||
#include "led_strip.h" | ||
#include "esp_err.h" | ||
#include "esp_openthread.h" | ||
|
||
static led_strip_handle_t s_led_strip; | ||
|
||
#define TAG "OT_LED" | ||
|
||
static void configure_led(void) | ||
{ | ||
/* LED strip initialization with the GPIO and pixels number*/ | ||
led_strip_config_t strip_config = { | ||
.strip_gpio_num = CONFIG_OPENTHREAD_STATE_INDICATOR_GPIO, | ||
.max_leds = 1, // at least one LED on board | ||
}; | ||
led_strip_rmt_config_t rmt_config = { | ||
.resolution_hz = 10 * 1000 * 1000, // 10MHz | ||
.flags.with_dma = false, | ||
}; | ||
ESP_ERROR_CHECK(led_strip_new_rmt_device(&strip_config, &rmt_config, &s_led_strip)); | ||
/* Set all LED off to clear all pixels */ | ||
ESP_ERROR_CHECK(led_strip_clear(s_led_strip)); | ||
} | ||
|
||
static void ot_indicator_change_callback(otChangedFlags changed_flags, void* ctx) | ||
{ | ||
otInstance *instance = esp_openthread_get_instance(); | ||
otDeviceRole role = otThreadGetDeviceRole(instance); | ||
if (role == OT_DEVICE_ROLE_DISABLED) { | ||
esp_openthread_state_indicator_clear(); | ||
} else if (role == OT_DEVICE_ROLE_DETACHED) { | ||
esp_openthread_state_indicator_set(0, 40, 0, 0); | ||
} else if (role == OT_DEVICE_ROLE_LEADER) { | ||
esp_openthread_state_indicator_set(0, 0, 40, 0); | ||
} else if (role == OT_DEVICE_ROLE_ROUTER) { | ||
esp_openthread_state_indicator_set(0, 0, 0, 40); | ||
} else if (role == OT_DEVICE_ROLE_CHILD) { | ||
esp_openthread_state_indicator_set(0, 40, 8, 60); | ||
} | ||
} | ||
|
||
esp_err_t esp_openthread_state_indicator_init(otInstance *instance) | ||
{ | ||
configure_led(); | ||
ESP_RETURN_ON_FALSE(otSetStateChangedCallback(instance, ot_indicator_change_callback, NULL) == OT_ERROR_NONE, | ||
ESP_FAIL, TAG, "Failed to install state change callback"); | ||
return ESP_OK; | ||
} | ||
|
||
esp_err_t esp_openthread_state_indicator_set(uint32_t index, uint32_t red, uint32_t green, uint32_t blue) | ||
{ | ||
ESP_RETURN_ON_ERROR(led_strip_set_pixel(s_led_strip, index, red, green, blue), TAG, "Failed to set color for openthread state"); | ||
ESP_RETURN_ON_ERROR(led_strip_refresh(s_led_strip), TAG, "Failed to refresh color for openthread state"); | ||
return ESP_OK; | ||
} | ||
|
||
esp_err_t esp_openthread_state_indicator_clear(void) | ||
{ | ||
ESP_RETURN_ON_ERROR(led_strip_clear(s_led_strip), TAG, "Failed to clear color for openthread state"); | ||
return ESP_OK; | ||
} |