diff --git a/drivers/led_strip/Kconfig b/drivers/led_strip/Kconfig index 269657dd0b8a0b7..ef9d2f7ba925383 100644 --- a/drivers/led_strip/Kconfig +++ b/drivers/led_strip/Kconfig @@ -27,6 +27,12 @@ config LED_STRIP_INIT_PRIORITY config LED_STRIP_RGB_SCRATCH bool +config LED_STRIP_WHITE_CHANNEL + bool "LED strip white channel" + depends on !LED_STRIP_RGB_SCRATCH + help + Enables support for a white channel in addition to RGB + source "drivers/led_strip/Kconfig.lpd880x" source "drivers/led_strip/Kconfig.ws2812" diff --git a/drivers/led_strip/Kconfig.ws2812 b/drivers/led_strip/Kconfig.ws2812 index fc91250c2f221de..db75ff1a1b26e66 100644 --- a/drivers/led_strip/Kconfig.ws2812 +++ b/drivers/led_strip/Kconfig.ws2812 @@ -9,7 +9,7 @@ menuconfig WS2812_STRIP bool "WS2812 (and compatible) LED strip driver" - select LED_STRIP_RGB_SCRATCH + select WS2812_STRIP_WHITE_CHANNEL help Enable LED strip driver for daisy chains of WS2812-ish (or WS2812B, WS2813, SK6812, Everlight B1414, or compatible) devices. @@ -47,3 +47,9 @@ config WS2812_STRIP_GPIO controller. endchoice + +config WS2812_STRIP_WHITE_CHANNEL + bool "White channel" + select LED_STRIP_WHITE_CHANNEL + help + Enables support for white channels in the led_strip API. diff --git a/drivers/led_strip/ws2812_gpio.c b/drivers/led_strip/ws2812_gpio.c index 692f25bd0dcac26..a8aabbc513a8180 100644 --- a/drivers/led_strip/ws2812_gpio.c +++ b/drivers/led_strip/ws2812_gpio.c @@ -157,9 +157,12 @@ static int ws2812_gpio_update_rgb(const struct device *dev, for (j = 0; j < config->num_colors; j++) { switch (config->color_mapping[j]) { - /* White channel is not supported by LED strip API. */ case LED_COLOR_ID_WHITE: +#ifdef CONFIG_LED_STRIP_WHITE_CHANNEL + *ptr++ = pixels[i].w; +#else *ptr++ = 0; +#endif break; case LED_COLOR_ID_RED: *ptr++ = pixels[i].r; diff --git a/drivers/led_strip/ws2812_i2s.c b/drivers/led_strip/ws2812_i2s.c index 8890c465046d6e7..cbc65773fbf85ba 100644 --- a/drivers/led_strip/ws2812_i2s.c +++ b/drivers/led_strip/ws2812_i2s.c @@ -110,9 +110,12 @@ static int ws2812_strip_update_rgb(const struct device *dev, struct led_rgb *pix uint8_t pixel; switch (cfg->color_mapping[j]) { - /* White channel is not supported by LED strip API. */ case LED_COLOR_ID_WHITE: +#ifdef CONFIG_LED_STRIP_WHITE_CHANNEL + pixel = pixels[i].w; +#else pixel = 0; +#endif break; case LED_COLOR_ID_RED: pixel = pixels[i].r; diff --git a/drivers/led_strip/ws2812_spi.c b/drivers/led_strip/ws2812_spi.c index c562d5c3dad743a..9c71a013deb458a 100644 --- a/drivers/led_strip/ws2812_spi.c +++ b/drivers/led_strip/ws2812_spi.c @@ -124,9 +124,12 @@ static int ws2812_strip_update_rgb(const struct device *dev, uint8_t pixel; switch (cfg->color_mapping[j]) { - /* White channel is not supported by LED strip API. */ case LED_COLOR_ID_WHITE: +#ifdef CONFIG_LED_STRIP_WHITE_CHANNEL + pixel = pixels[i].w; +#else pixel = 0; +#endif break; case LED_COLOR_ID_RED: pixel = pixels[i].r; diff --git a/include/zephyr/drivers/led_strip.h b/include/zephyr/drivers/led_strip.h index 210af850aed9d58..5446c9055d8556a 100644 --- a/include/zephyr/drivers/led_strip.h +++ b/include/zephyr/drivers/led_strip.h @@ -24,13 +24,14 @@ #include #include +#include #ifdef __cplusplus extern "C" { #endif /** - * @brief Color value for a single RGB LED. + * @brief Color value for a single RGB(W) LED. * * Individual strip drivers may ignore lower-order bits if their * resolution in any channel is less than a full byte. @@ -42,6 +43,9 @@ struct led_rgb { * ignore. */ uint8_t scratch; +#else defined(CONFIG_LED_STRIP_WHITE_CHANNEL) + /** White channel */ + uint8_t w; #endif /** Red channel */ uint8_t r;