diff options
author | Sam Guyer <sam.guyer@gmail.com> | 2020-12-30 17:58:39 +0300 |
---|---|---|
committer | Sam Guyer <sam.guyer@gmail.com> | 2020-12-30 17:58:39 +0300 |
commit | 51d2891cff0264dcb17c05939b09a27a47f87447 (patch) | |
tree | ce858d7e57d74af665e0ccf77e5a9c752b9a08ae /src/platforms/esp/32/clockless_rmt_esp32.h | |
parent | c8d9d2cb06333c627870b5d11a1572fcf9ee5c92 (diff) |
Fix for a bug that was limiting parallelism -- incorrectly managed mem blocks and max channel values
Diffstat (limited to 'src/platforms/esp/32/clockless_rmt_esp32.h')
-rw-r--r-- | src/platforms/esp/32/clockless_rmt_esp32.h | 61 |
1 files changed, 18 insertions, 43 deletions
diff --git a/src/platforms/esp/32/clockless_rmt_esp32.h b/src/platforms/esp/32/clockless_rmt_esp32.h index 2e723179..3a10f9ca 100644 --- a/src/platforms/esp/32/clockless_rmt_esp32.h +++ b/src/platforms/esp/32/clockless_rmt_esp32.h @@ -183,10 +183,9 @@ __attribute__ ((always_inline)) inline static uint32_t __clock_cycles() { #define FASTLED_RMT_MAX_CONTROLLERS 32 #endif -// -- Number of RMT channels to use (up to 8, but 4 by default) -// Redefine this value to 1 to force serial output +// -- Max RMT channel (default to 8) #ifndef FASTLED_RMT_MAX_CHANNELS -#define FASTLED_RMT_MAX_CHANNELS (8/FASTLED_RMT_MEM_BLOCKS) +#define FASTLED_RMT_MAX_CHANNELS 8 #endif class ESP32RMTController @@ -210,7 +209,7 @@ private: uint32_t mLastFill; // -- Pixel data - uint32_t * mPixelData; + uint8_t * mPixelData; int mSize; int mCur; @@ -225,18 +224,23 @@ private: uint16_t mBufferSize; // bytes int mCurPulse; + // -- These values need to be real variables, so we can access them + // in the cpp file + static int gMaxChannel; + static int gMemBlocks; + public: // -- Constructor // Mainly just stores the template parameters from the LEDController as // member variables. - ESP32RMTController(int DATA_PIN, int T1, int T2, int T3); + ESP32RMTController(int DATA_PIN, int T1, int T2, int T3, int maxChannel, int memBlocks); // -- Get max cycles per fill uint32_t IRAM_ATTR getMaxCyclesPerFill() const { return mMaxCyclesPerFill; } // -- Get or create the pixel data buffer - uint32_t * getPixelBuffer(int size_in_bytes); + uint8_t * getPixelBuffer(int size_in_bytes); // -- Initialize RMT subsystem // This only needs to be done once. The particular pin is not important, @@ -308,12 +312,11 @@ private: public: ClocklessController() - : mRMTController(DATA_PIN, T1, T2, T3) + : mRMTController(DATA_PIN, T1, T2, T3, FASTLED_RMT_MAX_CHANNELS, FASTLED_RMT_MEM_BLOCKS) {} void init() { - // mRMTController = new ESP32RMTController(DATA_PIN, T1, T2, T3); } virtual uint16_t getMaxRefreshRate() const { return 400; } @@ -329,43 +332,15 @@ protected: { // -- Make sure the buffer is allocated int size_in_bytes = pixels.size() * 3; - uint32_t * pData = mRMTController.getPixelBuffer(size_in_bytes); + uint8_t * pData = mRMTController.getPixelBuffer(size_in_bytes); - // -- Read out the pixel data using the pixel controller methods that - // perform the scaling and adjustments - int count = 0; - int which = 0; + // -- This might be faster while (pixels.has(1)) { - // -- Get the next four bytes of data - uint8_t four[4] = {0,0,0,0}; - for (int i = 0; i < 4; i++) { - switch (which) { - case 0: - four[i] = pixels.loadAndScale0(); - break; - case 1: - four[i] = pixels.loadAndScale1(); - break; - case 2: - four[i] = pixels.loadAndScale2(); - pixels.advanceData(); - pixels.stepDithering(); - break; - } - // -- Move to the next color - which++; - if (which > 2) which = 0; - - // -- Stop if there's no more data - if ( ! pixels.has(1)) break; - } - - // -- Pack the four bytes into a 32-bit value with the right bit order - uint8_t a = four[0]; - uint8_t b = four[1]; - uint8_t c = four[2]; - uint8_t d = four[3]; - pData[count++] = a << 24 | b << 16 | c << 8 | d; + *pData++ = pixels.loadAndScale0(); + *pData++ = pixels.loadAndScale1(); + *pData++ = pixels.loadAndScale2(); + pixels.advanceData(); + pixels.stepDithering(); } } |