1#define FASTLED_INTERNAL
5#if defined(NEED_CXX_BITS) && (defined(FL_IS_ESP32) || defined(FL_IS_ESP8266))
6#error FastLED #4994: NEED_CXX_BITS on ESP32/ESP8266 breaks thread-safe local statics with LTO
26#if SKETCH_HAS_LARGE_MEMORY
37#include "platforms/init.h"
40#include "platforms/is_platform.h"
46#ifndef MAX_CLED_CONTROLLERS
50#if defined(FL_IS_AVR_ATMEGA) && !defined(FL_IS_AVR_ATMEGA_328P)
51#define MAX_CLED_CONTROLLERS 16
53#define MAX_CLED_CONTROLLERS 8
56#define MAX_CLED_CONTROLLERS 64
61volatile fl::u32 fuckit;
65#ifndef FASTLED_NO_ATEXIT
66#define FASTLED_NO_ATEXIT 0
73#ifdef FASTLED_NEEDS_YIELD
74extern "C" void yield(
void) { }
81#if !FL_PLATFORM_HAS_TINY_MEMORY
130#if FL_COLOR_PIPELINE_SHARED
131const fl::FramePowerDispatch*& fl::activeFramePowerDispatch()
FL_NO_EXCEPT {
132 static const FramePowerDispatch* dispatch =
nullptr;
145 return (*
this)[0].size();
149 return (*
this)[0].leds();
155 int nOffset = (nLedsIfOffset > 0) ? nLedsOrOffset : 0;
156 int nLeds = (nLedsIfOffset > 0) ? nLedsIfOffset : nLedsOrOffset;
159 pLed->setLeds(data + nOffset, nLeds);
160 FastLED.setMaxRefreshRate(pLed->getMaxRefreshRate(),
true);
169#if FL_COLOR_PIPELINE_SHARED
173 return channel !=
nullptr ? channel->colorPipeline()
182 for (fl::size i = 0; i < registered.
size(); ++i) {
188 if (
spi ==
nullptr)
return policy;
189 switch (
spi->timing.chipset) {
203 spi->timing.chipset, profile !=
nullptr
226 if (chnls.has(channel)) {
229 chnls.push_back(channel);
248 auto clearFlag = [&flags](
ClearFlags flag) ->
bool {
250 flags =
static_cast<ClearFlags>(
static_cast<fl::u32
>(flags) & ~static_cast<fl::u32>(flag));
260 FastLED.mNPowerData = 0xFFFFFFFF;
261 FastLED.mLastRequestedScale = 255;
289 for (
auto& channel : channelsCopy) {
349#if SKETCH_HAS_LARGE_MEMORY
354 if (elapsed >= minMicros) {
357#if SKETCH_HAS_LARGE_MEMORY
358 const fl::u32 remaining = minMicros - elapsed;
398 ControllerIndex
length = 0;
454 if(pCur ==
nullptr) {
471#if FL_COLOR_PIPELINE_SHARED
472 const fl::FramePowerDispatch* dispatch = fl::activeFramePowerDispatch();
534#ifndef FASTLED_ACCURATE_CLOCK
571 min_field < 1 ? 1 : (min_field > 31 ? 31 : min_field);
579#if FL_COLOR_PIPELINE_SHARED
580 if (apply_limiter &&
mPPowerFunc && fl::activeFramePowerDispatch()) {
581 bool managed =
false;
583 if (p->getEnabled() && fl::channelColorPipeline(*p)) {
592 const fl::u32 mcu_mW = plan.
mcu_mW;
598 fl::u32 controllable_power_mW = 0;
599 fl::u32 dither_reserve_power_mW = 0;
611 const fl::u32 dark_mW = dark_mW_per_led *
static_cast<fl::u32
>(
leds.size());
613 controllable_power_mW += unscaled_mW > dark_mW ? unscaled_mW - dark_mW : 0;
617#if !FL_PLATFORM_HAS_TINY_MEMORY
638 if (effective_brightness != 0) {
698#if SKETCH_HAS_LARGE_MEMORY
699 typedef fl::u32 frame_ms_t;
702 typedef fl::u16 frame_ms_t;
704 static frame_ms_t lastframe = 0;
706 if(br++ >= nFrames) {
707 const frame_ms_t sample =
static_cast<frame_ms_t
>(
fl::millis());
708 frame_ms_t now =
static_cast<frame_ms_t
>(sample - lastframe);
712 mNFPS =
static_cast<fl::u16
>((
static_cast<fl::u32
>(br) * 1000) / now);
731 return FastLED.getBrightness();
743 FastLED.setMaxPowerInVoltsAndMilliamps(volts, milliamps);
748 FastLED.setMaxPowerInMilliWatts(powerInmW);
831 const fl::Bus bus = config.options.mBus;
832 const fl::u8 which = config.options.mBusWhich;
846 if (driver && (spi ? driver->getCapabilities().supportsSpi
847 : driver->getCapabilities().supportsClockless)) {
860 const bool bound = spi
866 if (driver && (spi ? driver->getCapabilities().supportsSpi
867 : driver->getCapabilities().supportsClockless)) {
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.");
880 auto channel = fl::Channel::create(config);
889 for (
const auto& config : configs) {
900 for (
const auto& config : configs) {
909 channels.reserve(multiConfig.mChannels.size());
911 for (
const auto& configPtr : multiConfig.mChannels) {
927#if defined(FL_IS_ESP32) || defined(FL_IS_ESP8266)
928#error FastLED #4994: NEED_CXX_BITS on ESP32/ESP8266 breaks thread-safe local statics with LTO
932 #if !defined(FL_IS_ESP8266) && !defined(FL_IS_ESP32) && !defined(ARDUINO)
933 extern "C" void __cxa_pure_virtual (
void) {}
939 __extension__
typedef int __guard __attribute__((mode(__DI__)));
941 extern "C" int __cxa_guard_acquire (__guard *)
FL_LINK_WEAK;
942 extern "C" void __cxa_guard_release (__guard *)
FL_LINK_WEAK;
943 extern "C" void __cxa_guard_abort (__guard *)
FL_LINK_WEAK;
945 extern "C" int __cxa_guard_acquire (__guard *g)
947 return !*(
char *)(g);
950 extern "C" void __cxa_guard_release (__guard *g)
955 extern "C" void __cxa_guard_abort (__guard *)
969 #if FASTLED_HAS_ENGINE_EVENTS
#define MAX_CLED_CONTROLLERS
FL_LINK_WEAK int atexit(void(*)())
void * pSmartMatrix
Pointer to the matrix object when using the Smart Matrix Library.
fl::u8 get_brightness() FL_NO_EXCEPT
static void * gControllersData[MAX_CLED_CONTROLLERS]
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
int noise_max
Unused value.
static void throttleToMaxRefreshRate(fl::u32 minMicros) FL_NO_EXCEPT
int noise_min
Unused value.
ClearFlags
Flags for FastLED.clear() to control what state gets cleared/reset.
@ CHANNELS
Remove all channels from controller list.
@ BRIGHTNESS
Reset global brightness to 255.
@ CHANNEL_ENGINES
Clear all channel drivers from ChannelManager.
@ POWER_SETTINGS
Reset power management (setMaxPowerInMilliWatts)
@ FPS_COUNTER
Reset FPS tracking counter to 0.
@ NONE
Clear nothing (no-op)
@ REFRESH_RATE
Reset refresh rate limiting to unlimited.
#define FL_DITHER_ENABLE_MIN_REFRESH_HZ
High level controller interface for FastLED.
CFastLED FastLED
Global LED strip management instance.
central include file for FastLED, defines the CFastLED class/object
CLEDController * controller
fl::UISlider scale("Scale", 4,.1, 4,.1)
Declaration of fl::enableAllDrivers() — enrolls every channel driver available on the current platfor...
#define FL_ASSERT(x, MSG)
ESP32-P4 Parallel IO (PARLIO) LED channel.
void clear(bool writeData=false) FL_NO_EXCEPT
Clear the leds, wiping the local array of data.
power_func mPPowerFunc
function for overriding brightness when using FastLED.show();
fl::u8 getHdFieldFloor() const FL_NO_EXCEPT
void setExclusiveDriver() FL_NO_EXCEPT
Register a single driver at a priority above the platform default (compile-time TU-linking variant).
void setCorrection(const CRGB &correction) FL_NO_EXCEPT
Set a global color correction.
static void _setWaitSpinBudgetUs(fl::u32 budget_us) FL_NO_EXCEPT
static void add(fl::ChannelPtr channel) FL_NO_EXCEPT
Add a Channel-based LED controller (from ChannelPtr)
void show() FL_NO_EXCEPT
Update all our controllers with the current led colors.
void setDriverEnabled(const char *name, bool enabled) FL_NO_EXCEPT
Enable or disable a channel driver by name at runtime.
static fl::ChannelEvents & channelEvents() FL_NO_EXCEPT
Access the channel event system.
void countFPS(int nFrames=25) FL_NO_EXCEPT
For debugging, this will keep track of time between calls to countFPS().
void onEndShowLeds() FL_NO_EXCEPT
Manually trigger the end show LEDs event.
static fl::u32 _getWaitSpinBudgetUs() FL_NO_EXCEPT
static fl::Watchdog & watchdog() FL_NO_EXCEPT
Access the unified cross-platform watchdog timer.
static void remove(fl::ChannelPtr channel) FL_NO_EXCEPT
Remove a channel from the LED controller list.
int size() FL_NO_EXCEPT
Get the number of leds in the first controller.
void clearData() FL_NO_EXCEPT
Clear out the local data array.
void setDither(fl::u8 ditherMode=BINARY_DITHER) FL_NO_EXCEPT
Set the dithering mode.
fl::u8 getLastShowBrightness() const FL_NO_EXCEPT
Brightness the most recent show() / showColor() actually applied, after the power limiter set by setM...
static fl::vector< fl::ChannelPtr > & channels() FL_NO_EXCEPT
stored ChannelPtrs to keep them alive
void onBeginFrame() FL_NO_EXCEPT
Manually trigger the begin frame event.
void showColor(const CRGB &color, fl::u8 scale) FL_NO_EXCEPT
Set all leds on all controllers to the given color/scale.
void wait() FL_NO_EXCEPT
Wait for all channel bus transmissions to complete.
fl::u8 mScale
the current global brightness scale setting
void onEndFrame() FL_NO_EXCEPT
bool isPowerLimited() const FL_NO_EXCEPT
True if the power limiter lowered the brightness of the most recent show() / showColor() below what i...
CRGB * leds() FL_NO_EXCEPT
Get a pointer to led data for the first controller.
void delay(unsigned long ms) FL_NO_EXCEPT
Delay for the given number of milliseconds.
static fl::RxChannelPtr addRx(const fl::RxChannelConfig &config) FL_NO_EXCEPT
Add an RX channel with runtime configuration.
fl::u32 mNPowerData
max power use parameter
fl::u16 mNFPS
tracking for current frames per second (FPS) value
void setMaxRefreshRate(fl::u16 refresh, bool constrain=false) FL_NO_EXCEPT
Set the maximum refresh rate.
void init() FL_NO_EXCEPT
Initialize platform-specific subsystems.
fl::u8 mLastShownScale
brightness the last show()/showColor() applied, after the power limiter
void setTemperature(const CRGB &temp) FL_NO_EXCEPT
Set a global color temperature.
int count() FL_NO_EXCEPT
Get how many controllers have been registered.
fl::u8 mLastRequestedScale
brightness the last show()/showColor() was asked for
CLEDController & operator[](int x) FL_NO_EXCEPT
Get a reference to a registered controller.
::CLEDController & addLeds(::CLEDController *pLed, CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0) FL_NO_EXCEPT
Add a CLEDController instance to the world.
fl::span< const fl::DriverInfo > getDriverInfos() const FL_NO_EXCEPT
Get full state of all registered channel drivers.
bool isDriverEnabled(const char *name) const FL_NO_EXCEPT
Check if a driver is enabled by name.
fl::u32 getEstimatedPowerInMilliWatts(bool apply_limiter=true) const FL_NO_EXCEPT
Get estimated power consumption in milliwatts.
void setHdFieldFloor(fl::u8 min_field) FL_NO_EXCEPT
Lowest 5-bit current field the colour-managed APA102-HD path may use (B1's flicker floor,...
fl::size getDriverCount() const FL_NO_EXCEPT
Get count of registered channel drivers.
static void enableAllDrivers() FL_NO_EXCEPT
Enroll every channel driver available on this platform with ChannelManager.
fl::u16 mMaxRefreshHz
frame-rate cap in Hz, 0 = unlimited (u16 saves 2 B over micros, #4788)
and refresh rates, and provides access functions for driving led data to controllers via the show() /...
void showColorInternal(const CRGB &data, int nLeds, fl::u8 brightness) FL_NO_EXCEPT
void showLedsInternal(fl::u8 brightness) FL_NO_EXCEPT
Write the data to the LEDs managed by this controller.
static void visitControllers(Visitor &&visitor) FL_NO_EXCEPT
Visit all controllers in the linked list with a visitor The visitor must be a callable that accepts (...
CLEDController & setTemperature(CRGB temperature) FL_NO_EXCEPT
Set the color temperature, aka white point, for this controller.
void clearLedDataInternal(int nLeds=-1) FL_NO_EXCEPT
Zero out the LED data managed by this controller.
static CLEDController * head() FL_NO_EXCEPT
Get the first LED controller in the linked list of controllers.
bool getEnabled() FL_NO_EXCEPT
VIRTUAL_IF_NOT_AVR void * beginShowLeds(int size) FL_NO_EXCEPT
VIRTUAL_IF_NOT_AVR int size() const FL_NO_EXCEPT
How many LEDs does this controller manage?
VIRTUAL_IF_NOT_AVR void endShowLeds(void *data) FL_NO_EXCEPT
CLEDController & setDither(fl::u8 ditherMode=BINARY_DITHER) FL_NO_EXCEPT
Set the dithering mode for this controller to use.
static CLEDController * mPHead
pointer to the first LED controller in the linked list
CLEDController * next() FL_NO_EXCEPT
Get the next controller in the linked list after this one.
CLEDController & setCorrection(CRGB correction) FL_NO_EXCEPT
The color corrction to use for this controller, expressed as a CRGB object.
void removeFromDrawList() FL_NO_EXCEPT
Remove this channel from the global controller draw list.
const EmitterProfile * emitterProfile() const FL_NO_EXCEPT
void addToDrawList() FL_NO_EXCEPT
Add this channel to the global controller draw list.
const ChipsetVariant & getChipset() const FL_NO_EXCEPT
Get the chipset configuration variant.
LED channel for parallel output, pretty much a CPixelLEDController but with timing and pin informatio...
void setDriverEnabled(const char *name, bool enabled) FL_NO_EXCEPT
Enable or disable a driver by name at runtime.
void reset() FL_NO_EXCEPT
Reset bus manager state, clearing all enqueued and transmitting channels.
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::size getDriverCount() const FL_NO_EXCEPT
Get count of registered drivers (including unnamed ones)
void clearAllDrivers() FL_NO_EXCEPT
Remove all drivers from the manager.
void setExclusiveDriver() FL_NO_EXCEPT
Register a single driver at a priority above the platform default and disable all others (compile-tim...
bool isDriverEnabled(const char *name) const FL_NO_EXCEPT
Check if a driver is enabled by name.
fl::span< const DriverInfo > getDriverInfos() const FL_NO_EXCEPT
Get full state of all registered drivers.
Unified channel manager with priority-based driver selection.
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 void onBeginFrame() FL_NO_EXCEPT
static void onStripAdded(CLEDController *strip, fl::u32 num_leds) FL_NO_EXCEPT
static void onEndShowLeds() FL_NO_EXCEPT
static void onEndFrame() FL_NO_EXCEPT
static RxChannelPtr create(const RxChannelConfig &config) FL_NO_EXCEPT
static Watchdog & instance() FL_NO_EXCEPT
Unified cross-platform watchdog interface.
void remove(shared_ptr< Processor > processor) FL_NO_EXCEPT
static AudioManager & instance() FL_NO_EXCEPT
shared_ptr< Processor > add(const Config &config) FL_NO_EXCEPT
static bool isAnyNetworkActive() FL_NO_EXCEPT
static string from_literal(const char *literal) FL_NO_EXCEPT
fl::size size() const FL_NO_EXCEPT
fl::CLEDController CLEDController
Delay utilities for FastLED Includes nanosecond-precision delays, cycle counting, and microsecond del...
fl::UISlider length("Length", 1.0f, 0.0f, 1.0f, 0.01f)
Opt-in, link-on-use channel driver bindings for FastLED.add(cfg).
Task executor — runs registered task runners and manages the run loop.
fl::u32 scale_power_for_brightness(fl::u32 total_mW, fl::u8 brightness) FL_NO_EXCEPT
Applies the configured power-scaling response to a total power value.
void delay_at_max_brightness_for_power(fl::u16 ms) FL_NO_EXCEPT
Similar to CFastLED::delay(), but pre-adjusts brightness to keep below the power threshold.
void set_max_power_in_milliwatts(fl::u32 powerInmW) FL_NO_EXCEPT
Set the maximum power used in watts.
fl::u32 controller_dither_reserve_mW(const fl::CLEDController &controller) FL_NO_EXCEPT
dither_reserve_mW() for a controller that dithers, and zero for one that does not: a mode other than ...
fl::u32 controller_unscaled_power_mW(const fl::CLEDController &controller) FL_NO_EXCEPT
One controller's demand at full brightness, in mW, including idle draw – the quantity the limiter sum...
void set_max_power_in_volts_and_milliamps(fl::u8 volts, fl::u32 milliamps) FL_NO_EXCEPT
Set the maximum power used in milliamps for a given voltage.
void show_at_max_brightness_for_power() FL_NO_EXCEPT
Similar to CFastLED::show(), but pre-adjusts brightness to keep below the power threshold.
PowerModelRGB get_power_model() FL_NO_EXCEPT
Get current RGB power model.
Functions to convert from the HSV colorspace to the RGB colorspace.
#define FL_WARN_EVERY(MILLIS,...)
Centralized logging categories for FastLED hardware interfaces and subsystems.
Unified manager for channel drivers with priority-based fallback.
constexpr remove_reference< T >::type && move(T &&t) FL_NO_EXCEPT
u8 & hdFieldFloor() FL_NO_EXCEPT
Backing store for CFastLED::setHdFieldFloor().
void setWaitSpinBudgetUs(fl::u32 budget_us) FL_NO_EXCEPT
Set the tiered-wait spin budget (microseconds).
fl::u32 getWaitSpinBudgetUs() FL_NO_EXCEPT
Get the current tiered-wait spin budget (microseconds).
u8 ditherFrame() FL_NO_EXCEPT
Return the temporal-dither phase shared by all controllers in this frame.
bool waitForDriverCompletion(u32 timeoutMs) FL_NO_EXCEPT
Wait for installed consumers using one deadline (zero means indefinitely).
bool bindDefaultDriver() FL_NO_EXCEPT
Bind the platform default driver for Chipset, if one exists.
void yield_system(fl::u32 microseconds) FL_NO_EXCEPT
OS-level yield only: same behavior as run(us, ExecFlags::SYSTEM).
void enableAllDrivers() FL_NO_EXCEPT
Register every channel driver available on this platform with ChannelManager, restoring 3....
u8 u8 fract8 blur_amount FL_NO_EXCEPT
typename conditional< B, T, F >::type conditional_t
void delay(u32 ms, bool run_async=true) FL_NO_EXCEPT
Public delay wrapper that keeps bare Arduino delay() preferred after using fl::delay; while still all...
ChannelManager & channelManager() FL_NO_EXCEPT
Get the global ChannelManager singleton instance.
u32 _retry_cnt
Frame retry counter for ESP8266 clockless drivers (FASTLED_DEBUG_COUNT_FRAME_RETRIES).
const char * busName(Bus b, fl::u8 which=0) FL_NO_EXCEPT
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
fl::u32 micros() FL_NO_EXCEPT
Universal microsecond timer - returns microseconds since system startup.
const char * busDriverName(Bus b, fl::u8 which=0, bool spi=false) FL_NO_EXCEPT
Concrete ChannelManager driver name for a portable bus.
u8 hdMinimumField(FiveBitSemantics semantics, u8 floor_setting) FL_NO_EXCEPT
The lowest field the managed HD path may choose: the configured flicker floor for a secondary slow-PW...
Bus
Portable public bus selector.
void yield() FL_NO_EXCEPT
Yield to the platform scheduler.
u32 _frame_cnt
Frame counter for ESP8266 clockless drivers (FASTLED_DEBUG_COUNT_FRAME_RETRIES).
PowerCodecPolicy powerChannelCodecPolicy(const CLEDController &controller) FL_NO_EXCEPT
Identify the channel's final current/quantization choice without adding a virtual slot or storage to ...
@ LPD6803
LPD6803 LED chipset.
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
@ DOTSTARHD
APA102HD LED chipset alias.
@ SK9822HD
SK9822 LED chipset with 5-bit gamma correction.
@ LPD8806
LPD8806 LED chipset.
@ HD107HD
Same as APA102HD, but in turbo 40-mhz mode.
FiveBitSemantics fiveBitSemanticsFor(SpiChipset chip, FiveBitSemantics profile) FL_NO_EXCEPT
The 5-bit semantics for chip, with profile overriding the chip's default when it is not NotApplicable...
Base definition for an LED controller.
Driver state information for channel manager.
Result of the shared frame-budget prepass on large-memory managed output.
Cross-platform facade for runtime network activity detection.
static fl::u32 fixed_power_mW(fl::u32 led_count) FL_NO_EXCEPT
#define FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS
#define FL_DISABLE_WARNING_PUSH
#define FL_RUN_ONCE(code)
#define FL_DISABLE_WARNING_POP
fl::u8 dark_mW
Dark (all channels off) draw per LED IC, in milliwatts, charged as an undimmable baseline.
Configuration for a single LED channel.
static ChannelEvents & instance() FL_NO_EXCEPT
Singleton event router for Channel lifecycle events.
SPI chipset configuration (data + clock pins)
FiveBitSemantics five_bit_semantics
Runtime-tunable microsecond spin budget for the channel-manager and driver wait loops (Phase 1 of #28...
Platform-aware cooperative yield for FastLED.