From a64ffd0f7362bf31e49ffd539c38df6caa372671 Mon Sep 17 00:00:00 2001 From: Davide Perini Date: Wed, 7 Aug 2024 12:59:06 +0200 Subject: [PATCH 01/18] fix(esp32): Fixed the hint for the builtin neopixleWrite() function --- cores/esp32/esp32-hal-rgb-led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 99c95e1943e..b55aa9f06fb 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -15,7 +15,7 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue return; } - int color[] = {green_val, red_val, blue_val}; // Color coding is in order GREEN, RED, BLUE + int color[] = {red_val, green_val, blue_val}; int i = 0; for (int col = 0; col < 3; col++) { for (int bit = 0; bit < 8; bit++) { From 96180dc3a0b16e37f61c902ac1a51bcf008d4f27 Mon Sep 17 00:00:00 2001 From: Davide Perini Date: Wed, 7 Aug 2024 16:09:38 +0200 Subject: [PATCH 02/18] change(esp32): Added neopixelWriteOrdered() function --- cores/esp32/esp32-hal-rgb-led.c | 40 +++++++++++++++++++++++++++++++-- cores/esp32/esp32-hal-rgb-led.h | 13 ++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index b55aa9f06fb..c05fd680878 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -2,7 +2,11 @@ #include "esp32-hal-rgb-led.h" -void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { +void neopixelWrite(uint8_t pin, uint8_t green_val, uint8_t red_val, uint8_t blue_val) { + neopixelWriteOrdered(pin, GRB, red_val, green_val, blue_val); +} + +void neopixelWriteOrdered(uint8_t pin, color_order_t color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { #if SOC_RMT_SUPPORTED rmt_data_t led_data[24]; @@ -15,7 +19,39 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue return; } - int color[] = {red_val, green_val, blue_val}; + int color[3]; + switch (color_order) { + case RGB: + color[0] = red_val; + color[1] = green_val; + color[2] = blue_val; + break; + case BGR: + color[0] = blue_val; + color[1] = green_val; + color[2] = red_val; + break; + case BRG: + color[0] = blue_val; + color[1] = red_val; + color[2] = green_val; + break; + case RBG: + color[0] = red_val; + color[1] = blue_val; + color[2] = green_val; + break; + case GBR: + color[0] = green_val; + color[1] = blue_val; + color[2] = red_val; + break; + default: + color[0] = green_val; + color[1] = red_val; + color[2] = blue_val; + break; + } int i = 0; for (int col = 0; col < 3; col++) { for (int bit = 0; bit < 8; bit++) { diff --git a/cores/esp32/esp32-hal-rgb-led.h b/cores/esp32/esp32-hal-rgb-led.h index 33f37c849b6..d32b5a691b5 100644 --- a/cores/esp32/esp32-hal-rgb-led.h +++ b/cores/esp32/esp32-hal-rgb-led.h @@ -11,7 +11,18 @@ extern "C" { #define RGB_BRIGHTNESS 64 #endif -void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); +typedef enum { + RGB, + BGR, + BRG, + RBG, + GBR, + GRB +} color_order_t; + +void neopixelWrite(uint8_t pin, uint8_t green_val, uint8_t red_val, uint8_t blue_val); + +void neopixelWriteOrdered(uint8_t pin, color_order_t color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val); #ifdef __cplusplus } From fc43ac4b3e71c5f6eaa516679028b5f4ce63f554 Mon Sep 17 00:00:00 2001 From: Davide Perini Date: Wed, 7 Aug 2024 16:39:46 +0200 Subject: [PATCH 03/18] change(esp32): Added neopixelWriteOrdered() function --- cores/esp32/esp32-hal-rgb-led.c | 2 +- cores/esp32/esp32-hal-rgb-led.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index c05fd680878..08aa5616c13 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -2,7 +2,7 @@ #include "esp32-hal-rgb-led.h" -void neopixelWrite(uint8_t pin, uint8_t green_val, uint8_t red_val, uint8_t blue_val) { +void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { neopixelWriteOrdered(pin, GRB, red_val, green_val, blue_val); } diff --git a/cores/esp32/esp32-hal-rgb-led.h b/cores/esp32/esp32-hal-rgb-led.h index d32b5a691b5..09ac57b10ad 100644 --- a/cores/esp32/esp32-hal-rgb-led.h +++ b/cores/esp32/esp32-hal-rgb-led.h @@ -20,7 +20,7 @@ typedef enum { GRB } color_order_t; -void neopixelWrite(uint8_t pin, uint8_t green_val, uint8_t red_val, uint8_t blue_val); +void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); void neopixelWriteOrdered(uint8_t pin, color_order_t color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val); From ff20b124abad30ac83bb03ad5da6a119159560df Mon Sep 17 00:00:00 2001 From: Davide Perini Date: Wed, 7 Aug 2024 16:56:42 +0200 Subject: [PATCH 04/18] change(esp32): Added neopixelWriteOrdered() function --- cores/esp32/esp32-hal-rgb-led.c | 16 ++++++++-------- cores/esp32/esp32-hal-rgb-led.h | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 08aa5616c13..53a1efab25a 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -3,10 +3,10 @@ #include "esp32-hal-rgb-led.h" void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { - neopixelWriteOrdered(pin, GRB, red_val, green_val, blue_val); + neopixelWriteOrdered(pin, LED_COLOR_ORDER_GRB, red_val, green_val, blue_val); } -void neopixelWriteOrdered(uint8_t pin, color_order_t color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { +void neopixelWriteOrdered(uint8_t pin, rgb_led_color_order_t rgb_led_color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { #if SOC_RMT_SUPPORTED rmt_data_t led_data[24]; @@ -20,28 +20,28 @@ void neopixelWriteOrdered(uint8_t pin, color_order_t color_order, uint8_t red_va } int color[3]; - switch (color_order) { - case RGB: + switch (rgb_led_color_order) { + case LED_COLOR_ORDER_RGB: color[0] = red_val; color[1] = green_val; color[2] = blue_val; break; - case BGR: + case LED_COLOR_ORDER_BGR: color[0] = blue_val; color[1] = green_val; color[2] = red_val; break; - case BRG: + case LED_COLOR_ORDER_BRG: color[0] = blue_val; color[1] = red_val; color[2] = green_val; break; - case RBG: + case LED_COLOR_ORDER_RBG: color[0] = red_val; color[1] = blue_val; color[2] = green_val; break; - case GBR: + case LED_COLOR_ORDER_GBR: color[0] = green_val; color[1] = blue_val; color[2] = red_val; diff --git a/cores/esp32/esp32-hal-rgb-led.h b/cores/esp32/esp32-hal-rgb-led.h index 09ac57b10ad..8f359510e9c 100644 --- a/cores/esp32/esp32-hal-rgb-led.h +++ b/cores/esp32/esp32-hal-rgb-led.h @@ -12,17 +12,17 @@ extern "C" { #endif typedef enum { - RGB, - BGR, - BRG, - RBG, - GBR, - GRB -} color_order_t; + LED_COLOR_ORDER_RGB, + LED_COLOR_ORDER_BGR, + LED_COLOR_ORDER_BRG, + LED_COLOR_ORDER_RBG, + LED_COLOR_ORDER_GBR, + LED_COLOR_ORDER_GRB +} rgb_led_color_order_t; void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); -void neopixelWriteOrdered(uint8_t pin, color_order_t color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val); +void neopixelWriteOrdered(uint8_t pin, rgb_led_color_order_t rgb_led_color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val); #ifdef __cplusplus } From 77f8caec2e90b5911c71ecb86f2de9a434d8ee48 Mon Sep 17 00:00:00 2001 From: Davide Perini Date: Tue, 13 Aug 2024 18:29:49 +0200 Subject: [PATCH 05/18] change(esp32): Added the possibility to specify LED color order --- cores/esp32/esp32-hal-rgb-led.c | 43 ++++----------------------- cores/esp32/esp32-hal-rgb-led.h | 11 ------- variants/lolin_s3_mini/pins_arduino.h | 1 + 3 files changed, 7 insertions(+), 48 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 53a1efab25a..5cc22f5856e 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -3,10 +3,6 @@ #include "esp32-hal-rgb-led.h" void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { - neopixelWriteOrdered(pin, LED_COLOR_ORDER_GRB, red_val, green_val, blue_val); -} - -void neopixelWriteOrdered(uint8_t pin, rgb_led_color_order_t rgb_led_color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { #if SOC_RMT_SUPPORTED rmt_data_t led_data[24]; @@ -19,39 +15,12 @@ void neopixelWriteOrdered(uint8_t pin, rgb_led_color_order_t rgb_led_color_order return; } - int color[3]; - switch (rgb_led_color_order) { - case LED_COLOR_ORDER_RGB: - color[0] = red_val; - color[1] = green_val; - color[2] = blue_val; - break; - case LED_COLOR_ORDER_BGR: - color[0] = blue_val; - color[1] = green_val; - color[2] = red_val; - break; - case LED_COLOR_ORDER_BRG: - color[0] = blue_val; - color[1] = red_val; - color[2] = green_val; - break; - case LED_COLOR_ORDER_RBG: - color[0] = red_val; - color[1] = blue_val; - color[2] = green_val; - break; - case LED_COLOR_ORDER_GBR: - color[0] = green_val; - color[1] = blue_val; - color[2] = red_val; - break; - default: - color[0] = green_val; - color[1] = red_val; - color[2] = blue_val; - break; - } +#ifdef RGB_BUILTIN_COLOR_ORDER_STRUCT + int color[] = RGB_BUILTIN_COLOR_ORDER_STRUCT; +#else + // WS2812B color bit order is G, R, B + int color[] = {green_val, red_val, blue_val}; +#endif int i = 0; for (int col = 0; col < 3; col++) { for (int bit = 0; bit < 8; bit++) { diff --git a/cores/esp32/esp32-hal-rgb-led.h b/cores/esp32/esp32-hal-rgb-led.h index 8f359510e9c..33f37c849b6 100644 --- a/cores/esp32/esp32-hal-rgb-led.h +++ b/cores/esp32/esp32-hal-rgb-led.h @@ -11,19 +11,8 @@ extern "C" { #define RGB_BRIGHTNESS 64 #endif -typedef enum { - LED_COLOR_ORDER_RGB, - LED_COLOR_ORDER_BGR, - LED_COLOR_ORDER_BRG, - LED_COLOR_ORDER_RBG, - LED_COLOR_ORDER_GBR, - LED_COLOR_ORDER_GRB -} rgb_led_color_order_t; - void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); -void neopixelWriteOrdered(uint8_t pin, rgb_led_color_order_t rgb_led_color_order, uint8_t red_val, uint8_t green_val, uint8_t blue_val); - #ifdef __cplusplus } #endif diff --git a/variants/lolin_s3_mini/pins_arduino.h b/variants/lolin_s3_mini/pins_arduino.h index 346c7628b23..a74e99a7e97 100644 --- a/variants/lolin_s3_mini/pins_arduino.h +++ b/variants/lolin_s3_mini/pins_arduino.h @@ -12,6 +12,7 @@ static const uint8_t LED_BUILTIN = 47 + SOC_GPIO_PIN_COUNT; #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 +#define RGB_BUILTIN_COLOR_ORDER_STRUCT {red_val, green_val, blue_val} static const uint8_t TX = 43; static const uint8_t RX = 44; From 35b0bc6eafeb6e385b2f8036d1e3b1d2c55214c9 Mon Sep 17 00:00:00 2001 From: Davide Perini Date: Tue, 13 Aug 2024 19:43:39 +0200 Subject: [PATCH 06/18] change(esp32): Added the possibility to specify LED color order --- cores/esp32/esp32-hal-rgb-led.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 5cc22f5856e..0a34caf278c 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -15,12 +15,10 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue return; } -#ifdef RGB_BUILTIN_COLOR_ORDER_STRUCT - int color[] = RGB_BUILTIN_COLOR_ORDER_STRUCT; -#else - // WS2812B color bit order is G, R, B - int color[] = {green_val, red_val, blue_val}; +#if !defined RGB_BUILTIN_COLOR_ORDER_STRUCT +#define RGB_BUILTIN_COLOR_ORDER_STRUCT {green_val, red_val, blue_val} #endif + int color[] = RGB_BUILTIN_COLOR_ORDER_STRUCT; int i = 0; for (int col = 0; col < 3; col++) { for (int bit = 0; bit < 8; bit++) { From 92f3d3bfdfbc05ab7c9e151686622ec53ea01a30 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 13 Aug 2024 16:20:56 -0300 Subject: [PATCH 07/18] feat(rgbled): add license information --- cores/esp32/esp32-hal-rgb-led.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 0a34caf278c..71a4dd2c6e1 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -1,3 +1,17 @@ +// Copyright 2024 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include "soc/soc_caps.h" #include "esp32-hal-rgb-led.h" From 84b20f0101faa7702511de1755d9cfcecaf9eb7b Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 14 Aug 2024 11:25:43 -0300 Subject: [PATCH 08/18] feat(rgbled): add color order enum --- cores/esp32/esp32-hal-rgb-led.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cores/esp32/esp32-hal-rgb-led.h b/cores/esp32/esp32-hal-rgb-led.h index 33f37c849b6..5951c77b4e0 100644 --- a/cores/esp32/esp32-hal-rgb-led.h +++ b/cores/esp32/esp32-hal-rgb-led.h @@ -11,6 +11,15 @@ extern "C" { #define RGB_BRIGHTNESS 64 #endif +typedef enum { + LED_COLOR_ORDER_RGB, + LED_COLOR_ORDER_BGR, + LED_COLOR_ORDER_BRG, + LED_COLOR_ORDER_RBG, + LED_COLOR_ORDER_GBR, + LED_COLOR_ORDER_GRB +} rgb_led_color_order_t; + void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); #ifdef __cplusplus From 1f0fc693111e16556aee9c9fc80298f2d4efff5d Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 14 Aug 2024 11:32:04 -0300 Subject: [PATCH 09/18] feat(rgbled): add color order feature --- cores/esp32/esp32-hal-rgb-led.c | 36 ++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 71a4dd2c6e1..e879a77074c 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -29,10 +29,40 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue return; } -#if !defined RGB_BUILTIN_COLOR_ORDER_STRUCT -#define RGB_BUILTIN_COLOR_ORDER_STRUCT {green_val, red_val, blue_val} +#if defined RGB_BUILTIN_LED_COLOR_ORDER_CHANGE + // the onboard RGB LED has a different color order + const int color[3]; + switch (RGB_BUILTIN_LED_COLOR_ORDER_CHANGE) { + case LED_COLOR_ORDER_RGB: + color[0] = red_val; + color[1] = green_val; + color[2] = blue_val; + break; + case LED_COLOR_ORDER_BGR: + color[0] = blue_val; + color[1] = green_val; + color[2] = red_val; + break; + case LED_COLOR_ORDER_BRG: + color[0] = blue_val; + color[1] = red_val; + color[2] = green_val; + break; + case LED_COLOR_ORDER_RBG: + color[0] = red_val; + color[1] = blue_val; + color[2] = green_val; + break; + case LED_COLOR_ORDER_GBR: + color[0] = green_val; + color[1] = blue_val; + color[2] = red_val; + } +#else + // default WS2812B color order is G, R, B + const int color[3] = {green_val, red_val, blue_val}; #endif - int color[] = RGB_BUILTIN_COLOR_ORDER_STRUCT; + int i = 0; for (int col = 0; col < 3; col++) { for (int bit = 0; bit < 8; bit++) { From 0ca996a4282c6b7df7544e190a023426054c78bd Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 14 Aug 2024 11:35:04 -0300 Subject: [PATCH 10/18] feat(rgbled): change color order for lolin_s3_mini --- variants/lolin_s3_mini/pins_arduino.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/variants/lolin_s3_mini/pins_arduino.h b/variants/lolin_s3_mini/pins_arduino.h index a74e99a7e97..e89061cd8a0 100644 --- a/variants/lolin_s3_mini/pins_arduino.h +++ b/variants/lolin_s3_mini/pins_arduino.h @@ -12,7 +12,9 @@ static const uint8_t LED_BUILTIN = 47 + SOC_GPIO_PIN_COUNT; #define LED_BUILTIN LED_BUILTIN // allow testing #ifdef LED_BUILTIN #define RGB_BUILTIN LED_BUILTIN #define RGB_BRIGHTNESS 64 -#define RGB_BUILTIN_COLOR_ORDER_STRUCT {red_val, green_val, blue_val} +// This board has a builtin RGB LED that works with a different signal color order +// Other order options can be found in https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-rgb-led.h +#define RGB_BUILTIN_LED_COLOR_ORDER_CHANGE LED_COLOR_ORDER_RGB static const uint8_t TX = 43; static const uint8_t RX = 44; From a0886afc7f5b570b4588b0d4733bab31a7696dda Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 14 Aug 2024 12:09:43 -0300 Subject: [PATCH 11/18] fix(rgbled): suffix --- cores/esp32/esp32-hal-rgb-led.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index e879a77074c..f5dbd5ebf25 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -29,10 +29,10 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue return; } -#if defined RGB_BUILTIN_LED_COLOR_ORDER_CHANGE +#if defined RGB_BUILTIN_LED_COLOR_ORDER // the onboard RGB LED has a different color order const int color[3]; - switch (RGB_BUILTIN_LED_COLOR_ORDER_CHANGE) { + switch (RGB_BUILTIN_LED_COLOR_ORDER) { case LED_COLOR_ORDER_RGB: color[0] = red_val; color[1] = green_val; From 2bf9d99d1267437b567e0c19391cd4acd59fde5a Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 14 Aug 2024 12:10:15 -0300 Subject: [PATCH 12/18] fix(rgbled): suffix --- variants/lolin_s3_mini/pins_arduino.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variants/lolin_s3_mini/pins_arduino.h b/variants/lolin_s3_mini/pins_arduino.h index e89061cd8a0..361d3238960 100644 --- a/variants/lolin_s3_mini/pins_arduino.h +++ b/variants/lolin_s3_mini/pins_arduino.h @@ -14,7 +14,7 @@ static const uint8_t LED_BUILTIN = 47 + SOC_GPIO_PIN_COUNT; #define RGB_BRIGHTNESS 64 // This board has a builtin RGB LED that works with a different signal color order // Other order options can be found in https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/esp32-hal-rgb-led.h -#define RGB_BUILTIN_LED_COLOR_ORDER_CHANGE LED_COLOR_ORDER_RGB +#define RGB_BUILTIN_LED_COLOR_ORDER LED_COLOR_ORDER_RGB static const uint8_t TX = 43; static const uint8_t RX = 44; From 3dd5f70b2d85dca4017816258488a7b73b3d2663 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 14 Aug 2024 15:41:42 +0000 Subject: [PATCH 13/18] ci(pre-commit): Apply automatic fixes --- cores/esp32/esp32-hal-rgb-led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index f5dbd5ebf25..576b6e83736 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -62,7 +62,7 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue // default WS2812B color order is G, R, B const int color[3] = {green_val, red_val, blue_val}; #endif - + int i = 0; for (int col = 0; col < 3; col++) { for (int bit = 0; bit < 8; bit++) { From 2814861fca05e1d277a2ccb2b1c5b91465922b4d Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Fri, 16 Aug 2024 09:31:13 -0300 Subject: [PATCH 14/18] fix(rgbled): it lacks GRB case Made GRB default + switch/case exceptions. --- cores/esp32/esp32-hal-rgb-led.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 576b6e83736..8ae4b06c4d5 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -29,9 +29,11 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue return; } + // default WS2812B color order is G, R, B + const int color[3] = {green_val, red_val, blue_val}; + #if defined RGB_BUILTIN_LED_COLOR_ORDER // the onboard RGB LED has a different color order - const int color[3]; switch (RGB_BUILTIN_LED_COLOR_ORDER) { case LED_COLOR_ORDER_RGB: color[0] = red_val; @@ -58,9 +60,6 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue color[1] = blue_val; color[2] = red_val; } -#else - // default WS2812B color order is G, R, B - const int color[3] = {green_val, red_val, blue_val}; #endif int i = 0; From 347b7c73688304eed688e57e7a4ab5f08327000f Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Fri, 16 Aug 2024 11:00:11 -0300 Subject: [PATCH 15/18] fix(rgbled): add guard for rgb_led_color_order_t If RGB_BUILTIN_LED_COLOR_ORDER is not defined, the type rgb_led_color_order_t won't be declared. --- cores/esp32/esp32-hal-rgb-led.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cores/esp32/esp32-hal-rgb-led.h b/cores/esp32/esp32-hal-rgb-led.h index 5951c77b4e0..114d26d7174 100644 --- a/cores/esp32/esp32-hal-rgb-led.h +++ b/cores/esp32/esp32-hal-rgb-led.h @@ -11,6 +11,7 @@ extern "C" { #define RGB_BRIGHTNESS 64 #endif +#if defined RGB_BUILTIN_LED_COLOR_ORDER typedef enum { LED_COLOR_ORDER_RGB, LED_COLOR_ORDER_BGR, @@ -19,6 +20,7 @@ typedef enum { LED_COLOR_ORDER_GBR, LED_COLOR_ORDER_GRB } rgb_led_color_order_t; +#endif void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); From 1705cafc31deacac01bcd7864a6b356d19510342 Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 19 Aug 2024 12:01:35 +0300 Subject: [PATCH 16/18] fix(rgb-led): Implement rgbLedWriteOrdered() --- cores/esp32/esp32-hal-rgb-led.c | 14 +++++++++----- cores/esp32/esp32-hal-rgb-led.h | 14 +++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 8ae4b06c4d5..754d5bb821f 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -16,7 +16,11 @@ #include "esp32-hal-rgb-led.h" -void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { +void rgbLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { + rgbLedWriteOrdered(pin, RGB_BUILTIN_LED_COLOR_ORDER, red_val, green_val, blue_val); +} + +void rgbLedWriteOrdered(uint8_t pin, rgb_led_color_order_t order, uint8_t red_val, uint8_t green_val, uint8_t blue_val) { #if SOC_RMT_SUPPORTED rmt_data_t led_data[24]; @@ -32,9 +36,7 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue // default WS2812B color order is G, R, B const int color[3] = {green_val, red_val, blue_val}; -#if defined RGB_BUILTIN_LED_COLOR_ORDER - // the onboard RGB LED has a different color order - switch (RGB_BUILTIN_LED_COLOR_ORDER) { + switch (order) { case LED_COLOR_ORDER_RGB: color[0] = red_val; color[1] = green_val; @@ -59,8 +61,10 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue color[0] = green_val; color[1] = blue_val; color[2] = red_val; + break; + default: // GRB + break; } -#endif int i = 0; for (int col = 0; col < 3; col++) { diff --git a/cores/esp32/esp32-hal-rgb-led.h b/cores/esp32/esp32-hal-rgb-led.h index 114d26d7174..bda0eaf51f5 100644 --- a/cores/esp32/esp32-hal-rgb-led.h +++ b/cores/esp32/esp32-hal-rgb-led.h @@ -11,7 +11,10 @@ extern "C" { #define RGB_BRIGHTNESS 64 #endif -#if defined RGB_BUILTIN_LED_COLOR_ORDER +#ifndef RGB_BUILTIN_LED_COLOR_ORDER +#define RGB_BUILTIN_LED_COLOR_ORDER LED_COLOR_ORDER_GRB // default WS2812B color order +#endif + typedef enum { LED_COLOR_ORDER_RGB, LED_COLOR_ORDER_BGR, @@ -20,9 +23,14 @@ typedef enum { LED_COLOR_ORDER_GBR, LED_COLOR_ORDER_GRB } rgb_led_color_order_t; -#endif -void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); +void rgbLedWriteOrdered(uint8_t pin, rgb_led_color_order_t order, uint8_t red_val, uint8_t green_val, uint8_t blue_val); + +// Will use RGB_BUILTIN_LED_COLOR_ORDER +void rgbLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); + +// Backward compatibility +#define neopixelWrite(p,r,g,b) rgbLedWrite(p,r,g,b) #ifdef __cplusplus } From e94fe39aeb2b62fcf220ddf4c66c629103012a45 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 09:02:13 +0000 Subject: [PATCH 17/18] ci(pre-commit): Apply automatic fixes --- cores/esp32/esp32-hal-rgb-led.c | 2 +- cores/esp32/esp32-hal-rgb-led.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 754d5bb821f..e23e2453cdf 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -62,7 +62,7 @@ void rgbLedWriteOrdered(uint8_t pin, rgb_led_color_order_t order, uint8_t red_va color[1] = blue_val; color[2] = red_val; break; - default: // GRB + default: // GRB break; } diff --git a/cores/esp32/esp32-hal-rgb-led.h b/cores/esp32/esp32-hal-rgb-led.h index bda0eaf51f5..84e5498abd7 100644 --- a/cores/esp32/esp32-hal-rgb-led.h +++ b/cores/esp32/esp32-hal-rgb-led.h @@ -12,7 +12,7 @@ extern "C" { #endif #ifndef RGB_BUILTIN_LED_COLOR_ORDER -#define RGB_BUILTIN_LED_COLOR_ORDER LED_COLOR_ORDER_GRB // default WS2812B color order +#define RGB_BUILTIN_LED_COLOR_ORDER LED_COLOR_ORDER_GRB // default WS2812B color order #endif typedef enum { @@ -30,7 +30,7 @@ void rgbLedWriteOrdered(uint8_t pin, rgb_led_color_order_t order, uint8_t red_va void rgbLedWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val); // Backward compatibility -#define neopixelWrite(p,r,g,b) rgbLedWrite(p,r,g,b) +#define neopixelWrite(p, r, g, b) rgbLedWrite(p, r, g, b) #ifdef __cplusplus } From 530b2636a4505fb244e5a385927c6a03079c11ad Mon Sep 17 00:00:00 2001 From: me-no-dev Date: Mon, 19 Aug 2024 12:05:29 +0300 Subject: [PATCH 18/18] Remove const to allow changing the order --- cores/esp32/esp32-hal-rgb-led.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index e23e2453cdf..5afec10f89b 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -34,7 +34,7 @@ void rgbLedWriteOrdered(uint8_t pin, rgb_led_color_order_t order, uint8_t red_va } // default WS2812B color order is G, R, B - const int color[3] = {green_val, red_val, blue_val}; + int color[3] = {green_val, red_val, blue_val}; switch (order) { case LED_COLOR_ORDER_RGB: