Skip to content

Commit

Permalink
trying to reduce flickering
Browse files Browse the repository at this point in the history
The NeoPixelBus RMT driver seems to get stalled when ESP.get.... functions are called (big kernel lock?). Also its glitching during flash file access.

This change tries to avoid some conflicts by first checking that the driver is not sending.
  • Loading branch information
softhack007 committed Apr 26, 2024
1 parent aa544ac commit 858610e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
4 changes: 2 additions & 2 deletions wled00/bus_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -1192,8 +1192,8 @@ class PolyBus {
if (num > 7) return I_NONE;
#else
if (num > 8) return I_NONE;
if (num == 1) offset = 2; // use I2S#1 as 2nd bus - seems to be a good compromise for performance, and reduces flickering for some users
// if (num == 0) offset = 2; // un-comment to use I2S#1 as 1st bus - sometimes helps, if you experience flickering during Wifi or filesystem activity.
//if (num == 1) offset = 2; // use I2S#1 as 2nd bus - seems to be a good compromise for performance, and reduces flickering for some users
if (num == 0) offset = 2; // un-comment to use I2S#1 as 1st bus - sometimes helps, if you experience flickering during Wifi or filesystem activity.
#endif
#endif
#endif
Expand Down
8 changes: 8 additions & 0 deletions wled00/file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ static File f; // don't export to other cpp files

//wrapper to find out how long closing takes
void closeFile() {
#ifdef ARDUINO_ARCH_ESP32
// WLEDMM: file.close() triggers flash writing. While flash is writing, the NPB RMT driver cannot fill its buffer which may create glitches.
unsigned long t_wait = millis();
while(strip.isUpdating() && (millis() - t_wait < 72)) delay(1); // WLEDMM try to catch a moment when strip is idle
while(strip.isUpdating() && (millis() - t_wait < 96)) delay(0); // try harder
//if (strip.isUpdating()) USER_PRINTLN("closeFile: strip still updating.");
delay(2); // might help
#endif
#ifdef WLED_DEBUG_FS
DEBUGFS_PRINT(F("Close -> "));
uint32_t s = millis();
Expand Down
8 changes: 8 additions & 0 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,14 @@ void serializeInfo(JsonObject root)
if(ESP.getChipCores() > 1) // WLEDMM
root[F("resetReason1")] = (int)rtc_get_reset_reason(1);
#endif

#if defined(ARDUINO_ARCH_ESP32)
unsigned long t_wait = millis();
while(strip.isUpdating() && (millis() - t_wait < 125)) delay(1); // WLEDMM try to catch a moment when strip is idle
while(strip.isUpdating() && (millis() - t_wait < 160)) yield(); // try harder
//if (strip.isUpdating()) USER_PRINTLN("serializeInfo: strip still updating.");
#endif

root[F("lwip")] = 0; //deprecated
root[F("totalheap")] = ESP.getHeapSize(); //WLEDMM
#else
Expand Down
8 changes: 7 additions & 1 deletion wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,12 @@ bool WLED::initEthernet()

void WLED::initConnection()
{
#ifdef ARDUINO_ARCH_ESP32
unsigned long t_wait = millis();
while(strip.isUpdating() && (millis() - t_wait < 86)) delay(1); // WLEDMM try to catch a moment when strip is idle
//if (strip.isUpdating()) USER_PRINTLN("WLED::initConnection: strip still updating.");
#endif

#ifdef WLED_ENABLE_WEBSOCKETS
ws.onEvent(wsEvent);
#endif
Expand Down Expand Up @@ -1208,7 +1214,7 @@ void WLED::handleConnection()
static unsigned retryCount = 0; // WLEDMM
#ifdef ARDUINO_ARCH_ESP32
// reconnect WiFi to clear stale allocations if heap gets too low
if (now - heapTime > 5000) { // WLEDMM: updated with better logic for small heap available by block, not total.
if ((!strip.isUpdating()) && (now - heapTime > 5000)) { // WLEDMM: updated with better logic for small heap available by block, not total. // WLEDMM trying to use a moment when the strip is idle
#if defined(ARDUINO_ARCH_ESP32S2)
uint32_t heap = ESP.getFreeHeap(); // WLEDMM works better on -S2
#else
Expand Down
2 changes: 1 addition & 1 deletion wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

// version code in format yymmddb (b = daily build)
#define VERSION 2404230
#define VERSION 2404260

// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
#define _MoonModules_WLED_
Expand Down

0 comments on commit 858610e

Please sign in to comment.