Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2df65a3

Browse files
committed
fixes #2084, reverts worker pools for rmt
1 parent 4f76784 commit 2df65a3

File tree

6 files changed

+27
-1027
lines changed

6 files changed

+27
-1027
lines changed

src/platforms/esp/32/rmt_5/idf5_rmt.cpp

Lines changed: 25 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#endif
1010

1111
#include "idf5_rmt.h"
12-
#include "rmt_worker_pool.h"
1312

1413
#include "freertos/FreeRTOS.h"
1514
#include "freertos/task.h"
@@ -18,64 +17,30 @@
1817
#include "fl/convert.h" // for convert_fastled_timings_to_timedeltas(...)
1918
#include "fl/namespace.h"
2019
#include "strip_rmt.h"
21-
#include "platforms/esp/32/esp_log_control.h"
22-
#include "esp_log.h"
2320

2421

2522
#define IDF5_RMT_TAG "idf5_rmt.cpp"
2623

27-
// Worker pool configuration
28-
// Enable worker pool by default - can be disabled via compile flag
29-
#ifndef FASTLED_RMT5_DISABLE_WORKER_POOL
30-
#define FASTLED_RMT5_USE_WORKER_POOL 1
31-
#else
32-
#define FASTLED_RMT5_USE_WORKER_POOL 0
33-
#endif
34-
35-
// Runtime worker pool control (can be overridden in constructor)
36-
#ifndef FASTLED_RMT5_FORCE_LEGACY_MODE
37-
#define FASTLED_RMT5_FORCE_LEGACY_MODE 0
38-
#endif
39-
4024
namespace fl {
4125

26+
4227
RmtController5::RmtController5(int DATA_PIN, int T1, int T2, int T3, RmtController5::DmaMode dma_mode)
43-
: mPin(DATA_PIN), mT1(T1), mT2(T2), mT3(T3), mDmaMode(dma_mode)
44-
, mWorkerConfig(nullptr)
45-
, mRegisteredWithPool(false)
46-
, mUseWorkerPool(FASTLED_RMT5_USE_WORKER_POOL && !FASTLED_RMT5_FORCE_LEGACY_MODE) {
47-
48-
if (mUseWorkerPool) {
49-
// Register with worker pool
50-
RmtWorkerPool::getInstance().registerController(this);
51-
mRegisteredWithPool = true;
52-
FASTLED_ESP_LOGD(IDF5_RMT_TAG, "RmtController5 registered with worker pool (pin %d)", mPin);
53-
} else {
54-
FASTLED_ESP_LOGD(IDF5_RMT_TAG, "RmtController5 using legacy mode (pin %d)", mPin);
55-
}
28+
: mPin(DATA_PIN), mT1(T1), mT2(T2), mT3(T3), mDmaMode(dma_mode) {
5629
}
5730

5831
RmtController5::~RmtController5() {
59-
if (mRegisteredWithPool) {
60-
RmtWorkerPool::getInstance().unregisterController(this);
61-
}
62-
6332
if (mLedStrip) {
6433
delete mLedStrip;
6534
}
66-
67-
if (mWorkerConfig) {
68-
delete mWorkerConfig;
69-
}
7035
}
7136

72-
IRmtStrip::DmaMode RmtController5::convertDmaMode(DmaMode dma_mode) {
37+
static IRmtStrip::DmaMode convertDmaMode(RmtController5::DmaMode dma_mode) {
7338
switch (dma_mode) {
74-
case DMA_AUTO:
39+
case RmtController5::DMA_AUTO:
7540
return IRmtStrip::DMA_AUTO;
76-
case DMA_ENABLED:
41+
case RmtController5::DMA_ENABLED:
7742
return IRmtStrip::DMA_ENABLED;
78-
case DMA_DISABLED:
43+
case RmtController5::DMA_DISABLED:
7944
return IRmtStrip::DMA_DISABLED;
8045
default:
8146
FL_ASSERT(false, "Invalid DMA mode");
@@ -84,141 +49,42 @@ IRmtStrip::DmaMode RmtController5::convertDmaMode(DmaMode dma_mode) {
8449
}
8550

8651
void RmtController5::loadPixelData(PixelIterator &pixels) {
87-
if (mUseWorkerPool) {
88-
// Worker pool mode - store pixel data in persistent buffer
89-
storePixelData(pixels);
90-
} else {
91-
// Legacy mode - use direct RMT strip
92-
const bool is_rgbw = pixels.get_rgbw().active();
93-
if (!mLedStrip) {
94-
uint16_t t0h, t0l, t1h, t1l;
95-
convert_fastled_timings_to_timedeltas(mT1, mT2, mT3, &t0h, &t0l, &t1h, &t1l);
96-
mLedStrip = IRmtStrip::Create(
97-
mPin, pixels.size(),
98-
is_rgbw, t0h, t0l, t1h, t1l, 280,
99-
convertDmaMode(mDmaMode));
100-
101-
} else {
102-
FASTLED_ASSERT(
103-
mLedStrip->numPixels() == pixels.size(),
104-
"mLedStrip->numPixels() (" << mLedStrip->numPixels() << ") != pixels.size() (" << pixels.size() << ")");
105-
}
52+
const bool is_rgbw = pixels.get_rgbw().active();
53+
if (!mLedStrip) {
54+
uint16_t t0h, t0l, t1h, t1l;
55+
convert_fastled_timings_to_timedeltas(mT1, mT2, mT3, &t0h, &t0l, &t1h, &t1l);
56+
mLedStrip = IRmtStrip::Create(
57+
mPin, pixels.size(),
58+
is_rgbw, t0h, t0l, t1h, t1l, 280,
59+
convertDmaMode(mDmaMode));
10660

107-
if (is_rgbw) {
108-
uint8_t r, g, b, w;
109-
for (uint16_t i = 0; pixels.has(1); i++) {
110-
pixels.loadAndScaleRGBW(&r, &g, &b, &w);
111-
mLedStrip->setPixelRGBW(i, r, g, b, w);
112-
pixels.advanceData();
113-
pixels.stepDithering();
114-
}
115-
} else {
116-
uint8_t r, g, b;
117-
for (uint16_t i = 0; pixels.has(1); i++) {
118-
pixels.loadAndScaleRGB(&r, &g, &b);
119-
mLedStrip->setPixel(i, r, g, b);
120-
pixels.advanceData();
121-
pixels.stepDithering();
122-
}
123-
}
124-
}
125-
}
126-
127-
void RmtController5::showPixels() {
128-
if (mUseWorkerPool) {
129-
// Worker pool mode - execute coordinated draw cycle
130-
executeWithWorkerPool();
13161
} else {
132-
// Legacy mode - direct async draw
133-
FL_ASSERT(mLedStrip != nullptr, "RMT strip not initialized");
134-
mLedStrip->drawAsync();
62+
FASTLED_ASSERT(
63+
mLedStrip->numPixels() == pixels.size(),
64+
"mLedStrip->numPixels() (" << mLedStrip->numPixels() << ") != pixels.size() (" << pixels.size() << ")");
13565
}
136-
}
137-
138-
void RmtController5::storePixelData(PixelIterator& pixels) {
139-
const bool is_rgbw = pixels.get_rgbw().active();
140-
const int bytesPerPixel = is_rgbw ? 4 : 3;
141-
const int bufferSize = pixels.size() * bytesPerPixel;
142-
143-
// Resize buffer if needed
144-
mPixelBuffer.resize(bufferSize);
145-
146-
// Update worker config with current pixel data info
147-
initializeWorkerConfig();
148-
mWorkerConfig->ledCount = pixels.size();
149-
mWorkerConfig->isRgbw = is_rgbw;
150-
151-
// Copy pixel data to persistent buffer
152-
uint8_t* bufPtr = mPixelBuffer.data();
15366
if (is_rgbw) {
154-
while (pixels.has(1)) {
155-
uint8_t r, g, b, w;
67+
uint8_t r, g, b, w;
68+
for (uint16_t i = 0; pixels.has(1); i++) {
15669
pixels.loadAndScaleRGBW(&r, &g, &b, &w);
157-
*bufPtr++ = r;
158-
*bufPtr++ = g;
159-
*bufPtr++ = b;
160-
*bufPtr++ = w;
70+
mLedStrip->setPixelRGBW(i, r, g, b, w); // Tested to be faster than memcpy of direct bytes.
16171
pixels.advanceData();
16272
pixels.stepDithering();
16373
}
16474
} else {
165-
while (pixels.has(1)) {
166-
uint8_t r, g, b;
75+
uint8_t r, g, b;
76+
for (uint16_t i = 0; pixels.has(1); i++) {
16777
pixels.loadAndScaleRGB(&r, &g, &b);
168-
*bufPtr++ = r;
169-
*bufPtr++ = g;
170-
*bufPtr++ = b;
78+
mLedStrip->setPixel(i, r, g, b); // Tested to be faster than memcpy of direct bytes.
17179
pixels.advanceData();
17280
pixels.stepDithering();
17381
}
17482
}
175-
}
176-
177-
void RmtController5::executeWithWorkerPool() {
178-
RmtWorkerPool& pool = RmtWorkerPool::getInstance();
179-
180-
if (pool.canStartImmediately(this)) {
181-
// Async path - return immediately
182-
pool.startControllerImmediate(this);
183-
} else {
184-
// This controller is queued - must wait for worker
185-
pool.startControllerQueued(this);
186-
}
187-
}
188-
189-
void RmtController5::initializeWorkerConfig() const {
190-
if (!mWorkerConfig) {
191-
mWorkerConfig = new RmtWorkerConfig();
192-
193-
// Convert FastLED timings to time deltas
194-
uint16_t t0h, t0l, t1h, t1l;
195-
convert_fastled_timings_to_timedeltas(mT1, mT2, mT3, &t0h, &t0l, &t1h, &t1l);
196-
197-
// Initialize configuration
198-
mWorkerConfig->pin = mPin;
199-
mWorkerConfig->ledCount = 0; // Will be set in storePixelData
200-
mWorkerConfig->isRgbw = false; // Will be set in storePixelData
201-
mWorkerConfig->t0h = t0h;
202-
mWorkerConfig->t0l = t0l;
203-
mWorkerConfig->t1h = t1h;
204-
mWorkerConfig->t1l = t1l;
205-
mWorkerConfig->reset = 280;
206-
mWorkerConfig->dmaMode = convertDmaMode(mDmaMode);
207-
mWorkerConfig->interruptPriority = 3;
208-
}
209-
}
210-
211-
const RmtWorkerConfig& RmtController5::getWorkerConfig() const {
212-
initializeWorkerConfig();
213-
return *mWorkerConfig;
214-
}
21583

216-
const uint8_t* RmtController5::getPixelBuffer() const {
217-
return mPixelBuffer.data();
21884
}
21985

220-
size_t RmtController5::getBufferSize() const {
221-
return mPixelBuffer.size();
86+
void RmtController5::showPixels() {
87+
mLedStrip->drawAsync();
22288
}
22389

22490
} // namespace fl

src/platforms/esp/32/rmt_5/idf5_rmt.h

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77
#include "pixel_iterator.h"
88
#include "fl/stdint.h"
99
#include "fl/namespace.h"
10-
#include "fl/vector.h"
11-
#include "strip_rmt.h"
1210

1311
namespace fl {
1412

15-
struct RmtWorkerConfig;
13+
class IRmtStrip;
1614

1715
// NOTE: LED_STRIP_RMT_DEFAULT_MEM_BLOCK_SYMBOLS controls the memory block size.
1816
// See codebase.
@@ -39,29 +37,12 @@ class RmtController5
3937

4038
void loadPixelData(PixelIterator &pixels);
4139
void showPixels();
42-
43-
// Worker pool integration methods
44-
const RmtWorkerConfig& getWorkerConfig() const;
45-
const uint8_t* getPixelBuffer() const;
46-
size_t getBufferSize() const;
47-
void executeWithWorkerPool();
4840

4941
private:
5042
int mPin;
5143
int mT1, mT2, mT3;
52-
IRmtStrip *mLedStrip = nullptr; // Legacy mode - will be nullptr when using worker pool
44+
IRmtStrip *mLedStrip = nullptr;
5345
DmaMode mDmaMode;
54-
55-
// Worker pool integration
56-
mutable RmtWorkerConfig* mWorkerConfig; // Cached worker configuration
57-
fl::vector<uint8_t> mPixelBuffer; // Persistent pixel buffer for worker pool
58-
bool mRegisteredWithPool;
59-
bool mUseWorkerPool; // Enable/disable worker pool usage
60-
61-
// Helper methods
62-
void initializeWorkerConfig() const;
63-
void storePixelData(PixelIterator& pixels);
64-
static IRmtStrip::DmaMode convertDmaMode(DmaMode dma_mode);
6546
};
6647

6748
} // namespace fl

0 commit comments

Comments
 (0)