Repository navigation
feat(channels): non-template FastLED.add() + typed mBus + remove mAffinity (closes #2459) - #2461
Conversation
…inity (closes #2459) Collapses the Channel API's compile-time selection layer per the design direction in #2459. Previously there were THREE templated entry points doing similar work (Channel::create<B>, FastLED.add<B>, FastLED.add<B,Chipset>), plus a runtime FastLED.add(Bus, cfg), plus a stringly-typed mAffinity field on ChannelOptions. After this PR: * FastLED.add(cfg) is the ONLY user-facing add overload. Non-template. * cfg.options.mBus (fl::Bus enum, default Bus::AUTO) selects the driver. * fl::TypedChannel<B, Chipset>::create(cfg) is the SINGLE template entry point for compile-time link-and-bind (the addLeds<..., fl::Bus B> trailing-template-arg path is planned in #2460). * mAffinity string field on ChannelOptions is gone. Production changes: * src/fl/channels/options.h - delete mAffinity, add mBus (fl::Bus). * src/fl/channels/channel.h / .cpp.hpp - drop mAffinity member; add mBus + mBusWarned; delete templated Channel::create<B>(); simplify dispatch to read mBus only. * src/fl/channels/bus.h - drop the now-unused isKnownBusName predicate (since dispatch only sees typed-Bus misses, the message is always the actionable hint - no need to distinguish "third-party name" branch). * src/FastLED.h - delete the three templated add<> overloads (templated add<B>, templated add<B,Chipset>(ChannelConfigOf), and runtime add(Bus, cfg)). Document mBus in the FastLED.enableAllDrivers() example. * src/FastLED.cpp.hpp - non-template FastLED.add(cfg) now auto-calls fl::enableAllDrivers() so any runtime mBus value can dispatch; emits one-shot FL_WARN_ONCE explaining the binary-size trade-off. Suppress with -DFASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING. Diagnostic message: the typed-Bus miss in Channel::showPixels still emits the one-shot FL_ERROR with the two currently-shipping remediations (enableDrivers<Bus::X>() and enableAllDrivers()). The third remediation (addLeds<..., Bus::X>) is deferred to #2460 because it requires touching 23 legacy addLeds template variants and a design choice between the Channel-API route vs the legacy-CLEDController pre-bind route. Tests: * 11 fastled_core tests + 3 channel tests + 11 driver tests + 2 spi tests had mAffinity = "MOCK_X" lines deleted. Each test that registers a single mock now relies on priority dispatch (mock is the only registered driver after clearAllDrivers); tests that need to force a specific driver among several use setExclusiveDriver(name). * Two channel.cpp tests testing the dual mAffinity/mBus precedence got deleted; two got rewritten to use mBus only. * One fastled_core test (low-priority-binding via affinity) lost half its coverage - the setExclusiveDriver path persists state between tests and breaks the next case. Captured as a documented coverage gap. A future clearExclusiveDriver() addition can restore it. * examples/AutoResearch/AutoResearchRemote.cpp converts its string driver-name lookup to an inline fl::Bus mapping. Linker contract: nothing changed at the binary-bloat layer. enableDrivers and addLeds<...> remain the only compile-time linker-keep-alive paths; FastLED.add(cfg) explicitly trades binary size for ergonomics by auto-enabling all drivers (the FL_WARN_ONCE makes this trade-off visible). Verified: 304/304 cpp tests pass, bash lint clean. Closes #2459. Follow-up: #2460 (addLeds<..., fl::Bus B>). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
📝 WalkthroughWalkthroughThis PR migrates the FastLED channel driver selection model from string-based ChangesString mAffinity to Typed mBus Migration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
examples/AutoResearch/AutoResearchRemote.cpp (1)
653-669: ⚡ Quick winConsider refactoring the manual string-to-Bus mapping.
The manual
if-elsechain mapping driver names tofl::Busenum values duplicates knowledge that already exists in thebusName()helper. This creates a maintenance burden — if thefl::Busenum is extended, this code must be updated manually.A more maintainable approach would be to iterate through all
fl::Busenum values and usebusName()to match the driver name, eliminating the duplication.♻️ Proposed refactor using busName() iteration
fl::ChannelOptions opts; - { - const fl::string& n = de.name; - if (n == "RMT") opts.mBus = fl::Bus::RMT; - else if (n == "PARLIO") opts.mBus = fl::Bus::PARLIO; - else if (n == "SPI") opts.mBus = fl::Bus::SPI; - else if (n == "I2S") opts.mBus = fl::Bus::I2S; - else if (n == "I2S_SPI") opts.mBus = fl::Bus::I2S_SPI; - else if (n == "LCD_RGB") opts.mBus = fl::Bus::LCD_RGB; - else if (n == "LCD_SPI") opts.mBus = fl::Bus::LCD_SPI; - else if (n == "LCD_CLOCKLESS") opts.mBus = fl::Bus::LCD_CLOCKLESS; - else if (n == "UART") opts.mBus = fl::Bus::UART; - else if (n == "FLEX_IO") opts.mBus = fl::Bus::FLEX_IO; - else if (n == "OBJECT_FLED") opts.mBus = fl::Bus::OBJECT_FLED; - else if (n == "BIT_BANG") opts.mBus = fl::Bus::BIT_BANG; - else if (n == "STUB") opts.mBus = fl::Bus::STUB; - // else: leave Bus::AUTO; priority dispatch will pick. - } + // Iterate Bus enum values and match against busName() + opts.mBus = fl::Bus::AUTO; // default + for (fl::u8 b = static_cast<fl::u8>(fl::Bus::RMT); + b <= static_cast<fl::u8>(fl::Bus::STUB); ++b) { + fl::Bus bus = static_cast<fl::Bus>(b); + if (de.name == fl::busName(bus)) { + opts.mBus = bus; + break; + } + }This eliminates 17 lines and automatically handles future
Busenum additions.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/AutoResearch/AutoResearchRemote.cpp` around lines 653 - 669, The long if-else chain mapping de.name to opts.mBus duplicates fl::Bus knowledge; replace it by iterating over fl::Bus enum values, calling busName(busVal) and comparing to the string n (de.name), and set opts.mBus to the matching busVal (leave Bus::AUTO if none match); use the existing helper busName() to drive the mapping so future fl::Bus additions are handled automatically — update the block around de.name/opts.mBus to perform this enum iteration and comparison instead of the manual checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@examples/AutoResearch/AutoResearchRemote.cpp`:
- Around line 653-669: The long if-else chain mapping de.name to opts.mBus
duplicates fl::Bus knowledge; replace it by iterating over fl::Bus enum values,
calling busName(busVal) and comparing to the string n (de.name), and set
opts.mBus to the matching busVal (leave Bus::AUTO if none match); use the
existing helper busName() to drive the mapping so future fl::Bus additions are
handled automatically — update the block around de.name/opts.mBus to perform
this enum iteration and comparison instead of the manual checks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: bcb83261-7b55-4dcd-b7a5-8a4d9d43cae8
📒 Files selected for processing (13)
examples/AutoResearch/AutoResearchRemote.cppsrc/FastLED.cpp.hppsrc/FastLED.hsrc/fl/channels/README.mdsrc/fl/channels/bus.hsrc/fl/channels/channel.cpp.hppsrc/fl/channels/channel.hsrc/fl/channels/options.htests/fastled_core.cpptests/fl/channels/channel.cpptests/fl/channels/channel_typed.cpptests/fl/channels/driver.cpptests/fl/channels/spi_channel.cpp
💤 Files with no reviewable changes (2)
- tests/fl/channels/spi_channel.cpp
- tests/fl/channels/driver.cpp
After #2461 merged (non-template FastLED.add + typed mBus + mAffinity removal), four small spots in the channels README still described the old shape. This pass aligns the wording with what shipped: * "Passing fl::Bus::AUTO clears the affinity" -> "skips the pinning step" (matches the now-typed mBus field, not the deleted mAffinity string). * Dispatch-flow bullet list under "Engine selection" rewritten to show that Channel::showPixels derives the bus key from cfg.options.mBus via busName(mBus) before passing it to selectDriverForChannel. Fixed the "Affinity-miss diagnostic" cross-reference to match the actual section title "Bus-miss diagnostic". * Reference -> channel.h line dropped the false "non-template create(cfg) and templated create<Bus B>(cfg) factories" claim. Only the non- template form survives; compile-time bus pinning lives on TypedChannel. * Reference -> options.h line replaced "affinity" with "mBus" and added "rgbw" to the field summary. No code changes; README only. bash lint clean. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
) (#2465) Adds an optional trailing `fl::Bus B = fl::Bus::AUTO` template parameter to every `FastLED.addLeds<>` variant. `B = AUTO` (the default) leaves existing call sites byte-for-byte unchanged; `B != AUTO` ODR-uses `fl::BusTraits<B>::instance` via a new `fl::busKeepAlive<B>()` helper so `--gc-sections` retains the named driver TU. For the `FASTLED_SPI_USES_CHANNEL_API` SPI variants (which already construct a `ChannelConfig`), the body also sets `config.options.mBus = B` so the channel routes through the named driver at runtime. Legacy non-Channel-API controllers keep their platform-default routing and rely on linker keep-alive alone — for full runtime routing through a specific Bus, prefer `FastLED.add(cfg)` with `cfg.options.mBus = B`. The runtime miss diagnostic in `channel.cpp.hpp` now lists three remediations: `fl::enableDrivers<>()`, `FastLED.enableAllDrivers()`, and the new `FastLED.addLeds<..., fl::Bus::X>(...)` shape. Tests cover the helper plus one clockless (WS2812) and one SPI (APA102) variant in `tests/fl/channels/bus_traits.cpp`, with default- AUTO regression guards. Verification: - bash test --cpp: 303/303 host tests pass - bash lint: clean - bash compile uno --examples Blink: AVR C++11 path compiles - ESP32 platform compile blocked by unrelated toolchain cache breakage (missing Arduino.h / WString.h / soc_caps.h in the framework-arduinoespressif32 cache); CHANNEL_API SPI path body change is textually a single-line write to the existing `mBus` field added in #2461 Closes #2460. Refs #2459, #2428. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Closes #2459. Collapses the Channel API's compile-time selection layer to one template entry point and one runtime entry point, per the SSOT direction from the design discussion.
Before (three templates + a runtime overload + a string field):
After (one of each):
Behaviour changes
Non-template `FastLED.add(cfg)`
Auto-enrolls every driver on the platform via `fl::enableAllDrivers()` so any runtime `cfg.options.mBus` value can be dispatched.
Emits one-shot `FL_WARN_ONCE` explaining the binary-size trade-off:
Suppress macro: `-DFASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING`.
Typed `mBus` dispatch
Removed APIs
Custom / mock driver binding
The pre-PR pattern was `opts.mAffinity = "MOCK"; FastLED.add(cfg)`. With no string field, custom drivers bind by:
Tests
Diff stats
```
13 files changed, 189 insertions(+), 501 deletions(-)
```
Net -312 lines — the simplification is real.
Test plan
Related
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
Bug Fixes
API Changes
Documentation
Tests