MCPcopy Create free account
hub / github.com/FastLED/FastLED / ClocklessController

Class ClocklessController

src/platforms/stub/clockless_channel_stub.h:36–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34/// for testing. It mirrors the architecture of ESP32's ClocklessIdf5.
35template <int DATA_PIN, typename TIMING, EOrder RGB_ORDER = RGB, int XTRA0 = 0, bool FLIP = false, int WAIT_TIME = 0>
36class ClocklessController : public CPixelLEDController<RGB_ORDER> {
37private:
38 // Channel data for transmission
39 ChannelDataPtr mChannelData;
40
41 // Channel driver reference (weak pointer for lifetime safety)
42 fl::weak_ptr<IChannelDriver> mDriver;
43
44 // LED capture tracker for simulation/testing
45 ActiveStripTracker mTracker;
46 fl::vector<u8> mCaptureData;
47
48public:
49 ClocklessController()
50 FL_NOEXCEPT {
51 // Create channel data with pin and timing configuration
52 ChipsetTimingConfig timing = makeTimingConfig<TIMING>();
53 mChannelData = ChannelData::create(DATA_PIN, timing);
54 // Phase 5b of #2428: pre-bind to the stub driver singleton so
55 // showPixels() bypasses ChannelManager entirely. Naming
56 // BusTraits<Bus::STUB>::instancePtr() here is the ODR-use that
57 // lets the linker keep ONLY the stub driver TU -- post-#2428
58 // drivers do not auto-register, so this pre-bind is what links
59 // the stub singleton.
60 mDriver = BusTraits<Bus::STUB>::instancePtr();
61 }
62
63 virtual void init() FL_NOEXCEPT override { }
64
65protected:
66 virtual void showPixels(PixelController<RGB_ORDER>& pixels) FL_NOEXCEPT override
67 {
68 // Phase 5b of #2428: use the pre-bound driver directly. Legacy
69 // `addLeds<>`-style controllers name `BusTraits<Bus::STUB>::instancePtr()`
70 // in their constructor so this is the platform-default stub driver.
71 // For runtime overrides, sketches use `FastLED.add(cfg)` (Channel API)
72 // with `cfg.options.mBus` -- the manager-driven Channel path stays.
73 fl::shared_ptr<IChannelDriver> driver = mDriver.lock();
74 if (!driver) {
75 FL_ERROR("ClocklessController(stub): No compatible driver found - cannot transmit");
76 return;
77 }
78
79 // Wait for previous transmission to complete and release buffer
80 // This prevents race conditions when show() is called faster than hardware can transmit
81 u32 startTime = fl::millis();
82 u32 lastWarnTime = startTime;
83 while (mChannelData->isInUse()) {
84 driver->poll(); // Keep polling until buffer is released
85
86 // Warn every second if still waiting (possible deadlock or hardware issue)
87 u32 elapsed = fl::millis() - startTime;
88 if (elapsed > 1000 && (fl::millis() - lastWarnTime) >= 1000) {
89 FL_WARN("ClocklessController(stub): Buffer still busy after " << elapsed << "ms total - possible deadlock or slow hardware");
90 lastWarnTime = fl::millis();
91 }
92 }
93

Callers

nothing calls this directly

Calls 12

RgbwInvalidClass · 0.85
isInUseMethod · 0.80
writeWS2812Method · 0.80
getDataMethod · 0.80
millisFunction · 0.50
lockMethod · 0.45
pollMethod · 0.45
clearMethod · 0.45
updateMethod · 0.45
getRgbwMethod · 0.45
enqueueMethod · 0.45

Tested by

no test coverage detected