From ecdc0a38001d5a815b0f774f061c016f21bab198 Mon Sep 17 00:00:00 2001 From: cschwinne Date: Sat, 3 Apr 2021 17:18:29 +0200 Subject: [PATCH] Fixed ESP32 crash on Drip effect with reversed segment (#1854) --- CHANGELOG.md | 7 +++++++ wled00/FX.cpp | 9 +++++---- wled00/FX_fcn.cpp | 2 +- wled00/wled.cpp | 11 +++++++++-- wled00/wled.h | 6 +++++- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a56fe813..03bde2e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ ## WLED changelog +### Builds after release 0.12.0 + +#### Build 2104030 + +- Fixed ESP32 crash on Drip effect with reversed segment (#1854) +- Added flag `WLED_DISABLE_BROWNOUT_DET` to disable ESP32 brownout detector (off by default) + ### WLED release 0.12.0 #### Build 2104020 diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 308b864c..f6509e52 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -3081,7 +3081,7 @@ uint16_t WS2812FX::mode_drip(void) gravity *= SEGLEN; int sourcedrop = 12; - for (int j=0;j255) drops[j].col=255; - setPixelColor(int(drops[j].pos),color_blend(BLACK,SEGCOLOR(0),drops[j].col)); + setPixelColor(uint16_t(drops[j].pos),color_blend(BLACK,SEGCOLOR(0),drops[j].col)); drops[j].col += map(SEGMENT.speed, 0, 255, 1, 6); // swelling @@ -3107,8 +3107,9 @@ uint16_t WS2812FX::mode_drip(void) if (drops[j].pos < 0) drops[j].pos = 0; drops[j].vel += gravity; - for (int i=1;i<7-drops[j].colIndex;i++) { // some minor math so we don't expand bouncing droplets - setPixelColor(int(drops[j].pos)+i,color_blend(BLACK,SEGCOLOR(0),drops[j].col/i)); //spread pixel with fade while falling + for (uint16_t i=1;i<7-drops[j].colIndex;i++) { // some minor math so we don't expand bouncing droplets + uint16_t pos = uint16_t(drops[j].pos) +i; //this is BAD, returns a pos >= SEGLEN occasionally + setPixelColor(pos,color_blend(BLACK,SEGCOLOR(0),drops[j].col/i)); //spread pixel with fade while falling } if (drops[j].colIndex > 2) { // during bounce, some water is on the floor diff --git a/wled00/FX_fcn.cpp b/wled00/FX_fcn.cpp index 58343c08..f58bee23 100644 --- a/wled00/FX_fcn.cpp +++ b/wled00/FX_fcn.cpp @@ -191,7 +191,7 @@ void WS2812FX::setPixelColor(uint16_t i, byte r, byte g, byte b, byte w) uint16_t realIndex = realPixelIndex(i); for (uint16_t j = 0; j < SEGMENT.grouping; j++) { - int16_t indexSet = realIndex + (reversed ? -j : j); + int indexSet = realIndex + (reversed ? -j : j); if (indexSet < customMappingSize) indexSet = customMappingTable[indexSet]; if (indexSet >= SEGMENT.start && indexSet < SEGMENT.stop) { busses.setPixelColor(indexSet + skip, col); diff --git a/wled00/wled.cpp b/wled00/wled.cpp index 6417b83f..7116edb0 100644 --- a/wled00/wled.cpp +++ b/wled00/wled.cpp @@ -2,6 +2,11 @@ #include "wled.h" #include +#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DISABLE_BROWNOUT_DET) +#include "soc/soc.h" +#include "soc/rtc_cntl_reg.h" +#endif + /* * Main WLED class implementation. Mostly initialization and connection logic */ @@ -285,6 +290,10 @@ void WLED::loop() void WLED::setup() { + #if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DISABLE_BROWNOUT_DET) + WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detection + #endif + Serial.begin(115200); Serial.setTimeout(50); DEBUG_PRINTLN(); @@ -337,8 +346,6 @@ void WLED::setup() pinMode(STATUSLED, OUTPUT); #endif - //DEBUG_PRINTLN(F("Load EEPROM")); - //loadSettingsFromEEPROM(); beginStrip(); userSetup(); usermods.setup(); diff --git a/wled00/wled.h b/wled00/wled.h index 63dee2ca..293be416 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2104020 +#define VERSION 2104030 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG @@ -47,6 +47,10 @@ // filesystem specific debugging //#define WLED_DEBUG_FS +//optionally disable brownout detector on ESP32. +//This is generally a terrible idea, but improves boot success on boards with a 3.3v regulator + cap setup that can't provide 400mA peaks +//#define WLED_DISABLE_BROWNOUT_DET + // Library inclusions. #include #ifdef ESP8266