FastLED 3.10.10
Loading...
Searching...
No Matches
channel.cpp.hpp
Go to the documentation of this file.
1
3
4#include "platforms/is_platform.h"
8#include "fl/channels/data.h"
10#include "fl/channels/manager.h"
11#include "fl/stl/atomic.h"
12#include "fl/log/log.h"
13#include "fl/channels/options.h"
16#include "pixel_controller.h"
17#include "fl/system/trace.h"
18
19#include "fl/system/pin.h"
21#include "fl/chipsets/ucs7604.h"
22#include "fl/math/ease.h"
23#include "fl/stl/iterator.h"
25#include "fl/math/xymap.h"
26#include "fl/stl/singleton.h"
27#include "fl/stl/noexcept.h"
28#include "fl/stl/compiler_control.h" // IWYU pragma: keep - FL_UNUSED
29
30namespace fl {
31
32namespace {
33
36 private:
44#if FL_COLOR_PROFILE_RUNTIME
45 // Present only when a colour profile is bound. The managed source keeps
46 // a reference to the controller it wraps, so it has to outlive the
47 // iterator built over it -- both live here, for the frame.
48 //
49 // Raw storage rather than the types themselves, because naming them here
50 // is what made the whole colour pipeline reachable from `show()` and cost
51 // every sketch ~3.5 KB of flash. `colorPipelineHooks()` builds into this,
52 // and only `setColorProfile` installs those hooks -- so a program that
53 // never binds a profile never references the pipeline and the linker
54 // drops it.
55 FL_ALIGNAS(8) unsigned char mManagedSourceStorage[kColorPipelineSourceStorage];
56 FL_ALIGNAS(8) unsigned char mManagedIteratorStorage[kColorPipelineIteratorStorage];
57 PixelIterator* mManagedIterator = nullptr;
58#endif
59
60 public:
69 const XYMap* addressing,
70 EOrder rgbOrder,
71 Rgbw rgbw,
72 Rgbww rgbww,
73 const fl::string& channelName,
75 const StreamingPipelineQ16* pipeline,
76#else
77 StreamingPipelineQ16* pipeline,
78#endif
79 u8 ditherPhase, u8 brightness) FL_NO_EXCEPT
80 : mPixelIterator(pixels, rgbOrder, rgbw, rgbww) {
81 FL_UNUSED(pipeline);
82 FL_UNUSED(ditherPhase); // read only by the colour-managed source
83 FL_UNUSED(brightness); // read only by the colour-managed source
84 FL_UNUSED(channelName); // only consumed by FL_ERROR, a no-op on small platforms
85
86 // Apply addressing transformation if configured
87 if (addressing) {
88 u16 numLeds = pixels.size();
89 u16 width = addressing->getWidth();
90 u16 height = addressing->getHeight();
91 u16 expectedLeds = width * height;
92
93 // Validate that XYMap dimensions match channel LED count
94 if (expectedLeds != numLeds) {
95 FL_ERROR("Channel '" << channelName << "': XYMap dimensions (" << width << "x" << height << "=" << expectedLeds << ") don't match LED count (" << numLeds << "). Addressing transformation may produce unexpected results.");
96 }
97
98 // Cast mData to CRGB array
99 const CRGB* pixelArray = (const CRGB*)pixels.mData;
100
101 // Get thread-local buffer (reuses allocation if size unchanged)
103 buffer.clear();
104 buffer.resize(numLeds);
105
106 // Fill buffer by mapping each physical index to its source
107 for (u16 physicalIdx = 0; physicalIdx < numLeds; physicalIdx++) {
108 u16 x = physicalIdx % width;
109 u16 y = physicalIdx / width;
110 u16 sourceIdx = addressing->mapToIndex(x, y);
111 buffer[physicalIdx] = (sourceIdx < numLeds) ? pixelArray[sourceIdx] : CRGB::Black;
112 }
113
114 // Construct PixelController with reordered buffer
115 mAddressedController.emplace(
116 buffer.data(), buffer.size(),
117 pixels.mColorAdjustment, DISABLE_DITHER);
118 mPixelIterator = PixelIteratorAny(mAddressedController.value(), rgbOrder, rgbw, rgbww);
119 }
120
121#if FL_COLOR_PROFILE_RUNTIME
122 const ColorPipelineHooks& hooks = colorPipelineHooks();
123 if (pipeline != nullptr && hooks.makeIterator != nullptr) {
124 // Colour-managed: build the iterator over a streaming source
125 // instead of over the order-variant controller. The source
126 // applies the colour order itself, so it wraps the RGB-ordered
127 // controller -- whichever of the two that is after addressing.
130 mManagedIterator = hooks.makeIterator(
131 mManagedSourceStorage, mManagedIteratorStorage, base, rgbOrder,
132 *pipeline, rgbw, rgbww, ditherPhase, brightness);
133 }
134#endif
135 }
136
138#if FL_COLOR_PROFILE_RUNTIME
139 // Placement-new'd into our own storage, so the teardown goes back
140 // through the hooks too -- this file must not name the types.
141 if (mManagedIterator != nullptr) {
142 const ColorPipelineHooks& hooks = colorPipelineHooks();
143 if (hooks.destroyIterator != nullptr) {
144 hooks.destroyIterator(mManagedSourceStorage,
145 mManagedIteratorStorage);
146 }
147 mManagedIterator = nullptr;
148 }
149#endif
150 }
151
158#if FL_COLOR_PROFILE_RUNTIME
159 if (mManagedIterator != nullptr) {
160 return *mManagedIterator;
161 }
162#endif
163 return mPixelIterator.get();
164 }
166 return const_cast<ReorderingPixelIteratorAny*>(this)->get();
167 }
168
177 bool isManaged() const FL_NO_EXCEPT {
178#if FL_COLOR_PROFILE_RUNTIME
179 return mManagedIterator != nullptr;
180#else
181 return false;
182#endif
183 }
184};
185
199#if FASTLED_LOG_RUNTIME_ENABLED // only caller is guarded the same way
201static void emitDisabledDriverError(const fl::string& channelName,
202 const fl::string& driverName,
203 const fl::string& exclusive) FL_NO_EXCEPT {
204 FL_UNUSED(channelName); // only consumed by FL_ERROR, a no-op on small platforms
205 FL_UNUSED(driverName);
206 if (!exclusive.empty()) {
207 FL_ERROR("Channel '" << channelName << "': bound driver '" << driverName << "' is currently DISABLED by exclusive-driver selection '" << exclusive << "'. Frame will be silently dropped. Resolve with: FastLED.enableDrivers<fl::Bus::" << driverName << ">() or FastLED.enableAllDrivers().");
208 } else {
209 FL_ERROR("Channel '" << channelName << "': bound driver '" << driverName << "' is currently DISABLED. Frame will be silently dropped. Resolve with: FastLED.enableDrivers<fl::Bus::" << driverName << ">() or FastLED.enableAllDrivers().");
210 }
211}
212#endif // FASTLED_LOG_RUNTIME_ENABLED
213
214} // anonymous namespace
215
216Channel::PixelEncoder
217Channel::selectPixelEncoder(const ChipsetVariant& chipset) FL_NO_EXCEPT {
218 if (const ClocklessChipset* clockless = chipset.ptr<ClocklessChipset>()) {
219 switch (clockless->encoder) {
221 return &Channel::encodeWS2812;
223 return &Channel::encodeTM1812RGBWW;
225 return &Channel::encodeTM1908;
226#if !defined(FASTLED_DISABLE_UCS7604) || !FASTLED_DISABLE_UCS7604
230 return &Channel::encodeUCS7604;
231#endif
232 }
233 } else if (const SpiChipsetConfig* spi = chipset.ptr<SpiChipsetConfig>()) {
234#if !defined(FASTLED_DISABLE_SPI_CHIPSETS) || !FASTLED_DISABLE_SPI_CHIPSETS
235 switch (spi->timing.chipset) {
242 return &Channel::encodeAPA102;
245 return &Channel::encodeSK9822;
247 return &Channel::encodeWS2801;
249 return &Channel::encodeWS2803;
251 return &Channel::encodeP9813;
253 return &Channel::encodeLPD8806;
255 return &Channel::encodeLPD6803;
257 return &Channel::encodeSM16716;
259 return &Channel::encodeMY9221;
261 return &Channel::encodeHD108;
262 }
263#endif // !FASTLED_DISABLE_SPI_CHIPSETS
264 }
265 return nullptr;
266}
267
268i32 Channel::nextId() FL_NO_EXCEPT {
269 static fl::atomic<i32> gNextChannelId(0); // okay static in header
270 return gNextChannelId.fetch_add(1);
271}
272
273fl::string Channel::makeName(i32 id, const fl::optional<fl::string>& configName) FL_NO_EXCEPT {
274 if (configName.has_value()) {
275 return configName.value();
276 }
277 // Auto-naming `"Channel_<id>"` only matters for diagnostics — in release
278 // builds (NDEBUG → FASTLED_LOG_VERBOSITY=0 per Stage 1) every FL_WARN /
279 // FL_ERROR site that reads mName collapses to `do { } while(0)`, so the
280 // string and the supporting `fl::to_string` + `operator+` chain go
281 // unused. Empty in release saves the `fl::to_string<i64>` instantiation
282 // plus the heap allocation per Channel ctor. See #2942 / #2886.
283#if FASTLED_LOG_RUNTIME_ENABLED
284 return "Channel_" + fl::to_string(static_cast<i64>(id));
285#else
286 (void)id;
287 return {};
288#endif
289}
290
291ChannelPtr Channel::create(const ChannelConfig &config) FL_NO_EXCEPT {
292 // Late binding strategy: Always create with empty driver
293 // Engine binding happens on first showPixels() call:
294 // - Affinity channels: Look up by name and cache
295 // - Non-affinity channels: Select dynamically each frame
296
297 auto channel = fl::make_shared<Channel>(config.chipset, config.mLeds,
298 config.rgb_order, config.options);
299 auto& events = ChannelEvents::instance();
300#if FL_COLOR_PROFILE_RUNTIME
301 if (channel->reconcileColorProfile(config.options)) {
302 events.onColorProfileFallback(
303 ColorProfileEvent{channel->id(), channel->colorProfileStatus(), {}});
304 }
305#endif
306 channel->mName = makeName(channel->mId, config.mName);
307 events.onChannelCreated(*channel);
308 return channel;
309}
310
311int Channel::getPin() const FL_NO_EXCEPT {
312 if (const ClocklessChipset* cs = mChipset.ptr<ClocklessChipset>()) {
313 return cs->pin;
314 }
315 if (const SpiChipsetConfig* spi = mChipset.ptr<SpiChipsetConfig>()) {
316 return spi->dataPin;
317 }
318 return -1;
319}
320
321const ChipsetTimingConfig& Channel::getTiming() const FL_NO_EXCEPT {
322 if (const ClocklessChipset* cs = mChipset.ptr<ClocklessChipset>()) {
323 return cs->timing;
324 }
325 static const ChipsetTimingConfig sEmpty(0, 0, 0, 0);
326 return sEmpty;
327}
328
329Channel::Channel(const ChipsetVariant& chipset, fl::span<CRGB> leds,
330 EOrder rgbOrder, const ChannelOptions& options) FL_NO_EXCEPT
331 : CPixelLEDController<RGB>(RegistrationMode::DeferRegister) // Defer registration until FastLED.add()
332 , mChipset(chipset)
334 , mRgbOrder(rgbOrder)
335 , mDriver() // Empty weak_ptr - late binding on first showPixels()
336 , mBus(options.mBus) // Bus selection (#2459)
337 , mBusWhich(options.mBusWhich)
338 , mId(nextId())
339 , mName(makeName(mId)) {
340 // NOTE: Do NOT call fl::pinMode() here. The pin may already be
341 // configured for SPI output by a persistent driver (ChannelEngineSpi).
342 // Calling pinMode(InputPulldown) would disconnect the SPI MOSI from the
343 // GPIO matrix, causing subsequent transmissions to produce no output.
344 // The driver will configure the pin when it first uses it.
345
346 // Set the LED data array
347 setLeds(leds);
348
349 // Channels owns its options; copy only the legacy rendering fields into
350 // the base controller.
351 mSettings = options;
352
353 // Set color correction/temperature/dither/rgbw from ChannelOptions
355
356 // Create ChannelData during construction with chipset variant
358}
359
360// Backwards-compatible constructor (deprecated)
361Channel::Channel(int pin, const ChipsetTimingConfig& timing, fl::span<CRGB> leds,
362 EOrder rgbOrder, const ChannelOptions& options) FL_NO_EXCEPT
363 : CPixelLEDController<RGB>(RegistrationMode::DeferRegister) // Defer registration until FastLED.add()
364 , mChipset(ClocklessChipset(pin, timing)) // Convert to variant
366 , mRgbOrder(rgbOrder)
367 , mDriver() // Empty weak_ptr - late binding on first showPixels()
368 , mBus(options.mBus) // Bus selection (#2459)
369 , mBusWhich(options.mBusWhich)
370 , mId(nextId())
371 , mName(makeName(mId)) {
372 // NOTE: Do NOT call fl::pinMode() here — see comment in the
373 // Channel(ChipsetVariant, span, EOrder, ChannelOptions) constructor.
374
375 // Set the LED data array
376 setLeds(leds);
377
378 // Channels owns its options; synchronize the base rendering fields.
379 mSettings = options;
380
381 // Set color correction/temperature/dither/rgbw from ChannelOptions
383
384 // Create ChannelData during construction
386}
387
388Channel::~Channel() FL_NO_EXCEPT {
389 auto& events = ChannelEvents::instance();
390 events.onChannelBeginDestroy(*this);
391}
392
393void Channel::syncLegacySettings() FL_NO_EXCEPT {
394 mLegacySettings.mCorrection = mSettings.mCorrection;
395 mLegacySettings.mTemperature = mSettings.mTemperature;
396 mLegacySettings.mDitherMode = mSettings.mDitherMode;
397 mLegacySettings.mWhiteCfg = mSettings.mWhiteCfg;
398 // Active white config assigned straight into ChannelOptions.mWhiteCfg
399 // never passed through setRgbw()/setRgbww(): install its conversion here
400 // (#4795).
401 if (const Rgbw* rgbw = mLegacySettings.mWhiteCfg.ptr<Rgbw>()) {
402 if (rgbw->active()) {
404 }
405 } else if (const Rgbww* rgbww = mLegacySettings.mWhiteCfg.ptr<Rgbww>()) {
406 if (rgbww->active()) {
408 }
409 }
410 if (const auto* rgbw = mSettings.mWhiteCfg.ptr<Rgbw>()) {
413 }
414}
415
416#ifndef FL_IS_AVR
417void Channel::onSettingsChanged(SettingsChange change) FL_NO_EXCEPT {
418 // Frame completion restores dithering through the base setter. Dithering
419 // does not change pipeline coefficients and must not rebuild the pipeline.
420 mSettings.mDitherMode = mLegacySettings.mDitherMode;
421 if (change == SettingsChange::Dither) return;
422 mSettings.mWhiteCfg = mLegacySettings.mWhiteCfg;
423 if (change == SettingsChange::Correction || change == SettingsChange::Temperature) {
425 if (change == SettingsChange::Correction) {
426 mSettings.setLegacyCorrection(mLegacySettings.mCorrection);
427 } else {
428 mSettings.setLegacyTemperature(mLegacySettings.mTemperature);
429 }
430 }
431#if FL_COLOR_PROFILE_RUNTIME
432 reconcileColorProfile(mSettings);
433#endif
434}
435#endif
436
437#if FL_COLOR_PROFILE_RUNTIME
438void Channel::raiseColorProfileFallback(const char* reason) FL_NO_EXCEPT {
439 mColorProfileFallback = true;
440 mProfileBindingAccepted = !detail::colorProfileStrictMode();
441 // C5's one-time warning. The event fired by the callers is the
442 // machine-readable half; this is the half a sketch sees without
443 // subscribing to anything (#4333). Strict mode turns the same condition
444 // into a disabled channel, so say which happened.
445 if (mWarnedColorProfileFallback) {
446 return;
447 }
448 if (mProfileBindingAccepted) {
449 FL_WARN("Channel " << id() << ": color management requested but " << reason << "; falling back to the legacy path");
450 } else {
451 FL_WARN("Channel " << id() << ": color management requested but " << reason << "; strict mode disables this channel");
452 }
453 mWarnedColorProfileFallback = true;
454}
455
456bool Channel::reconcileColorProfile(const ChannelOptions& options) FL_NO_EXCEPT {
457 // A strict-mode rejection disables the channel. Remember whether the
458 // current disabled state is ours, so that withdrawing the rejection
459 // re-enables the channel without also overriding a caller's own
460 // setEnabled(false).
461 const bool wasRejectedByUs = mColorProfileFallback && !mProfileBindingAccepted;
462
463 // Recompute from scratch. Reconfiguration must not inherit the verdict of
464 // the configuration it replaces: a valid profile applied over a rejected
465 // one has to clear the fallback, not keep reporting it.
466 mColorProfileFallback = false;
467 mProfileBindingAccepted = true;
468
469 // C5's fallback, raised by the two conditions that mean the same thing to
470 // a caller: management was asked for and is not happening. The second one
471 // -- a profile that binds but builds no pipeline -- is raised further
472 // down, once the build has been attempted.
473 if (options.mColorProfile.mRequested && !options.hasColorProfile()) {
474 raiseColorProfileFallback("no profile bound");
475 }
476 if (options.mColorProfile.mUseGlobalSourceDefault) {
477 mSettings.mColorProfile.mSource = detail::defaultSourceProfile();
478 }
479 // Guards the build below: a binding already rejected by strict mode must
480 // not be built. It is deliberately *not* reused for the enablement
481 // branch -- the build can raise the fallback itself (#4345), and reading
482 // this stale value there left a strict-mode channel reporting Rejected
483 // while still enabled and rendering through the legacy path, which is the
484 // one thing strict mode exists to prevent.
485 const bool rejectedBeforeBuild = mColorProfileFallback && !mProfileBindingAccepted;
486
487 // Derive the pipeline once, here, rather than per frame: it inverts
488 // matrices and bisects a lightness bound. A binding that does not
489 // describe a usable pipeline leaves the channel on the legacy path
490 // rather than failing -- an unbound channel is the ordinary case, not an
491 // error.
492 mPipeline.reset();
493 const ColorPipelineHooks& hooks = colorPipelineHooks();
494 if (!rejectedBeforeBuild && hooks.build != nullptr) {
495 // Through the hook, not by name. Calling `buildPipelineForBinding`
496 // directly from here is what kept the entire pipeline alive in every
497 // build; the pointer is null until `setColorProfile` installs it.
498 // Built on the stack first, so a binding that does not describe a
499 // usable pipeline costs no allocation -- that is the failing half of
500 // an ordinary unbound channel, not an exceptional path.
501 StreamingPipelineQ16 pipeline;
502 if (hooks.build(mSettings.mColorProfile, mSettings, mChipset,
503 &pipeline)) {
504#if FL_COLOR_PIPELINE_SHARED
505 mPipeline = fl::make_shared<StreamingPipelineQ16>(pipeline);
506#else
507 mPipeline = fl::make_unique<StreamingPipelineQ16>(pipeline);
508#endif
509 } else if (options.hasColorProfile()) {
510 // R6: a profile outside the numerical bounds must "fail
511 // explicitly" and "not become native-drive input". A binding that
512 // cannot produce a pipeline used to leave every reporting surface
513 // saying the channel was fine -- Configured, no fallback flag, no
514 // warning -- while it rendered through the legacy path (#4345).
515 //
516 // This reports; it does not reject. Refusing the binding at
517 // setColorProfile() time is R6's fuller reading and needs the
518 // published coefficient bounds it also asks for, which do not
519 // exist yet.
520 raiseColorProfileFallback("bound profile builds no usable pipeline");
521 }
522 }
523
524 // Recomputed after the build, so a rejection raised by a failed build
525 // reaches this branch.
526 const bool rejectedNow = mColorProfileFallback && !mProfileBindingAccepted;
527 if (rejectedNow) {
528 setEnabled(false);
529 } else if (wasRejectedByUs) {
530 setEnabled(true);
531 }
532 return mColorProfileFallback;
533}
534#endif
535
536void Channel::applyConfig(const ChannelConfig& config) FL_NO_EXCEPT {
537 const auto* currentClockless = mChipset.ptr<ClocklessChipset>();
538 const auto* incomingClockless = config.chipset.ptr<ClocklessChipset>();
539 const auto* currentSpi = mChipset.ptr<SpiChipsetConfig>();
540 const auto* incomingSpi = config.chipset.ptr<SpiChipsetConfig>();
541 const bool compatible = currentClockless && incomingClockless
542 ? currentClockless->timing == incomingClockless->timing &&
543 currentClockless->encoder == incomingClockless->encoder
544 : currentSpi && incomingSpi && currentSpi->timing == incomingSpi->timing &&
545 currentSpi->spiBus == incomingSpi->spiBus;
546 if (!compatible) {
547 FL_WARN("Channel " << id() << ": applyConfig rejected, chipset conflicts with the existing binding");
548 return;
549 }
550 if (config.options.mBus != Bus::AUTO &&
551 (config.options.mBus != mBus || config.options.mBusWhich != mBusWhich)) {
552 FL_WARN("Channel " << id() << ": applyConfig rejected, bus conflicts with the existing binding");
553 return;
554 }
555 mRgbOrder = config.rgb_order;
556 if (config.mName.has_value()) {
557 mName = config.mName.value();
558 }
559 setLeds(config.mLeds);
560 // Replace Channel-owned options and synchronize the base rendering fields.
561 mSettings = config.options;
562#if !FL_COLOR_PROFILE_RUNTIME && !defined(FL_IS_AVR)
563 // Tiny options cannot carry a replacement profile; applying them is a
564 // legacy transition, just like the base correction/temperature setters.
566#endif
567 mSettings.mBus = mBus;
568 mSettings.mBusWhich = mBusWhich;
570 auto& events = ChannelEvents::instance();
571#if FL_COLOR_PROFILE_RUNTIME
572 if (reconcileColorProfile(config.options)) {
573 events.onColorProfileFallback(ColorProfileEvent{id(), colorProfileStatus(), {}});
574 }
575#endif
576 events.onChannelConfigured(*this, config);
577}
578
579int Channel::getClockPin() const FL_NO_EXCEPT {
580 if (const SpiChipsetConfig* spi = mChipset.ptr<SpiChipsetConfig>()) {
581 return spi->clockPin;
582 }
583 return -1; // Clockless chipsets don't have a clock pin
584}
585
586
587namespace {
588
596 ClocklessEncoder encoder, const ChannelOptions& settings,
597 EOrder rgbOrder, bool managed) FL_NO_EXCEPT {
598 // Map encoder enum to UCS7604Mode
599 UCS7604Mode mode;
600 switch (encoder) {
603 break;
606 break;
609 break;
610 default:
611 // Should never happen — caller already checked
613 break;
614 }
615
616 // Get current control from global UCS7604 brightness
618
619 // Reorder current control values to match wire order (same logic as UCS7604ControllerT)
620 u8 rgb_currents[3] = {current.r, current.g, current.b};
621 u8 pos0 = (static_cast<int>(rgbOrder) >> 6) & 0x3;
622 u8 pos1 = (static_cast<int>(rgbOrder) >> 3) & 0x3;
623 u8 pos2 = (static_cast<int>(rgbOrder) >> 0) & 0x3;
624 UCS7604CurrentControl wire_current(
625 rgb_currents[pos0], rgb_currents[pos1], rgb_currents[pos2], current.w);
626
627 // Get gamma LUT.
628 //
629 // Only the unbound path uses it. With a profile bound the pixel source
630 // has already produced the device drive and quantized it once, to 16
631 // bits, so widening it again through a curve is the second shaping stage
632 // B1 and section 6 forbid after the device solve -- and the 2.8 here is
633 // `value_or`'s default rather than anything the caller asked for, since
634 // `setColorProfile` clears `mGamma`. #4326.
635 // The iterator's own state, not the options'. `hasColorProfile()` says a
636 // profile is configured; it does not say the managed iterator was built.
637 // A rejected binding leaves the legacy controller in place, and taking
638 // the no-gamma path over its 8-bit pixels would drop a stage that path
639 // still needs.
640 const bool wide_source = managed;
641 float gamma = settings.mGamma.value_or(2.8f);
643
644 bool is_rgbw = pixelIterator.get_rgbw().active();
645 size_t num_leds = pixelIterator.size();
646
647 // (#2558) UCS7604 is a 4-channel chipset (always RGBW). If the user
648 // configured this channel for 5-channel RGBWW (warm-W + cool-W), the
649 // chipset can't carry the second W byte. Warn loudly — silently dropping
650 // the white channels would be very hard to diagnose. The pixel iterator
651 // continues to emit RGB-only bytes (is_rgbw=false) so the strip still
652 // lights up, just without the W diode.
653 if (pixelIterator.get_rgbww().active() && !is_rgbw) {
654 FL_WARN_ONCE("UCS7604 cannot carry 5-channel RGBWW — this chipset "
655 "always emits 4-channel RGBW. The warm/cool white "
656 "channels in your Rgbww config will be dropped. "
657 "Set ChannelOptions.mWhiteCfg = Rgbw{...} instead to "
658 "silence this warning.");
659 }
660
661 // Encode into the data buffer
662 encodeUCS7604(pixelIterator, num_leds, fl::back_inserter(*data),
663 mode, wire_current, is_rgbw, gamma8.get(), wide_source);
664}
665
666} // anonymous namespace
667
668namespace {
669
674 bool managed, fl::vector_psram<u8>& output,
675 SpiChipset chipset)
677#if FL_COLOR_PROFILE_RUNTIME
678 if (!managed) {
679 return false;
680 }
681 const ColorPipelineHooks& hooks = colorPipelineHooks();
682 return hooks.encodeManagedSpi != nullptr &&
683 hooks.encodeManagedSpi(pixels, &output, chipset, channel);
684#else
685 FL_UNUSED(channel);
686 FL_UNUSED(pixels);
687 FL_UNUSED(managed);
688 FL_UNUSED(output);
689 FL_UNUSED(chipset);
690 return false;
691#endif
692}
693
695 const SpiChipsetConfig* spi =
696 channel.getChipset().ptr<SpiChipsetConfig>();
697 return spi->timing.chipset;
698}
699
700} // anonymous namespace
701
703void Channel::encodeWS2812(Channel&, PixelIterator& pixels,
704 bool, fl::vector_psram<u8>& output) FL_NO_EXCEPT {
705 pixels.writeWS2812(&output);
706}
707
709void Channel::encodeTM1812RGBWW(Channel&, PixelIterator& pixels,
710 bool, fl::vector_psram<u8>& output) FL_NO_EXCEPT {
711 pixels.writeTM1812RGBWW(&output);
712}
713
715void Channel::encodeTM1908(Channel&, PixelIterator& pixels,
716 bool, fl::vector_psram<u8>& output) FL_NO_EXCEPT {
717 pixels.writeTM1908(&output);
718}
719
721void Channel::encodeUCS7604(Channel& channel, PixelIterator& pixels,
722 bool managed,
724 const ClocklessChipset* clockless =
725 channel.mChipset.ptr<ClocklessChipset>();
726 writeUCS7604(&output, pixels, clockless->encoder, channel.mSettings,
727 channel.mRgbOrder, managed);
728}
729
731void Channel::encodeAPA102(Channel& channel, PixelIterator& pixels,
732 bool managed, fl::vector_psram<u8>& output)
734 const SpiChipset chipset = spiChipsetFor(channel);
735 if (tryEncodeManagedSpi(channel, pixels, managed, output, chipset)) {
736 return;
737 }
738 const bool hdGamma = chipset == SpiChipset::APA102HD ||
739 chipset == SpiChipset::DOTSTARHD ||
740 chipset == SpiChipset::HD107HD;
741 pixels.writeAPA102(&output, hdGamma);
742}
743
745void Channel::encodeSK9822(Channel& channel, PixelIterator& pixels,
746 bool managed, fl::vector_psram<u8>& output)
748 const SpiChipset chipset = spiChipsetFor(channel);
749 if (tryEncodeManagedSpi(channel, pixels, managed, output, chipset)) {
750 return;
751 }
752 pixels.writeSK9822(&output, chipset == SpiChipset::SK9822HD);
753}
754
756void Channel::encodeWS2801(Channel& channel, PixelIterator& pixels,
757 bool managed, fl::vector_psram<u8>& output)
759 if (tryEncodeManagedSpi(channel, pixels, managed, output,
760 spiChipsetFor(channel))) {
761 return;
762 }
763 pixels.writeWS2801(&output);
764}
765
767void Channel::encodeWS2803(Channel& channel, PixelIterator& pixels,
768 bool managed, fl::vector_psram<u8>& output)
770 if (tryEncodeManagedSpi(channel, pixels, managed, output,
771 spiChipsetFor(channel))) {
772 return;
773 }
774 pixels.writeWS2803(&output);
775}
776
778void Channel::encodeP9813(Channel& channel, PixelIterator& pixels,
779 bool managed, fl::vector_psram<u8>& output)
781 if (tryEncodeManagedSpi(channel, pixels, managed, output,
782 spiChipsetFor(channel))) {
783 return;
784 }
785 pixels.writeP9813(&output);
786}
787
789void Channel::encodeLPD8806(Channel& channel, PixelIterator& pixels,
790 bool managed, fl::vector_psram<u8>& output)
792 if (tryEncodeManagedSpi(channel, pixels, managed, output,
793 spiChipsetFor(channel))) {
794 return;
795 }
796 pixels.writeLPD8806(&output);
797}
798
800void Channel::encodeLPD6803(Channel& channel, PixelIterator& pixels,
801 bool managed, fl::vector_psram<u8>& output)
803 if (tryEncodeManagedSpi(channel, pixels, managed, output,
804 spiChipsetFor(channel))) {
805 return;
806 }
807 pixels.writeLPD6803(&output);
808}
809
811void Channel::encodeSM16716(Channel& channel, PixelIterator& pixels,
812 bool managed, fl::vector_psram<u8>& output)
814 if (tryEncodeManagedSpi(channel, pixels, managed, output,
815 spiChipsetFor(channel))) {
816 return;
817 }
818 pixels.writeSM16716(&output);
819}
820
822void Channel::encodeHD108(Channel& channel, PixelIterator& pixels,
823 bool managed, fl::vector_psram<u8>& output)
825 if (tryEncodeManagedSpi(channel, pixels, managed, output,
826 spiChipsetFor(channel))) {
827 return;
828 }
829 pixels.writeHD108(&output, managed);
830}
831
833void Channel::encodeMY9221(Channel& channel, PixelIterator& pixels,
834 bool managed, fl::vector_psram<u8>& output)
836 (void)tryEncodeManagedSpi(channel, pixels, managed, output,
837 spiChipsetFor(channel));
838}
839
849fl::shared_ptr<IChannelDriver> Channel::resolveDynamicDriver() FL_NO_EXCEPT {
850#if defined(FASTLED_DISABLE_DYNAMIC_DRIVER) && FASTLED_DISABLE_DYNAMIC_DRIVER
851 // Body excluded via FASTLED_DISABLE_DYNAMIC_DRIVER (#2926). The
852 // showPixels call site is also gated so this is unreachable; the
853 // empty body lets the linker dead-strip ChannelManager::findDriverByName
854 // and selectDriverForChannel along with this symbol.
855 return {};
856#else
857 // Build busKey only when we actually need it (mBus != AUTO).
858 fl::string busKey;
859 if (mBus != Bus::AUTO) {
861 }
862
865 if (!mSettings.mWorker.isDefault()) {
866 // Explicit worker isolation must never silently fall back to a
867 // different bus or an engine that ignores the requested affinity.
868 if (!driver || (mBus != Bus::AUTO && driver->getName() != busKey) ||
869 !driver->configureWorker(mSettings.mWorker)) {
870 FL_ERROR("Channel: worker configuration rejected - dropping frame");
871 mDriver.reset();
872 return {};
873 }
874 }
875 mDriver = driver;
876
877 // #2455 / #2459: diagnostic when a typed-Bus request is not honored.
878 // Probe via `findDriverByName` (silent) to tell "not enabled", "disabled"
879 // and "cannot handle this chipset" apart; each names its own fix.
880#if FASTLED_LOG_RUNTIME_ENABLED
881 if (mBus != Bus::AUTO && (!driver || driver->getName() != busKey)) {
882 // Repeats once a second while the requested driver is unavailable, so
883 // the problem stays visible for as long as it lasts.
884 const fl::string using_name = driver ? driver->getName()
885 : fl::string::from_literal("nothing (frame dropped)");
886 auto busDriver = ChannelManager::instance().findDriverByName(busKey);
887 if (!busDriver) {
888 FL_WARN_EVERY(1000, "Channel '" << mName << "': driver '" << busKey
889 << "' is not enabled - falling back to " << using_name
890 << ". Fix: FastLED.enable<fl::Bus::" << busKey
891 << ">() (links only this driver) or FastLED.enableAllDrivers().");
892 } else if (!ChannelManager::instance().isDriverEnabled(*busDriver)) {
893 FL_WARN_EVERY(1000, "Channel '" << mName << "': driver '" << busKey
894 << "' is disabled - falling back to " << using_name
895 << ". Fix: FastLED.setDriverEnabled(\"" << busKey
896 << "\", true), or drop the setExclusiveDriver() that disabled it.");
897 } else {
898 FL_WARN_EVERY(1000, "Channel '" << mName << "': driver '" << busKey
899 << "' cannot handle this chipset (bus/chipset mismatch) - falling back to "
900 << using_name << ". Fix: pick a bus that supports this chipset.");
901 }
902 }
903 if (!driver) {
904 FL_ERROR("Channel '" << mName << "': No compatible driver found - cannot transmit");
905 }
906#endif // FASTLED_LOG_RUNTIME_ENABLED — release skips the per-frame
907 // driver->getName() != busKey compare + the silent
908 // findDriverByName probe (used only to differentiate the
909 // FL_ERROR message). The functional return value below is
910 // preserved in both builds. See #2952.
911 return driver;
912#endif // !FASTLED_DISABLE_DYNAMIC_DRIVER
913}
914
915// Cold path of showPixels(): the previous frame's buffer is still owned by the
916// driver. Returns false when showPixels() must drop this frame (#4566).
917bool Channel::waitForInUseBuffer() FL_NO_EXCEPT {
918 FL_WARN("Channel '" << mName << "': showPixels() called while mChannelData is in use by driver, attempting to wait");
919 auto driver = mDriver.lock();
920 if (!driver) {
921 FL_ERROR("Channel '" << mName << "': No driver bound yet the mChannelData is in use - cannot transmit");
922 return false;
923 }
924 // wait until the driver is in a READY state.
925 bool ok = driver->waitForReady();
926 if (!ok) {
927 FL_ERROR("Channel '" << mName << "': Timeout occurred while waiting for driver to become READY");
928 return false;
929 }
930 FL_WARN("Channel '" << mName << "': Engine became READY after waiting");
931 return true;
932}
933
934// showPixels() is only a dispatcher (#4566): in-use wait, driver resolution,
935// encodeFrame(), submitFrame(). Each helper is FL_NO_INLINE so the entry
936// point stays small and the bodies exist exactly once.
937void Channel::showPixels(PixelController<RGB, 1, 0xFFFFFFFF> &pixels) FL_NO_EXCEPT {
939
940 // Safety check: don't modify buffer if driver is currently transmitting it
941 if (mChannelData->isInUse() && !waitForInUseBuffer()) {
942 return;
943 }
944
945 // Channels created via the manager-based API (Channel::create(cfg))
946 // always resolve their driver dynamically through resolveDynamicDriver(),
947 // which handles the busKey construction, ChannelManager lookup, and
948 // diagnostics. Legacy addLeds<> controllers no longer go through Channel
949 // at all -- they route through fl::SlimBridgeController.
951#if !defined(FASTLED_DISABLE_DYNAMIC_DRIVER) || !FASTLED_DISABLE_DYNAMIC_DRIVER
952 driver = resolveDynamicDriver();
953 if (!driver) {
954 return;
955 }
956#else
957 // Dynamic-driver lookup gated out via FASTLED_DISABLE_DYNAMIC_DRIVER
958 // (#2926). The gate lets `--gc-sections` drop the resolveDynamicDriver
959 // body plus the ChannelManager::findDriverByName /
960 // selectDriverForChannel chain (~400-900 B). Under this flag, runtime
961 // Channels emit nothing -- user accepts the constraint.
962 return;
963#endif
964
965 encodeFrame(pixels);
966 submitFrame(driver);
967}
968
969// Encode `pixels` into mChannelData with the construction-bound encoder and
970// fire onChannelDataEncoded (#4566: out of line from showPixels()).
971void Channel::encodeFrame(PixelController<RGB, 1, 0xFFFFFFFF> &pixels) FL_NO_EXCEPT {
972 // Build pixel iterator with optional addressing transformation
973 // (#2558) Pass both Rgbw and Rgbww from the current rendering settings; the iterator
974 // carries both, and the encoder dispatch below picks the right path based
975 // on which white-channel variant the controller currently holds.
976#if FL_COLOR_PROFILE_RUNTIME
977 // Brightness reaches the pipeline as C4's flux scalar and nowhere else.
978 // `premixed` is the brightness on this path: binding a profile sets
979 // correction and temperature to identity, so nothing else is folded into
980 // it -- and reading it rather than `ColorAdjustment::brightness` keeps
981 // this working when FASTLED_HD_COLOR_MIXING is off, where that field
982 // does not exist.
983 //
984 // The shared pipeline is never written after it is built (#4440): this
985 // managed iterator takes a reference, copies it, and sets flux on the copy, so a
986 // concurrent reader -- the power estimate copies the same pipeline --
987 // never sees a half-written flux, and a reconfiguration replaces
988 // `mPipeline` without touching what this frame encodes through. Small
989 // tiers encode synchronously and keep single ownership, mutated in place.
990#if FL_COLOR_PIPELINE_SHARED
991 const ColorPipelineStorage pipeline_ref = mPipeline;
992 const StreamingPipelineQ16* pipeline = pipeline_ref.get();
993#else
994 StreamingPipelineQ16* pipeline = mPipeline.get();
995#endif
996#else
997 StreamingPipelineQ16* pipeline = nullptr;
998#endif
999 // Dither advances on presentation, not on attempt (#4347, R8): this
1000 // channel's phase moves only when its driver accepts a frame (submitFrame()), so
1001 // a dropped submission -- no driver, a disabled one, a busy buffer --
1002 // does not consume a phase and the cycle's average stays unbiased. Both
1003 // the legacy offsets and the colour-managed temporal dither read it.
1004 if (pixels.ditherActive()) {
1005 pixels.reseed_binary_dithering(mDitherPhase);
1006 }
1007#ifdef FL_IS_AVR
1008 // AVR omits base settings notifications, so base setters are authoritative.
1009 const auto& whiteSettings = mLegacySettings;
1010#else
1011 const auto& whiteSettings = mSettings;
1012#endif
1013 ReorderingPixelIteratorAny iterator(pixels, mScreenMap.getXYMap(), mRgbOrder,
1014 whiteSettings.rgbw(), whiteSettings.rgbww(),
1015 mName, pipeline, mDitherPhase,
1016 pixels.mColorAdjustment.premixed.r);
1017 PixelIterator& pixelIterator = iterator.get();
1018
1019 // Encode pixels with the writer selected once from the immutable chipset.
1020 auto& data = mChannelData->getData();
1021 data.clear();
1022 const auto* rgbww = whiteSettings.mWhiteCfg.ptr<Rgbww>();
1023 const auto* rgbw = whiteSettings.mWhiteCfg.ptr<Rgbw>();
1024 if (rgbww != nullptr && rgbww->active()) {
1025 mChannelData->setPixelFormat(ChannelPixelFormat::RGBWW);
1026 } else if (rgbw != nullptr && rgbw->active()) {
1027 mChannelData->setPixelFormat(ChannelPixelFormat::RGBW);
1028 } else {
1029 mChannelData->setPixelFormat(ChannelPixelFormat::RGB);
1030 }
1031
1032 if (mPixelEncoder != nullptr) {
1033 mPixelEncoder(*this, pixelIterator, iterator.isManaged(), data);
1034 }
1035
1036 // Fire event after encoding completes
1037 {
1038 auto& events = ChannelEvents::instance();
1039 events.onChannelDataEncoded(*this, *mChannelData);
1040 }
1041}
1042
1043// Submit the encoded frame to `driver` (#4566: out of line from showPixels()).
1044void Channel::submitFrame(const fl::shared_ptr<IChannelDriver>& driver) FL_NO_EXCEPT {
1045 // #2517: detect the silent-drop scenario before enqueuing — if the
1046 // resolved driver is registered with ChannelManager but currently
1047 // disabled (typically by `FastLED.setExclusiveDriver<OtherBus>()`),
1048 // `ChannelManager::onEndFrame()` will skip its `show()` call and the
1049 // frame is silently dropped on the floor. Emit an actionable
1050 // FL_ERROR so users can diagnose the missing output.
1051 //
1052 // One-shot via `mDisabledDriverWarned` to avoid per-frame spam.
1053 // Reset the latch whenever the driver returns to ENABLED so a later
1054 // disable re-emits the diagnostic.
1055 fl::string driverName = driver->getName();
1056 auto status = ChannelManager::instance().driverStatus(driverName);
1058#if FASTLED_LOG_RUNTIME_ENABLED
1059 if (!mDisabledDriverWarned) {
1060 emitDisabledDriverError(
1061 mName, driverName,
1062 ChannelManager::instance().exclusiveDriverName());
1063 mDisabledDriverWarned = true;
1064 }
1065#endif
1066 // Skip the enqueue — the data wouldn't be sent anyway, and dropping
1067 // it here matches the existing behaviour (rather than leaving stale
1068 // bytes in the driver's pending queue across an enable/disable flip).
1069 // The drop happens in both debug and release; only the diagnostic
1070 // and the one-shot latch are gated. In release, the empty
1071 // emitDisabledDriverError + the exclusiveDriverName() call + the
1072 // 3-arg fl::string chain dead-strip (see #2950).
1073 return;
1074 } else if (status == ChannelManager::DriverStatus::STATUS_ENABLED) {
1075#if FASTLED_LOG_RUNTIME_ENABLED
1076 // Reset the one-shot guard so a future disable re-emits the diagnostic.
1077 mDisabledDriverWarned = false;
1078#endif
1079 }
1080 // NOT_REGISTERED: driver is not managed by ChannelManager (e.g. a custom
1081 // test driver, or one that was removed). Fall through to enqueue and let
1082 // the driver decide what to do — this is the historic behaviour.
1083
1084 // Enqueue for transmission (will be sent when driver->show() is called)
1085 driver->enqueue(mChannelData);
1086 // Presented, per the driver contract: an accepted enqueue is the frame.
1087 ++mDitherPhase;
1088 auto& events = ChannelEvents::instance();
1089 // Reuse the name fetched for driverStatus() instead of a second getName().
1090 events.onChannelEnqueued(*this, driverName);
1091}
1092
1093void Channel::init() FL_NO_EXCEPT {
1094 // TODO: Implement initialization
1095}
1096
1097// Stub driver - provides no-op implementation for testing or unsupported platforms
1098namespace {
1100public:
1102
1103 virtual bool canHandle(const ChannelDataPtr& data) const FL_NO_EXCEPT override {
1104 (void)data;
1105 return true; // Test driver accepts all channel types
1106 }
1107
1108 virtual void enqueue(ChannelDataPtr /*channelData*/) FL_NO_EXCEPT override {
1109 // No-op: stub driver does nothing
1110 static bool warned = false;
1111 if (!warned) {
1112 FL_DBG("StubChannelEngine: No-op enqueue (use for testing or unsupported platforms)");
1113 warned = true;
1114 }
1115 }
1116
1117 virtual void show() FL_NO_EXCEPT override {
1118 // No-op: no hardware to drive
1119 }
1120
1121 virtual DriverState poll() FL_NO_EXCEPT override {
1122 return DriverState(DriverState::READY); // Always "ready" (does nothing)
1123 }
1124
1125 virtual fl::string getName() const FL_NO_EXCEPT override {
1126 return fl::string::from_literal("STUB");
1127 }
1128
1129 virtual Capabilities getCapabilities() const FL_NO_EXCEPT override {
1130 return Capabilities(true, true); // Stub accepts both clockless and SPI
1131 }
1132};
1133
1134} // anonymous namespace
1135
1137 static StubChannelEngine instance;
1138 return &instance;
1139}
1140
1141// Re-exposed protected base class methods
1142void Channel::addToDrawList() FL_NO_EXCEPT {
1143 if (isInList()) {
1144 FL_WARN("Channel '" << mName << "': Skipping addToDrawList() - already in draw list");
1145 return;
1146 }
1148 // Fire event after adding to draw list (detectable even if user bypasses FastLED.add())
1149 auto& events = ChannelEvents::instance();
1150 events.onChannelAdded(*this);
1151}
1152
1153void Channel::removeFromDrawList() FL_NO_EXCEPT {
1154 if (!isInList()) {
1155 FL_WARN("Channel '" << mName << "': Skipping removeFromDrawList() - not in draw list");
1156 return;
1157 }
1159 // Fire event after removing from draw list (detectable even if user bypasses FastLED.remove())
1160 auto& events = ChannelEvents::instance();
1161 events.onChannelRemoved(*this);
1162
1163 // Clear driver weak_ptr when removed from draw list
1164 mDriver.reset();
1165}
1166
1167int Channel::size() const FL_NO_EXCEPT {
1169}
1170
1174
1175u8 Channel::ditherPhase() const FL_NO_EXCEPT {
1176 return mDitherPhase;
1177}
1178
1179bool Channel::isInDrawList() const FL_NO_EXCEPT {
1181}
1182
1186
1190
1191CRGB Channel::getCorrection() FL_NO_EXCEPT {
1193}
1194
1195CRGB Channel::getTemperature() FL_NO_EXCEPT {
1197}
1198
1199u8 Channel::getDither() FL_NO_EXCEPT {
1201}
1202
1203#if FL_COLOR_PIPELINE_SHARED
1204fl::shared_ptr<StreamingPipelineQ16> Channel::colorPipeline() const FL_NO_EXCEPT {
1205 return mPipeline;
1206}
1207#endif
1208
1209Rgbw Channel::getRgbw() const FL_NO_EXCEPT {
1211}
1212
1213Channel& Channel::setGamma(float gamma) FL_NO_EXCEPT {
1214 mSettings.mGamma = gamma;
1215 return *this;
1216}
1217
1218fl::optional<float> Channel::getGamma() const FL_NO_EXCEPT {
1219 return mSettings.mGamma;
1220}
1221
1222fl::string Channel::getEngineName() const FL_NO_EXCEPT {
1223 // Lock the weak_ptr to get a shared_ptr
1224 auto driver = mDriver.lock();
1225 if (driver) {
1226 return driver->getName();
1227 }
1228 return fl::string(); // Return empty string if no driver bound
1229}
1230
1231Channel& Channel::setScreenMap(const fl::XYMap& map, float diameter) FL_NO_EXCEPT {
1232 fl::ScreenMap screenmap = map.toScreenMap();
1233 if (diameter <= 0.0f) {
1234 screenmap.setDiameter(.15f); // Default diameter for small matrices
1235 } else {
1236 screenmap.setDiameter(diameter);
1237 }
1240 return *this;
1241}
1242
1243Channel& Channel::setScreenMap(const fl::ScreenMap& map) FL_NO_EXCEPT {
1244 mScreenMap = map;
1246 return *this;
1247}
1248
1249Channel& Channel::setScreenMap(fl::u16 width, fl::u16 height, float diameter) FL_NO_EXCEPT {
1251 return setScreenMap(xymap, diameter);
1252}
1253
1254Channel& Channel::setScreenMap(const fl::XMap& map) FL_NO_EXCEPT {
1255 // Convert 1D XMap to 2D XYMap (width=length, height=1) and reuse existing logic
1257 return setScreenMap(xymap, .15f); // Use default diameter for 1D strips
1258}
1259
1260const fl::ScreenMap& Channel::getScreenMap() const FL_NO_EXCEPT {
1261 return mScreenMap;
1262}
1263
1264bool Channel::hasScreenMap() const FL_NO_EXCEPT {
1265 return mScreenMap.getLength() > 0;
1266}
1267
1268} // namespace fl
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
XYMap xymap
fl::ScreenMap screenmap
Rgbw rgbw
ESP32-P4 Parallel IO (PARLIO) LED channel.
CPixelLEDController(RegistrationMode mode) FL_NO_EXCEPT
T fetch_add(T value) FL_NO_EXCEPT
Definition atomic.h:159
bool isInList() const FL_NO_EXCEPT
Check if this controller is in the linked list.
@ DeferRegister
Defer registration until addToList() is called.
LegacySettings mLegacySettings
VIRTUAL_IF_NOT_AVR int size() const FL_NO_EXCEPT
How many LEDs does this controller manage?
CLEDController & setLeds(CRGB *data, int nLeds) FL_NO_EXCEPT
Set the default array of LEDs to be used by this controller.
CRGB getCorrection() FL_NO_EXCEPT
Get the correction value used by this controller.
fl::u8 getDither() const FL_NO_EXCEPT
Get the dithering option currently set for this controller.
CRGB getTemperature() FL_NO_EXCEPT
Get the color temperature, aka white point, for this controller.
void removeFromDrawList() FL_NO_EXCEPT
Remove this controller from the draw list.
CRGB * leds() FL_NO_EXCEPT
Pointer to the CRGB array for this controller.
Rgbw getRgbw() const FL_NO_EXCEPT
VIRTUAL_IF_NOT_AVR void showLeds(fl::u8 brightness) FL_NO_EXCEPT
void addToList() FL_NO_EXCEPT
Add this controller to the linked list.
EOrder mRgbOrder
Definition channel.h:417
static i32 nextId() FL_NO_EXCEPT
fl::u8 mBusWhich
Definition channel.h:441
i32 id() const FL_NO_EXCEPT override
Get the channel ID.
Definition channel.h:106
ChipsetVariant mChipset
Definition channel.h:415
bool isSpi() const FL_NO_EXCEPT
Check if this is an SPI chipset.
Definition channel.h:146
PixelEncoder mPixelEncoder
Definition channel.h:416
u8 mDitherPhase
This channel's temporal-dither phase.
Definition channel.h:445
static fl::string makeName(i32 id, const fl::optional< fl::string > &configName=fl::optional< fl::string >()) FL_NO_EXCEPT
fl::span< CRGB > leds() FL_NO_EXCEPT
Get the LED array as a span (non-const)
FL_NO_INLINE fl::shared_ptr< IChannelDriver > resolveDynamicDriver() FL_NO_EXCEPT
Cold slow-path helper for showPixels().
fl::ScreenMap mScreenMap
Definition channel.h:455
ChannelDataPtr mChannelData
Definition channel.h:454
static PixelEncoder selectPixelEncoder(const ChipsetVariant &) FL_NO_EXCEPT
The chipset is fixed when a Channel is constructed, so bind its pixel encoder once instead of switchi...
Channel & setScreenMap(const fl::XYMap &map, float diameter=-1.f) FL_NO_EXCEPT
Set screen map for JS canvas visualization from XYMap.
FL_NO_INLINE bool waitForInUseBuffer() FL_NO_EXCEPT
Cold helper for showPixels() when mChannelData is still in use by the driver: warns and waits for REA...
Channel(const ChipsetVariant &chipset, fl::span< CRGB > leds, EOrder rgbOrder, const ChannelOptions &options) FL_NO_EXCEPT
Private constructor (use create() factory method)
ColorProfileStatus colorProfileStatus() const FL_NO_EXCEPT
Definition channel.h:277
CLEDController * asController() FL_NO_EXCEPT
Get pointer to base CLEDController for linked list traversal.
Definition channel.h:194
void syncLegacySettings() FL_NO_EXCEPT
FL_NO_INLINE void encodeFrame(PixelController< RGB, 1, 0xFFFFFFFF > &pixels) FL_NO_EXCEPT
Encode pixels into mChannelData and fire onChannelDataEncoded (#4566).
bool mDisabledDriverWarned
Definition channel.h:446
fl::weak_ptr< IChannelDriver > mDriver
Definition channel.h:435
bool mStaticProfileCleared
Definition channel.h:458
const i32 mId
Definition channel.h:452
FL_NO_INLINE void submitFrame(const fl::shared_ptr< IChannelDriver > &driver) FL_NO_EXCEPT
Submit the encoded frame to driver: disabled-driver drop + one-shot diagnostic, enqueue,...
fl::string mName
Definition channel.h:453
ChannelOptions mSettings
Definition channel.h:456
static ChannelDataPtr create(const ChipsetVariant &chipset, fl::vector_psram< u8 > &&encodedData=fl::vector_psram< u8 >(), ChannelPixelFormat pixelFormat=ChannelPixelFormat::RGB) FL_NO_EXCEPT
Create channel transmission data (modern variant-based API)
Definition data.cpp.hpp:12
LED channel for parallel output, pretty much a CPixelLEDController but with timing and pin informatio...
Definition channel.h:60
fl::shared_ptr< IChannelDriver > findDriverByName(const fl::string &name) const FL_NO_EXCEPT
Silent counterpart to getDriverByName().
static ChannelManager & instance() FL_NO_EXCEPT
Get the global singleton instance.
DriverStatus driverStatus(const fl::string &name) const FL_NO_EXCEPT
Look up a driver's registration status without logging on miss.
@ STATUS_ENABLED
Driver is registered and enabled.
Definition manager.h:199
@ STATUS_DISABLED
Driver is registered but disabled.
Definition manager.h:198
fl::shared_ptr< IChannelDriver > selectDriverForChannel(const ChannelDataPtr &data, const fl::string &affinity) FL_NO_EXCEPT
Select best driver for channel data (used by Channel::showPixels)
static void onCanvasUiSet(CLEDController *strip, const ScreenMap &xymap) FL_NO_EXCEPT
static fl::shared_ptr< const Gamma8 > getOrCreate(float gamma) FL_NO_EXCEPT
Definition ease.cpp.hpp:460
IChannelDriver() FL_NO_EXCEPT=default
Minimal interface for LED channel transmission drivers.
Definition driver.h:53
Adapter class that creates a PixelIterator from any color order.
static XYMap constructRectangularGrid(u16 width, u16 height, u16 offset=0) FL_NO_EXCEPT
Definition xymap.cpp.hpp:36
static XYMap fromXMap(const XMap &xmap) FL_NO_EXCEPT
Create an XYMap from an XMap (treats 1D as 2D with height=1)
Definition xymap.cpp.hpp:68
bool isManaged() const FL_NO_EXCEPT
True when get() hands back the colour-managed iterator.
ReorderingPixelIteratorAny(PixelController< RGB, 1, 0xFFFFFFFF > &pixels, const XYMap *addressing, EOrder rgbOrder, Rgbw rgbw, Rgbww rgbww, const fl::string &channelName, StreamingPipelineQ16 *pipeline, u8 ditherPhase, u8 brightness) FL_NO_EXCEPT
Construct pixel iterator with optional addressing transformation.
PixelIterator & get() FL_NO_EXCEPT
Get the constructed pixel iterator.
static fl::vector< CRGB > & getReorderBufferTLS() FL_NO_EXCEPT
Get thread-local buffer for addressing transformation.
fl::optional< PixelController< RGB, 1, 0xFFFFFFFF > > mAddressedController
virtual void enqueue(ChannelDataPtr) FL_NO_EXCEPT override
Enqueue channel data for transmission.
virtual void show() FL_NO_EXCEPT override
Trigger transmission of enqueued data.
virtual fl::string getName() const FL_NO_EXCEPT override
Get the driver name for affinity binding.
virtual bool canHandle(const ChannelDataPtr &data) const FL_NO_EXCEPT override
Check if this driver can handle the given channel data.
virtual DriverState poll() FL_NO_EXCEPT override
Query driver state and perform maintenance.
virtual Capabilities getCapabilities() const FL_NO_EXCEPT override
Get driver capabilities (clockless, SPI, or both)
T * get() const FL_NO_EXCEPT
Definition shared_ptr.h:342
static string from_literal(const char *literal) FL_NO_EXCEPT
fl::size size() const FL_NO_EXCEPT
void resize(fl::size n) FL_NO_EXCEPT
Definition vector.h:593
void clear() FL_NO_EXCEPT
Definition vector.h:634
T * data() FL_NO_EXCEPT
Definition vector.h:619
Channel transmission data - lightweight DTO for driver transmission.
#define DISABLE_DITHER
Disable dithering.
Definition dither_mode.h:14
UCS7604 LED chipset encoder implementation.
#define FL_WARN_ONCE(...)
Definition log.h:439
#define FL_WARN(...)
Definition log.h:437
#define FL_WARN_EVERY(MILLIS,...)
Definition log.h:442
#define FL_DBG
Definition log.h:553
#define FL_ERROR(...)
Definition log.h:373
Centralized logging categories for FastLED hardware interfaces and subsystems.
Unified manager for channel drivers with priority-based fallback.
fl::enable_if<!fl::is_array< T >::value, unique_ptr< T > >::type make_unique(Args &&... args) FL_NO_EXCEPT
Definition unique_ptr.h:263
shared_ptr< T > make_shared(Args &&... args) FL_NO_EXCEPT
Definition shared_ptr.h:423
FL_NO_INLINE bool tryEncodeManagedSpi(Channel &channel, PixelIterator &pixels, bool managed, fl::vector_psram< u8 > &output, SpiChipset chipset) FL_NO_EXCEPT
Shared color-managed SPI override check.
void writeUCS7604(fl::vector_psram< u8 > *data, PixelIterator &pixelIterator, ClocklessEncoder encoder, const ChannelOptions &settings, EOrder rgbOrder, bool managed) FL_NO_EXCEPT
Encode UCS7604 pixel data into the channel data buffer.
SpiChipset spiChipsetFor(const Channel &channel) FL_NO_EXCEPT
void enable_rgbww_conversion() FL_NO_EXCEPT
Installs the RGBWW pixel conversion (see enable_rgbw_conversion, #4795).
bool & colorProfileStrictMode() FL_NO_EXCEPT
void enable_rgbw_conversion() FL_NO_EXCEPT
Installs the RGBW pixel conversion used by PixelIterator.
Definition rgbw.cpp.hpp:732
void enable_rgbw_power_estimate() FL_NO_EXCEPT
Lets the power limiter charge a controller's RGBW conversion.
SourceProfile & defaultSourceProfile() FL_NO_EXCEPT
CurrentControl brightness() FL_NO_EXCEPT
Get current global UCS7604 brightness value.
back_insert_iterator< Container > back_inserter(Container &c) FL_NO_EXCEPT
Helper function to create a back_insert_iterator.
Definition iterator.h:139
unsigned char u8
Definition stdint.h:132
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
ClocklessEncoder
Identifies which encoder to use for clockless chipsets in the Channel API.
@ CLOCKLESS_ENCODER_UCS7604_8BIT
UCS7604 8-bit 800KHz.
@ CLOCKLESS_ENCODER_TM1812_RGBWW
TM1812: two 5-byte RGBWW pixels in each 12-byte IC frame.
@ CLOCKLESS_ENCODER_UCS7604_16BIT
UCS7604 16-bit 800KHz.
@ CLOCKLESS_ENCODER_UCS7604_16BIT_1600
UCS7604 16-bit 1600KHz.
@ CLOCKLESS_ENCODER_WS2812
Default, no preamble (WS2812 and compatible)
@ CLOCKLESS_ENCODER_TM1908
TM1908: command prefix followed by RGB pixels.
AtomicFake< T > atomic
Definition atomic.h:26
IChannelDriver * getStubChannelEngine() FL_NO_EXCEPT
Get stub channel driver for testing or unsupported platforms.
MapRedBlackTree< Key, T, Compare, fl::allocator_slab< char > > map
Definition map.h:283
constexpr u32 gamma(float g) FL_NO_EXCEPT
Definition gamma_lut.h:36
u8 u8 height
Definition blur.h:186
Optional< T > optional
Definition optional.h:16
void prepare_rgbw_colorimetric(const Rgbw &) FL_NO_EXCEPT
Definition rgbw.cpp.hpp:626
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
constexpr fl::size kColorPipelineSourceStorage
The two things Channel needs from the colour pipeline, reached through pointers rather than by name.
fl::variant< ClocklessChipset, SpiChipsetConfig > ChipsetVariant
Definition config.h:157
ColorPipelineHooks & colorPipelineHooks() FL_NO_EXCEPT
The installed hooks.
@ AUTO
Definition bus.h:32
fl::i64 i64
Definition s16x16x4.h:222
u8 width
Definition blur.h:186
struct FL_ALIGNAS(4) Wave3BitExpansionLut
Lookup table for nibble-to-waveform expansion in wave3 format (32 bytes)
Definition wave3.h:32
constexpr fl::size kColorPipelineIteratorStorage
UCS7604Mode
UCS7604 protocol configuration modes.
Definition ucs7604.h:30
@ UCS7604_MODE_8BIT_800KHZ
Definition ucs7604.h:31
@ UCS7604_MODE_16BIT_1600KHZ
Definition ucs7604.h:33
@ UCS7604_MODE_16BIT_800KHZ
Definition ucs7604.h:32
string to_string(T value) FL_NO_EXCEPT
Definition string.h:459
EOrder
RGB color channel orderings, used when instantiating controllers to determine what order the controll...
Definition eorder.h:15
void encodeUCS7604(PixelIterator &pixel_iter, size_t num_leds, OutputIterator out, UCS7604Mode mode, const UCS7604CurrentControl &current, bool is_rgbw, const Gamma8 *gamma=nullptr, bool wide_source=false) FL_NO_EXCEPT
Encode complete UCS7604 frame (preamble + padding + pixel data)
Definition ucs7604.h:273
SpiChipset
LED chipsets with SPI interface (clocked protocols) Modern type-safe enum class - prefer this for new...
@ SM16716
SM16716 LED chipset.
@ LPD6803
LPD6803 LED chipset.
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
@ HD107
Same as APA102, but in turbo 40-mhz mode.
@ DOTSTARHD
APA102HD LED chipset alias.
@ SK9822HD
SK9822 LED chipset with 5-bit gamma correction.
@ SK9822
SK9822 LED chipset.
@ DOTSTAR
APA102 LED chipset alias.
@ P9813
P9813 LED chipset.
@ APA102
APA102 LED chipset.
@ HD108
16-bit variant of HD107, always gamma corrected. No SD (standard definition) option available - all H...
@ LPD8806
LPD8806 LED chipset.
@ WS2803
WS2803 LED chipset.
@ MY9221
MY9221 12-channel LED driver (dual-edge clocked; 4 RGB LEDs per chip)
@ WS2801
WS2801 LED chipset.
@ HD107HD
Same as APA102HD, but in turbo 40-mhz mode.
Base definition for an LED controller.
void(* destroyIterator)(void *source_storage, void *iterator_storage)
Destroys what makeIterator built. Null until installed.
bool(* encodeManagedSpi)(PixelIterator &pixels, vector_psram< u8 > *out, SpiChipset chip, const Channel &controller)
Unscaled (full-brightness) power demand of leds as the pipeline will drive them, in mW,...
PixelIterator *(* makeIterator)(void *source_storage, void *iterator_storage, PixelController< RGB, 1, 0xFFFFFFFF > &controller, EOrder order, ColorPipelineFrameRef pipeline, const Rgbw &rgbw, Rgbww rgbww, u8 dither_phase, u8 brightness)
Constructs a colour-managed PixelIterator in caller-provided storage.
Payload shared by every color-profile notification.
Everything the per-pixel path needs, derived once when a profile binds.
Definition pipeline.h:73
#define FL_COLOR_PIPELINE_SHARED
Shared ownership of a channel's colour pipeline, the controller accessor that hands it out,...
Definition options.h:61
Low level pixel data writing class.
#define FL_UNUSED(x)
#define FL_NO_INLINE
#define FL_ALIGNAS(N)
Pixel controller class.
@ Black
<div style='background:#000000;width:4em;height:4em;'></div>
Definition crgb.h:517
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
Configuration for a single LED channel.
Definition config.h:167
static ChannelEvents & instance() FL_NO_EXCEPT
Optional channel configuration parameters All fields have sensible defaults and can be overridden as ...
Definition options.h:93
Runtime bit-period timing for a clockless chipset.
ChipsetTimingConfig timing
T1/T2/T3 timing parameters.
Definition config.h:35
ClocklessEncoder encoder
Byte-level encoding pipeline (default: WS2812)
Definition config.h:36
Clockless chipset configuration (single data pin)
Definition config.h:33
Driver capabilities.
Definition driver.h:155
Driver state with optional error message.
Definition driver.h:169
SpiEncoder timing
SPI encoder configuration.
Definition config.h:106
Esp32SpiBus spiBus
ESP-IDF host override, or AUTO.
Definition config.h:107
SPI chipset configuration (data + clock pins)
Definition config.h:103
u8 g
Green channel current (0x0-0xF)
Definition ucs7604.h:39
u8 b
Blue channel current (0x0-0xF)
Definition ucs7604.h:40
u8 w
White channel current (0x0-0xF)
Definition ucs7604.h:41
u8 r
Red channel current (0x0-0xF)
Definition ucs7604.h:38
UCS7604 current control structure with 4-bit fields for each channel.
Definition ucs7604.h:37
#define FL_SCOPED_TRACE
Definition trace.h:128
UCS7604 LED chipset controller implementation for FastLED.