Skip to content

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

Closed

Description

@zackees

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:

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-templated

Pros: 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

Activity

  1. added
    type: feature
    area: core
    on May 11, 2026
  2. added a commit that references this issue on May 12, 2026
    55182fe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coretype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions