Skip to content

Channel API: collapse to non-template FastLED.add(), Bus-typed affinity, addLeds<..., fl::Bus> trailing parameter #2459

Closed

Description

@zackees

Context

After #2451 / #2454 / #2456 landed, the Channel API has three templated entry points doing almost the same job:

Template Asserts Sets affinity Bus::AUTO allowed?
`Channel::create(ChannelConfig)` (#2451) `BusSupports<B, ANY>` yes no (`static_assert`)
`TypedChannel<B, Chipset>::create(ChannelConfigOf)` (#2449) `BusSupports<B, Chipset>` (stricter) no yes (resolves via `DefaultBus`)
`FastLED.add(ChannelConfig)` / `FastLED.add<B, Chipset>(ChannelConfigOf)` forwards mixed mixed

This is a real SSOT violation: each template independently does the `BusTraits::instancePtr()` ODR-use + `static_assert` dance, and they don't even agree on whether `AUTO` is legal or whether the affinity gets set.

Direction

Collapse to a single non-template `FastLED.add(cfg)` user-facing API; move `Bus` selection out of the templates and into the runtime config.

Required changes

  1. Bus-typed affinity field. Convert `ChannelOptions::mAffinity` from `fl::string` to `fl::Bus mBus` (default `fl::Bus::AUTO`). This is the Phase 4 cleanup listed in feat(channels): compile-time Bus binding via templated ChannelConfig (eliminates Channel API binary bloat) #2428's "Deletions / simplifications" table.

  2. Non-template FastLED.add(). Remove the templated `FastLED.add(cfg)` and `FastLED.add<B = AUTO, Chipset>(ChannelConfigOf)` overloads. The user-facing surface is just:

    FastLED.add(cfg);                       // dispatches by cfg.options.mBus (default AUTO -> priority)
    FastLED.add(fl::Bus::RMT, cfg);         // runtime-Bus convenience (sets cfg.options.mBus then add)
  3. Runtime miss diagnostic. If `cfg.options.mBus` names a driver that is NOT in `ChannelManager`'s registered table, emit one-shot `FL_ERROR` listing the missing driver and the remediations:

    • `fl::enableDriversfl::Bus::X()` (selective opt-in for one bus)
    • `fl::enableAllDrivers()` (every driver on this platform)
    • `addLeds<..., fl::Bus::X>(...)` (legacy API; sets the Bus AND triggers linker keep-alive at compile time)
      Then default to `AUTO` / priority dispatch. The infrastructure for this already exists from feat(channels): one-shot affinity-miss diagnostic + normalized driver names (closes #2455) #2456; this issue swaps the input from `fl::string` to `fl::Bus` and updates the message.
  4. Legacy addLeds<> Bus support. Add a trailing default template parameter to every `FastLED.addLeds<>` variant:

    template<ESPIChipsets CHIPSET, fl::u8 DATA_PIN, fl::u8 CLOCK_PIN,
             fl::EOrder RGB_ORDER, fl::u32 SPI_DATA_RATE,
             fl::Bus B = fl::Bus::AUTO>
    static ::CLEDController& addLeds(CRGB* data, int nLedsOrOffset, int nLedsIfOffset = 0);
    
    template<template<fl::u8 DATA_PIN, fl::EOrder RGB_ORDER> class CHIPSET,
             fl::u8 DATA_PIN, fl::EOrder RGB_ORDER,
             fl::Bus B = fl::Bus::AUTO>
    static ::CLEDController& addLeds(CRGB* data, int nLedsOrOffset, int nLedsIfOffset = 0);

    When the user writes `addLeds<WS2812, 4, GRB, fl::Bus::RMT>(leds, n)`, the function sets `cfg.options.mBus = fl::Bus::RMT` AND ODR-uses `BusTraitsfl::Bus::RMT::instancePtr()` inside the body, so the linker keeps the RMT TU. The default `fl::Bus::AUTO` preserves all existing call sites byte-for-byte.

  5. Template removals. `Channel::create(ChannelConfig)` and `FastLED.add(...)` go away. `TypedChannel<B, Chipset>::create()` and the new `addLeds<..., fl::Bus B>` trailing parameter become the two remaining compile-time `Bus` entry points.

  6. README catch-up. The `src/fl/channels/README.md` examples and the API surface section need a sweep — every `FastLED.addBus::X(cfg)` example must turn into either `FastLED.add(cfg)` with `cfg.options.mBus = fl::Bus::X`, OR `FastLED.add(fl::Bus::X, cfg)`, OR `addLeds<..., fl::Bus::X>(...)`. The dual-mode dispatch section needs rewriting.

Acceptance criteria

  • `ChannelOptions::mBus` is `fl::Bus` (not `fl::string`); no remaining `mAffinity` field.
  • No templated `FastLED.add<>()` overloads. `FastLED.add(cfg)` and `FastLED.add(fl::Bus, cfg)` are the only public `add` shapes that take a Bus.
  • `addLeds<..., fl::Bus B>` exists; default `fl::Bus::AUTO` keeps every existing call site working.
  • Calling `FastLED.add(cfg)` with `cfg.options.mBus = fl::Bus::RMT` on a build that hasn't registered RMT prints exactly one `FL_ERROR` with the three remediation options listed above, falls through to priority dispatch.
  • README is rewritten to reflect the new single-entry API.
  • Full cpp test suite still passes.

Related

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