From c2adb5be34240183678e2db64477b08d6c3596c2 Mon Sep 17 00:00:00 2001 From: Troy <5659019+troyhacks@users.noreply.github.com> Date: Mon, 9 Sep 2024 18:47:49 -0400 Subject: [PATCH 1/3] HUB75 PSRAM Buffers --- wled00/bus_manager.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ wled00/bus_manager.h | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index 5f10ec77ca..a214e901b4 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -588,6 +588,29 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh mxconfig.gpio.d = 35; mxconfig.gpio.e = 21; +#elif defined(CONFIG_IDF_TARGET_ESP32S3) && defined(HUB75_TROYHACKS) // ESP32-S3 + + // TroyHacks HUB75 + + USER_PRINTLN("MatrixPanel_I2S_DMA - TroyHacks with PSRAM"); + + mxconfig.gpio.r1 = 1; + mxconfig.gpio.g1 = 2; + mxconfig.gpio.b1 = 42; + // 4th pin is GND + mxconfig.gpio.r2 = 41; + mxconfig.gpio.g2 = 40; + mxconfig.gpio.b2 = 39; + mxconfig.gpio.e = 38; + mxconfig.gpio.a = 45; + mxconfig.gpio.b = 48; + mxconfig.gpio.c = 47; + mxconfig.gpio.d = 21; // this says GND but should be the "D" pin + mxconfig.gpio.clk = 20; + mxconfig.gpio.lat = 19; + mxconfig.gpio.oe = 0; + // 16th pin is GND + #elif defined(CONFIG_IDF_TARGET_ESP32S3) // ESP32-S3 // Huidu HD-WF2 ESP32-S3 @@ -704,6 +727,7 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh #endif + mxconfig.clkphase = false; mxconfig.chain_length = max((u_int8_t) 1, min(bc.pins[0], (u_int8_t) 4)); // prevent bad data preventing boot due to low memory USER_PRINTF("MatrixPanel_I2S_DMA config - %ux%u length: %u\n", mxconfig.mx_width, mxconfig.mx_height, mxconfig.chain_length); @@ -750,7 +774,16 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh if (_ledBuffer) free(_ledBuffer); // should not happen if (_ledsDirty) free(_ledsDirty); // should not happen + + #if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM) + if (psramFound()){ + _ledsDirty = (byte*) ps_malloc(getBitArrayBytes(_len)); // create LEDs dirty bits + } else { + _ledsDirty = (byte*) malloc(getBitArrayBytes(_len)); // create LEDs dirty bits + } + #else _ledsDirty = (byte*) malloc(getBitArrayBytes(_len)); // create LEDs dirty bits + #endif if (_ledsDirty == nullptr) { display->stopDMAoutput(); @@ -762,7 +795,15 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh setBitArray(_ledsDirty, _len, false); // reset dirty bits if (mxconfig.double_buff == false) { + #if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM) + if (psramFound()){ + _ledBuffer = (CRGB*) ps_calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK) + } else { + _ledBuffer = (CRGB*) calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK) + } + #else _ledBuffer = (CRGB*) calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK) + #endif } } diff --git a/wled00/bus_manager.h b/wled00/bus_manager.h index 2379f43048..b336088196 100644 --- a/wled00/bus_manager.h +++ b/wled00/bus_manager.h @@ -360,7 +360,7 @@ class BusHub75Matrix : public Bus { public: BusHub75Matrix(BusConfig &bc); - uint16_t getMaxPixels() const override { return 4096; }; + uint16_t getMaxPixels() const override { return MAX_LEDS; }; bool hasRGB() const override { return true; } bool hasWhite() const override { return false; } From 3ee05a74b4263c15a9a6520e356840ae6e55cda5 Mon Sep 17 00:00:00 2001 From: Troy <5659019+troyhacks@users.noreply.github.com> Date: Tue, 10 Sep 2024 15:11:17 -0400 Subject: [PATCH 2/3] PSRAM buffer fixes as per SoftHack007 --- wled00/bus_manager.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index bbae989d63..a29ae46817 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -719,7 +719,12 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh #endif - mxconfig.clkphase = false; + // mxconfig.double_buff = true; // <------------- Turn on double buffer + // mxconfig.driver = HUB75_I2S_CFG::ICN2038S; // experimental - use specific shift register driver + // mxconfig.latch_blanking = 3; + // mxconfig.i2sspeed = HUB75_I2S_CFG::HZ_10M; // experimental - 5MHZ should be enugh, but colours looks slightly better at 10MHz + // mxconfig.min_refresh_rate = 90; + mxconfig.clkphase = false; // can help in case that the leftmost column is invisible, or pixels on the right side "bleeds out" to the left. mxconfig.chain_length = max((u_int8_t) 1, min(bc.pins[0], (u_int8_t) 4)); // prevent bad data preventing boot due to low memory USER_PRINTF("MatrixPanel_I2S_DMA config - %ux%u length: %u\n", mxconfig.mx_width, mxconfig.mx_height, mxconfig.chain_length); @@ -769,15 +774,7 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh if (_ledBuffer) free(_ledBuffer); // should not happen if (_ledsDirty) free(_ledsDirty); // should not happen - #if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM) - if (psramFound()){ - _ledsDirty = (byte*) ps_malloc(getBitArrayBytes(_len)); // create LEDs dirty bits - } else { - _ledsDirty = (byte*) malloc(getBitArrayBytes(_len)); // create LEDs dirty bits - } - #else _ledsDirty = (byte*) malloc(getBitArrayBytes(_len)); // create LEDs dirty bits - #endif if (_ledsDirty == nullptr) { display->stopDMAoutput(); @@ -789,7 +786,7 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh setBitArray(_ledsDirty, _len, false); // reset dirty bits if (mxconfig.double_buff == false) { - #if defined(ARDUINO_ARCH_ESP32) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM) + #if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM) && defined(CONFIG_SPIRAM_MODE_OCT) if (psramFound()){ _ledBuffer = (CRGB*) ps_calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK) } else { From 08c2446f61ce8f8d185f83ed2b96f42f53b46039 Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Tue, 17 Sep 2024 18:11:06 +0200 Subject: [PATCH 3/3] better PSRAM flags handling (minor) in MM, we can have WLED_USE_PSRAM_JSON instead of WLED_USE_PSRAM. --- wled00/bus_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wled00/bus_manager.cpp b/wled00/bus_manager.cpp index a29ae46817..0811ea5de9 100644 --- a/wled00/bus_manager.cpp +++ b/wled00/bus_manager.cpp @@ -786,8 +786,8 @@ BusHub75Matrix::BusHub75Matrix(BusConfig &bc) : Bus(bc.type, bc.start, bc.autoWh setBitArray(_ledsDirty, _len, false); // reset dirty bits if (mxconfig.double_buff == false) { - #if defined(CONFIG_IDF_TARGET_ESP32S3) && defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM) && defined(CONFIG_SPIRAM_MODE_OCT) - if (psramFound()){ + #if defined(CONFIG_IDF_TARGET_ESP32S3) && CONFIG_SPIRAM_MODE_OCT && defined(BOARD_HAS_PSRAM) && (defined(WLED_USE_PSRAM) || defined(WLED_USE_PSRAM_JSON)) + if (psramFound()) { _ledBuffer = (CRGB*) ps_calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK) } else { _ledBuffer = (CRGB*) calloc(_len, sizeof(CRGB)); // create LEDs buffer (initialized to BLACK)