Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib8tion/random8.h10
-rw-r--r--pixeltypes.h16
-rw-r--r--platforms/esp/32/clockless_rmt_esp32.h28
3 files changed, 50 insertions, 4 deletions
diff --git a/lib8tion/random8.h b/lib8tion/random8.h
index ba60cf57..d834abd5 100644
--- a/lib8tion/random8.h
+++ b/lib8tion/random8.h
@@ -12,13 +12,19 @@
#define FASTLED_RAND16_2053 ((uint16_t)(2053))
#define FASTLED_RAND16_13849 ((uint16_t)(13849))
+#if defined(LIB8_ATTINY)
+#define APPLY_FASTLED_RAND16_2053(x) (x << 11) + (x << 2) + x
+#else
+#define APPLY_FASTLED_RAND16_2053(x) (x * FASTLED_RAND16_2053)
+#endif
+
/// random number seed
extern uint16_t rand16seed;// = RAND16_SEED;
/// Generate an 8-bit random number
LIB8STATIC uint8_t random8()
{
- rand16seed = (rand16seed * FASTLED_RAND16_2053) + FASTLED_RAND16_13849;
+ rand16seed = APPLY_FASTLED_RAND16_2053(rand16seed) + FASTLED_RAND16_13849;
// return the sum of the high and low bytes, for better
// mixing and non-sequential correlation
return (uint8_t)(((uint8_t)(rand16seed & 0xFF)) +
@@ -28,7 +34,7 @@ LIB8STATIC uint8_t random8()
/// Generate a 16 bit random number
LIB8STATIC uint16_t random16()
{
- rand16seed = (rand16seed * FASTLED_RAND16_2053) + FASTLED_RAND16_13849;
+ rand16seed = APPLY_FASTLED_RAND16_2053(rand16seed) + FASTLED_RAND16_13849;
return rand16seed;
}
diff --git a/pixeltypes.h b/pixeltypes.h
index ff327fd9..f4e57061 100644
--- a/pixeltypes.h
+++ b/pixeltypes.h
@@ -38,6 +38,18 @@ struct CHSV {
uint8_t raw[3];
};
+ /// Array access operator to index into the chsv object
+ inline uint8_t& operator[] (uint8_t x) __attribute__((always_inline))
+ {
+ return raw[x];
+ }
+
+ /// Array access operator to index into the chsv object
+ inline const uint8_t& operator[] (uint8_t x) const __attribute__((always_inline))
+ {
+ return raw[x];
+ }
+
/// default values are UNITIALIZED
inline CHSV() __attribute__((always_inline))
{
@@ -106,7 +118,7 @@ struct CRGB {
uint8_t raw[3];
};
- /// Array access operator to index into the crgb object
+ /// Array access operator to index into the crgb object
inline uint8_t& operator[] (uint8_t x) __attribute__((always_inline))
{
return raw[x];
@@ -478,7 +490,7 @@ struct CRGB {
uint8_t max = red;
if( green > max) max = green;
if( blue > max) max = blue;
-
+
// stop div/0 when color is black
if(max > 0) {
uint16_t factor = ((uint16_t)(limit) * 256) / max;
diff --git a/platforms/esp/32/clockless_rmt_esp32.h b/platforms/esp/32/clockless_rmt_esp32.h
index de5b7c98..b8cd1f42 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 1
*
* 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);
+
+#if FASTLED_ESP32_FLASH_LOCK == 1
+ // -- 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;
+
+#if FASTLED_ESP32_FLASH_LOCK == 1
+ // -- Release the lock on flash operations
+ spi_flash_op_unlock();
+#endif
}
}