From 993b43ec06ec2018ec50ab287a627ce32b73b891 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 7 Nov 2023 09:48:33 -0300 Subject: [PATCH 1/6] improve neopixel definition for all boards --- .../RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino b/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino index 9a381def79b..d8e9e662085 100644 --- a/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino +++ b/libraries/ESP32/examples/RMT/RMTWriteNeoPixel/RMTWriteNeoPixel.ino @@ -19,15 +19,11 @@ * Parameters can be changed by the user. In a single LED circuit, it will just blink. */ -// The effect seen in ESP32C3, ESP32S2 and ESP32S3 is like a Blink of RGB LED -#if CONFIG_IDF_TARGET_ESP32S2 -#define BUILTIN_RGBLED_PIN 18 -#elif CONFIG_IDF_TARGET_ESP32S3 -#define BUILTIN_RGBLED_PIN 48 // 48 or 38 -#elif CONFIG_IDF_TARGET_ESP32C3 -#define BUILTIN_RGBLED_PIN 8 +// The effect seen in (Espressif devkits) ESP32C6, ESP32H2, ESP32C3, ESP32S2 and ESP32S3 is like a Blink of RGB LED +#ifdef PIN_NEOPIXEL +#define BUILTIN_RGBLED_PIN PIN_NEOPIXEL #else -#define BUILTIN_RGBLED_PIN 21 // ESP32 has no builtin RGB LED +#define BUILTIN_RGBLED_PIN 21 // ESP32 has no builtin RGB LED (PIN_NEOPIXEL) #endif #define NR_OF_LEDS 8*4 From 7e00eed2945f4a3a8cb1079a53b562f8421ad4ff Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 7 Nov 2023 09:50:41 -0300 Subject: [PATCH 2/6] Improve NeoPixel definition for all boards --- .../RMT/RMT_CPUFreq_Test/RMT_CPUFreq_Test.ino | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libraries/ESP32/examples/RMT/RMT_CPUFreq_Test/RMT_CPUFreq_Test.ino b/libraries/ESP32/examples/RMT/RMT_CPUFreq_Test/RMT_CPUFreq_Test.ino index 8150dcc7069..b55f7ad4d39 100644 --- a/libraries/ESP32/examples/RMT/RMT_CPUFreq_Test/RMT_CPUFreq_Test.ino +++ b/libraries/ESP32/examples/RMT/RMT_CPUFreq_Test/RMT_CPUFreq_Test.ino @@ -26,14 +26,11 @@ // Default DevKit RGB LED GPIOs: -#if CONFIG_IDF_TARGET_ESP32S2 -#define MY_LED_GPIO 18 -#elif CONFIG_IDF_TARGET_ESP32S3 -#define MY_LED_GPIO 48 // 48 or 38 -#elif CONFIG_IDF_TARGET_ESP32C3 -#define MY_LED_GPIO 8 +// The effect seen in (Espressif devkits) ESP32C6, ESP32H2, ESP32C3, ESP32S2 and ESP32S3 is like a Blink of RGB LED +#ifdef PIN_NEOPIXEL +#define MY_LED_GPIO PIN_NEOPIXEL #else -#define MY_LED_GPIO 21 // Any, ESP32 has no RGB LED - depends on circuit setup +#define MY_LED_GPIO 21 // ESP32 has no builtin RGB LED (PIN_NEOPIXEL) #endif // Set the correct GPIO to any necessary by changing RGB_LED_GPIO value From 167b1f3d2539ab5001cf6c37340519f8bf144506 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 7 Nov 2023 09:54:40 -0300 Subject: [PATCH 3/6] neopixelWrite uses Peirpheral Manager now The function can now be used for many GPIOs in the same sketch by using Peripheral Manager attach/detach, not being necesary to worry about initialization. --- cores/esp32/esp32-hal-rgb-led.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index c74c812f3bb..bcae8f64249 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -3,34 +3,22 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){ rmt_data_t led_data[24]; - static bool initialized = false; - - uint8_t _pin = pin; -#ifdef RGB_BUILTIN - if(pin == RGB_BUILTIN){ - _pin = RGB_BUILTIN - SOC_GPIO_PIN_COUNT; - } -#endif - - if(!initialized){ - if (!rmtInit(_pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)){ - log_e("RGB LED driver initialization failed!"); - return; - } - initialized = true; + if (!rmtInit(pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) { + log_e("RGB LED driver initialization failed!"); + return; } int color[] = {green_val, red_val, blue_val}; // Color coding is in order GREEN, RED, BLUE int i = 0; - for(int col=0; col<3; col++ ){ - for(int bit=0; bit<8; bit++){ - if((color[col] & (1<<(7-bit)))){ + for (int col = 0; col < 3; col++ ) { + for (int bit = 0; bit < 8; bit++) { + if ((color[col] & (1 << (7 - bit)))) { // HIGH bit led_data[i].level0 = 1; // T1H led_data[i].duration0 = 8; // 0.8us led_data[i].level1 = 0; // T1L led_data[i].duration1 = 4; // 0.4us - }else{ + } else { // LOW bit led_data[i].level0 = 1; // T0H led_data[i].duration0 = 4; // 0.4us @@ -40,5 +28,5 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue i++; } } - rmtWrite(_pin, led_data, RMT_SYMBOLS_OF(led_data), RMT_WAIT_FOR_EVER); + rmtWrite(pin, led_data, RMT_SYMBOLS_OF(led_data), RMT_WAIT_FOR_EVER); } From 88d786ffa1013d421e5cfe7d33dd856904ef1c87 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 7 Nov 2023 09:55:34 -0300 Subject: [PATCH 4/6] improve error message --- 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 bcae8f64249..2b34317ba40 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -4,7 +4,7 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){ rmt_data_t led_data[24]; if (!rmtInit(pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) { - log_e("RGB LED driver initialization failed!"); + log_e("RGB LED driver initialization failed for GPIO%d!", pin); return; } From 056771544468be7b39891663380812e7ab9ab9d4 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 7 Nov 2023 11:05:38 -0300 Subject: [PATCH 5/6] check if pin is RGB_BUILTIN --- cores/esp32/esp32-hal-rgb-led.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index 2b34317ba40..b4a58440b76 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -3,6 +3,9 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue_val){ rmt_data_t led_data[24]; + + // Verify if the pin used is RGB_BUILTIN and fix GPIO number + pin = pin == RGB_BUILTIN ? pin - SOC_GPIO_PIN_COUNT : pin; if (!rmtInit(pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) { log_e("RGB LED driver initialization failed for GPIO%d!", pin); return; From 631d2fdf5160f289adf7230c08603a475413bc77 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 7 Nov 2023 11:14:05 -0300 Subject: [PATCH 6/6] fixes boards that don't RGB_BUILTIN --- cores/esp32/esp32-hal-rgb-led.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cores/esp32/esp32-hal-rgb-led.c b/cores/esp32/esp32-hal-rgb-led.c index b4a58440b76..27aee7bfac4 100644 --- a/cores/esp32/esp32-hal-rgb-led.c +++ b/cores/esp32/esp32-hal-rgb-led.c @@ -5,7 +5,9 @@ void neopixelWrite(uint8_t pin, uint8_t red_val, uint8_t green_val, uint8_t blue rmt_data_t led_data[24]; // Verify if the pin used is RGB_BUILTIN and fix GPIO number +#ifdef RGB_BUILTIN pin = pin == RGB_BUILTIN ? pin - SOC_GPIO_PIN_COUNT : pin; +#endif if (!rmtInit(pin, RMT_TX_MODE, RMT_MEM_NUM_BLOCKS_1, 10000000)) { log_e("RGB LED driver initialization failed for GPIO%d!", pin); return;