Skip to content

Commit

Permalink
bsp: Add classic RGB LED support into generic BSP.
Browse files Browse the repository at this point in the history
  • Loading branch information
espzav committed Dec 8, 2023
1 parent c92774c commit fc933d7
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 50 deletions.
50 changes: 39 additions & 11 deletions bsp/esp_bsp_generic/Kconfig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
menu "Board Support Package"
menu "Board Support Package (generic)"

config BSP_ERROR_CHECK
bool "Enable error check in BSP"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -398,15 +434,13 @@ 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
range -1 ENV_GPIO_OUT_RANGE_MAX
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
Expand All @@ -419,15 +453,13 @@ 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
range -1 ENV_GPIO_OUT_RANGE_MAX
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
Expand All @@ -440,15 +472,13 @@ 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
range -1 ENV_GPIO_OUT_RANGE_MAX
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
Expand All @@ -461,15 +491,13 @@ 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
range -1 ENV_GPIO_OUT_RANGE_MAX
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
Expand Down
3 changes: 2 additions & 1 deletion bsp/esp_bsp_generic/idf_component.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ dependencies:
public: true

led_indicator:
version: ">=0.7,<=0.8"
version: "^0.9"
public: true
public: true

examples:
Expand Down
60 changes: 22 additions & 38 deletions bsp/esp_bsp_generic/src/esp_bsp_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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] = {
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
15 changes: 15 additions & 0 deletions examples/generic_button_led/sdkconfig.esp32_c2_devkitm_1
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fc933d7

Please sign in to comment.