FastLED 3.9.15
Loading...
Searching...
No Matches
FastLED.h
Go to the documentation of this file.
1#pragma once
2#ifndef __INC_FASTSPI_LED2_H
3#define __INC_FASTSPI_LED2_H
4
5#include <stdint.h>
6
9
10#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 4)
11#define FASTLED_HAS_PRAGMA_MESSAGE
12#endif
13
19#define FASTLED_VERSION 3009019
20#ifndef FASTLED_INTERNAL
21# ifdef FASTLED_SHOW_VERSION
22# ifdef FASTLED_HAS_PRAGMA_MESSAGE
23# pragma message "FastLED version 3.009.019"
24# else
25# warning FastLED version 3.009.019 (Not really a warning, just telling you here.)
26# endif
27# endif
28#endif
29
30
31#if !defined(FASTLED_FAKE_SPI_FORWARDS_TO_FAKE_CLOCKLESS)
32#if defined(__EMSCRIPTEN__)
33#define FASTLED_FAKE_SPI_FORWARDS_TO_FAKE_CLOCKLESS 1
34#else
35#define FASTLED_FAKE_SPI_FORWARDS_TO_FAKE_CLOCKLESS 0
36#endif
37#endif
38
39#ifndef __PROG_TYPES_COMPAT__
43#define __PROG_TYPES_COMPAT__
44#endif
45
46#ifdef __EMSCRIPTEN__
47#include "platforms/wasm/js.h"
48#include "platforms/wasm/led_sysdefs_wasm.h"
49#include "platforms/wasm/compiler/Arduino.h"
50#endif
51
52#ifdef SmartMatrix_h
53#include <SmartMatrix.h>
54#endif
55
56#ifdef DmxSimple_h
57#include <DmxSimple.h>
58#endif
59
60#ifdef DmxSerial_h
61#include <DMXSerial.h>
62#endif
63
64#ifdef USE_OCTOWS2811
65#include <OctoWS2811.h>
66#endif
67
68
69
70#include "fl/force_inline.h"
71#include "cpp_compat.h"
72
73#include "fastled_config.h"
74#include "led_sysdefs.h"
75
76// Utility functions
77#include "fastled_delay.h"
78#include "bitswap.h"
79
80#include "controller.h"
81#include "fastpin.h"
82#include "fastspi_types.h"
83#include "dmx.h"
84
85#include "platforms.h"
86#include "fastled_progmem.h"
87
88#include "lib8tion.h"
89#include "pixeltypes.h"
90#include "hsv2rgb.h"
91#include "colorutils.h"
92#include "pixelset.h"
93#include "colorpalettes.h"
94
95#include "noise.h"
96#include "power_mgt.h"
97
98#include "fastspi.h"
99#include "chipsets.h"
100#include "fl/engine_events.h"
101
102#include "fl/leds.h"
103
105
106// Backdoor to get the size of the CLedController object. The one place
107// that includes this just uses extern to declare the function.
108uint16_t cled_contoller_size();
109
128
132
137
142
143#ifdef HAS_PIXIE
144template<uint8_t DATA_PIN, EOrder RGB_ORDER> class PIXIE : public PixieController<DATA_PIN, RGB_ORDER> {};
145#endif
146
147#ifdef FASTLED_HAS_CLOCKLESS
152
155template<uint8_t DATA_PIN> class NEOPIXEL : public WS2812Controller800Khz<DATA_PIN, GRB> {};
156
159template<uint8_t DATA_PIN, EOrder RGB_ORDER>
160class SM16703 : public SM16703Controller<DATA_PIN, RGB_ORDER> {};
161
164template<uint8_t DATA_PIN, EOrder RGB_ORDER>
165class TM1829 : public TM1829Controller800Khz<DATA_PIN, RGB_ORDER> {};
166
169template<uint8_t DATA_PIN, EOrder RGB_ORDER>
170class TM1812 : public TM1809Controller800Khz<DATA_PIN, RGB_ORDER> {};
171
174template<uint8_t DATA_PIN, EOrder RGB_ORDER>
175class TM1809 : public TM1809Controller800Khz<DATA_PIN, RGB_ORDER> {};
176
179template<uint8_t DATA_PIN, EOrder RGB_ORDER>
180class TM1804 : public TM1809Controller800Khz<DATA_PIN, RGB_ORDER> {};
181
184template<uint8_t DATA_PIN, EOrder RGB_ORDER>
185class TM1803 : public TM1803Controller400Khz<DATA_PIN, RGB_ORDER> {};
186
189template<uint8_t DATA_PIN, EOrder RGB_ORDER>
190class UCS1903 : public UCS1903Controller400Khz<DATA_PIN, RGB_ORDER> {};
191
194template<uint8_t DATA_PIN, EOrder RGB_ORDER>
195class UCS1903B : public UCS1903BController800Khz<DATA_PIN, RGB_ORDER> {};
196
199template<uint8_t DATA_PIN, EOrder RGB_ORDER>
200class UCS1904 : public UCS1904Controller800Khz<DATA_PIN, RGB_ORDER> {};
201
204template<uint8_t DATA_PIN, EOrder RGB_ORDER>
205class UCS2903 : public UCS2903Controller<DATA_PIN, RGB_ORDER> {};
206
209template<uint8_t DATA_PIN, EOrder RGB_ORDER>
210class WS2812 : public WS2812Controller800Khz<DATA_PIN, RGB_ORDER> {};
211
213template<uint8_t DATA_PIN, EOrder RGB_ORDER>
214class WS2815 : public WS2815Controller<DATA_PIN, RGB_ORDER> {};
215
217template <uint8_t DATA_PIN, EOrder RGB_ORDER>
218class WS2816 : public WS2816Controller<DATA_PIN, RGB_ORDER> {};
219
222template<uint8_t DATA_PIN, EOrder RGB_ORDER>
223class WS2852 : public WS2812Controller800Khz<DATA_PIN, RGB_ORDER> {};
224
227template<uint8_t DATA_PIN, EOrder RGB_ORDER>
228class WS2812B : public WS2812Controller800Khz<DATA_PIN, RGB_ORDER> {};
229
232template<uint8_t DATA_PIN, EOrder RGB_ORDER>
233class GS1903 : public WS2812Controller800Khz<DATA_PIN, RGB_ORDER> {};
234
237template<uint8_t DATA_PIN, EOrder RGB_ORDER>
238class SK6812 : public SK6812Controller<DATA_PIN, RGB_ORDER> {};
239
242template<uint8_t DATA_PIN, EOrder RGB_ORDER>
243class SK6822 : public SK6822Controller<DATA_PIN, RGB_ORDER> {};
244
247template<uint8_t DATA_PIN, EOrder RGB_ORDER>
248class APA106 : public SK6822Controller<DATA_PIN, RGB_ORDER> {};
249
252template<uint8_t DATA_PIN, EOrder RGB_ORDER>
253class PL9823 : public PL9823Controller<DATA_PIN, RGB_ORDER> {};
254
257template<uint8_t DATA_PIN, EOrder RGB_ORDER>
258class WS2811 : public WS2811Controller800Khz<DATA_PIN, RGB_ORDER> {};
259
262template<uint8_t DATA_PIN, EOrder RGB_ORDER>
263class WS2813 : public WS2813Controller<DATA_PIN, RGB_ORDER> {};
264
267template<uint8_t DATA_PIN, EOrder RGB_ORDER>
268class APA104 : public WS2811Controller800Khz<DATA_PIN, RGB_ORDER> {};
269
272template<uint8_t DATA_PIN, EOrder RGB_ORDER>
273class WS2811_400 : public WS2811Controller400Khz<DATA_PIN, RGB_ORDER> {};
274
277template<uint8_t DATA_PIN, EOrder RGB_ORDER>
278class GE8822 : public GE8822Controller800Khz<DATA_PIN, RGB_ORDER> {};
279
282template<uint8_t DATA_PIN, EOrder RGB_ORDER>
283class GW6205 : public GW6205Controller800Khz<DATA_PIN, RGB_ORDER> {};
284
287template<uint8_t DATA_PIN, EOrder RGB_ORDER>
288class GW6205_400 : public GW6205Controller400Khz<DATA_PIN, RGB_ORDER> {};
289
292template<uint8_t DATA_PIN, EOrder RGB_ORDER>
293class LPD1886 : public LPD1886Controller1250Khz<DATA_PIN, RGB_ORDER> {};
294
297template<uint8_t DATA_PIN, EOrder RGB_ORDER>
298class LPD1886_8BIT : public LPD1886Controller1250Khz_8bit<DATA_PIN, RGB_ORDER> {};
299
301template<uint8_t DATA_PIN, EOrder RGB_ORDER>
302class UCS1912 : public UCS1912Controller<DATA_PIN, RGB_ORDER> {};
303
304#if defined(DmxSimple_h) || defined(FASTLED_DOXYGEN)
306template<uint8_t DATA_PIN, EOrder RGB_ORDER> class DMXSIMPLE : public DMXSimpleController<DATA_PIN, RGB_ORDER> {};
307#endif
308#if defined(DmxSerial_h) || defined(FASTLED_DOXYGEN)
310template<EOrder RGB_ORDER> class DMXSERIAL : public DMXSerialController<RGB_ORDER> {};
311#endif
312#endif
315
316
319#ifdef PORTA_FIRST_PIN
320 WS2811_PORTA,
321 WS2813_PORTA,
322 WS2811_400_PORTA,
323 TM1803_PORTA,
324 UCS1903_PORTA,
325#endif
326#ifdef PORTB_FIRST_PIN
327 WS2811_PORTB,
328 WS2813_PORTB,
329 WS2811_400_PORTB,
330 TM1803_PORTB,
331 UCS1903_PORTB,
332#endif
333#ifdef PORTC_FIRST_PIN
334 WS2811_PORTC,
335 WS2813_PORTC,
336 WS2811_400_PORTC,
337 TM1803_PORTC,
338 UCS1903_PORTC,
339#endif
340#ifdef PORTD_FIRST_PIN
341 WS2811_PORTD,
342 WS2813_PORTD,
343 WS2811_400_PORTD,
344 TM1803_PORTD,
345 UCS1903_PORTD,
346#endif
347#ifdef HAS_PORTDC
348 WS2811_PORTDC,
349 WS2813_PORTDC,
350 WS2811_400_PORTDC,
351 TM1803_PORTDC,
352 UCS1903_PORTDC,
353#endif
354};
355
362typedef uint8_t (*power_func)(uint8_t scale, uint32_t data);
363
370class CFastLED {
371 // int m_nControllers;
372 uint8_t m_Scale;
373 uint16_t m_nFPS;
374 uint32_t m_nMinMicros;
375 uint32_t m_nPowerData;
377
378public:
379 CFastLED();
380
381 // Useful when you want to know when an event like onFrameBegin or onFrameEnd is happening.
382 // This is disabled on AVR to save space.
385
397 static CLEDController &addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0);
398
418
419
420 // Base template: Causes a compile-time error if an unsupported CHIPSET is used
421 template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN>
423 // Default implementation, will be specialized for supported chipsets
424 static const bool IS_VALID = false;
425 };
426
427 // Macro to define a mapping from the ESPIChipeset enum to the controller class
428 // in it's various template configurations.
429 #define _FL_MAP_CLOCKED_CHIPSET(CHIPSET_ENUM, CONTROLLER_CLASS) \
430 template<uint8_t DATA_PIN, uint8_t CLOCK_PIN> \
431 struct ClockedChipsetHelper<CHIPSET_ENUM, DATA_PIN, CLOCK_PIN> { \
432 static const bool IS_VALID = true; \
433 typedef CONTROLLER_CLASS<DATA_PIN, CLOCK_PIN> ControllerType; \
434 /* Controller type with RGB_ORDER specified */ \
435 template<EOrder RGB_ORDER> \
436 struct CONTROLLER_CLASS_WITH_ORDER { \
437 typedef CONTROLLER_CLASS<DATA_PIN, CLOCK_PIN, RGB_ORDER> ControllerType; \
438 }; \
439 /* Controller type with RGB_ORDER and spi frequency specified */ \
440 template<EOrder RGB_ORDER, uint32_t FREQ> \
441 struct CONTROLLER_CLASS_WITH_ORDER_AND_FREQ { \
442 typedef CONTROLLER_CLASS<DATA_PIN, CLOCK_PIN, RGB_ORDER, FREQ> ControllerType; \
443 }; \
444 };
445
446 // Define specializations for each supported CHIPSET
453
454 // Both DOTSTAR and APA102 use the same controller class
457
458 // Both DOTSTARHD and APA102HD use the same controller class
461
464
467
468
469 #if FASTLED_FAKE_SPI_FORWARDS_TO_FAKE_CLOCKLESS
473 template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER, uint32_t SPI_DATA_RATE > CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
474 // Instantiate the controller using ClockedChipsetHelper
475 // Always USE WS2812 clockless controller since it's the common path.
476 return addLeds<WS2812, DATA_PIN, RGB_ORDER>(data, nLedsOrOffset, nLedsIfOffset);
477 }
478
480 template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN > static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
481 // Always USE WS2812 clockless controller since it's the common path.
482 return addLeds<WS2812, DATA_PIN>(data, nLedsOrOffset, nLedsIfOffset);
483 }
484
485
486 // The addLeds function using ChipsetHelper
487 template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER>
488 CLEDController& addLeds(struct CRGB* data, int nLedsOrOffset, int nLedsIfOffset = 0) {
489 // Always USE WS2812 clockless controller since it's the common path.
490 return addLeds<WS2812, DATA_PIN, RGB_ORDER>(data, nLedsOrOffset, nLedsIfOffset);
491 }
492
493 #else
494
495
497 template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER, uint32_t SPI_DATA_RATE > CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
498 // Instantiate the controller using ClockedChipsetHelper
500 typedef typename CHIP::template CONTROLLER_CLASS_WITH_ORDER_AND_FREQ<RGB_ORDER, SPI_DATA_RATE>::ControllerType ControllerTypeWithFreq;
501 static_assert(CHIP::IS_VALID, "Unsupported chipset");
502 static ControllerTypeWithFreq c;
503 return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset);
504 }
505
507 template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN > static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
509 typedef typename CHIP::ControllerType ControllerType;
510 static_assert(CHIP::IS_VALID, "Unsupported chipset");
511 static ControllerType c;
512 return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset);
513 }
514
515
516 // The addLeds function using ChipsetHelper
517 template<ESPIChipsets CHIPSET, uint8_t DATA_PIN, uint8_t CLOCK_PIN, EOrder RGB_ORDER>
518 CLEDController& addLeds(struct CRGB* data, int nLedsOrOffset, int nLedsIfOffset = 0) {
520 static_assert(CHIP::IS_VALID, "Unsupported chipset");
521 typedef typename CHIP::template CONTROLLER_CLASS_WITH_ORDER<RGB_ORDER>::ControllerType ControllerTypeWithOrder;
522 static ControllerTypeWithOrder c;
523 return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset);
524 }
525 #endif
526
527
528#ifdef SPI_DATA
529 template<ESPIChipsets CHIPSET> static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
530 return addLeds<CHIPSET, SPI_DATA, SPI_CLOCK, RGB>(data, nLedsOrOffset, nLedsIfOffset);
531 }
532
533 template<ESPIChipsets CHIPSET, EOrder RGB_ORDER> static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
534 return addLeds<CHIPSET, SPI_DATA, SPI_CLOCK, RGB_ORDER>(data, nLedsOrOffset, nLedsIfOffset);
535 }
536
537 template<ESPIChipsets CHIPSET, EOrder RGB_ORDER, uint32_t SPI_DATA_RATE> static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
538 return addLeds<CHIPSET, SPI_DATA, SPI_CLOCK, RGB_ORDER, SPI_DATA_RATE>(data, nLedsOrOffset, nLedsIfOffset);
539 }
540
541#endif
543
544#ifdef FASTLED_HAS_CLOCKLESS
565
567 template<template<uint8_t DATA_PIN, EOrder RGB_ORDER> class CHIPSET, uint8_t DATA_PIN, EOrder RGB_ORDER>
568 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
570 return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset);
571 }
572
574 template<template<uint8_t DATA_PIN, EOrder RGB_ORDER> class CHIPSET, uint8_t DATA_PIN>
575 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
576 static CHIPSET<DATA_PIN, RGB> c;
577 return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset);
578 }
579
581 template<template<uint8_t DATA_PIN> class CHIPSET, uint8_t DATA_PIN>
582 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
583 static CHIPSET<DATA_PIN> c;
584 return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset);
585 }
586
587 template<template<uint8_t DATA_PIN> class CHIPSET, uint8_t DATA_PIN>
588 static CLEDController &addLeds(class fl::Leds& leds, int nLedsOrOffset, int nLedsIfOffset = 0) {
589 CRGB* rgb = leds;
590 return addLeds<CHIPSET, DATA_PIN>(rgb, nLedsOrOffset, nLedsIfOffset);
591 }
592
593#if defined(__FASTLED_HAS_FIBCC) && (__FASTLED_HAS_FIBCC == 1)
594 template<uint8_t NUM_LANES, template<uint8_t DATA_PIN, EOrder RGB_ORDER> class CHIPSET, uint8_t DATA_PIN, EOrder RGB_ORDER=RGB>
595 static CLEDController &addLeds(struct CRGB *data, int nLeds) {
596 static __FIBCC<CHIPSET, DATA_PIN, NUM_LANES, RGB_ORDER> c;
597 return addLeds(&c, data, nLeds);
598 }
599#endif
600
601 #ifdef FASTSPI_USE_DMX_SIMPLE
602 template<EClocklessChipsets CHIPSET, uint8_t DATA_PIN, EOrder RGB_ORDER=RGB>
603 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0)
604 {
605 switch(CHIPSET) {
606 case DMX: { static DMXController<DATA_PIN> controller; return addLeds(&controller, data, nLedsOrOffset, nLedsIfOffset); }
607 }
608 }
609 #endif
611#endif
612
633
635 template<template<EOrder RGB_ORDER> class CHIPSET, EOrder RGB_ORDER>
636 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
637 static CHIPSET<RGB_ORDER> c;
638 return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset);
639 }
640
642 template<template<EOrder RGB_ORDER> class CHIPSET>
643 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
644 static CHIPSET<RGB> c;
645 return addLeds(&c, data, nLedsOrOffset, nLedsIfOffset);
646 }
647
648#ifdef USE_OCTOWS2811
652 template<OWS2811 CHIPSET, EOrder RGB_ORDER>
653 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0)
654 {
655 switch(CHIPSET) {
656 case OCTOWS2811: { static COctoWS2811Controller<RGB_ORDER,WS2811_800kHz> controller; return addLeds(&controller, data, nLedsOrOffset, nLedsIfOffset); }
657 case OCTOWS2811_400: { static COctoWS2811Controller<RGB_ORDER,WS2811_400kHz> controller; return addLeds(&controller, data, nLedsOrOffset, nLedsIfOffset); }
658#ifdef WS2813_800kHz
659 case OCTOWS2813: { static COctoWS2811Controller<RGB_ORDER,WS2813_800kHz> controller; return addLeds(&controller, data, nLedsOrOffset, nLedsIfOffset); }
660#endif
661 }
662 }
663
667 template<OWS2811 CHIPSET>
668 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0)
669 {
670 return addLeds<CHIPSET,GRB>(data,nLedsOrOffset,nLedsIfOffset);
671 }
672
673#endif
674
675#ifdef USE_WS2812SERIAL
679 template<SWS2812 CHIPSET, int DATA_PIN, EOrder RGB_ORDER>
680 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0)
681 {
682 static CWS2812SerialController<DATA_PIN,RGB_ORDER> controller;
683 return addLeds(&controller, data, nLedsOrOffset, nLedsIfOffset);
684 }
685#endif
686
687#ifdef SmartMatrix_h
690 template<ESM CHIPSET>
691 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0)
692 {
693 switch(CHIPSET) {
694 case SMART_MATRIX: { static CSmartMatrixController controller; return addLeds(&controller, data, nLedsOrOffset, nLedsIfOffset); }
695 }
696 }
697#endif
699
700
701#ifdef FASTLED_HAS_BLOCKLESS
702
723
725 template<EBlockChipsets CHIPSET, int NUM_LANES, EOrder RGB_ORDER>
726 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
727 switch(CHIPSET) {
728 #ifdef PORTA_FIRST_PIN
729 case WS2811_PORTA: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTA_FIRST_PIN, NS(320), NS(320), NS(640), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
730 case WS2811_400_PORTA: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTA_FIRST_PIN, NS(800), NS(800), NS(900), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
731 case WS2813_PORTA: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTA_FIRST_PIN, NS(320), NS(320), NS(640), RGB_ORDER, 0, false, 300>(), data, nLedsOrOffset, nLedsIfOffset);
732 case TM1803_PORTA: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTA_FIRST_PIN, NS(700), NS(1100), NS(700), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
733 case UCS1903_PORTA: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTA_FIRST_PIN, NS(500), NS(1500), NS(500), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
734 #endif
735 #ifdef PORTB_FIRST_PIN
736 case WS2811_PORTB: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTB_FIRST_PIN, NS(320), NS(320), NS(640), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
737 case WS2811_400_PORTB: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTB_FIRST_PIN, NS(800), NS(800), NS(900), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
738 case WS2813_PORTB: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTB_FIRST_PIN, NS(320), NS(320), NS(640), RGB_ORDER, 0, false, 300>(), data, nLedsOrOffset, nLedsIfOffset);
739 case TM1803_PORTB: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTB_FIRST_PIN, NS(700), NS(1100), NS(700), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
740 case UCS1903_PORTB: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTB_FIRST_PIN, NS(500), NS(1500), NS(500), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
741 #endif
742 #ifdef PORTC_FIRST_PIN
743 case WS2811_PORTC: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTC_FIRST_PIN, NS(320), NS(320), NS(640), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
744 case WS2811_400_PORTC: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTC_FIRST_PIN, NS(800), NS(800), NS(900), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
745 case WS2813_PORTC: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTC_FIRST_PIN, NS(320), NS(320), NS(640), RGB_ORDER, 0, false, 300>(), data, nLedsOrOffset, nLedsIfOffset);
746 case TM1803_PORTC: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTC_FIRST_PIN, NS(700), NS(1100), NS(700), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
747 case UCS1903_PORTC: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTC_FIRST_PIN, NS(500), NS(1500), NS(500), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
748 #endif
749 #ifdef PORTD_FIRST_PIN
750 case WS2811_PORTD: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTD_FIRST_PIN, NS(320), NS(320), NS(640), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
751 case WS2811_400_PORTD: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTD_FIRST_PIN, NS(800), NS(800), NS(900), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
752 case WS2813_PORTD: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTD_FIRST_PIN, NS(320), NS(320), NS(640), RGB_ORDER, 0, false, 300>(), data, nLedsOrOffset, nLedsIfOffset);
753 case TM1803_PORTD: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTD_FIRST_PIN, NS(700), NS(1100), NS(700), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
754 case UCS1903_PORTD: return addLeds(new InlineBlockClocklessController<NUM_LANES, PORTD_FIRST_PIN, NS(500), NS(1500), NS(500), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
755 #endif
756 #ifdef HAS_PORTDC
757 case WS2811_PORTDC: return addLeds(new SixteenWayInlineBlockClocklessController<NUM_LANES,NS(320), NS(320), NS(640), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
758 case WS2811_400_PORTDC: return addLeds(new SixteenWayInlineBlockClocklessController<NUM_LANES,NS(800), NS(800), NS(900), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
759 case WS2813_PORTDC: return addLeds(new SixteenWayInlineBlockClocklessController<NUM_LANES, NS(320), NS(320), NS(640), RGB_ORDER, 0, false, 300>(), data, nLedsOrOffset, nLedsIfOffset);
760 case TM1803_PORTDC: return addLeds(new SixteenWayInlineBlockClocklessController<NUM_LANES, NS(700), NS(1100), NS(700), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
761 case UCS1903_PORTDC: return addLeds(new SixteenWayInlineBlockClocklessController<NUM_LANES, NS(500), NS(1500), NS(500), RGB_ORDER>(), data, nLedsOrOffset, nLedsIfOffset);
762 #endif
763 }
764 }
765
767 template<EBlockChipsets CHIPSET, int NUM_LANES>
768 static CLEDController &addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset = 0) {
769 return addLeds<CHIPSET,NUM_LANES,GRB>(data,nLedsOrOffset,nLedsIfOffset);
770 }
771
772#endif
773
776 void setBrightness(uint8_t scale) { m_Scale = scale; }
777
780 uint8_t getBrightness() { return m_Scale; }
781
785 inline void setMaxPowerInVoltsAndMilliamps(uint8_t volts, uint32_t milliamps) { setMaxPowerInMilliWatts(volts * milliamps); }
786
789 inline void setMaxPowerInMilliWatts(uint32_t milliwatts) { m_pPowerFunc = &calculate_max_brightness_for_power_mW; m_nPowerData = milliwatts; }
790
793 void show(uint8_t scale);
794
796 void show() { show(m_Scale); }
797
798 // Called automatically at the end of show().
799 void onEndFrame();
800
804 void clear(bool writeData = false);
805
807 void clearData();
808
812 void showColor(const struct CRGB & color, uint8_t scale);
813
816 void showColor(const struct CRGB & color) { showColor(color, m_Scale); }
817
822 void delay(unsigned long ms);
823
827 void setTemperature(const struct CRGB & temp);
828
832 void setCorrection(const struct CRGB & correction);
833
837 void setDither(uint8_t ditherMode = BINARY_DITHER);
838
846 void setMaxRefreshRate(uint16_t refresh, bool constrain=false);
847
852 void countFPS(int nFrames=25);
853
856 uint16_t getFPS() { return m_nFPS; }
857
860 int count();
861
865
868 int size();
869
872 CRGB *leds();
873};
874
876#define FastSPI_LED FastLED
878#define FastSPI_LED2 FastLED
879#ifndef LEDS
881#define LEDS FastLED
882#endif
883
885extern CFastLED FastLED;
886
890#ifndef HAS_HARDWARE_PIN_SUPPORT
891#warning "No pin/port mappings found, pin access will be slightly slower. See fastpin.h for info."
892#define NO_HARDWARE_PIN_SUPPORT
893#endif
894
895
897
898#endif
899
900
902
903#if !defined(FASTLED_INTERNAL) && !defined(FASTLED_LEAN_AND_MEAN)
904
905#include "fl/str.h" // Awesome Str class that has stack allocation and heap overflow, copy on write.
906#include "fl/xymap.h" // XYMap class for mapping 2D coordinates on seperintine matrices.
907
908#include "fl/clamp.h" // fl::clamp(value, min, max)
909#include "fl/map_range.h" // fl::map_range(value, in_min, in_max, out_min, out_max)
910
911#include "fl/warn.h" // FASTLED_WARN("time now: " << millis()), FASTLED_WARN_IF(condition, "time now: " << millis());"
912#include "fl/assert.h" // FASTLED_ASSERT(condition, "message");
913#include "fl/unused.h" // FASTLED_UNUSED(variable), for strict compiler settings.
914
915// provides:
916// fl::vector<T> - Standard heap vector
917// fl::vector_inlined<T,N> - Allocate on stack N elements, then overflow to heap vector.
918// fl::vector_fixed<T,N> - Stack allocated fixed size vector, elements will fail to add when full.
919#include "fl/vector.h"
920
921// Flexible callbacks in the style of std::function.
922#include "fl/function.h"
923
924// Clears the led data and other objects.
925// CRGB leds[NUM_LEDS];
926// fl::clear(leds)
927#include "fl/clear.h"
928
929// Leds has a CRGB block and an XYMap
930#include "fl/leds.h"
931
932#include "fl/ui.h" // Provides UIButton, UISlider, UICheckbox, UINumberField and UITitle, UIDescription.
933using fl::UIButton; // These names are unique enough that we don't need to namespace them
934using fl::UICheckbox;
936using fl::UISlider;
937using fl::XYMap;
938#define FASTLED_TITLE(text) fl::UITitle g_title(text)
939#define FASTLED_DESCRIPTION(text) fl::UIDescription g_description(text)
940
941
942#endif // FASTLED_INTERNAL && !FASTLED_LEAN_AND_MEAN
943
944
945// Auto namespace if necessary.
946#if defined(FASTLED_FORCE_USE_NAMESPACE) && FASTLED_FORCE_USE_NAMESPACE==1
947using namespace fl;
948#endif
949
950
951#pragma GCC diagnostic push
952#pragma GCC diagnostic ignored "-Wcomment"
953
954// Experimental: loop() hijacking.
955//
956// EngineEvents requires that FastLED.show() be invoked.
957// If the user skips that then certain updates will be skipped.
958//
959// Right now this isn't a big deal, but in the future it could be.
960//
961// Therefore this experiment is done so that this loop() hijack trick
962// can be used to insert code at the start of every loop(), such as a
963// scoped object that forces a begin and end frame event.
964//
965// It's possible to hijack the loop() via a macro so that
966// extra code can be injected at the start of every frame.
967//
968// #define loop() \
969// real_loop(); \
970// void loop() { FASTLED_WARN("hijacked the loop"); real_loop(); } \
971// void real_loop()
972
973#pragma GCC diagnostic pop
int x
Definition Audio.ino:71
UISlider scale("Scale", 1.0f, 0.0f, 1.0f, 0.01f)
#define CHIPSET
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:58
#define _FL_MAP_CLOCKED_CHIPSET(CHIPSET_ENUM, CONTROLLER_CLASS)
Definition FastLED.h:429
FASTLED_NAMESPACE_BEGIN uint16_t cled_contoller_size()
Definition FastLED.cpp:48
SWS2812
WS2812Serial Library controller type.
Definition FastLED.h:141
@ WS2812SERIAL
Definition FastLED.h:141
OWS2811
Octo WS2811 LED Library controller types.
Definition FastLED.h:136
@ OCTOWS2811
Definition FastLED.h:136
@ OCTOWS2813
Definition FastLED.h:136
@ OCTOWS2811_400
Definition FastLED.h:136
uint8_t(* power_func)(uint8_t scale, uint32_t data)
Typedef for a power consumption calculation function.
Definition FastLED.h:362
ESPIChipsets
LED chipsets with SPI interface.
Definition FastLED.h:111
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
Definition FastLED.h:123
@ P9813
P9813 LED chipset.
Definition FastLED.h:117
@ SK9822HD
SK9822 LED chipset with 5-bit gamma correction.
Definition FastLED.h:120
@ SK9822
SK9822 LED chipset.
Definition FastLED.h:119
@ WS2803
WS2803 LED chipset.
Definition FastLED.h:115
@ HD107
Definition FastLED.h:124
@ WS2801
WS2801 LED chipset.
Definition FastLED.h:114
@ DOTSTAR
APA102 LED chipset alias.
Definition FastLED.h:121
@ APA102
APA102 LED chipset.
Definition FastLED.h:118
@ LPD8806
LPD8806 LED chipset.
Definition FastLED.h:113
@ HD107HD
Same as APA102, but in turbo 40-mhz mode.
Definition FastLED.h:125
@ LPD6803
LPD6803 LED chipset.
Definition FastLED.h:112
@ DOTSTARHD
APA102HD LED chipset alias.
Definition FastLED.h:122
@ SM16716
SM16716 LED chipset.
Definition FastLED.h:116
ESM
Smart Matrix Library controller type.
Definition FastLED.h:131
@ SMART_MATRIX
Definition FastLED.h:131
EBlockChipsets
Blockless output port enum.
Definition FastLED.h:318
CLEDController * controller
Functions for doing a rotation of bits/bytes used by parallel output.
Contains the bulk of the definitions for the various LED chipsets supported.
APA102 high definition controller class.
Definition chipsets.h:546
APA102 controller class.
Definition chipsets.h:375
APA104 controller class.
Definition FastLED.h:268
APA106 controller class.
Definition FastLED.h:248
_FL_MAP_CLOCKED_CHIPSET(LPD6803, LPD6803Controller) _FL_MAP_CLOCKED_CHIPSET(LPD8806
void onEndFrame()
Definition FastLED.cpp:161
int size()
Get the number of leds in the first controller.
Definition FastLED.cpp:84
uint32_t m_nMinMicros
minimum µs between frames, used for capping frame rates
Definition FastLED.h:374
void setMaxRefreshRate(uint16_t refresh, bool constrain=false)
Set the maximum refresh rate.
Definition FastLED.cpp:350
CRGB * leds()
Get a pointer to led data for the first controller.
Definition FastLED.cpp:88
CLEDController & addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Definition FastLED.h:518
void setTemperature(const struct CRGB &temp)
Set a global color temperature.
Definition FastLED.cpp:259
static CLEDController & addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add an SPI based CLEDController instance to the world.
Definition FastLED.h:507
uint16_t m_nFPS
tracking for current frames per second (FPS) value
Definition FastLED.h:373
void show()
Update all our controllers with the current led colors.
Definition FastLED.h:796
power_func m_pPowerFunc
function for overriding brightness when using FastLED.show();
Definition FastLED.h:376
void removeListener(fl::EngineEvents::Listener *listener)
Definition FastLED.h:384
void showColor(const struct CRGB &color)
Set all leds on all controllers to the given color.
Definition FastLED.h:816
void countFPS(int nFrames=25)
For debugging, this will keep track of time between calls to countFPS().
Definition FastLED.cpp:334
CLEDController & operator[](int x)
Get a reference to a registered controller.
Definition FastLED.cpp:175
void delay(unsigned long ms)
Delay for the given number of milliseconds.
Definition FastLED.cpp:245
LPD8806Controller WS2803Controller P9813Controller APA102Controller APA102ControllerHD APA102ControllerHD SK9822ControllerHD CLEDController & addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add an SPI based CLEDController instance to the world.
Definition FastLED.h:497
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:776
void showColor(const struct CRGB &color, uint8_t scale)
Set all leds on all controllers to the given color/scale.
Definition FastLED.cpp:187
uint8_t m_Scale
the current global brightness scale setting
Definition FastLED.h:372
void setDither(uint8_t ditherMode=BINARY_DITHER)
Set the dithering mode.
Definition FastLED.cpp:275
void setMaxPowerInVoltsAndMilliamps(uint8_t volts, uint32_t milliamps)
Set the maximum power to be used, given in volts and milliamps.
Definition FastLED.h:785
uint16_t getFPS()
Get the number of frames/second being written out.
Definition FastLED.h:856
void setMaxPowerInMilliWatts(uint32_t milliwatts)
Set the maximum power to be used, given in milliwatts.
Definition FastLED.h:789
uint32_t m_nPowerData
max power use parameter
Definition FastLED.h:375
uint8_t getBrightness()
Get the current global brightness setting.
Definition FastLED.h:780
void clearData()
Clear out the local data array.
Definition FastLED.cpp:237
void addListener(fl::EngineEvents::Listener *listener)
Definition FastLED.h:383
void setCorrection(const struct CRGB &correction)
Set a global color correction.
Definition FastLED.cpp:267
int count()
Get how many controllers have been registered.
Definition FastLED.cpp:165
static CLEDController & addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a 3rd party library based CLEDController instance to the world.
Definition FastLED.h:643
void clear(bool writeData=false)
Clear the leds, wiping the local array of data.
Definition FastLED.cpp:230
static CLEDController & addLeds(class fl::Leds &leds, int nLedsOrOffset, int nLedsIfOffset=0)
Definition FastLED.h:588
static CLEDController & addLeds(struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a clockless based CLEDController instance to the world.
Definition FastLED.h:575
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:92
High level controller interface for FastLED.
Definition FastLED.h:370
Base definition for an LED controller.
DMX512 based LED controller class, using the DMXSerial library.
Definition FastLED.h:310
DMX512 based LED controller class, using the DmxSimple library.
Definition FastLED.h:306
DMX512 based LED controller class, using the DMXSerial library.
Definition dmx.h:64
DMX512 based LED controller class, using the DmxSimple library.
Definition dmx.h:28
GE8822 controller class.
Definition chipsets.h:777
GE8822 controller class.
Definition FastLED.h:278
GS1903 controller class.
Definition FastLED.h:233
GW6205_400 controller class.
Definition FastLED.h:288
GW6205 controller class @ 400 KHz.
Definition chipsets.h:878
UCS1904 controller class @ 800 KHz.
Definition chipsets.h:883
GW6205 controller class.
Definition FastLED.h:283
LPD1886_8BIT controller class.
Definition FastLED.h:298
LPD1886 controller class.
Definition chipsets.h:787
LPD1886 controller class.
Definition chipsets.h:782
LPD1886 controller class.
Definition FastLED.h:293
LPD6803 controller class (LPD1101).
Definition chipsets.h:312
LPD8806 controller class.
Definition chipsets.h:231
LED controller for WS2812 LEDs with GRB color order.
Definition FastLED.h:155
P9813 controller class.
Definition chipsets.h:641
PL9823 controller class.
Definition chipsets.h:888
PL9823 controller class.
Definition FastLED.h:253
SK6812 controller class.
Definition chipsets.h:838
SK6812 controller class.
Definition FastLED.h:238
SK6822 controller class.
Definition chipsets.h:828
SK6822 controller class.
Definition FastLED.h:243
SK9822 controller class.
Definition chipsets.h:593
SK9822 controller class.
Definition chipsets.h:571
SM16703 controller class.
Definition chipsets.h:833
SM16703 controller class.
Definition FastLED.h:160
SM16716 controller class.
Definition chipsets.h:691
TM1803 controller class.
Definition chipsets.h:868
TM1803 controller class.
Definition FastLED.h:185
TM1804 controller class.
Definition FastLED.h:180
TM1809 controller class.
Definition chipsets.h:863
TM1809 controller class.
Definition FastLED.h:175
TM1812 controller class.
Definition FastLED.h:170
TM1829 controller class.
Definition chipsets.h:873
TM1829 controller class.
Definition FastLED.h:165
UCS1903B controller class.
Definition chipsets.h:848
UCS1903B controller class.
Definition FastLED.h:195
UCS1903 controller class @ 400 KHz.
Definition chipsets.h:843
UCS1903 controller class.
Definition FastLED.h:190
UCS1904 controller class.
Definition chipsets.h:853
UCS1904 controller class.
Definition FastLED.h:200
UCS1912 controller class.
Definition FastLED.h:302
UCS2903 controller class.
Definition chipsets.h:858
UCS2903 controller class.
Definition FastLED.h:205
WS2801 controller class.
Definition chipsets.h:274
WS2803 controller class.
Definition chipsets.h:301
WS2811_400 controller class.
Definition FastLED.h:273
WS2811 controller class @ 400 KHz.
Definition chipsets.h:823
WS2811 controller class @ 800 KHz.
Definition chipsets.h:803
WS2811 controller class.
Definition FastLED.h:258
WS2812B controller class.
Definition FastLED.h:228
WS2812 controller class @ 800 KHz.
Definition chipsets.h:793
WS2812 controller class.
Definition FastLED.h:210
WS2813 controller class.
Definition chipsets.h:818
WS2813 controller class.
Definition FastLED.h:263
WS2815 controller class @ 400 KHz.
Definition chipsets.h:798
WS2815 controller class.
Definition FastLED.h:214
WS2816 controller class.
Definition FastLED.h:218
WS2852 controller class.
Definition FastLED.h:223
static void addListener(Listener *listener, int priority=0)
static void removeListener(Listener *listener)
Declarations for the predefined color palettes supplied by FastLED.
deprecated: base definitions used by led controllers for writing out led data
Compatibility functions based on C++ version.
#define BINARY_DITHER
Enable dithering using binary dithering (only option)
Definition dither_mode.h:13
Defines the DMX512-based LED controllers.
EOrder
RGB color channel orderings, used when instantiating controllers to determine what order the controll...
Definition eorder.h:14
@ RGB
Red, Green, Blue (0012)
Definition eorder.h:15
Contains definitions that can be used to configure FastLED at compile time.
#define NS(_NS)
Convert from nanoseconds to number of clock cycles.
Utility functions and classes for managing delay cycles.
Wrapper definitions to allow seamless use of PROGMEM in environments that have it.
Class base definitions for defining fast pin access.
Serial peripheral interface (SPI) definitions per platform.
Data types and constants used by SPI interfaces.
uint8_t calculate_max_brightness_for_power_mW(const CRGB *ledbuffer, uint16_t numLeds, uint8_t target_brightness, uint32_t max_power_mW)
Determines the highest brightness level you can use and still stay under the specified power budget f...
Definition power_mgt.cpp:95
Functions to convert from the HSV colorspace to the RGB colorspace.
Determines which platform system definitions to include.
Fast, efficient 8-bit math functions specifically designed for high-performance LED programming.
#define FASTLED_NAMESPACE_END
Definition namespace.h:23
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Functions to generate and fill arrays with noise.
Declares classes for managing logical groups of LEDs.
Includes defintions for RGB and HSV pixels.
Determines which platforms headers to include.
Functions to limit the power used by FastLED.
static const bool IS_VALID
Definition FastLED.h:424
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55