Skip to content

feat(channels): runtime FastLED.add(fl::Bus, cfg) dispatch (closes #2453) - #2454

Merged
zackees merged 1 commit into
masterfrom
feat/channels-runtime-bus-dispatch-2453
May 11, 2026
Merged

zackees merged 1 commit into
masterfrom
feat/channels-runtime-bus-dispatch-2453

Conversation

@zackees

@zackees zackees commented May 11, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #2453. Adds the missing runtime counterpart to the templated `FastLED.add<fl::Bus B>(cfg)` form from #2451:

```cpp
#include "fl/channels/all_drivers.h"

void setup() {
FastLED.enableAllDrivers(); // PR #2448
FastLED.add(fl::Bus::RMT, cfg); // ← new: runtime dispatch by enum
}
```

API Bus chosen Driver TU linked when
`FastLED.addBus::RMT(cfg)` (templated, PR #2451) at compile time the call site names `Bus::RMT`
`FastLED.add(Bus::RMT, cfg)` (this PR) at runtime something else in the build named `Bus::RMT` (e.g. `enableAllDrivers()`)

What changed

  • New `static fl::ChannelPtr add(fl::Bus, fl::ChannelConfig)` member on `CFastLED` in `src/FastLED.h`.
  • Sets `cfg.options.mAffinity = fl::busName(b)` so `ChannelManager` dispatches by name (the strings match each driver's `getName()` exactly via the table in `bus.h`).
  • `Bus::AUTO` clears `mAffinity` so the manager falls back to priority dispatch — same contract as not setting an affinity at all.

Why this preserves the binary-bloat fix

The implementation deliberately does not name `BusTraits::instance()` or `instancePtr()`. That means this overload contributes zero per-call-site linker keep-alive. Sketches that don't otherwise reference a bus's traits still let `--gc-sections` drop the driver — the binary-bloat fix from #2420 / #2421 is preserved end to end.

The driver gets linked only if something else in the build names that bus:

Tests

Three new host-side cases in `tests/fl/channels/channel.cpp`:

  • `FastLED.add(Bus::STUB, cfg)` lands on the STUB driver (verified via `channel->getEngineName()` after `showLeds()`).
  • The overload overwrites prior `mAffinity` strings.
  • `FastLED.add(Bus::AUTO, cfg)` clears affinity → priority-dispatch fallback (channel still binds to a registered driver on the host).

Test plan

Reviewer

Code-reviewed by the c-cpp-expert-agent before commit. Verified:

  • No ODR-use of `BusTraits::instance/instancePtr` (binary-bloat fix preserved).
  • `fl::busName(b)` returns static-storage string literals (safe for `from_literal`).
  • `Bus::AUTO` mapping is consistent with the legacy empty-affinity contract.
  • Overload resolution unambiguous against the six other `CFastLED::add` overloads (unique 2-arg signature, `Bus` first param).
  • `FL_NOEXCEPT` annotation added for consistency with the templated counterpart at L877.

Related

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a new channel configuration method supporting runtime bus selection, enabling explicit driver specification with automatic fallback to compatible drivers.
  • Tests

    • Added comprehensive test coverage for the new runtime bus selection functionality across multiple configuration scenarios.

Review Change Stack

)

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]>
@coderabbitai

coderabbitai Bot commented May 11, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b8825253-b31c-4218-8908-647a0867c44a

📥 Commits

Reviewing files that changed from the base of the PR and between 3ff64f7 and 161f215.

📒 Files selected for processing (2)
  • src/FastLED.h
  • tests/fl/channels/channel.cpp

📝 Walkthrough

Walkthrough

A new CFastLED::add(fl::Bus, fl::ChannelConfig) static method is added to the Channel API, enabling runtime bus selection. The method derives and writes channel affinity from the provided Bus value or clears it when Bus is AUTO, then forwards to the existing add(config) implementation. Three test cases verify explicit bus binding, affinity overwriting, and AUTO mode behavior.

Changes

Runtime Bus Dispatch API

Layer / File(s) Summary
API Declaration
src/FastLED.h
New static add(fl::Bus b, fl::ChannelConfig config) overload that clears affinity when b == AUTO, otherwise sets affinity via busName(b), then forwards to add(config).
Runtime Dispatch Test Coverage
tests/fl/channels/channel.cpp
Three test cases verify explicit Bus::STUB selection binds the correct driver, the overload overwrites incorrect pre-set affinity, and Bus::AUTO clears affinity to allow fallback to eligible drivers.

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • FastLED/FastLED#2453: Implements the same non-templated runtime Bus-based dispatch overload with identical affinity-setting logic and test coverage.
  • FastLED/FastLED#2428: Related design discussion proposing Bus-driven add() variants for channel creation.

Possibly related PRs

  • FastLED/FastLED#2451: Adds templated compile-time FastLED.add<Bus>() overload alongside runtime dispatch logic for the same Channel API.
  • FastLED/FastLED#2429: Introduces the fl::Bus enum and runtime bus-based dispatch infrastructure that this PR depends on.

Poem

🐰 A rabbit hops with joy today,
For buses now can find their way!
Runtime routes, no templates bound,
New channels twirl all around. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(channels): runtime FastLED.add(fl::Bus, cfg) dispatch (closes #2453)' accurately and specifically describes the main change: adding a runtime dispatch overload to the FastLED.add() method that accepts a Bus parameter and ChannelConfig.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/channels-runtime-bus-dispatch-2453

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Channel API: dual-mode dispatch — templated link-and-bind AND runtime-only selection after enableAllDrivers()

1 participant