FastLED 3.9.15
Loading...
Searching...
No Matches

◆ add() [2/8]

fl::ChannelPtr CFastLED::add ( const fl::ChannelConfig & config)
static

Add LED channel with runtime configuration (from ChannelConfig)

Creates and registers a Channel-based LED controller with runtime-configurable timing. Returns a shared_ptr for lifetime control - controller auto-removes on destruction.

Parameters
configChannel configuration (pin, timing, leds, rgb order, settings)
Returns
Shared pointer to Channel (extends CLEDController), or nullptr if unsupported
Note
Supported platforms: ESP32, ESP32-S2, ESP32-S3, ESP32-C3, ESP32-C6, ESP32-P4

Example:

auto channel = FastLED.add(config);
FastLED.show();
channel.reset(); // Destroy controller
#define NUM_LEDS
#define PIN_DATA
CFastLED FastLED
Global LED strip management instance.
CRGB * leds()
Get a pointer to led data for the first controller.
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NOEXCEPT
Fill a range of LEDs with a solid color.
Definition fill.cpp.hpp:9
constexpr EOrder RGB
Definition eorder.h:17
constexpr ChipsetTimingConfig makeTimingConfig() FL_NOEXCEPT
Convert compile-time CHIPSET type to runtime timing config.
@ Red
<div style='background:#FF0000;width:4em;height:4em;'></div>
Definition crgb.h:622
Configuration for a single LED channel.
Definition config.h:163

Definition at line 616 of file FastLED.cpp.hpp.

616 {
617 // Issue #2459: the non-template `FastLED.add(cfg)` path is the runtime-
618 // selection mode. To make sure `cfg.options.mBus` (or priority dispatch
619 // when `mBus == Bus::AUTO`) can actually find the requested driver at
620 // runtime, we eagerly enroll every driver available on this platform.
621 // That trades binary size for ergonomics — the user wanted runtime
622 // selection, so they get runtime selection.
623 //
624 // For minimum binary size, callers should use the compile-time path:
625 // FastLED.addLeds<CHIPSET, PIN, ORDER, fl::Bus::X>(leds, n);
626 // which ODR-uses only `BusTraits<X>::instancePtr()` and lets
627 // `--gc-sections` drop every other driver TU.
628 //
629 // The warning fires at most once per process (FL_WARN_ONCE) and can be
630 // disabled with `-DFASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING`.
631 #ifndef FASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING
632 FL_WARN_ONCE("FastLED.add(cfg): runtime-selection mode — enrolling every "
633 "available driver via fl::enableAllDrivers(). For minimum "
634 "binary size, prefer FastLED.addLeds<CHIPSET, PIN, ORDER, "
635 "fl::Bus::X>(leds, n) which links only the named driver. "
636 "Suppress this warning with -DFASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING.");
637 #endif
639
640 fl::ChannelManager& manager = fl::channelManager();
641 FL_ASSERT(manager.getDriverCount() > 0,
642 "No channel drivers available - channel API requires at least one registered driver");
643 auto channel = fl::Channel::create(config);
644 add(channel);
645 return channel;
646}
#define FL_ASSERT(x, MSG)
Definition assert.h:6
static void add(fl::ChannelPtr channel)
Add a Channel-based LED controller (from ChannelPtr)
static ChannelPtr create(const ChannelConfig &config)
Create a new channel with optional mBus driver pinning.
fl::size getDriverCount() const FL_NOEXCEPT
Get count of registered drivers (including unnamed ones)
#define FL_WARN_ONCE(X)
Definition log.h:278
ChannelManager & channelManager()
Get the global ChannelManager singleton instance.
void enableAllDrivers() FL_NOEXCEPT
Register every channel driver available on this platform with ChannelManager, restoring 3....

References add(), fl::channelManager(), fl::enableAllDrivers(), FL_ASSERT, FL_WARN_ONCE, and fl::ChannelManager::getDriverCount().

+ Here is the call graph for this function: