From 172c8f6626e9aba0877f164f2752a9aa6e8a7a37 Mon Sep 17 00:00:00 2001 From: Jared Harrison Date: Fri, 1 Nov 2024 11:35:47 -0400 Subject: [PATCH] LEDs: Add support for the WRGB/RGBW color order (WS2814+ LED chip) Feature: Add new LED Color Order configs > Add LED Color Order options with support for the WRGB/RGBW order (WS2814 LED chip). Allows for simplified bit OR logic. > Also replaces LED_TYPE_RGB and LED_TYPE_RGBW with simplified LED_TYPE_INTERNAL option. Related logic has been updated to follow suit. --- src/conf/datatypes.h | 9 +++++---- src/conf/settings.xml | 5 +++-- src/led_driver.c | 15 +++++++-------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/conf/datatypes.h b/src/conf/datatypes.h index 92a51c8..eb0e1f3 100644 --- a/src/conf/datatypes.h +++ b/src/conf/datatypes.h @@ -35,9 +35,8 @@ typedef enum { typedef enum { LED_TYPE_NONE = 0, - LED_TYPE_RGB, - LED_TYPE_RGBW, - LED_TYPE_EXTERNAL, + LED_TYPE_INTERNAL, + LED_TYPE_EXTERNAL } LedType; typedef enum { @@ -47,7 +46,9 @@ typedef enum { typedef enum { LED_COLOR_GRB = 0, - LED_COLOR_RGB + LED_COLOR_RGB, + LED_COLOR_WRGB, + LED_COLOR_RGBW } LedColorOrder; typedef enum { diff --git a/src/conf/settings.xml b/src/conf/settings.xml index fde5f21..ef2fb4c 100644 --- a/src/conf/settings.xml +++ b/src/conf/settings.xml @@ -3117,8 +3117,7 @@ p, li { white-space: pre-wrap; } CFG_DFLT_HARDWARE_LED_TYPE 0 None - RGB - RGBW + Internal Module External Module @@ -3160,6 +3159,8 @@ p, li { white-space: pre-wrap; } 0 GRB RGB + WRGB + RGBW Status LED Strip Length diff --git a/src/led_driver.c b/src/led_driver.c index 99a4e70..a3bebde 100644 --- a/src/led_driver.c +++ b/src/led_driver.c @@ -130,13 +130,13 @@ static void deinit_dma(LedPin pin) { bool led_driver_init( LedDriver *driver, LedPin pin, LedType type, LedColorOrder color_order, uint8_t led_nr ) { - if (type != LED_TYPE_RGB && type != LED_TYPE_RGBW) { + if (type != LED_TYPE_INTERNAL) { driver->bitbuffer = NULL; driver->bitbuffer_length = 0; return false; } - driver->bit_nr = type == LED_TYPE_RGBW ? 32 : 24; + driver->bit_nr = (color_order == LED_COLOR_WRGB || color_order == LED_COLOR_RGBW) ? 32 : 24; driver->bitbuffer_length = driver->bit_nr * led_nr + BITBUFFER_PAD; driver->bitbuffer = VESC_IF->malloc(sizeof(uint16_t) * driver->bitbuffer_length); driver->pin = pin; @@ -174,13 +174,12 @@ void led_driver_paint(LedDriver *driver, uint32_t *data, uint32_t length) { if (driver->color_order == LED_COLOR_GRB) { color = (g << 16) | (r << 8) | b; - } else { + } else if (driver->color_order == LED_COLOR_RGB) { color = (r << 16) | (g << 8) | b; - } - - if (driver->bit_nr == 32) { - color <<= 8; - color |= w; + } else if (driver->color_order == LED_COLOR_RGBW) { + color = (r << 24) | (g << 16) | (b << 8) | w; + } else if (driver->color_order == LED_COLOR_WRGB) { + color = (w << 24) | (r << 16) | (g << 8) | b; } for (int8_t bit = driver->bit_nr - 1; bit >= 0; --bit) {