Repository navigation
Description
Context
PRs #2448 (fl::enableAllDrivers()) and #2451 (FastLED.add<fl::Bus::X>(cfg)) each cover one of the two driver-dispatch modes called out in #2428. The two modes need to coexist cleanly; today they only partially do.
The two modes
Mode A — templated link-and-bind (compile-time, post #2451)
#include \"platforms/esp/32/drivers/rmt/rmt_5/bus_traits.h\"
auto ch = FastLED.add<fl::Bus::RMT>(cfg);- ODR-uses `BusTraitsfl::Bus::RMT::instancePtr()` → linker keeps the RMT driver TU.
- `static_assert` rejects `fl::Bus::AUTO` and any unsupported chipset combo.
- Affinity is set to `busName(B)` automatically.
- Use when: you want minimum binary size — only the bus you name is linked.
Mode B — runtime-only selection (after `enableAllDrivers()`, today)
#include \"fl/channels/all_drivers.h\"
void setup() {
FastLED.enableAllDrivers();
fl::ChannelOptions opts;
opts.mAffinity = \"RMT\"; // ← stringly typed
FastLED.add(fl::ChannelConfig(...)); // non-template, runtime dispatch
}- All drivers linked + registered with `ChannelManager`.
- Affinity selection is stringly typed today — typos compile silently and fall through to priority dispatch.
- Use when: you want the 3.10.3-style "any driver, any time" flexibility (third-party drivers, dynamic switching, MoonLight-style behaviour).
Gap
Mode B has no Bus-enum-typed entry point. Users can call `FastLED.add(cfg)` with a string affinity, but there is no:
- `FastLED.add(fl::Bus::RMT, cfg)` — non-templated, runtime bus selection by enum, without ODR-using `BusTraits<...>::instancePtr()`.
- `cfg.options.mAffinity = fl::Bus::RMT` — Bus-typed affinity field (the conversion called out under Phase 4 of feat(channels): compile-time Bus binding via templated ChannelConfig (eliminates Channel API binary bloat) #2428 — "Convert `mAffinity` from `fl::string` to `fl::Bus`").
The templated overload from #2451 looks like Mode B at the call site (`FastLED.addBus::RMT(cfg)`) but it is Mode A — it forces the RMT driver TU to link regardless of `enableAllDrivers()`. A user who already opted in to `enableAllDrivers()` cannot use the Bus enum to select a driver without also paying the per-bus link cost.
Proposed API
Solution 1 — add a runtime overload
namespace fl {
// Non-templated, Bus passed at runtime. Does NOT ODR-use BusTraits<B>::instancePtr().
// Requires the named driver to already be registered with ChannelManager
// (typically via enableAllDrivers() or explicit enableDrivers<...>()).
inline fl::ChannelPtr addWithAffinity(Bus b, ChannelConfig cfg) {
cfg.options.mAffinity = fl::string::from_literal(busName(b));
return Channel::create(cfg);
}
} // namespace fl
// On CFastLED:
static fl::ChannelPtr add(fl::Bus b, const fl::ChannelConfig& cfg); // non-templatedPros: minimal change, no field-type churn, clean dual-mode separation.
Solution 2 — typed `mAffinity` field
Convert `ChannelOptions::mAffinity` from `fl::string` to `fl::Bus`. This is Phase 4 cleanup work from #2428 and gives every call site a typed affinity, but it's a breaking change (the field is part of the public API).
Recommendation
Land Solution 1 as a follow-up to #2451 to close the immediate gap — additive, no breaking change. Solution 2 ships later as part of the broader Phase 4 cleanup.
Acceptance criteria
- Calling `FastLED.add(fl::Bus::RMT, cfg)` after `FastLED.enableAllDrivers()` dispatches to the RMT driver at runtime.
- Calling the same on a build that did NOT call `enableAllDrivers()` and did NOT include the RMT `bus_traits.h` produces a clean runtime warning (`getDriverByName("RMT")` returns null → existing manager fallback) but does NOT force the RMT TU to link. `--gc-sections` still drops drivers the user never named at link time.
- Calling `FastLED.addfl::Bus::RMT(cfg)` (templated, feat(channels): templated Channel::create<Bus B>() / FastLED.add<Bus B>() (#2428, closes #2167) #2451) is unchanged — it still ODR-uses and links the RMT TU.
- New test verifies both paths land on the same driver instance when `enableAllDrivers()` is in effect.
Related
- feat(channels): compile-time Bus binding via templated ChannelConfig (eliminates Channel API binary bloat) #2428 — parent (compile-time Bus binding via templated ChannelConfig)
- FastLED Channels API #2167 — closed by feat(channels): templated Channel::create<Bus B>() / FastLED.add<Bus B>() (#2428, closes #2167) #2451 (templated `create`)
- feat(channels): add fl::enableAllDrivers() one-shot driver enrollment (#2428) #2448 — `enableAllDrivers()` convenience (merged)
- feat(channels): templated Channel::create<Bus B>() / FastLED.add<Bus B>() (#2428, closes #2167) #2451 — `FastLED.addfl::Bus::X(cfg)` template (mergeable)
- feat(channels): templatize Channel<Bus, Chipset> + FastLED.add<B, Chipset>(cfg) (#2428) #2449 — full Phase 3b templatization (mergeable; supersedes parts of feat(channels): templated Channel::create<Bus B>() / FastLED.add<Bus B>() (#2428, closes #2167) #2451)
- feat(channels): gate driver aggregator + pre-bind remaining legacy clockless (Phase 5c of #2428) #2450 — Phase 5c aggregator gating (mergeable; complements both modes)
Activity
feat(channels): runtime FastLED.add(fl::Bus, cfg) dispatch (closes Fa…