File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed
components/FastLED-idf/platforms/esp/32 Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -684,14 +684,20 @@ void IRAM_ATTR ESP32RMTController::fillNext()
684684// This function is only used when the built-in RMT driver is chosen
685685void ESP32RMTController::initPulseBuffer (int size_in_bytes)
686686{
687- if (mBuffer == 0 ) {
688- // -- Each byte has 8 bits, each bit needs a 32-bit RMT item
689- mBufferSize = size_in_bytes * 8 * 4 ;
690687
691- mBuffer = (rmt_item32_t *) calloc ( mBufferSize , sizeof (rmt_item32_t ));
692-
693- }
694688 mCurPulse = 0 ;
689+
690+ // maybe we already have a buffer of the right size, it's likely
691+ if (mBuffer && (mBufferSize == size_in_bytes * 8 ))
692+ return ;
693+
694+ if (mBuffer ) { free (mBuffer ); mBuffer = 0 ; }
695+
696+ // -- Each byte has 8 bits, each bit needs a 32-bit RMT item
697+ mBufferSize = size_in_bytes * 8 ;
698+
699+ mBuffer = (rmt_item32_t *) calloc ( mBufferSize , sizeof (rmt_item32_t ) );
700+
695701}
696702
697703// -- Convert a byte into RMT pulses
@@ -700,7 +706,7 @@ void ESP32RMTController::convertByte(uint32_t byteval)
700706{
701707 // -- Write one byte's worth of RMT pulses to the big buffer
702708 byteval <<= 24 ;
703- for (register uint32_t j = 0 ; j < 8 ; j++) {
709+ for (uint32_t j = 0 ; j < 8 ; j++) {
704710 mBuffer [mCurPulse ] = (byteval & 0x80000000L ) ? mOne : mZero ;
705711 byteval <<= 1 ;
706712 mCurPulse ++;
You can’t perform that action at this time.
0 commit comments