From fc933d79ab98d21ad8970ca9772f5341d8f7c9ff Mon Sep 17 00:00:00 2001 From: Vilem Zavodny Date: Tue, 28 Nov 2023 13:19:23 +0100 Subject: [PATCH] bsp: Add classic RGB LED support into generic BSP. --- bsp/esp_bsp_generic/Kconfig | 50 ++++++++++++---- bsp/esp_bsp_generic/idf_component.yml | 3 +- bsp/esp_bsp_generic/src/esp_bsp_generic.c | 60 +++++++------------ .../sdkconfig.esp32_c2_devkitm_1 | 15 +++++ 4 files changed, 78 insertions(+), 50 deletions(-) create mode 100644 examples/generic_button_led/sdkconfig.esp32_c2_devkitm_1 diff --git a/bsp/esp_bsp_generic/Kconfig b/bsp/esp_bsp_generic/Kconfig index 37c0b88e..7fdbfee0 100644 --- a/bsp/esp_bsp_generic/Kconfig +++ b/bsp/esp_bsp_generic/Kconfig @@ -1,4 +1,4 @@ -menu "Board Support Package" +menu "Board Support Package (generic)" config BSP_ERROR_CHECK bool "Enable error check in BSP" @@ -339,6 +339,8 @@ menu "Board Support Package" Select a LED type GPIO or Adressable RGB config BSP_LED_TYPE_GPIO bool "GPIO LED" + config BSP_LED_TYPE_RGB_CLASSIC + bool "Classic RGB LED" config BSP_LED_TYPE_RGB bool "Adressable RGB LED" endchoice @@ -351,6 +353,42 @@ menu "Board Support Package" range -1 ENV_GPIO_OUT_RANGE_MAX help The GPIO pin for adressable LEDs. + + config BSP_LED_RGB_CLASSIC_LEVEL + depends on BSP_LED_TYPE_RGB_CLASSIC + int + prompt "Classic RGB LED Active Level" + default 0 + range 0 1 + help + The active level for classic RGB LED. + + config BSP_LED_RGB_RED_GPIO + depends on BSP_LED_TYPE_RGB_CLASSIC + int + prompt "Classic RGB LED red GPIO" + default -1 + range -1 ENV_GPIO_OUT_RANGE_MAX + help + The GPIO pin for red color RGB LED. + + config BSP_LED_RGB_GREEN_GPIO + depends on BSP_LED_TYPE_RGB_CLASSIC + int + prompt "Classic RGB LED green GPIO" + default -1 + range -1 ENV_GPIO_OUT_RANGE_MAX + help + The GPIO pin for green color RGB LED. + + config BSP_LED_RGB_BLUE_GPIO + depends on BSP_LED_TYPE_RGB_CLASSIC + int + prompt "Classic RGB LED blue GPIO" + default -1 + range -1 ENV_GPIO_OUT_RANGE_MAX + help + The GPIO pin for blue color RGB LED. config BSP_ESP_IDF_VERSION string @@ -376,7 +414,6 @@ menu "Board Support Package" depends on BSP_LEDS_NUM > 0 && BSP_LED_TYPE_GPIO config BSP_LED_1_GPIO - depends on BSP_LED_1_TYPE_GPIO int prompt "LED 1 GPIO" default 0 @@ -385,7 +422,6 @@ menu "Board Support Package" The GPIO pin for LED 1. config BSP_LED_1_LEVEL - depends on BSP_LED_1_TYPE_GPIO int prompt "LED 1 Active Level" default 1 @@ -398,7 +434,6 @@ menu "Board Support Package" depends on BSP_LEDS_NUM > 1 && BSP_LED_TYPE_GPIO config BSP_LED_2_GPIO - depends on BSP_LED_2_TYPE_GPIO int prompt "LED 2 GPIO" default 0 @@ -406,7 +441,6 @@ menu "Board Support Package" help The GPIO pin for LED 2. config BSP_LED_2_LEVEL - depends on BSP_LED_2_TYPE_GPIO int prompt "LED 2 Active Level" default 1 @@ -419,7 +453,6 @@ menu "Board Support Package" depends on BSP_LEDS_NUM > 2 && BSP_LED_TYPE_GPIO config BSP_LED_3_GPIO - depends on BSP_LED_3_TYPE_GPIO int prompt "LED 3 GPIO" default 0 @@ -427,7 +460,6 @@ menu "Board Support Package" help The GPIO pin for LED 3. config BSP_LED_3_LEVEL - depends on BSP_LED_3_TYPE_GPIO int prompt "LED 3 Active Level" default 1 @@ -440,7 +472,6 @@ menu "Board Support Package" depends on BSP_LEDS_NUM > 3 && BSP_LED_TYPE_GPIO config BSP_LED_4_GPIO - depends on BSP_LED_4_TYPE_GPIO int prompt "LED 4 GPIO" default 0 @@ -448,7 +479,6 @@ menu "Board Support Package" help The GPIO pin for LED 4. config BSP_LED_4_LEVEL - depends on BSP_LED_4_TYPE_GPIO int prompt "LED 4 Active Level" default 1 @@ -461,7 +491,6 @@ menu "Board Support Package" depends on BSP_LEDS_NUM > 4 && BSP_LED_TYPE_GPIO config BSP_LED_5_GPIO - depends on BSP_LED_5_TYPE_GPIO int prompt "LED 5 GPIO" default 0 @@ -469,7 +498,6 @@ menu "Board Support Package" help The GPIO pin for LED 5. config BSP_LED_5_LEVEL - depends on BSP_LED_5_TYPE_GPIO int prompt "LED 5 Active Level" default 1 diff --git a/bsp/esp_bsp_generic/idf_component.yml b/bsp/esp_bsp_generic/idf_component.yml index 247e67da..a84a9d73 100644 --- a/bsp/esp_bsp_generic/idf_component.yml +++ b/bsp/esp_bsp_generic/idf_component.yml @@ -11,7 +11,8 @@ dependencies: public: true led_indicator: - version: ">=0.7,<=0.8" + version: "^0.9" + public: true public: true examples: diff --git a/bsp/esp_bsp_generic/src/esp_bsp_generic.c b/bsp/esp_bsp_generic/src/esp_bsp_generic.c index 8bbb11f6..b1eb7d1e 100644 --- a/bsp/esp_bsp_generic/src/esp_bsp_generic.c +++ b/bsp/esp_bsp_generic/src/esp_bsp_generic.c @@ -20,24 +20,6 @@ sdmmc_card_t *bsp_sdcard = NULL; // Global uSD card handler static bool i2c_initialized = false; extern blink_step_t const *bsp_led_blink_defaults_lists[]; -typedef struct { - uint16_t hue; - uint8_t saturation; -} HS_color_t; - -static const HS_color_t temp_table[] = { - {4, 100}, {8, 100}, {11, 100}, {14, 100}, {16, 100}, {18, 100}, {20, 100}, {22, 100}, {24, 100}, {25, 100}, - {27, 100}, {28, 100}, {30, 100}, {31, 100}, {31, 95}, {30, 89}, {30, 85}, {29, 80}, {29, 76}, {29, 73}, - {29, 69}, {28, 66}, {28, 63}, {28, 60}, {28, 57}, {28, 54}, {28, 52}, {27, 49}, {27, 47}, {27, 45}, - {27, 43}, {27, 41}, {27, 39}, {27, 37}, {27, 35}, {27, 33}, {27, 31}, {27, 30}, {27, 28}, {27, 26}, - {27, 25}, {27, 23}, {27, 22}, {27, 21}, {27, 19}, {27, 18}, {27, 17}, {27, 15}, {28, 14}, {28, 13}, - {28, 12}, {29, 10}, {29, 9}, {30, 8}, {31, 7}, {32, 6}, {34, 5}, {36, 4}, {41, 3}, {49, 2}, - {0, 0}, {294, 2}, {265, 3}, {251, 4}, {242, 5}, {237, 6}, {233, 7}, {231, 8}, {229, 9}, {228, 10}, - {227, 11}, {226, 11}, {226, 12}, {225, 13}, {225, 13}, {224, 14}, {224, 14}, {224, 15}, {224, 15}, {223, 16}, - {223, 16}, {223, 17}, {223, 17}, {223, 17}, {222, 18}, {222, 18}, {222, 19}, {222, 19}, {222, 19}, {222, 19}, - {222, 20}, {222, 20}, {222, 20}, {222, 21}, {222, 21} -}; - static const button_config_t bsp_button_config[] = { #if CONFIG_BSP_BUTTONS_NUM > 0 #if CONFIG_BSP_BUTTON_1_TYPE_GPIO @@ -208,6 +190,20 @@ static led_indicator_strips_config_t bsp_leds_rgb_config = { .led_strip_spi_cfg = bsp_leds_rgb_spi_config, #endif }; + +#elif CONFIG_BSP_LED_TYPE_RGB_CLASSIC && CONFIG_BSP_LEDS_NUM > 0 // CONFIG_BSP_LED_TYPE_RGB_CLASSIC + +static led_indicator_rgb_config_t bsp_leds_rgb_config = { + .is_active_level_high = CONFIG_BSP_LED_RGB_CLASSIC_LEVEL, + .timer_num = LEDC_TIMER_0, + .red_gpio_num = CONFIG_BSP_LED_RGB_RED_GPIO, + .green_gpio_num = CONFIG_BSP_LED_RGB_GREEN_GPIO, + .blue_gpio_num = CONFIG_BSP_LED_RGB_BLUE_GPIO, + .red_channel = LEDC_CHANNEL_0, + .green_channel = LEDC_CHANNEL_1, + .blue_channel = LEDC_CHANNEL_2, +}; + #endif // CONFIG_BSP_LED_TYPE_RGB static const led_indicator_config_t bsp_leds_config[BSP_LED_NUM] = { @@ -218,6 +214,13 @@ static const led_indicator_config_t bsp_leds_config[BSP_LED_NUM] = { .blink_lists = bsp_led_blink_defaults_lists, .blink_list_num = BSP_LED_MAX, }, +#elif CONFIG_BSP_LED_TYPE_RGB_CLASSIC + { + .mode = LED_RGB_MODE, + .led_indicator_rgb_config = &bsp_leds_rgb_config, + .blink_lists = bsp_led_blink_defaults_lists, + .blink_list_num = BSP_LED_MAX, + }, #elif CONFIG_BSP_LED_TYPE_GPIO #if CONFIG_BSP_LEDS_NUM > 0 @@ -435,24 +438,5 @@ esp_err_t bsp_led_set(led_indicator_handle_t handle, const bool on) esp_err_t bsp_led_set_temperature(led_indicator_handle_t handle, const uint16_t temperature) { - uint32_t hsv = led_indicator_get_hsv(handle); - uint16_t hue; - uint8_t saturation; - - if (temperature < 600) { - hue = 0; - saturation = 100; - } else if (temperature > 10000) { - hue = 222; - saturation = 21 + (temperature - 10000) * 41 / 990000; - } else { - hue = temp_table[(temperature - 600) / 100].hue; - saturation = temp_table[(temperature - 600) / 100].saturation; - } - saturation = (saturation * 255) / 100; - - SET_SATURATION(hsv, saturation); - SET_HUE(hsv, hue); - - return led_indicator_set_hsv(handle, hsv); + return led_indicator_set_color_temperature(handle, temperature); } diff --git a/examples/generic_button_led/sdkconfig.esp32_c2_devkitm_1 b/examples/generic_button_led/sdkconfig.esp32_c2_devkitm_1 new file mode 100644 index 00000000..dbba8cba --- /dev/null +++ b/examples/generic_button_led/sdkconfig.esp32_c2_devkitm_1 @@ -0,0 +1,15 @@ +# This file was generated using idf.py save-defconfig. It can be edited manually. +# Espressif IoT Development Framework (ESP-IDF) Project Minimal Configuration +# +CONFIG_IDF_TARGET="esp32c2" + +# ESP8684-DevKitM-1 v1.1 Settings +# Buttons +CONFIG_BSP_BUTTONS_NUM=0 +# LEDs +CONFIG_BSP_LEDS_NUM=1 +CONFIG_BSP_LED_TYPE_RGB_CLASSIC=y +CONFIG_BSP_LED_RGB_CLASSIC_LEVEL=0 +CONFIG_BSP_LED_RGB_RED_GPIO=0 +CONFIG_BSP_LED_RGB_GREEN_GPIO=1 +CONFIG_BSP_LED_RGB_BLUE_GPIO=8