Repository navigation
feat(channels): templatize Channel<Bus, Chipset> + FastLED.add<B, Chipset>(cfg) (#2428) - #2449
Conversation
…pset>(cfg) (#2428) Phase 3b of issue #2428. Adds compile-time bus/chipset enforcement to the Channel API without disturbing any existing callers: - New `fl::ChannelConfigOf<Chipset>` template — strongly-typed channel configuration that carries the chipset family as a type parameter. Implicitly converts to/from the existing non-template `fl::ChannelConfig` so all current call sites (`Channel::create(cfg)`, the non-template `FastLED.add(cfg)` overloads, the 16+ examples/tests using `fl::ChannelConfig`) keep working unchanged. - New `fl::TypedChannel<Bus, Chipset>` template — thin facade around the existing non-template `fl::Channel` runtime object. `Channel::create()` is guarded by a `FL_STATIC_ASSERT(BusSupports<B, Chipset>::value)` so routing a clockless config to an SPI-only bus (or vice versa) is a compile error. Naming an undefined `BusTraits<Bus::X>` on the current platform produces a clean "implicit instantiation of undefined template" diagnostic. - New `FastLED.add<fl::Bus = AUTO, typename Chipset>(const ChannelConfigOf<...>&)` template overload. `Bus::AUTO` resolves to `DefaultBus<Chipset>::value` per platform. The `static_assert` rejects nonsense combinations at instantiation time before the call reaches the runtime manager. - Tests in `tests/fl/channels/channel_typed.cpp` cover: * Positive — host-default path (`Bus::AUTO` → `Bus::STUB`) and explicit `Bus::STUB` both resolve and produce a working `ChannelPtr`. * Negative — `FL_STATIC_ASSERT` proofs that `BusSupports<Bus::STUB, SpiChipsetConfig>::value` and `BusSupports<Bus::PARLIO, SpiChipsetConfig>::value` are `false`, which is exactly the predicate guarding the `FastLED.add<>()` static_assert. Compiling a real `FastLED.add<Bus::STUB>(spi_cfg)` would fail at the static_assert site, so the test verifies the predicate without inducing a build failure. * Implicit conversion `ChannelConfigOf<ClocklessChipset>` → `ChannelConfig` preserves chipset/pin/order/leds. * `ChannelConfigOf<ClocklessChipset>` deduced via CTAD. Backwards compatibility: - `addLeds<WS2812, 4, GRB>(leds, n)` unchanged — does not touch this path. - `Channel::create(const ChannelConfig&)` unchanged. - `FastLED.add(const ChannelConfig&)` (non-template) unchanged. - `ClocklessIdf5 : public Channel` (and any other Channel subclass) unchanged because the non-template `fl::Channel` class is preserved. - `IChannel` ABC unchanged (still the polymorphic anchor). - `FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY` semantics unchanged (Phase 5c). Verified: `bash test fl_channels_channel_typed --cpp` and the broader `fl_channels_*` + `fastled_core` test suites pass, lint clean, `bash compile wasm --examples Blink` succeeds. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR introduces compile-time typed bus and chipset binding for FastLED's channel API. It adds ChangesTyped Bus/Chipset Binding API
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 3b of #2428 — adds compile-time bus/chipset enforcement to the Channel API without disturbing any existing callers.
fl::ChannelConfigOf<Chipset>template — strongly-typed channel configuration that carries the chipset family as a type parameter. Implicitly converts to/from the existing non-templatefl::ChannelConfigso all current call sites keep working unchanged.fl::TypedChannel<Bus, Chipset>template — thin facade around the existing non-templatefl::Channelruntime object.create()is guarded byFL_STATIC_ASSERT(BusSupports<B, Chipset>::value)so a mismatched bus/chipset combination is a compile error rather than a runtime warning. Naming an undefinedBusTraits<Bus::X>on the current platform produces a clean "implicit instantiation of undefined template" diagnostic.FastLED.add<fl::Bus = AUTO, typename Chipset>(const ChannelConfigOf<...>&)template overload.Bus::AUTOresolves toDefaultBus<Chipset>::valueper platform. Thestatic_assertrejects nonsense combinations at instantiation time, before the call reaches the runtime manager.Compile-time enforcement examples that now hold:
Backwards compatibility
addLeds<WS2812, 4, GRB>(leds, n)unchanged.Channel::create(const ChannelConfig&)unchanged.FastLED.add(const ChannelConfig&)(non-template) unchanged.ClocklessIdf5 : public Channel(and any other Channel subclass) unchanged because the non-templatefl::Channelis preserved.IChannelABC unchanged (still the polymorphic anchor forChannelEvents).FASTLED_DISABLE_LEGACY_DRIVER_REGISTRYsemantics unchanged (Phase 5c handles that separately).Test plan
TypedChannel<Bus::AUTO, ClocklessChipset>::createresolves to hostBus::STUBand produces a working channelFastLED.add<Bus::STUB>(clockless_cfg)compiles and binds the channel (pin survives the round trip)FastLED.add(cfg)(defaultBus::AUTO) resolves toDefaultBus<ClocklessChipset> == Bus::STUBChannelConfigOf<ClocklessChipset>→ChannelConfigpreserves chipset/pin/order/ledsFL_STATIC_ASSERTproofs thatBusSupports<Bus::STUB, SpiChipsetConfig>::valueandBusSupports<Bus::PARLIO, SpiChipsetConfig>::valuearefalse— the same predicate that guards theFastLED.add<>()static_assertfl_channels_bus_traits,fl_channels_channel,fl_channels_channel_manager,fl_channels_all_drivers,fl_channels_spi,fl_channels_data,fl_channels_driver,fl_channels_manager,fl_channels_wave8,fl_channels_wave8_spi,fl_channels_validation,fastled_corebash lintclean for all changed filesbash compile wasm --examples Blinksucceeds — the WASM build still includes the templated APIs throughFastLED.hCloses a portion of #2428 (Phase 3b of N). Phases 1, 2, 3a, 4, 5a, 5b are already merged. Phase 5c (binary-size opt-in macro semantics) is handled separately.
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests