Repository navigation
feat(channels): templated Channel::create<Bus B>() / FastLED.add<Bus B>() (#2428, closes #2167) - #2451
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds compile-time bus-pinned channel creation: ChangesCompile-Time Bus-Pinned Channel Creation
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 |
…B>() (#2428, closes #2167) Issue #2167 asked for `Channel::create<EngineType>(config)` to be a real template; #2428 generalized that into Phase 3b's compile-time bus selection. This commit adds both APIs as additive overloads — no breaking change. #include "platforms/esp/32/drivers/rmt/rmt_5/bus_traits.h" auto ch = fl::Channel::create<fl::Bus::RMT>(cfg); // ...or: auto ch = FastLED.add<fl::Bus::RMT>(cfg); The template: - `static_assert`s `B != Bus::AUTO` (use the non-template form for default) and that `BusSupports<B, *>` has a specialization (so unsupported buses are a compile-time error rather than a runtime warning). - ODR-uses `BusTraits<B>::instancePtr()` so `--gc-sections` keeps only the named driver's TU — the per-bus binary-bloat fix from #2420 / #2421. - Derives the affinity string from a compile-time `busName(B)` switch so typos (`Bus::RTM`) become "no such enumerator" instead of silent runtime fall-through. `busName(Bus)` is the single source of truth mapping each enum value to the exact string returned by the driver's `getName()`. Drift is guarded by an `FL_STATIC_ASSERT` on the last enumerator's value, and at test time by `ChannelManager::getDriverByName(busName(B))` having to find the singleton. Tests in `tests/fl/channels/channel.cpp` cover both overloads on the host stub bus, including the affinity overwrite, the channel-registration path, and driver-identity match against `BusTraits<Bus::STUB>::instance()`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
3349091 to
685da3c
Compare
) (#2454) Sister API to the templated FastLED.add<fl::Bus B>(cfg) from #2451. The templated form ODR-uses BusTraits<B>::instancePtr() at the call site to link the named driver — that is the binary-bloat fix from #2420/#2421. But that mode is wrong for sketches that have already called fl::enableAllDrivers() and want runtime dispatch by enum without the per- call-site linker keep-alive. The new non-template overload: FastLED.add(fl::Bus::RMT, cfg); - Sets cfg.options.mAffinity = fl::busName(b) so ChannelManager dispatches by name (matches each driver's getName() exactly via the bus.h table). - Maps fl::Bus::AUTO to "clear affinity" so the manager falls back to priority dispatch — same contract as not setting an affinity at all. - Does NOT name BusTraits<B>::instance, so the driver TU is only linked when something else in the build named it (enableAllDrivers, the templated form, or a per-driver bus_traits.h include + enableDrivers). Tests cover: - Runtime dispatch lands on the named driver (Bus::STUB on host). - Overload overwrites prior mAffinity strings. - Bus::AUTO clears affinity and falls through to priority dispatch. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…bleAllDrivers + diagnostics) (#2458) The channels README hadn't been updated since #2435 (Phase 3a) while the real API surface grew through #2437/2438/2441/2448/2449/2450/2451/2454/ 2456. This refresh aligns the docs with what the code actually does today. Reviewed in three independent sub-agent passes: - Pass 1 (broad accuracy): added the new dual-mode dispatch architecture section (compile-time `fl::Bus` binding vs runtime `ChannelManager`), the templated `Channel::create<Bus B>(cfg)` / `FastLED.add<Bus B>(cfg)` examples, the `ChannelConfigOf<Chipset>` + `TypedChannel<Bus, Chipset>` Phase 3b API, the `enableDrivers<>()` / `enableAllDrivers()` opt-in registry, the `FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY` binary-size macro, the one-shot affinity-miss diagnostic (#2456), and the driver-name rename callout (BITBANG -> BIT_BANG, FLEXIO -> FLEX_IO, OBJECTFLED -> OBJECT_FLED). Updated the registration example to the current 2-arg `addDriver(priority, driver)` signature; the name comes from `driver->getName()`. Expanded the Reference section to list the new headers (`bus.h`, `bus_traits.h`, `all_drivers.h`, `channel_typed.h`, `ichannel.h`) and to include `findDriverByName` / `clearAllDrivers` on `manager.h`. - Pass 2 (independent verification): fixed two real bugs the first pass left in place. (a) DMA wait-pattern snippet referenced a nonexistent `EngineState::READY` — corrected to `IChannelDriver::DriverState::READY`. (b) "Overriding Engine Selection" examples called a nonexistent `FastLED.setDriverPriority(...)` — the method lives only on `ChannelManager::setDriverPriority`; rewrote both call sites to `fl::ChannelManager::instance().setDriverPriority(...)` with an explanatory comment about the API asymmetry vs the `setDriverEnabled` / `setExclusiveDriver` helpers that DO have CFastLED forwarders. - Pass 3 (polish): added missing file-scope `CRGB leds[60];` declarations to two example snippets that referenced `leds` without anchoring it. Inserted an "alternatives, not a sequence" clarifier above the three Override Methods so a careful reader doesn't think calling all three in order is intended. Verified the `Bus::AUTO` story end-to-end: `FastLED.add<fl::Bus::AUTO>(cfg)` never appears as an example (the static_assert from #2451 rejects it); only `FastLED.add(cfg)` (implicit default via `ChannelConfigOf`) and `FastLED.add(fl::Bus::AUTO, cfg)` (runtime form, clears affinity) are shown. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
…default-as-opt-in) Closes the binary-bloat half of #2421 by making the previously opt-in "no driver auto-registration" behavior the default and removing the macro entirely. Drivers now link only when their `BusTraits<Bus::X>::instance` is named via: - Legacy `addLeds<>` Phase 5b pre-bind (platform-default driver) - `addLeds<..., fl::Bus::X>` trailing template parameter (#2460) - `fl::TypedChannel<Bus::X, Chipset>::create(cfg)` (#2451) - `fl::enableDrivers<fl::Bus::X, ...>()` opt-in - `FastLED.enableAllDrivers()` (3.10.3-style universal enrollment) - `FastLED.setExclusiveDriver<fl::Bus::X>()` (NEW template overload) Stock `examples/Blink/Blink.ino` on ESP32-S3 drops from ~776 KB to 657 KB with no source change or build flag needed. Only `ChannelEngineRMT` (the platform default) is linked; UART / LCD_SPI / LCD_CLOCKLESS / I2S / SPI driver TUs are all garbage-collected. `setExclusiveDriver` is now also exposed as a template overload that links + registers a non-default driver at priority above the platform default. The string-form `setExclusiveDriver(const char*)` is kept for mock/test scenarios (drivers already registered with the manager that aren't in the `fl::Bus` enum). Test harness changes: - `tests/doctest_main.cpp` calls `fl::enableAllDrivers()` at startup so unit tests that depend on runtime driver dispatch keep working. - `tests/fastled_core.cpp` "Legacy API 4 parallel strips" test rewritten to use the Channel API (`FastLED.add(cfg)`) instead of the legacy `addLeds<>` path; the legacy path now pre-binds to the platform default and bypasses the manager, so the mock-driver pattern only works via Channel API. - `tests/platforms/shared/active_strip_data` updated to probe the `BusTraits<Bus::STUB>::instancePtr()` singleton directly rather than expecting auto-registration. - `examples/AutoResearch/AutoResearch.ino` calls `FastLED.enableAllDrivers()` in `setup()` for its driver-enumeration flow. Closes #2421 (binary-bloat half). Refs #2428. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…default-as-opt-in) (#2469) Closes the binary-bloat half of #2421 by making the previously opt-in "no driver auto-registration" behavior the default and removing the macro entirely. Drivers now link only when their `BusTraits<Bus::X>::instance` is named via: - Legacy `addLeds<>` Phase 5b pre-bind (platform-default driver) - `addLeds<..., fl::Bus::X>` trailing template parameter (#2460) - `fl::TypedChannel<Bus::X, Chipset>::create(cfg)` (#2451) - `fl::enableDrivers<fl::Bus::X, ...>()` opt-in - `FastLED.enableAllDrivers()` (3.10.3-style universal enrollment) - `FastLED.setExclusiveDriver<fl::Bus::X>()` (NEW template overload) Stock `examples/Blink/Blink.ino` on ESP32-S3 drops from ~776 KB to 657 KB with no source change or build flag needed. Only `ChannelEngineRMT` (the platform default) is linked; UART / LCD_SPI / LCD_CLOCKLESS / I2S / SPI driver TUs are all garbage-collected. `setExclusiveDriver` is now also exposed as a template overload that links + registers a non-default driver at priority above the platform default. The string-form `setExclusiveDriver(const char*)` is kept for mock/test scenarios (drivers already registered with the manager that aren't in the `fl::Bus` enum). Test harness changes: - `tests/doctest_main.cpp` calls `fl::enableAllDrivers()` at startup so unit tests that depend on runtime driver dispatch keep working. - `tests/fastled_core.cpp` "Legacy API 4 parallel strips" test rewritten to use the Channel API (`FastLED.add(cfg)`) instead of the legacy `addLeds<>` path; the legacy path now pre-binds to the platform default and bypasses the manager, so the mock-driver pattern only works via Channel API. - `tests/platforms/shared/active_strip_data` updated to probe the `BusTraits<Bus::STUB>::instancePtr()` singleton directly rather than expecting auto-registration. - `examples/AutoResearch/AutoResearch.ino` calls `FastLED.enableAllDrivers()` in `setup()` for its driver-enumeration flow. Closes #2421 (binary-bloat half). Refs #2428. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Adds the Bus-templated APIs explicitly called out in issue #2428's Phase 3b and closes #2167 (which asked for `Channel::create(config)` to be a real template). Additive — no breaking changes to existing call sites.
```cpp
#include "platforms/esp/32/drivers/rmt/rmt_5/bus_traits.h"
auto ch = fl::Channel::createfl::Bus::RMT(cfg);
// or:
auto ch = FastLED.addfl::Bus::RMT(cfg);
// Mismatches caught at compile time:
FastLED.addfl::Bus::RTM(cfg); // ❌ no enumerator
FastLED.addfl::Bus::AUTO(cfg); // ❌ static_assert: use non-template form
FastLED.addfl::Bus::SOME_HYPOTHETICAL(cfg); // ❌ no BusSupports specialization
```
How it preserves the binary-bloat fix
The template body does `(void) BusTraits::instancePtr();`. That ODR-uses the singleton's storage, so `--gc-sections` keeps the driver's translation unit. Sketches that only ever name one `Bus::X` link only that one driver — the per-bus version of the fix from #2420 / #2421.
If the user calls `FastLED.addfl::Bus::RMT(cfg)` without including `platforms/esp/32/drivers/rmt/rmt_5/bus_traits.h`, the compile fails with `implicit instantiation of undefined template 'BusTraitsBus::RMT'`. That diagnostic IS the explicit opt-in.
What's in the PR
Test plan
Issue #2428 remaining items
Per the issue author's status comment, what's left after this merges:
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Tests