FastLED 3.10.10
Loading...
Searching...
No Matches
power_mgt.cpp.hpp
Go to the documentation of this file.
1
3
5#include "led_sysdefs.h" // Must be included first (required by lib8tion.h)
6#include "pixeltypes.h" // CRGB
7#include "controller.h" // CLEDController
8#include "fastpin.h" // Pin
10#include "fl/stl/compiler_control.h" // FL_UNUSED
11#if SKETCH_HAS_LARGE_MEMORY
12#include "fl/math/math.h" // fl::pow, fl::lround — libm-gated wrappers
13#include "fl/stl/array.h"
14#endif
15#include "fl/stl/int.h" // fl::u32, fl::u8
16#include "fl/stl/type_traits.h" // fl::conditional
18#include "power_mgt.h" // Function declarations (to avoid redefinition errors)
19#include "fl/channels/pipeline_binding.h" // colorPipelineHooks (#4344)
22#include "pixel_controller.h"
23#include "fl/stl/singleton.h" // fl::Singleton
24#include "fl/gfx/rgbw.h" // fl::Rgbw, fl::rgb_2_rgbw
25#include "fl/stl/noexcept.h"
26// POWER MANAGEMENT
27
46
47static constexpr float kLinearPowerScalingExponent = 1.0f;
48static constexpr float kPowerScalingExponentEpsilon = 0.0001f;
49
52 // Constant-initialized (constexpr constructor, trivial destructor), so it
53 // needs neither Singleton's lazy placement-new nor a guard: there is no
54 // initialization order to protect and nothing to destroy.
55 static PowerModelRGB model;
56 return model;
57}
58
71
75
80
84
85// Source order, not wire order: RGB, then W or warm-W/cool-W. An undeclared
86// white gets the maximum representable emitter draw, so a managed channel
87// cannot silently under-budget it. Legacy estimates keep their old fallback.
88static void emitter_power_weights(fl::u8 count, fl::u8 (&weights)[5]) FL_NO_EXCEPT {
89 const PowerModelRGB& rgb = gPowerModel();
90 weights[0] = rgb.red_mW;
91 weights[1] = rgb.green_mW;
92 weights[2] = rgb.blue_mW;
93 weights[3] = 0;
94 weights[4] = 0;
95 if (count == 4) {
96 const fl::u8 white = gWhiteEmitterPower().mW;
97 weights[3] = white != 0 ? white : 255;
98 } else if (count == 5) {
100 if (rgbww.declared) {
101 weights[0] = rgbww.model.red_mW;
102 weights[1] = rgbww.model.green_mW;
103 weights[2] = rgbww.model.blue_mW;
104 weights[3] = rgbww.model.warm_white_mW;
105 weights[4] = rgbww.model.white_mW;
106 } else {
107 weights[3] = 255;
108 weights[4] = 255;
109 }
110 }
111}
112
113#if SKETCH_HAS_LARGE_MEMORY
114static constexpr fl::size kPowerScalingTableSize = 256;
115
119struct PowerScalingState {
120 fl::array<fl::u8, kPowerScalingTableSize> forward;
121 fl::array<fl::u8, kPowerScalingTableSize> reverse;
124 fl::u8 max_step = 1;
125
126 PowerScalingState() FL_NO_EXCEPT {
127 reset_identity();
128 }
129
130 void reset_identity() FL_NO_EXCEPT {
131 for (fl::size i = 0; i < kPowerScalingTableSize; ++i) {
132 forward[i] = static_cast<fl::u8>(i);
133 reverse[i] = static_cast<fl::u8>(i);
134 }
135 max_step = 1;
136 }
137};
138
139static PowerScalingState& gPowerScaling() FL_NO_EXCEPT {
141}
142
145static void rebuild_power_scaling_tables(float exponent) FL_NO_EXCEPT {
146 PowerScalingState& state = gPowerScaling();
147 if (!(exponent > 0.0f) ||
149 state.reset_identity();
150 return;
151 }
152
153 // Forward LUT: source brightness -> scaled brightness via pow(x/255, exponent)
154 state.forward[0] = 0;
155 for (fl::size i = 1; i < kPowerScalingTableSize; ++i) {
156 float normalized = static_cast<float>(i) / 255.0f;
157 // Route through fl::powf / fl::lroundf (libm-gated via FL_MATH_USE_LIBM,
158 // see fl/math/math.cpp.hpp). Use the float overloads — fl::pow takes
159 // double, so passing floats would auto-promote and re-anchor the
160 // double-precision soft-FP chain that #3002 is trying to avoid.
161 int mapped = static_cast<int>(
162 fl::lroundf(fl::powf(normalized, exponent) * 255.0f));
163 state.forward[i] = static_cast<fl::u8>(fl::clamp(mapped, 0, 255));
164 }
165 state.forward[255] = 255;
166 state.max_step = 1;
167 for (fl::size i = 1; i < kPowerScalingTableSize; ++i) {
168 const int step = state.forward[i] - state.forward[i - 1];
169 if (step > state.max_step) {
170 state.max_step = static_cast<fl::u8>(step);
171 }
172 }
173
174 // Reverse LUT: scaled brightness -> largest source whose forward value is
175 // <= the scaled value. Floor-inverse, so `unmap_power_value()` never
176 // rounds a budgeted scaled brightness *up* past the power budget.
177 state.reverse[0] = 0;
178 int source = 0;
179 for (int scaled = 1; scaled < static_cast<int>(kPowerScalingTableSize); ++scaled) {
180 while (source < 255 && state.forward[source + 1] <= scaled) {
181 ++source;
182 }
183 state.reverse[scaled] = static_cast<fl::u8>(source);
184 }
185}
186#endif
187
189#if SKETCH_HAS_LARGE_MEMORY
190 return gPowerScaling().forward[brightness];
191#else
192 return brightness;
193#endif
194}
195
196static fl::u8 unmap_power_value(fl::u8 scaled_brightness) FL_NO_EXCEPT {
197#if SKETCH_HAS_LARGE_MEMORY
198 return gPowerScaling().reverse[scaled_brightness];
199#else
200 return scaled_brightness;
201#endif
202}
203
206#if !FL_PLATFORM_HAS_TINY_MEMORY
208#if SKETCH_HAS_LARGE_MEMORY
209 return gPowerScaling().max_step;
210#else
211 return 1;
212#endif
213}
214#endif
215
217 return fl::scale32by8(total_mW, map_power_value(brightness));
218}
219
221
222// Alternate calibration by RAtkins via pre-PSU wattage measurments;
223// these are all probably about 20%-25% too high due to PSU heat losses,
224// but if you're measuring wattage on the PSU input side, this may
225// be a better set of calibrations. (WS2812B)
226// static const uint8_t gRed_mW = 100;
227// static const uint8_t gGreen_mW = 48;
228// static const uint8_t gBlue_mW = 100;
229// static const uint8_t gDark_mW = 12;
230
231
234#define POWER_LED 1
235
238#define POWER_DEBUG_PRINT 0
239
240
241// Power consumed by the MCU board (typical active draw, radios idle), charged
242// as an undimmable baseline. Compile-time per family; define
243// FL_MCU_POWER_MW to override for a specific board.
244#ifndef FL_MCU_POWER_MW
245#if defined(FL_IS_TEENSY_4X)
246#define FL_MCU_POWER_MW 500 // ~100 mA @ 5 V (600 MHz Cortex-M7)
247#elif defined(FL_IS_TEENSY_3X)
248#define FL_MCU_POWER_MW 200 // ~40 mA @ 5 V
249#elif defined(FL_IS_ESP_32C2) || defined(FL_IS_ESP_32C3) || \
250 defined(FL_IS_ESP_32C5) || defined(FL_IS_ESP_32C6) || defined(FL_IS_ESP_32H2)
251#define FL_MCU_POWER_MW 150 // ~30 mA @ 5 V (single-core RISC-V)
252#elif defined(FL_IS_ESP_32P4)
253#define FL_MCU_POWER_MW 500 // ~100 mA @ 5 V (dual-core 360 MHz)
254#elif defined(FL_IS_ESP32) || defined(FL_IS_ESP8266)
255#define FL_MCU_POWER_MW 250 // ~50 mA @ 5 V (Xtensa, radio idle)
256#else
257#define FL_MCU_POWER_MW 125 // 25 mA @ 5 V: AVR, RP2040 and the default
258#endif
259#endif
260// FL_LINT_ALLOW_GLOBAL(two bytes in .data; runtime override of the MCU baseline)
261static fl::u16 gMCU_mW = FL_MCU_POWER_MW;
262
263void set_mcu_power_mW(fl::u16 mcu_mW) FL_NO_EXCEPT { gMCU_mW = mcu_mW; }
265
266static fl::u8 gMaxPowerIndicatorLEDPinNumber = 0; // default = Arduino onboard LED pin. set to zero to skip this.
267
268
269// Span-based version (primary implementation)
271 fl::u32 red32 = 0, green32 = 0, blue32 = 0;
272
273 // Iterate using span's safe indexing
274 for(size_t i = 0; i < leds.size(); i++) {
275 red32 += map_power_value(leds[i].r);
276 green32 += map_power_value(leds[i].g);
277 blue32 += map_power_value(leds[i].b);
278 }
279
280 red32 *= gPowerModel().red_mW;
281 green32 *= gPowerModel().green_mW;
282 blue32 *= gPowerModel().blue_mW;
283
284 red32 >>= 8;
285 green32 >>= 8;
286 blue32 >>= 8;
287
288 fl::u32 total = red32 + green32 + blue32 + (gPowerModel().dark_mW * leds.size());
289
290 return total;
291}
292
294 fl::u8 emitter_count) FL_NO_EXCEPT {
295 if (emitter_count < 3 || emitter_count > 5 ||
296 codes.size() % emitter_count != 0) {
297 return 0;
298 }
299 fl::u8 weights[5];
300 emitter_power_weights(emitter_count, weights);
301 fl::u32 sums[5] = {};
302 for (fl::size i = 0; i < codes.size(); i += emitter_count) {
303 for (fl::u8 channel = 0; channel < emitter_count; ++channel) {
304 sums[channel] += map_power_value(codes[i + channel]);
305 }
306 }
307 fl::u32 total = static_cast<fl::u32>(gPowerModel().dark_mW) *
308 (codes.size() / emitter_count);
309 for (fl::u8 channel = 0; channel < emitter_count; ++channel) {
310 total += (sums[channel] * weights[channel]) >> 8;
311 }
312 return total;
313}
314
315// Pointer-based version (delegates to span version)
316fl::u32 calculate_unscaled_power_mW( const CRGB* ledbuffer, fl::u16 numLeds ) FL_NO_EXCEPT //25354
317{
318 return calculate_unscaled_power_mW(fl::span<const CRGB>(ledbuffer, numLeds));
319}
320
321// Four emitters, using the conversion the encoder will actually run.
322//
323// The three-emitter overload reads the source triple the sketch wrote. For an
324// RGBW controller that triple is an input to `rgb_2_rgbw`, not a description
325// of the drives, and the two disagree by more than rounding: at full white on
326// the shipped default model the source triple reads 249 while the strip draws
327// 348 under `kRGBWMaxBrightness` and 99 under `kRGBWExactColors`. #4156 R3.
328//
329// Scales are passed as 255 because this is the demand at full brightness --
330// the caller scales the result. That is exact for `kRGBWExactColors` and
331// `kRGBWMaxBrightness`, whose conversions commute with the scale to within
332// 0.4% over the measured cases. It is not exact for `kRGBWBoostedWhite`,
333// which reallocates between emitters as the scale drops: demand there runs up
334// to 12.1% above the linear projection at low brightness. Charging four
335// emitters instead of three is the larger correction by far, and the residual
336// is stated rather than hidden -- closing it needs demand evaluated per
337// candidate brightness, which is a pixel walk per step of the limiter's
338// search.
340 const fl::u8 white_mW = gWhiteEmitterPower().mW;
341 // `!rgbw.active()` is a fast path, not a different answer: the only
342 // inactive mode is `kRGBWInvalid`, which `rgb_2_rgbw` dispatches to
343 // null-white -- RGB passed through with w = 0 -- so the loop below would
344 // return the same total. Removing the test changes nothing observable
345 // and costs one conversion per pixel on every plain RGB controller in
346 // the sketch, which the estimator walks once per frame.
347 //
348 // The `white_mW == 0` half *is* behavioural: with no declared white
349 // there is nothing to charge the fourth diode at.
350 if (!rgbw.active() || white_mW == 0) {
351 if (rgbw.active()) {
352 FL_WARN_ONCE("power: controller is in RGBW mode but the power model "
353 "declares no white emitter, so the budget covers three "
354 "of its four diodes. Call "
355 "FastLED.setPowerModel(PowerModelRGBW(...)) to fix it.");
356 }
358 }
359
360 fl::u32 red32 = 0, green32 = 0, blue32 = 0, white32 = 0;
361 for (fl::size i = 0; i < leds.size(); i++) {
362 fl::u8 r = 0, g = 0, b = 0, w = 0;
363 fl::rgb_2_rgbw(rgbw, leds[i].r, leds[i].g, leds[i].b, 255, 255, 255,
364 &r, &g, &b, &w);
365 red32 += map_power_value(r);
366 green32 += map_power_value(g);
367 blue32 += map_power_value(b);
368 white32 += map_power_value(w);
369 }
370
371 red32 *= gPowerModel().red_mW;
372 green32 *= gPowerModel().green_mW;
373 blue32 *= gPowerModel().blue_mW;
374 white32 *= white_mW;
375
376 red32 >>= 8;
377 green32 >>= 8;
378 blue32 >>= 8;
379 white32 >>= 8;
380
381 return red32 + green32 + blue32 + white32 +
382 (gPowerModel().dark_mW * leds.size());
383}
384
385
386// The part of the estimate a brightness scalar cannot touch: every controller
387// IC draws its quiescent current whether or not an emitter is lit, and the MCU
388// draws its own regardless of what the strip is doing. #4156 R4:
389//
390// Fixed idle consumption cannot be reduced by multiplying LED flux.
391//
392// Scaling that baseline along with the emitters is what let the limiter
393// under-report. At 300 WS2812s on the default model the baseline is 1500 mW,
394// and a 2000 mW budget used to be answered with a brightness that draws 3461.
395static fl::u32 fixed_power_mW(fl::u32 led_count) FL_NO_EXCEPT {
396 return static_cast<fl::u32>(gPowerModel().dark_mW) * led_count;
397}
398
399// min(255, floor(255 * num / den)) for den > 0, in 32-bit arithmetic only.
400//
401// The product needs 40 bits, and on AVR a 64-bit divide links ~600 B of
402// libgcc helpers into every sketch that limits power. A quotient of 255 or
403// more is clamped by the only caller anyway, so only num < den matters:
404// eight restoring-division steps give q = floor(256 * num / den) with
405// remainder r, and since 256 * num = q * den + r, the 255 * num answer is
406// q when r >= num and q - 1 otherwise (0 < num - r <= num < den). The
407// doubling is written as a comparison so it cannot overflow for any den.
408fl::u32 power_ratio_of_255(fl::u32 num, fl::u32 den) FL_NO_EXCEPT {
409 if (num >= den) {
410 return 255;
411 }
412 fl::u32 q = 0;
413 fl::u32 r = num;
414 for (fl::u8 bit = 0; bit < 8; ++bit) {
415 q <<= 1;
416 if (r >= den - r) {
417 r -= den - r;
418 q |= 1;
419 } else {
420 r += r;
421 }
422 }
423 return r >= num ? q : q - 1;
424}
425
426// Largest brightness whose *total* demand -- baseline included -- stays inside
427// the budget, floored at the classic answer for a budget at the baseline.
428// When the baseline alone is already over the budget no brightness meets it,
429// and blanking the strip would not either: the baseline is drawn at
430// brightness zero too. Such budgets were written against the classic model,
431// which scaled the whole estimate, so they get the classic answer back rather
432// than a dark strip (#5139: 1 W on 271 LEDs lit nothing from 3.10.6). The
433// floor keeps the answer monotone across the baseline; see its comment below.
434static fl::u8 brightness_within_budget(fl::u32 fixed_mW, fl::u32 controllable_mW,
435 fl::u8 target_brightness,
436 fl::u32 max_power_mW) FL_NO_EXCEPT {
437 const fl::u32 requested_mW =
438 fixed_mW + scale_power_for_brightness(controllable_mW, target_brightness);
439 if (requested_mW <= max_power_mW) {
440 return target_brightness;
441 }
442 if (controllable_mW == 0) {
443 // Nothing left to scale: every brightness draws the same baseline.
444 // Also keeps the division below from dividing by zero.
445 return 0;
446 }
447 if (max_power_mW <= fixed_mW) {
448 // The baseline alone meets or exceeds the budget: no brightness fits,
449 // and the budget is an upper bound. Dark is also the monotone answer,
450 // since just above the baseline the headroom buys almost nothing.
451 // Also keeps the subtraction below from underflowing.
452 FL_WARN_EVERY(1000, "power: budget " << max_power_mW
453 << " mW is at or under the " << fixed_mW
454 << " mW baseline (MCU + LED dark current); LEDs blanked."
455 << " Raise the budget or set FL_MCU_POWER_MW.");
456 return 0;
457 }
458 // The ratio is taken over the whole 0-255 scaled range, because
459 // `controllable_mW` is the demand at *full* brightness. Scaling it by the
460 // requested brightness first would answer "what fraction of the request
461 // fits", which is smaller than "what brightness fits" by exactly that
462 // fraction -- and the step-down below only ever decreases, so it cannot
463 // recover it. The cap is where the request comes back in.
464 //
465 // The cap cannot actually fire from here: the caller only reaches this
466 // branch when the request is already over budget, which is the same
467 // inequality. It is kept because that argument runs through
468 // `map_power_value`'s rounding, and a helper that clamps to its own
469 // argument is cheaper than depending on that.
470 const fl::u32 headroom_mW = max_power_mW - fixed_mW;
471 const fl::u8 target_scaled = map_power_value(target_brightness);
472 fl::u32 allowed_scaled = power_ratio_of_255(headroom_mW, controllable_mW);
473 if (allowed_scaled > target_scaled) {
474 allowed_scaled = target_scaled;
475 }
476 const fl::u32 recommended_scaled = static_cast<fl::u32>(allowed_scaled);
477 fl::u8 recommended = unmap_power_value(static_cast<fl::u8>(recommended_scaled));
478
479 // Then check the answer instead of trusting the division. Inverting the
480 // ratio in scaled space is off by the rounding of whichever `scale32by8`
481 // the platform compiled -- the FASTLED_SCALE8_FIXED form computes
482 // `i * (s + 1) >> 8`, so the closed form lands about `controllable/256`
483 // over the budget, which was 176 mW of a 5000 mW budget on the default
484 // model. Demand is monotone in brightness, so stepping down until it fits
485 // is exact whatever the rounding, and terminates: 0 always fits here,
486 // because the branch above already returned for a budget at or under
487 // baseline. The result is the largest brightness whose modeled draw fits,
488 // so it never exceeds the budget and never falls as the budget rises.
489 while (recommended > 0 &&
490 fixed_mW + scale_power_for_brightness(controllable_mW, recommended) >
491 max_power_mW) {
492 --recommended;
493 }
494 return recommended;
495}
496
497fl::u8 calculate_max_brightness_for_power_vmA(const CRGB* ledbuffer, fl::u16 numLeds, fl::u8 target_brightness, fl::u32 max_power_V, fl::u32 max_power_mA) FL_NO_EXCEPT {
498 return calculate_max_brightness_for_power_mW(ledbuffer, numLeds, target_brightness, max_power_V * max_power_mA);
499}
500
501fl::u8 calculate_max_brightness_for_power_mW(const CRGB* ledbuffer, fl::u16 numLeds, fl::u8 target_brightness, fl::u32 max_power_mW) FL_NO_EXCEPT {
502 const fl::u32 total_mW = calculate_unscaled_power_mW( ledbuffer, numLeds);
503 const fl::u32 fixed_mW = fixed_power_mW(numLeds);
504 const fl::u32 controllable_mW = total_mW > fixed_mW ? total_mW - fixed_mW : 0;
505
506 return brightness_within_budget(fixed_mW, controllable_mW, target_brightness,
507 max_power_mW);
508}
509
510// The RGBW estimate, once something has stored an Rgbw into a controller.
511// Reached through a pointer so that the conversion (~1 KB on AVR) links only
512// into sketches that configure RGBW; until then every stored white config is
513// absent, and the RGB estimate is the answer the overload would give.
514typedef fl::u32 (*rgbw_power_fn)(fl::span<const CRGB>, const fl::Rgbw&);
515// FL_LINT_ALLOW_GLOBAL(one zero-initialized pointer in .bss; a Singleton would add its init code to every limiter sketch)
517
521
524 static_cast<fl::size>(controller.size()));
525#if FL_COLOR_PIPELINE_SHARED
526 // Through the pipeline hook, which exists whenever a pipeline does; naming
527 // the estimator directly would link the colour pipeline into sketches that
528 // limit power but never bind a profile. `pipeline` is this estimate's own
529 // reference, so reconfiguring the controller mid-pass cannot free the
530 // pipeline it is walking (#4440).
531 const fl::shared_ptr<fl::StreamingPipelineQ16> pipeline = fl::channelColorPipeline(controller);
533 if (pipeline && hooks.unscaledPowerMilliwatts != nullptr) {
534 // The callback charges already-solved physical emitter bytes. In
535 // particular, the RGBW legacy estimator must not convert them again.
536 const fl::u8 emitters = controller.getRgbww().active()
537 ? 5 : (controller.getRgbw().active() ? 4 : 3);
538 return hooks.unscaledPowerMilliwatts(
539 *pipeline, leds, emitters, &calculate_unscaled_emitter_power_mW);
540 }
541#endif
542 // Below the large-memory tier only this is compiled: a managed channel
543 // there is charged for its source (FL_COLOR_PIPELINE_SHARED).
544 // No stored Rgbw reads as RgbwInvalid, which the overload answers with the
545 // RGB estimate; asking for it directly skips copying the Rgbw value.
546 const fl::Rgbw* rgbw = controller.rgbwConfig();
549}
550
551// Two output codes: the most one `BINARY_DITHER` offset can lift a lit channel
552// once scaled. `d <= 256/s` scales back to at most one code, and the
553// FASTLED_SCALE8_FIXED form `(x * (s + 1)) >> 8` can carry one more; an
554// exhaustive check over every source, scale and offset finds 2 as the maximum.
555static constexpr fl::u32 kDitherReserveCodes = 2;
556
557#if FL_PLATFORM_HAS_TINY_MEMORY
558// TINY tier: no reserve, and none of the 64-bit arithmetic that computes it
559// (#4478). A target with 8 KiB of flash cannot spend 468 B on a bound that
560// only matters when a sketch also limits power.
563 return 0;
564}
565
568 return 0;
569}
570#else
571// Wide enough for the reserve's worst case without 64-bit libgcc helpers on
572// targets where it provably fits: with a 16-bit `fl::size` at most 65535
573// pixels light a channel, each charged at most 255 mW, and below the large
574// tier `max_power_step()` is 1, so the sum is at most
575// 65535 * 3 * 255 * kDitherReserveCodes + 255 < 2^32.
576#if SKETCH_HAS_LARGE_MEMORY
577typedef fl::u64 dither_acc_t;
578#else
579typedef fl::conditional<sizeof(fl::size) <= 2, fl::u32, fl::u64>::type dither_acc_t;
580FL_STATIC_ASSERT(sizeof(fl::size) > 2 ||
581 65535ull * 3u * 255u * kDitherReserveCodes + 255u <= 0xFFFFFFFFull,
582 "dither reserve must fit 32 bits on 16-bit-size targets");
583#endif
584
586 fl::u32 lit_r = 0, lit_g = 0, lit_b = 0;
587 for (fl::size i = 0; i < leds.size(); ++i) {
588 // A zero channel is never dithered: `dither()` returns 0 for it.
589 lit_r += leds[i].r != 0 ? 1u : 0u;
590 lit_g += leds[i].g != 0 ? 1u : 0u;
591 lit_b += leds[i].b != 0 ? 1u : 0u;
592 }
593 const PowerModelRGB& model = gPowerModel();
594 const dither_acc_t per_code =
595 static_cast<dither_acc_t>(lit_r) * model.red_mW +
596 static_cast<dither_acc_t>(lit_g) * model.green_mW +
597 static_cast<dither_acc_t>(lit_b) * model.blue_mW;
598 // Same >> 8 as the estimator, rounded up: this is a bound, and truncating
599 // it would hand back the under-charge it exists to remove.
600 const dither_acc_t scaled = per_code * kDitherReserveCodes * max_power_step();
601 const dither_acc_t reserve = (scaled + 255) >> 8;
602 // Saturate rather than wrap: an under-stated reserve is the failure this
603 // exists to prevent.
604 return reserve > 0xFFFFFFFFu ? 0xFFFFFFFFu : static_cast<fl::u32>(reserve);
605}
606
608 if (controller.getDither() != BINARY_DITHER) {
609 return 0;
610 }
611#if FL_COLOR_PIPELINE_SHARED
612 // A managed channel never takes the legacy offsets (C5); with
613 // BINARY_DITHER it runs the pipeline's temporal dither instead, which
614 // emits floor(x) or floor(x) + 1 of the exact code -- at most one code
615 // above the rounded code its estimate charges. The solve can light a
616 // channel the source left dark, so every channel of every lit pixel is
617 // reserved one code.
618 if (fl::channelColorPipeline(controller)) {
620 static_cast<fl::size>(controller.size()));
621 fl::u32 lit = 0;
622 for (fl::size i = 0; i < leds.size(); ++i) {
623 lit += (leds[i].r | leds[i].g | leds[i].b) != 0 ? 1u : 0u;
624 }
625 const fl::u8 emitters = controller.getRgbww().active()
626 ? 5 : (controller.getRgbw().active() ? 4 : 3);
627 fl::u8 weights[5];
628 emitter_power_weights(emitters, weights);
629 fl::u32 sum_weights = 0;
630 for (fl::u8 i = 0; i < emitters; ++i) {
631 sum_weights += weights[i];
632 }
633 const fl::u64 per_code = static_cast<fl::u64>(lit) * sum_weights;
634 const fl::u64 reserve = (per_code * max_power_step() + 255) >> 8;
635 return reserve > 0xFFFFFFFFu ? 0xFFFFFFFFu
636 : static_cast<fl::u32>(reserve);
637 }
638#endif
639#if !defined(FL_IS_AVR)
640 // Legacy RGBW and RGBWW conversions read the raw pixel, not the
641 // dithered one. Managed channels have already returned above.
642 if (controller.getRgbw().active() || controller.getRgbww().active()) {
643 return 0;
644 }
645#endif
647 controller.leds(), static_cast<fl::size>(controller.size())));
648}
649#endif // FL_PLATFORM_HAS_TINY_MEMORY
650
651#if FL_COLOR_PIPELINE_SHARED
652namespace {
653
654// Candidate-specific legacy demand. Unlike the old unity-demand projection,
655// this runs the same brightness premix and white extraction as PixelController.
656// Dither can raise a lit channel by at most two codes, so charge that upward
657// choice without touching the global/frame phase.
658fl::u32 legacyFramePowerMilliwatts(fl::CLEDController& controller,
660 const fl::u32 count = static_cast<fl::u32>(controller.size());
661 const fl::u8 emitters = controller.getRgbww().active() ? 5 :
662 (controller.getRgbw().active() ? 4 : 3);
663 fl::u8 weights[5];
664 emitter_power_weights(emitters, weights);
665 fl::u64 sums[5] = {};
667 controller.leds(), controller.size(),
668 controller.getAdjustmentData(brightness), DISABLE_DITHER);
669 for (fl::u32 i = 0; i < count; ++i) {
670 fl::u8 codes[5] = {};
671 if (emitters == 5) {
672 pixels.loadAndScaleRGBWWUnordered(controller.getRgbww(),
673 &codes[0], &codes[1], &codes[2], &codes[3], &codes[4]);
674 } else if (emitters == 4) {
675 pixels.loadAndScaleRGBWUnordered(controller.getRgbw(),
676 &codes[0], &codes[1], &codes[2], &codes[3]);
677 } else {
678 pixels.loadAndScaleRGB(&codes[0], &codes[1], &codes[2]);
679 }
680 const CRGB& source = controller.leds()[i];
681 const bool dithered = controller.getDither() == BINARY_DITHER &&
682 (source.r | source.g | source.b) != 0 && brightness != 0;
683 for (fl::u8 c = 0; c < emitters; ++c) {
684 const fl::u8 upper = dithered
685 ? static_cast<fl::u8>(codes[c] > 253 ? 255 : codes[c] + 2)
686 : codes[c];
687 sums[c] += map_power_value(upper);
688 }
689 pixels.advanceData();
690 }
691 fl::u64 total = static_cast<fl::u64>(gPowerModel().dark_mW) * count;
692 for (fl::u8 c = 0; c < emitters; ++c) {
693 total += (sums[c] * weights[c] + 255u) >> 8;
694 }
695 return total > 0xFFFFFFFFu ? 0xFFFFFFFFu : static_cast<fl::u32>(total);
696}
697
698struct ManagedFramePower {
699 fl::shared_ptr<fl::StreamingPipelineQ16> pipeline;
700 fl::ManagedPowerHistogram histogram;
701 fl::PowerCodecPolicy codec;
702 fl::u8 weights[5] = {};
703};
704
705struct FramePowerSnapshot {
706 fl::vector<ManagedFramePower> managed;
707 fl::vector<fl::CLEDController*> legacy;
708};
709
710bool captureFramePowerSnapshot(FramePowerSnapshot* snapshot) FL_NO_EXCEPT {
711 const fl::PowerFrameHooks& hooks = fl::powerFrameHooks();
712 fl::size managed_count = 0;
713 fl::size legacy_count = 0;
715 controller != nullptr; controller = controller->next()) {
716 if (!controller->getEnabled()) continue;
717 if (fl::channelColorPipeline(*controller) && hooks.buildPowerHistogram) {
718 ++managed_count;
719 } else {
720 ++legacy_count;
721 }
722 }
723 // Allocate exactly once, then construct histograms in their final slots.
724 // fl::vector silently leaves size unchanged when allocation fails.
725 snapshot->managed.resize(managed_count);
726 snapshot->legacy.resize(legacy_count);
727 if (snapshot->managed.size() != managed_count ||
728 snapshot->legacy.size() != legacy_count) return false;
729 fl::size managed_index = 0;
730 fl::size legacy_index = 0;
732 controller != nullptr; controller = controller->next()) {
733 if (!controller->getEnabled()) continue;
735 fl::channelColorPipeline(*controller);
736 if (pipeline && hooks.buildPowerHistogram != nullptr) {
737 if (managed_index >= managed_count) return false;
738 ManagedFramePower& entry = snapshot->managed[managed_index++];
739 entry.pipeline = pipeline;
741 const fl::u8 emitters = controller->getRgbww().active() ? 5 :
742 (controller->getRgbw().active() ? 4 : 3);
743 emitter_power_weights(emitters, entry.weights);
744 hooks.buildPowerHistogram(
745 *pipeline,
747 emitters, &entry.histogram);
748 } else {
749 if (legacy_index >= legacy_count) return false;
750 snapshot->legacy[legacy_index++] = controller;
751 }
752 }
753 // A binding/list mutation during capture would invalidate the model.
754 return managed_index == managed_count && legacy_index == legacy_count;
755}
756
757fl::u32 framePowerAtFluxMilliwatts(const FramePowerSnapshot& snapshot,
758 fl::u32 flux_q16,
759 fl::u8 legacy_brightness) FL_NO_EXCEPT {
760 fl::u64 total = gMCU_mW;
762 static_cast<fl::i32>(flux_q16));
763 const fl::PowerFrameHooks& hooks = fl::powerFrameHooks();
764 for (fl::size i = 0; i < snapshot.managed.size(); ++i) {
765 const ManagedFramePower& entry = snapshot.managed[i];
766 const fl::u64 numerator = hooks.histogramPowerNumerator(
767 *entry.pipeline, entry.histogram, flux, entry.codec,
768 entry.weights,
770 total += static_cast<fl::u64>(gPowerModel().dark_mW) *
771 entry.histogram.pixels + ((numerator + 255u) >> 8);
772 }
773 for (fl::size i = 0; i < snapshot.legacy.size(); ++i) {
774 total += legacyFramePowerMilliwatts(*snapshot.legacy[i],
775 legacy_brightness);
776 }
777 return total > 0xFFFFFFFFu ? 0xFFFFFFFFu : static_cast<fl::u32>(total);
778}
779
780} // namespace
781
782fl::FramePowerPlan fl::calculateFramePowerPlan(
783 fl::u8 requested_brightness, fl::u32 budget_mW) FL_NO_EXCEPT {
784 FramePowerPlan plan;
785 plan.mcu_mW = gMCU_mW;
786 FramePowerSnapshot snapshot;
787 if (!captureFramePowerSnapshot(&snapshot)) {
788 // Never solve against a partial set of enabled channels. Zero is the
789 // minimum controllable output; the unknown demand is not certified.
790 plan.flux_q16 = 0;
791 plan.legacy_brightness = 0;
792 plan.modeled_mW = 0xFFFFFFFFu;
793 plan.infeasible = true;
794 plan.limited = requested_brightness != 0;
795 return plan;
796 }
797 const fl::u32 request_flux = fl::FluxScalar::fromBrightness(
798 requested_brightness).rawQ16();
799 const fl::u32 zero_demand = framePowerAtFluxMilliwatts(snapshot, 0, 0);
800 if (zero_demand > budget_mW) {
801 plan.flux_q16 = 0;
802 plan.legacy_brightness = 0;
803 plan.modeled_mW = zero_demand;
804 plan.infeasible = true;
805 plan.limited = requested_brightness != 0;
806 return plan;
807 }
808 fl::u32 low = 0;
809 fl::u32 high = request_flux;
810 const auto legacy_at_flux = [request_flux, requested_brightness](
811 fl::u32 candidate) -> fl::u8 {
812 return candidate == request_flux ? requested_brightness
813 : static_cast<fl::u8>((static_cast<fl::u64>(candidate) * 255u) >> 16);
814 };
815 while (low < high) {
816 const fl::u32 candidate = low + (high - low + 1) / 2;
817 if (framePowerAtFluxMilliwatts(snapshot, candidate,
818 legacy_at_flux(candidate)) <= budget_mW) {
819 low = candidate;
820 } else {
821 high = candidate - 1;
822 }
823 }
824 plan.flux_q16 = low;
825 plan.limited = low < request_flux;
826 // Preserve the caller's exact byte when no limiting was needed. Q16's
827 // representation of b/255 is rounded, so projecting it back with a floor
828 // can otherwise turn even an unlimited b=1 into zero.
829 plan.legacy_brightness = legacy_at_flux(low);
830 plan.modeled_mW = framePowerAtFluxMilliwatts(
831 snapshot, low, plan.legacy_brightness);
832 return plan;
833}
834
835fl::u32 fl::framePowerMCUBaselineMilliwatts() FL_NO_EXCEPT {
836 return gMCU_mW;
837}
838
839namespace {
840bool hasManagedPowerChannel() FL_NO_EXCEPT {
841 for (CLEDController* p = CLEDController::head(); p; p = p->next()) {
842 if (p->getEnabled() && fl::channelColorPipeline(*p)) {
843 return true;
844 }
845 }
846 return false;
847}
848void beginManagedPowerFrame(fl::u8 requested_brightness, fl::u32 budget_mW,
849 fl::u8* legacy_brightness) FL_NO_EXCEPT {
850 const fl::FramePowerPlan plan =
851 fl::calculateFramePowerPlan(requested_brightness, budget_mW);
852 *legacy_brightness = plan.legacy_brightness;
853 fl::PowerFrameHooks& hooks = fl::powerFrameHooks();
854 hooks.frameFluxQ16 = plan.flux_q16;
855 hooks.frameFluxActive = true;
856}
857void endManagedPowerFrame() FL_NO_EXCEPT {
858 fl::PowerFrameHooks& hooks = fl::powerFrameHooks();
859 hooks.frameFluxActive = false;
860 hooks.frameFluxQ16 = 0;
861}
862
863// Registered only when setMaxPowerInMilliWatts() is used. This keeps the
864// ordinary show() body and its linked Blink image free of managed-power code.
865class FramePowerEndListener : public fl::EngineEvents::Listener {
866 public:
867 void onEndFrame() FL_NO_EXCEPT override { endManagedPowerFrame(); }
868 ~FramePowerEndListener() FL_NO_EXCEPT override {
870 }
871};
872
873FramePowerEndListener& framePowerEndListener() FL_NO_EXCEPT {
874 static FramePowerEndListener listener;
875 return listener;
876}
877
878fl::u8 managedShowBrightness(fl::u8 requested_brightness,
879 fl::u32 budget_mW) FL_NO_EXCEPT {
880 if (!hasManagedPowerChannel()) {
881 return calculate_max_brightness_for_power_mW(requested_brightness,
882 budget_mW);
883 }
884#if FASTLED_HAS_ENGINE_EVENTS
885 // addListener() may fail to grow its registry. Never leave a Q16 flux
886 // active across frames if the end-of-frame reset could not be installed.
887 if (!fl::EngineEvents::hasListener(&framePowerEndListener())) {
888 endManagedPowerFrame();
889 return 0;
890 }
891#else
892 // A managed Q16 frame requires a guaranteed reset after encode. Without
893 // frame events, fail closed rather than retaining flux into later frames.
894 return 0;
895#endif
896 fl::u8 legacy_brightness = requested_brightness;
897 beginManagedPowerFrame(requested_brightness, budget_mW,
898 &legacy_brightness);
899 return legacy_brightness;
900}
901} // namespace
902
903const fl::FramePowerDispatch* fl::framePowerDispatch() FL_NO_EXCEPT {
904 static const FramePowerDispatch dispatch = {
905 &calculateFramePowerPlan, &managedShowBrightness,
907#if FASTLED_HAS_ENGINE_EVENTS
908 fl::EngineEvents::addListener(&framePowerEndListener(), 1000000);
909#endif
910 return &dispatch;
911}
912#endif // FL_COLOR_PIPELINE_SHARED
913
914// sets brightness to
915// - no more than target_brightness
916// - no more than max_mW milliwatts
917fl::u8 calculate_max_brightness_for_power_mW( fl::u8 target_brightness, fl::u32 max_power_mW)
919 // gMCU_mW and every controller's dark current are baseline: present at any
920 // brightness, and so kept out of the part the scalar acts on (#4156 R4).
921 fl::u32 fixed_mW = gMCU_mW;
922 fl::u32 controllable_mW = 0;
923
925 while(pCur) {
926 const fl::u32 count = pCur->size();
927 // Through its RGBW conversion, and for a bound colour profile the
928 // solved drives rather than the source (#4344).
929 const fl::u32 unscaled_mW = controller_unscaled_power_mW(*pCur);
930 const fl::u32 dark_mW = fixed_power_mW(count);
931 // Dither's upward reserve does not scale with brightness, so it is
932 // charged with the baseline (#4342).
933 fixed_mW += dark_mW + controller_dither_reserve_mW(*pCur);
934 controllable_mW += unscaled_mW > dark_mW ? unscaled_mW - dark_mW : 0;
935 pCur = pCur->next();
936 }
937
938#if POWER_DEBUG_PRINT == 1
939 Serial.print("power demand at full brightness mW = ");
940 Serial.println( fixed_mW + controllable_mW);
941#endif
942
943 const fl::u32 requested_power_mW =
944 fixed_mW + scale_power_for_brightness(controllable_mW, target_brightness);
945#if POWER_DEBUG_PRINT == 1
946 if( target_brightness != 255 ) {
947 Serial.print("power demand at scaled brightness mW = ");
948 Serial.println( requested_power_mW);
949 }
950 Serial.print("power limit mW = ");
951 Serial.println( max_power_mW);
952#endif
953
954 if( requested_power_mW <= max_power_mW) {
955#if POWER_LED > 0
957 Pin(gMaxPowerIndicatorLEDPinNumber).lo(); // turn the LED off
958 }
959#endif
960#if POWER_DEBUG_PRINT == 1
961 Serial.print("demand is under the limit");
962#endif
963 return target_brightness;
964 }
965
966 const fl::u8 recommended_brightness = brightness_within_budget(
967 fixed_mW, controllable_mW, target_brightness, max_power_mW);
968#if POWER_DEBUG_PRINT == 1
969 Serial.print("recommended brightness # = ");
970 Serial.println( recommended_brightness);
971
972 fl::u32 resultant_power_mW =
973 fixed_mW + scale_power_for_brightness(controllable_mW, recommended_brightness);
974 Serial.print("resultant power demand mW = ");
975 Serial.println( resultant_power_mW);
976
977 Serial.println();
978#endif
979
980#if POWER_LED > 0
982 Pin(gMaxPowerIndicatorLEDPinNumber).hi(); // turn the LED on
983 }
984#endif
985
986 return recommended_brightness;
987}
988
993
994// The RGB half of installing a model. Split out because the white emitter's
995// lifetime is not the same as the RGB model's: declaring an RGB model retracts
996// a white declaration, but changing the exponent must not.
998 gPowerModel() = model;
999#if SKETCH_HAS_LARGE_MEMORY
1000 rebuild_power_scaling_tables(model.exponent);
1001#else
1002 // Small-memory targets ignore non-linear exponent and keep linear behavior;
1003 // clamp the stored field so get_power_scaling_exponent() reports the truth.
1005#endif
1006}
1007
1009 apply_rgb_power_model(model);
1010 // An RGB model describes a strip with three emitters. Leaving a white
1011 // declaration from an earlier RGBW model standing would charge this one
1012 // for a diode the caller just said it does not have.
1013 gWhiteEmitterPower().mW = 0;
1014 gRgbwwEmitterPower().declared = false;
1015}
1016
1018 apply_rgb_power_model(model.toRGB());
1019 gWhiteEmitterPower().mW = model.white_mW;
1020 gRgbwwEmitterPower().declared = false;
1021}
1022
1024 // Preserve the legacy folded-RGB estimate while retaining the physical
1025 // weights for a managed five-emitter pipeline.
1026 apply_rgb_power_model(model.toRGB());
1027 gWhiteEmitterPower().mW = 0;
1028 gRgbwwEmitterPower().model = model;
1030}
1031
1035
1037 PowerModelRGB model = gPowerModel();
1038 model.exponent = exponent;
1039 // Not `set_power_model`: the exponent is a property of the response
1040 // curve, and changing it is not a statement about how many emitters the
1041 // strip has.
1042 apply_rgb_power_model(model);
1043}
1044
1046 // Authoritative storage lives in the model; on small-memory builds the
1047 // field is clamped to 1.0 by set_power_model.
1048 return gPowerModel().exponent;
1049}
1050
1054
1055// Note: The following deprecated wrapper functions have been moved to FastLED.cpp:
1056// - set_max_power_in_volts_and_milliamps()
1057// - set_max_power_in_milliwatts()
1058// - show_at_max_brightness_for_power()
1059// - delay_at_max_brightness_for_power()
1060// These functions depend on the FastLED singleton and don't belong in this core power calculation file.
CRGB leds[1]
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
TestState state
CLEDController * controller
Rgbw rgbw
static CLEDController * head() FL_NO_EXCEPT
Get the first LED controller in the linked list of controllers.
VIRTUAL_IF_NOT_AVR int size() const FL_NO_EXCEPT
How many LEDs does this controller manage?
CLEDController * next() FL_NO_EXCEPT
Get the next controller in the linked list after this one.
virtual void onEndFrame() FL_NO_EXCEPT
static void removeListener(Listener *listener) FL_NO_EXCEPT
static void addListener(Listener *listener, int priority=0) FL_NO_EXCEPT
static bool hasListener(Listener *listener) FL_NO_EXCEPT
static FluxScalar fromRawQ16(i32 raw) FL_NO_EXCEPT
A limiter fraction already in s16.16, clamped to [0, 1].
i32 rawQ16() const FL_NO_EXCEPT
static FluxScalar fromBrightness(u8 brightness) FL_NO_EXCEPT
setBrightness(b) as the linear flux scalar b/255.
A linear flux scalar in s16.16.
Definition flux_scalar.h:21
static T & instance() FL_NO_EXCEPT
Definition singleton.h:41
fl::CLEDController CLEDController
#define BINARY_DITHER
Enable dithering using binary dithering (only option)
Definition dither_mode.h:16
#define DISABLE_DITHER
Disable dithering.
Definition dither_mode.h:14
Backward compatibility header - use fl/fastpin.h directly.
Functions for red, green, blue, white (RGBW) output.
fl::CRGB CRGB
Definition crgb.h:25
void set_max_power_indicator_LED(fl::u8 pinNumber) FL_NO_EXCEPT
Select a pin with an LED that will be flashed to indicate that power management is pulling down the b...
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.
fl::u8 calculate_max_brightness_for_power_vmA(const CRGB *ledbuffer, fl::u16 numLeds, fl::u8 target_brightness, fl::u32 max_power_V, fl::u32 max_power_mA) FL_NO_EXCEPT
Determines the highest brightness level you can use and still stay under the specified power budget f...
fl::u32 calculate_unscaled_power_mW(fl::span< const CRGB > leds) FL_NO_EXCEPT
fl::u8 calculate_max_brightness_for_power_mW(const CRGB *ledbuffer, fl::u16 numLeds, fl::u8 target_brightness, fl::u32 max_power_mW) FL_NO_EXCEPT
Determines the highest brightness level you can use and still stay under the specified power budget f...
fl::u32 power_ratio_of_255(fl::u32 num, fl::u32 den) FL_NO_EXCEPT
min(255, floor(255 * num / den)) for den > 0, computed in 32-bit arithmetic.
fl::u32 dither_reserve_mW(fl::span< const CRGB > leds) FL_NO_EXCEPT
The most BINARY_DITHER can add to one latched frame of leds, in mW (#4342, contract R4: "quantization...
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_power_scaling_exponent(float exponent) FL_NO_EXCEPT
Set a non-linear brightness-to-power response exponent.
PowerModelRGB get_power_model() FL_NO_EXCEPT
Get current RGB power model.
void set_power_model(const PowerModelRGB &model) FL_NO_EXCEPT
Set custom RGB LED power consumption model.
fl::u32 calculate_unscaled_emitter_power_mW(fl::span< const fl::u8 > codes, fl::u8 emitter_count) FL_NO_EXCEPT
Charge already-solved physical output bytes in source emitter order: RGB, RGBW, or RGB + warm white +...
fl::u16 get_mcu_power_mW() FL_NO_EXCEPT
The MCU baseline currently charged, in milliwatts.
float get_power_scaling_exponent() FL_NO_EXCEPT
Get the current brightness-to-power response exponent.
void set_mcu_power_mW(fl::u16 mcu_mW) FL_NO_EXCEPT
Override the MCU board's undimmable baseline draw, in milliwatts.
fl::u8 get_white_emitter_mW() FL_NO_EXCEPT
The white-emitter draw the caller declared, or zero if they declared only an RGB model.
Determines which platform system definitions to include.
#define FL_WARN_ONCE(...)
Definition log.h:439
#define FL_WARN_EVERY(MILLIS,...)
Definition log.h:442
void reverse(Iterator first, Iterator last) FL_NO_EXCEPT
Definition algorithm.h:14
void enable_rgbw_power_estimate() FL_NO_EXCEPT
Lets the power limiter charge a controller's RGBW conversion.
constexpr T && forward(typename remove_reference< T >::type &t) FL_NO_EXCEPT
Definition s16x16x4.h:236
unsigned char u8
Definition stdint.h:132
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
constexpr bool almost_equal(T a, T b, U tolerance) FL_NO_EXCEPT
Definition math.h:98
constexpr enable_if< is_fixed_point< T >::value, T >::type clamp(T x, T lo, T hi) FL_NO_EXCEPT
FASTLED_FORCE_INLINE void rgb_2_rgbw(const Rgbw &cfg, u8 r, u8 g, u8 b, u8 r_scale, u8 g_scale, u8 b_scale, u8 *out_r, u8 *out_g, u8 *out_b, u8 *out_w) FL_NO_EXCEPT
Converts RGB to RGBW using one of the functions.
Definition rgbw.h:406
ColorPipelineHooks & colorPipelineHooks() FL_NO_EXCEPT
The installed hooks.
constexpr enable_if< is_fixed_point< T >::value, T >::type step(T edge, T x) FL_NO_EXCEPT
PowerCodecPolicy powerChannelCodecPolicy(const CLEDController &controller) FL_NO_EXCEPT
Identify the channel's final current/quantization choice without adding a virtual slot or storage to ...
float powf(float base, float exponent) FL_NO_EXCEPT
Definition math.h:444
fl::u64 u64
Definition s16x16x4.h:221
long lroundf(float value) FL_NO_EXCEPT
Definition math.h:338
Result of the shared frame-budget prepass on large-memory managed output.
Low level pixel data writing class.
Includes defintions for RGB and HSV pixels.
static constexpr fl::u32 kDitherReserveCodes
fl::conditional< sizeof(fl::size)<=2, fl::u32, fl::u64 >::type dither_acc_t
static constexpr float kLinearPowerScalingExponent
static rgbw_power_fn gRgbwPowerEstimate
static PowerModelRGB & gPowerModel() FL_NO_EXCEPT
Global RGB power model (initialized to WS2812 @ 5V defaults, linear response)
#define FL_MCU_POWER_MW
static void apply_rgb_power_model(const PowerModelRGB &model) FL_NO_EXCEPT
static constexpr float kPowerScalingExponentEpsilon
static fl::u8 max_power_step() FL_NO_EXCEPT
What one output code can cost at the steepest point of the response, in the 0-255 scaled units calcul...
static void emitter_power_weights(fl::u8 count, fl::u8(&weights)[5]) FL_NO_EXCEPT
static fl::u8 map_power_value(fl::u8 brightness) FL_NO_EXCEPT
static fl::u8 gMaxPowerIndicatorLEDPinNumber
static RgbwwEmitterPower & gRgbwwEmitterPower() FL_NO_EXCEPT
fl::u32(* rgbw_power_fn)(fl::span< const CRGB >, const fl::Rgbw &)
static fl::u16 gMCU_mW
static fl::u32 fixed_power_mW(fl::u32 led_count) FL_NO_EXCEPT
static fl::u8 brightness_within_budget(fl::u32 fixed_mW, fl::u32 controllable_mW, fl::u8 target_brightness, fl::u32 max_power_mW) FL_NO_EXCEPT
static WhiteEmitterPower & gWhiteEmitterPower() FL_NO_EXCEPT
static fl::u8 unmap_power_value(fl::u8 scaled_brightness) FL_NO_EXCEPT
PowerModelRGBWW model
The white emitter's draw, when the caller declared one.
Functions to limit the power used by FastLED.
#define FL_STATIC_ASSERT(...)
#define FL_UNUSED(x)
#define FL_NO_EXCEPT
Portable compile-time assertion wrapper.
Pixel controller class.
fl::u8 blue_mW
Blue channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:33
fl::u8 dark_mW
Dark (all channels off) draw per LED IC, in milliwatts, charged as an undimmable baseline.
Definition power_mgt.h:41
fl::u8 red_mW
Red channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:31
float exponent
Brightness-to-power response exponent (1.0 = linear)
Definition power_mgt.h:42
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:32
RGB LED power consumption model Used for standard 3-channel LEDs (WS2812, WS2812B,...
Definition power_mgt.h:30
RGBW LED power consumption model Used for 4-channel LEDs (SK6812 RGBW and similar).
Definition power_mgt.h:65
fl::u8 white_mW
Cool white channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:110
fl::u8 green_mW
Green channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:108
fl::u8 warm_white_mW
Warm white channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:111
fl::u8 red_mW
Red channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:107
fl::u8 blue_mW
Blue channel power at full brightness (255), in milliwatts.
Definition power_mgt.h:109
RGBWW LED power consumption model (RGB + warm white + cool white).
Definition power_mgt.h:106
#define Serial
Definition serial.h:314