diff options
author | Sam Guyer <sam.guyer@gmail.com> | 2020-02-09 07:22:09 +0300 |
---|---|---|
committer | Sam Guyer <sam.guyer@gmail.com> | 2020-02-09 07:22:09 +0300 |
commit | 264b444fc065ea4bd9f28abe3e1868df403c31d8 (patch) | |
tree | 86a0b3091d58a361cad8536208615c886faf1a03 | |
parent | 9ab13502aaef22f92329741e2cbac0310ce60120 (diff) |
Two changes to improve stability. First, added a min wait that forces calls to show() to be at least 50 microseconds apart. Second, added optional calls to ESP-IDF functions that force flash operations to wait until show() is complete.
-rw-r--r-- | platforms/esp/32/clockless_rmt_esp32.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/platforms/esp/32/clockless_rmt_esp32.h b/platforms/esp/32/clockless_rmt_esp32.h index de5b7c98..bc18589e 100644 --- a/platforms/esp/32/clockless_rmt_esp32.h +++ b/platforms/esp/32/clockless_rmt_esp32.h @@ -58,6 +58,13 @@ * represented by a 32-bit pulse specification, so it is a 32X blow-up * in memory use. * + * NEW: Use of Flash memory on the ESP32 can interfere with the timing + * of pixel output. The ESP-IDF system code disables all other + * code running on *either* core during these operation. To prevent + * this from happening, define this flag. It will force flash + * operations to wait until the show() is done. + * + * #define FASTLED_ESP32_FLASH_LOCK * * Based on public domain code created 19 Nov 2016 by Chris Osborn <fozztexx@fozztexx.com> * http://insentricity.com * @@ -101,6 +108,9 @@ extern "C" { #include "esp_log.h" +extern void spi_flash_op_lock(void); +extern void spi_flash_op_unlock(void); + #ifdef __cplusplus } #endif @@ -200,6 +210,9 @@ class ClocklessController : public CPixelLEDController<RGB_ORDER> rmt_item32_t * mBuffer; uint16_t mBufferSize; + // -- Make sure we can't call show() too quickly + CMinWait<50> mWait; + public: void init() @@ -294,6 +307,11 @@ protected: initRMT(); } xSemaphoreTake(gTX_sem, portMAX_DELAY); + +#ifdef FASTLED_ESP32_FLASH_LOCK + // -- Make sure no flash operations happen right now + spi_flash_op_lock(); +#endif } if (FASTLED_RMT_BUILTIN_DRIVER) @@ -321,6 +339,9 @@ protected: channel++; } + // -- Make sure it's been at least 50ms since last show + mWait.wait(); + // -- Start them all for (int i = 0; i < channel; i++) { ClocklessController * pController = static_cast<ClocklessController*>(gControllers[i]); @@ -333,10 +354,17 @@ protected: xSemaphoreTake(gTX_sem, portMAX_DELAY); xSemaphoreGive(gTX_sem); + mWait.mark(); + // -- Reset the counters gNumStarted = 0; gNumDone = 0; gNext = 0; + +#ifdef FASTLED_ESP32_FLASH_LOCK + // -- Release the lock on flash operations + spi_flash_op_unlock(); +#endif } } |