FastLED 3.10.10
Loading...
Searching...
No Matches

◆ add() [2/11]

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
CFastLED FastLED
Global LED strip management instance.
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
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 825 of file FastLED.cpp.hpp.

825 {
826 // Runtime-selection mode links no driver by itself. Drivers come from
827 // FastLED.enable<fl::Bus::X>() bindings (constructed here, on first use),
828 // from FastLED.enableAllDrivers() (the catch-all), or from anything else
829 // that registered one. A channel no driver can serve gets a warning, not
830 // every driver on the platform.
831 const fl::Bus bus = config.options.mBus;
832 const fl::u8 which = config.options.mBusWhich;
834
835 fl::ChannelManager& manager = fl::ChannelManager::registry();
836 const bool spi = config.getChipset().is<fl::SpiChipsetConfig>();
837 bool served = false;
838 if (bus != fl::Bus::AUTO) {
840 fl::busDriverName(bus, which, spi))) != nullptr;
841 } else {
842 // AUTO needs a registered driver for this chipset family, not just
843 // any driver: an SPI-only binding cannot serve a clockless channel.
844 for (const fl::DriverInfo& info : manager.getDriverInfos()) {
845 auto driver = manager.findDriverByName(info.name);
846 if (driver && (spi ? driver->getCapabilities().supportsSpi
847 : driver->getCapabilities().supportsClockless)) {
848 served = true;
849 break;
850 }
851 }
852 }
853 if (!served && bus == fl::Bus::AUTO && fl::DriverBindings::instance().empty()) {
854 // Legacy (3.10.9) compatibility: the sketch never opted into any
855 // driver, so bind the platform default driver for this chipset
856 // family, as 3.10.9's add(cfg) did. Only the default clockless and
857 // default SPI drivers are referenced here (not every driver), so
858 // explicit enable<Bus>() sketches keep most of the link-time saving.
859 // Platforms without a DefaultBus specialization bind nothing here.
860 const bool bound = spi
862 : fl::detail::bindDefaultDriver<fl::ClocklessChipset>();
863 if (bound) {
864 for (const fl::DriverInfo& info : manager.getDriverInfos()) {
865 auto driver = manager.findDriverByName(info.name);
866 if (driver && (spi ? driver->getCapabilities().supportsSpi
867 : driver->getCapabilities().supportsClockless)) {
868 served = true;
869 break;
870 }
871 }
872 }
873 }
874 if (!served) {
875 FL_WARN_EVERY(1000, "FastLED.add(cfg): no channel driver is enabled for bus '"
876 << fl::busName(bus) << "'. Call FastLED.enable<fl::Bus::"
877 << fl::busName(bus) << ">() before add() to link only that "
878 "driver, or FastLED.enableAllDrivers() to link every driver.");
879 }
880 auto channel = fl::Channel::create(config);
881 add(channel);
882 return channel;
883}
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.
static ChannelManager & registry() FL_NO_EXCEPT
Get the singleton WITHOUT registering platform default drivers.
fl::shared_ptr< IChannelDriver > findDriverByName(const fl::string &name) const FL_NO_EXCEPT
Silent counterpart to getDriverByName().
fl::span< const DriverInfo > getDriverInfos() const FL_NO_EXCEPT
Get full state of all registered drivers.
bool bind(Bus bus, u8 which) FL_NO_EXCEPT
Bind (register) every node matching bus/which, or every node when bus is Bus::AUTO.
static DriverBindings & instance() FL_NO_EXCEPT
static string from_literal(const char *literal) FL_NO_EXCEPT
#define FL_WARN_EVERY(MILLIS,...)
Definition log.h:442
bool bindDefaultDriver() FL_NO_EXCEPT
Bind the platform default driver for Chipset, if one exists.
unsigned char u8
Definition stdint.h:132
const char * busName(Bus b, fl::u8 which=0) FL_NO_EXCEPT
Definition bus.h:176
const char * busDriverName(Bus b, fl::u8 which=0, bool spi=false) FL_NO_EXCEPT
Concrete ChannelManager driver name for a portable bus.
Definition bus.h:193
Bus
Portable public bus selector.
Definition bus.h:31
@ AUTO
Definition bus.h:32
const ChipsetVariant & getChipset() const FL_NO_EXCEPT
Get the chipset configuration variant.
Definition config.h:233
ChannelOptions options
Optional channel settings (correction, temperature, dither, rgbw, affinity)
Definition config.h:277

References add(), fl::AUTO, fl::DriverBindings::bind(), fl::detail::bindDefaultDriver(), fl::busDriverName(), fl::busName(), fl::ChannelManager::findDriverByName(), FL_NO_EXCEPT, FL_WARN_EVERY, fl::string::from_literal(), fl::ChannelManager::getDriverInfos(), fl::DriverBindings::instance(), and fl::ChannelManager::registry().

+ Here is the call graph for this function: