FastLED 3.10.8
Loading...
Searching...
No Matches

◆ add() [2/9]

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 handle for later inspection, reconfiguration, or removal. FastLED retains its own reference until remove(channel) is called.

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();
FastLED.remove(channel); // Unregister and release FastLED's reference
#define NUM_LEDS
#define PIN_DATA
CRGB * leds() FL_NO_EXCEPT
Get a pointer to led data for the first controller.
void fill_solid(CRGB *targetArray, int numToFill, const CRGB &color) FL_NO_EXCEPT
Fill a range of LEDs with a solid color.
Definition fill.cpp.hpp:10
constexpr EOrder RGB
Definition eorder.h:17
CFastLED FastLED
Global LED strip management instance.
constexpr ChipsetTimingConfig makeTimingConfig() FL_NO_EXCEPT
Convert compile-time CHIPSET type to runtime timing config.
@ Red
<div style='background:#FF0000;width:4em;height:4em;'></div>
Definition crgb.h:629
Configuration for a single LED channel.
Definition config.h:167

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

817 {
818 // Issue #2459: the non-template `FastLED.add(cfg)` path is the runtime-
819 // selection mode. To make sure `cfg.options.mBus` (or priority dispatch
820 // when `mBus == Bus::AUTO`) can actually find the requested driver at
821 // runtime, we eagerly enroll every driver available on this platform.
822 // That trades binary size for ergonomics — the user wanted runtime
823 // selection, so they get runtime selection.
824 //
825 // For minimum binary size, callers should use the compile-time path:
826 // FastLED.addLeds<CHIPSET, PIN, ORDER, fl::Bus::X>(leds, n);
827 // which ODR-uses only `BusTraits<X>::instancePtr()` and lets
828 // `--gc-sections` drop every other driver TU.
829 //
830 // The warning fires at most once per process (FL_WARN_ONCE) and can be
831 // disabled with `-DFASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING`.
832 #ifndef FASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING
833 FL_WARN_ONCE("FastLED.add(cfg): runtime-selection mode — enrolling every "
834 "available driver via fl::enableAllDrivers(). For minimum "
835 "binary size, prefer FastLED.addLeds<CHIPSET, PIN, ORDER, "
836 "fl::Bus::X>(leds, n) which links only the named driver. "
837 "Suppress this warning with -DFASTLED_SUPPRESS_RUNTIME_DRIVER_WARNING.");
838 #endif
840
841 fl::ChannelManager& manager = fl::channelManager();
842 FL_ASSERT(manager.getDriverCount() > 0,
843 "No channel drivers available - channel API requires at least one registered driver");
844 auto channel = fl::Channel::create(config);
845 add(channel);
846 return channel;
847}
#define FL_ASSERT(x, MSG)
Definition assert.h:6
static void add(fl::ChannelPtr channel) FL_NO_EXCEPT
Add a Channel-based LED controller (from ChannelPtr)
static ChannelPtr create(const ChannelConfig &config) FL_NO_EXCEPT
Create a new channel with optional mBus driver pinning.
fl::size getDriverCount() const FL_NO_EXCEPT
Get count of registered drivers (including unnamed ones)
#define FL_WARN_ONCE(...)
Definition log.h:439
void enableAllDrivers() FL_NO_EXCEPT
Register every channel driver available on this platform with ChannelManager, restoring 3....
ChannelManager & channelManager() FL_NO_EXCEPT
Get the global ChannelManager singleton instance.

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

+ Here is the call graph for this function: