From 20ed81cd86a7eb3ee1ffcfad4d7c3b2cf84d2a3a Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sat, 30 Mar 2024 11:02:28 +0100 Subject: [PATCH] Prefer I2S1 over RMT on ESP32 - remove Audioreactive limitation --- wled00/bus_manager.cpp | 2 +- wled00/bus_wrapper.h | 37 +++++++++++++++++++++++++++++-------- wled00/const.h | 20 ++++++-------------- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index 88b4cc32b..764ab6e2b 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -129,7 +129,7 @@ BusDigital::BusDigital(BusConfig &bc, uint8_t nr, const ColorOrderMap &com) if (bc.type == TYPE_WS2812_1CH_X3) lenToCreate = NUM_ICS_WS2812_1CH_3X(bc.count); // only needs a third of "RGB" LEDs for NeoPixelBus _busPtr = PolyBus::create(_iType, _pins, lenToCreate + _skip, nr, _frequencykHz); _valid = (_busPtr != nullptr); - DEBUG_PRINTF("%successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u). mA=%d/%d\n", _valid?"S":"Uns", nr, bc.count, bc.type, _pins[0], _pins[1], _iType, _milliAmpsPerLed, _milliAmpsMax); + DEBUG_PRINTF_P(PSTR("%successfully inited strip %u (len %u) with type %u and pins %u,%u (itype %u). mA=%d/%d\n"), _valid?"S":"Uns", nr, bc.count, bc.type, _pins[0], IS_2PIN(bc.type)?_pins[1]:255, _iType, _milliAmpsPerLed, _milliAmpsMax); } //fine tune power estimation constants for your setup diff --git a/wled00/bus_wrapper.h b/wled00/bus_wrapper.h index d13b1a945..ebbeca4ad 100644 --- a/wled00/bus_wrapper.h +++ b/wled00/bus_wrapper.h @@ -206,81 +206,101 @@ //RGB #define B_32_RN_NEO_3 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS -#define B_32_I0_NEO_3 NeoPixelBusLg +#define B_32_I0_NEO_3 NeoPixelBusLg +//#define B_32_I0_NEO_3 NeoPixelBusLg // parallel I2S #endif #ifndef WLED_NO_I2S1_PIXELBUS -#define B_32_I1_NEO_3 NeoPixelBusLg +#define B_32_I1_NEO_3 NeoPixelBusLg +//#define B_32_I1_NEO_3 NeoPixelBusLg // parallel I2S #endif //RGBW -#define B_32_RN_NEO_4 NeoPixelBusLg +#define B_32_RN_NEO_4 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS -#define B_32_I0_NEO_4 NeoPixelBusLg +#define B_32_I0_NEO_4 NeoPixelBusLg +//#define B_32_I0_NEO_4 NeoPixelBusLg // parallel I2S #endif #ifndef WLED_NO_I2S1_PIXELBUS -#define B_32_I1_NEO_4 NeoPixelBusLg +#define B_32_I1_NEO_4 NeoPixelBusLg +//#define B_32_I1_NEO_4 NeoPixelBusLg // parallel I2S #endif //400Kbps #define B_32_RN_400_3 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS #define B_32_I0_400_3 NeoPixelBusLg +//#define B_32_I0_400_3 NeoPixelBusLg // parallel I2S #endif #ifndef WLED_NO_I2S1_PIXELBUS #define B_32_I1_400_3 NeoPixelBusLg +//#define B_32_I1_400_3 NeoPixelBusLg // parallel I2S #endif //TM1814 (RGBW) #define B_32_RN_TM1_4 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS #define B_32_I0_TM1_4 NeoPixelBusLg +//#define B_32_I0_TM1_4 NeoPixelBusLg // parallel I2S #endif #ifndef WLED_NO_I2S1_PIXELBUS #define B_32_I1_TM1_4 NeoPixelBusLg +//#define B_32_I1_TM1_4 NeoPixelBusLg // parallel I2S #endif //TM1829 (RGB) #define B_32_RN_TM2_3 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS #define B_32_I0_TM2_3 NeoPixelBusLg +//#define B_32_I0_TM2_3 NeoPixelBusLg // parallel I2S #endif #ifndef WLED_NO_I2S1_PIXELBUS #define B_32_I1_TM2_3 NeoPixelBusLg +//#define B_32_I1_TM2_3 NeoPixelBusLg // parallel I2S #endif //UCS8903 #define B_32_RN_UCS_3 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS #define B_32_I0_UCS_3 NeoPixelBusLg +//#define B_32_I0_UCS_3 NeoPixelBusLg // parallel I2S #endif #ifndef WLED_NO_I2S1_PIXELBUS #define B_32_I1_UCS_3 NeoPixelBusLg +//#define B_32_I1_UCS_3 NeoPixelBusLg // parallel I2S #endif //UCS8904 #define B_32_RN_UCS_4 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS #define B_32_I0_UCS_4 NeoPixelBusLg +//#define B_32_I0_UCS_4 NeoPixelBusLg// parallel I2S #endif #ifndef WLED_NO_I2S1_PIXELBUS #define B_32_I1_UCS_4 NeoPixelBusLg +//#define B_32_I1_UCS_4 NeoPixelBusLg// parallel I2S #endif #define B_32_RN_APA106_3 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS #define B_32_I0_APA106_3 NeoPixelBusLg +//#define B_32_I0_APA106_3 NeoPixelBusLg // parallel I2S #endif #ifndef WLED_NO_I2S1_PIXELBUS #define B_32_I1_APA106_3 NeoPixelBusLg +//#define B_32_I1_APA106_3 NeoPixelBusLg // parallel I2S #endif //FW1906 GRBCW #define B_32_RN_FW6_5 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS #define B_32_I0_FW6_5 NeoPixelBusLg +//#define B_32_I0_FW6_5 NeoPixelBusLg // parallel I2S #endif #ifndef WLED_NO_I2S1_PIXELBUS #define B_32_I1_FW6_5 NeoPixelBusLg +//#define B_32_I1_FW6_5 NeoPixelBusLg // parallel I2S #endif //WS2805 RGBWC #define B_32_RN_2805_5 NeoPixelBusLg #ifndef WLED_NO_I2S0_PIXELBUS #define B_32_I0_2805_5 NeoPixelBusLg +//#define B_32_I0_2805_5 NeoPixelBusLg // parallel I2S #endif #ifndef WLED_NO_I2S1_PIXELBUS #define B_32_I1_2805_5 NeoPixelBusLg +//#define B_32_I1_2805_5 NeoPixelBusLg // parallel I2S #endif #endif @@ -1458,11 +1478,11 @@ class PolyBus { return I_8266_U0_2805_5 + offset; } #else //ESP32 - uint8_t offset = 0; //0 = RMT (num 0-7) 8 = I2S0 9 = I2S1 + uint8_t offset = 0; // 0 = RMT (num 1-8), 1 = I2S0 (used by Audioreactive), 2 = I2S1 #if defined(CONFIG_IDF_TARGET_ESP32S2) // ESP32-S2 only has 4 RMT channels if (num > 4) return I_NONE; - if (num > 3) offset = 1; // only one I2S + if (num > 3) offset = 1; // only one I2S (use last to allow Audioreactive) #elif defined(CONFIG_IDF_TARGET_ESP32C3) // On ESP32-C3 only the first 2 RMT channels are usable for transmitting if (num > 1) return I_NONE; @@ -1474,7 +1494,8 @@ class PolyBus { #else // standard ESP32 has 8 RMT and 2 I2S channels if (num > 9) return I_NONE; - if (num > 7) offset = num -7; + if (num > 8) offset = 1; + if (num == 0) offset = 2; // prefer I2S1 for 1st bus (less flickering but more RAM needed) #endif switch (busType) { case TYPE_WS2812_1CH_X3: diff --git a/wled00/const.h b/wled00/const.h index de07c314a..c8a4b7ffe 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -53,24 +53,16 @@ #define WLED_MAX_BUSSES 3 // will allow 2 digital & 1 analog (or the other way around) #define WLED_MIN_VIRTUAL_BUSSES 3 #elif defined(CONFIG_IDF_TARGET_ESP32S2) // 4 RMT, 8 LEDC, only has 1 I2S bus, supported in NPB - #if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33 - #define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog - #define WLED_MIN_VIRTUAL_BUSSES 4 - #else - #define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog - #define WLED_MIN_VIRTUAL_BUSSES 3 - #endif + // the 5th bus (I2S) will prevent Audioreactive usermod from functioning (it is last used though) + #define WLED_MAX_BUSSES 7 // will allow 5 digital & 2 analog + #define WLED_MIN_VIRTUAL_BUSSES 3 #elif defined(CONFIG_IDF_TARGET_ESP32S3) // 4 RMT, 8 LEDC, has 2 I2S but NPB does not support them ATM #define WLED_MAX_BUSSES 6 // will allow 4 digital & 2 analog #define WLED_MIN_VIRTUAL_BUSSES 4 #else - #if defined(USERMOD_AUDIOREACTIVE) // requested by @softhack007 https://github.com/blazoncek/WLED/issues/33 - #define WLED_MAX_BUSSES 8 - #define WLED_MIN_VIRTUAL_BUSSES 2 - #else - #define WLED_MAX_BUSSES 10 - #define WLED_MIN_VIRTUAL_BUSSES 0 - #endif + // the 10th digital bus (I2S0) will prevent Audioreactive usermod from functioning (it is last used though) + #define WLED_MAX_BUSSES 10 + #define WLED_MIN_VIRTUAL_BUSSES 0 #endif #endif #else