Repository navigation
feat(channels): unify singletons + opt-in disable macro (Phase 5a of #2428) - #2438
Conversation
…2428) Two changes, both backward-compatible (default behavior unchanged): 1) Unify legacy auto-init with the new BusTraits singletons. Pre-Phase-5a, `addParlioIfPossible()` etc. in channel_manager_esp32.cpp.hpp constructed fresh driver instances via `fl::make_shared<ChannelDriverPARLIO>()`, distinct from the singleton owned by `BusTraits<Bus::PARLIO>`. If a user called `fl::enableDrivers<fl::Bus::PARLIO>()` after the legacy auto-init, a *second* PARLIO driver was constructed which then tried to claim the PARLIO peripheral concurrently. Phase 4 documented this caveat; Phase 5a fixes it. All 9 `addXxxIfPossible()` helpers now delegate to `BusTraits<Bus::X>::instancePtr()`. The legacy and new APIs share the same singleton — `mgr.getDriverByName("PARLIO")` returns the same `shared_ptr` whether you reach it via auto-init or explicit `enableDrivers`. Same change applied to `src/platforms/stub/init_channel_driver.h`. The unified-SPI hardware adapter (SpiHw1 via SpiChannelEngineAdapter) is intentionally *not* unified -- it has no Bus enum value because it wraps a runtime-discovered set of controllers. Stays on its existing path. 2) Add `FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY` opt-in macro. When defined to 1, `initChannelDrivers()` becomes a no-op (on both ESP32 and stub). Users opting in must call `fl::enableDrivers<fl::Bus::X...>()` explicitly. This is the pathway that lets the linker drop unused driver TUs (#2420 binary-bloat fix). Default 0 -- behavior unchanged. Phase 5b will: - Flip the default to 1. - Retarget the legacy `addLeds<>` clockless path to call `BusTraits<DefaultBus<ClocklessChipset>::value>::instance()` directly, bypassing `ChannelManager::selectDriverForChannel()` so no manager drivers need to be registered for legacy sketches. - Gate the `_build.cpp.hpp` driver aggregator behind the same flag so unused driver TUs don't link. 3) New regression test: tests/fl/channels/bus_traits.cpp adds "Legacy initChannelDrivers() and enableDrivers<Bus::STUB>() share singleton" which would have failed pre-5a (legacy registered a different instance than the BusTraits singleton). Verifies pointer identity in both directions. Verification: - bash lint clean. - bash test --cpp passes 303/303. - New singleton-identity test passes. - Default behavior is byte-for-byte unchanged on ESP32 and stub auto-init paths. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughThis PR unifies ESP32 and stub channel driver initialization by replacing direct driver construction with ChangesDriver Registration via BusTraits
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Phase 5a of #2428. Two changes, both backward-compatible (default behavior unchanged):
FASTLED_DISABLE_LEGACY_DRIVER_REGISTRYopt-in macro — sets up Phase 5b (the actual binary-bloat fix). Default 0, no behavior change.Change 1: Singleton unification
Pre-Phase-5a,
addParlioIfPossible()etc. inchannel_manager_esp32.cpp.hppconstructed fresh driver instances viafl::make_shared<ChannelDriverPARLIO>(), distinct from the singleton owned byBusTraits<Bus::PARLIO>. Callingfl::enableDrivers<fl::Bus::PARLIO>()after the legacy auto-init created a second PARLIO driver that tried to claim the PARLIO peripheral concurrently.All 9
addXxxIfPossible()helpers now delegate toBusTraits<Bus::X>::instancePtr(). The legacy and new APIs share the same singleton —mgr.getDriverByName(\"PARLIO\")returns the sameshared_ptrwhether you reach it via auto-init or explicitenableDrivers.Same change applied to
src/platforms/stub/init_channel_driver.h.The unified-SPI hardware adapter (
SpiHw1viaSpiChannelEngineAdapter) is intentionally not unified — it has noBusenum value because it wraps a runtime-discovered set of controllers. Stays on its existing path.Change 2:
FASTLED_DISABLE_LEGACY_DRIVER_REGISTRYWhen defined to 1,
initChannelDrivers()becomes a no-op (on both ESP32 and stub). Users opting in must callfl::enableDrivers<fl::Bus::X...>()explicitly. This is the pathway that lets the linker drop unused driver TUs (#2420 binary-bloat fix). Default 0 — behavior unchanged in this PR.Phase 5b (next, not in this PR) will
FASTLED_DISABLE_LEGACY_DRIVER_REGISTRYto 1.addLeds<>clockless path to callBusTraits<DefaultBus<ClocklessChipset>::value>::instance()directly, bypassingChannelManager::selectDriverForChannel()so no manager drivers need to be registered for legacy sketches._build.cpp.hppdriver aggregator behind the same flag so unused driver TUs don't link.New regression test
tests/fl/channels/bus_traits.cppadds\"Legacy initChannelDrivers() and enableDrivers<Bus::STUB>() share singleton\"— would have failed pre-5a (legacy registered a different instance than the BusTraits singleton). Verifies pointer identity in both directions.Verification
bash lintclean.bash test --cpppasses 303/303.Test plan
FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY=1and measure binary size.Related
enableDrivers<>API; this PR removes its singleton-duplication caveat.🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
Refactor