| 34 | /// for testing. It mirrors the architecture of ESP32's ClocklessIdf5. |
| 35 | template <int DATA_PIN, typename TIMING, EOrder RGB_ORDER = RGB, int XTRA0 = 0, bool FLIP = false, int WAIT_TIME = 0> |
| 36 | class ClocklessController : public CPixelLEDController<RGB_ORDER> { |
| 37 | private: |
| 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 | |
| 48 | public: |
| 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 | |
| 65 | protected: |
| 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 |
nothing calls this directly
no test coverage detected