From 4ece6168ace8b4ecaae803091f79decf1871a833 Mon Sep 17 00:00:00 2001 From: TD-er Date: Sun, 5 Nov 2023 19:49:20 +0100 Subject: [PATCH] [ESP-IDF5.1] Tweak NeoPixel support on ESP32-C3 --- lib/NeoPixelBus/src/NeoPixelBus.h | 2 +- .../src/internal/NeoEsp32RmtMethod_idf5.h | 13 +++++++++---- .../src/NeoPixelBus_wrapper.cpp | 16 +++++++--------- platformio_esp32c3_envs.ini | 8 ++++++++ 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/NeoPixelBus/src/NeoPixelBus.h b/lib/NeoPixelBus/src/NeoPixelBus.h index d810e2a94..375b70756 100644 --- a/lib/NeoPixelBus/src/NeoPixelBus.h +++ b/lib/NeoPixelBus/src/NeoPixelBus.h @@ -165,7 +165,7 @@ public: { } - ~NeoPixelBus() + virtual ~NeoPixelBus() { } diff --git a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h index 6b5218de7..bed4f5e5b 100644 --- a/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h +++ b/lib/NeoPixelBus/src/internal/NeoEsp32RmtMethod_idf5.h @@ -395,7 +395,7 @@ public: construct(); } - ~NeoEsp32RmtMethodBase() + virtual ~NeoEsp32RmtMethodBase() { // wait until the last send finishes before destructing everything // arbitrary time out of 10 seconds @@ -421,6 +421,8 @@ public: #ifndef NEOESP32_RMT_FLAGS_WITH_DMA #if defined(CONFIG_IDF_TARGET_ESP32S3) #define NEOESP32_RMT_FLAGS_WITH_DMA true +#elif defined(CONFIG_IDF_TARGET_ESP32C3) +#define NEOESP32_RMT_FLAGS_WITH_DMA false #else #define NEOESP32_RMT_FLAGS_WITH_DMA false #endif @@ -430,15 +432,18 @@ public: #ifndef NEOESP32_RMT_MEM_BLOCK_SYMBOLS #if defined(CONFIG_IDF_TARGET_ESP32S3) #ifdef NEOESP32_RMT_FLAGS_WITH_DMA -#define NEOESP32_RMT_MEM_BLOCK_SYMBOLS 1536 +#define NEOESP32_RMT_MEM_BLOCK_SYMBOLS 1536 // 16 RGB pixels or 12 RGBW pixels #else -#define NEOESP32_RMT_MEM_BLOCK_SYMBOLS 96 +#define NEOESP32_RMT_MEM_BLOCK_SYMBOLS 96 // Use 2x platform default #endif #elif defined(CONFIG_IDF_TARGET_ESP32) // Uses DMA, but should not set config.flags.with_dma = true; #define NEOESP32_RMT_MEM_BLOCK_SYMBOLS 384 #elif defined(CONFIG_IDF_TARGET_ESP32S2) -#define NEOESP32_RMT_MEM_BLOCK_SYMBOLS 128 // Use 2x platform default (Only ESP32 and ESP32-S2 have 64) +// We use RMT channel 1, so we only can use upto 3x he default mem_block_symbols of 64 +#define NEOESP32_RMT_MEM_BLOCK_SYMBOLS 192 // Use 3x platform default (Only ESP32 and ESP32-S2 have 64) +#elif defined(CONFIG_IDF_TARGET_ESP32C3) +#define NEOESP32_RMT_MEM_BLOCK_SYMBOLS 192 #else #define NEOESP32_RMT_MEM_BLOCK_SYMBOLS 96 // Use 2x platform default #endif diff --git a/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp index 54c5c9dc7..b05ad349b 100644 --- a/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp +++ b/lib/NeoPixelBus_wrapper/src/NeoPixelBus_wrapper.cpp @@ -6,15 +6,6 @@ NeoPixelBus_wrapper::NeoPixelBus_wrapper(uint16_t _maxPixels, int16_t _gpioPin, neoPixelType _stripType) : numLEDs(_maxPixels) { - if (NEO_GRB == (_stripType & NEO_GRB)) { - #ifdef ESP8266 - neopixels_grb = new (std::nothrow) NEOPIXEL_LIB(_maxPixels); - #endif // ifdef ESP8266 - #ifdef ESP32 - neopixels_grb = new (std::nothrow) NEOPIXEL_LIB(_maxPixels, _gpioPin); - #endif // ifdef ESP32 - } - if (NEO_GRBW == (_stripType & NEO_GRBW)) { #ifdef ESP8266 neopixels_grbw = new (std::nothrow) NEOPIXEL_LIB(_maxPixels); @@ -22,6 +13,13 @@ NeoPixelBus_wrapper::NeoPixelBus_wrapper(uint16_t _maxPixels, #ifdef ESP32 neopixels_grbw = new (std::nothrow) NEOPIXEL_LIB(_maxPixels, _gpioPin); #endif // ifdef ESP32 + } else if (NEO_GRB == (_stripType & NEO_GRB)) { + #ifdef ESP8266 + neopixels_grb = new (std::nothrow) NEOPIXEL_LIB(_maxPixels); + #endif // ifdef ESP8266 + #ifdef ESP32 + neopixels_grb = new (std::nothrow) NEOPIXEL_LIB(_maxPixels, _gpioPin); + #endif // ifdef ESP32 } } diff --git a/platformio_esp32c3_envs.ini b/platformio_esp32c3_envs.ini index b97ff00cb..191529d58 100644 --- a/platformio_esp32c3_envs.ini +++ b/platformio_esp32c3_envs.ini @@ -134,3 +134,11 @@ build_flags = ${esp32c3_common.build_flags} -DFEATURE_ARDUINO_OTA=1 -DFEATURE_SD=1 -DPLUGIN_NEOPIXEL_COLLECTION + +[env:neopixel_ESP32c3_4M316k_LittleFS_CDC] +extends = esp32c3_common_LittleFS +board = esp32c3cdc +build_flags = ${esp32c3_common_LittleFS.build_flags} + -DFEATURE_ARDUINO_OTA=1 + -DFEATURE_SD=1 + -DPLUGIN_NEOPIXEL_COLLECTION