FastLED 3.10.8
Loading...
Searching...
No Matches
LegacyClocklessProxy.h
Go to the documentation of this file.
1// LegacyClocklessProxy.h - Runtime-to-template pin dispatch for legacy addLeds API
2//
3// Maps a runtime pin number and chipset name to compile-time clockless template
4// instantiations via a switch statement. This allows AutoResearch testing of the
5// legacy template API path: CHIPSET<PIN> -> ClocklessControllerImpl ->
6// ClocklessIdf5 -> SlimBridgeController -> RMT5 driver.
7
8#pragma once
9
10#include <FastLED.h>
11#include "fl/stl/unique_ptr.h"
12
19
20#if defined(FL_IS_TEENSY_4X)
21#define AUTORESEARCH_LEGACY_SUPPORTS_PIN_22 1
22#else
23#define AUTORESEARCH_LEGACY_SUPPORTS_PIN_22 0
24#endif
25
26// GPIO6/7/8 on the classic ESP32 (esp32dev / WROOM modules) are
27// reserved for SPI flash (SD2/SD3/CMD/CLK/SD0/SD1 — pins 6-11) and
28// FastLED's `FASTLED_UNUSABLE_PIN_MASK` for esp32dev marks pins
29// {6, 7, 8, 9, 10, 11, 20} as `validpin() == false`. Instantiating any
30// clockless driver bound to those pins fails the FastLED static_assert
31// at compile time. Other ESP32 variants (S2/S3/C-series, P4) repurpose
32// GPIO6-8 and accept them as valid output pins, and every non-ESP
33// family treats them as normal digital pins. The classic-ESP32
34// sentinel is `FL_IS_ESP_32DEV` (defined in `src/platforms/esp/is_esp.h`);
35// the prior #3447 attempt used `FL_IS_ESP_32` which is not a real macro,
36// so the gate never fired and esp32dev compile still hit the
37// static_assert. LegacyClocklessProxy iterates pins 0-8 so all three
38// of 6/7/8 must be excluded for the classic ESP32 build.
39#if defined(FL_IS_ESP_32DEV)
40#define AUTORESEARCH_LEGACY_SUPPORTS_PIN_6 0
41#define AUTORESEARCH_LEGACY_SUPPORTS_PIN_7 0
42#define AUTORESEARCH_LEGACY_SUPPORTS_PIN_8 0
43#else
44#define AUTORESEARCH_LEGACY_SUPPORTS_PIN_6 1
45#define AUTORESEARCH_LEGACY_SUPPORTS_PIN_7 1
46#define AUTORESEARCH_LEGACY_SUPPORTS_PIN_8 1
47#endif
48
50 switch (chipset) {
52 return "WS2812B";
54 return "WS2814";
56 return "WS2818";
58 return "SK6812";
59 }
60 return "UNKNOWN";
61}
62
65 if (name == "WS2812B" || name == "WS2812") {
66 if (out) *out = LegacyClocklessChipset::WS2812B;
67 return true;
68 }
69 if (name == "SK6812") {
70 if (out) *out = LegacyClocklessChipset::SK6812;
71 return true;
72 }
73 if (name == "WS2814") {
74 if (out) *out = LegacyClocklessChipset::WS2814;
75 return true;
76 }
77 if (name == "WS2818") {
78 if (out) *out = LegacyClocklessChipset::WS2818;
79 return true;
80 }
81 return false;
82}
83
88
95inline const char* legacyClocklessBoundDriverName() {
96#if defined(FL_IS_ESP32)
97 #if defined(FL_ESP32_LEGACY_CLOCKLESS_USE_RMT) && \
98 FL_ESP32_LEGACY_CLOCKLESS_USE_RMT
99 return "RMT";
100 #elif FASTLED_ESP32_HAS_PARLIO && \
101 (defined(FL_IS_ESP_32P4) || defined(FL_IS_ESP_32C6) || \
102 defined(FL_IS_ESP_32H2) || defined(FL_IS_ESP_32C5))
103 return "PARLIO";
104 #elif FASTLED_ESP32_HAS_RMT && \
105 !defined(FASTLED_ESP32_USE_CLOCKLESS_SPI)
106 return "RMT";
107 #elif FASTLED_ESP32_HAS_CLOCKLESS_SPI
108 return "SPI";
109 #else
110 return "BIT_BANG";
111 #endif
112#elif defined(FL_IS_TEENSY_4X)
113 return "OBJECT_FLED";
114#elif defined(FL_IS_RP)
115 // RP legacy templates are slim bridges onto PIO0
116 // (BusTraits<Bus::FLEX_IO, 0>), or the M0 bit-bang engine when the PIO
117 // path is disabled (#4623).
118 #if FASTLED_RP2040_CLOCKLESS_PIO
119 return "PIO0";
120 #else
121 return "BIT_BANG";
122 #endif
123#else
124 return nullptr;
125#endif
126}
127
144
145 template<typename Controller>
147 bool rgbw) {
149 FastLED.addLeds(c.get(), leds, numLeds);
150 if (rgbw) {
151 c->setRgbw(RgbwDefault());
152 }
153 return c;
154 }
155
156 template<int PIN>
159 bool rgbw) {
160 switch (chipset) {
162 return createTyped<WS2812B<PIN, RGB>>(leds, numLeds, rgbw);
164 return createTyped<WS2814<PIN, RGB>>(leds, numLeds, rgbw);
166 return createTyped<WS2818<PIN, RGB>>(leds, numLeds, rgbw);
168 return createTyped<SK6812<PIN, RGB>>(leds, numLeds, rgbw);
169 }
170 return nullptr;
171 }
172
173public:
175 int pin, CRGB* leds, int numLeds,
177 bool rgbw = false) {
178 switch (pin) {
179 case 0: mController = create<0>(leds, numLeds, chipset, rgbw); break;
180 case 1: mController = create<1>(leds, numLeds, chipset, rgbw); break;
181 case 2: mController = create<2>(leds, numLeds, chipset, rgbw); break;
182 case 3: mController = create<3>(leds, numLeds, chipset, rgbw); break;
183 case 4: mController = create<4>(leds, numLeds, chipset, rgbw); break;
184 case 5: mController = create<5>(leds, numLeds, chipset, rgbw); break;
185#if AUTORESEARCH_LEGACY_SUPPORTS_PIN_6
186 case 6: mController = create<6>(leds, numLeds, chipset, rgbw); break;
187#endif
188#if AUTORESEARCH_LEGACY_SUPPORTS_PIN_7
189 case 7: mController = create<7>(leds, numLeds, chipset, rgbw); break;
190#endif
191#if AUTORESEARCH_LEGACY_SUPPORTS_PIN_8
192 case 8: mController = create<8>(leds, numLeds, chipset, rgbw); break;
193#endif
194#if AUTORESEARCH_LEGACY_SUPPORTS_PIN_22
195 case 22: mController = create<22>(leds, numLeds, chipset, rgbw); break;
196#endif
197 default: break; // mController stays nullptr
198 }
199 }
200
202
203 // Non-copyable (unique_ptr already enforces this, but be explicit)
206
208 bool valid() const { return mController != nullptr; }
209};
CRGB leds[1]
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
LegacyClocklessChipset
bool legacyClocklessChipsetFromName(const fl::string &name, LegacyClocklessChipset *out)
const char * legacyClocklessChipsetName(LegacyClocklessChipset chipset)
const char * legacyClocklessBoundDriverName()
Name of the driver to which public legacy templates are bound.
bool legacyClocklessChipsetHasAutomaticRgbw(LegacyClocklessChipset chipset)
Rgbw rgbw
fl::unique_ptr< CLEDController > create(CRGB *leds, int numLeds, LegacyClocklessChipset chipset, bool rgbw)
LegacyClocklessProxy(int pin, CRGB *leds, int numLeds, LegacyClocklessChipset chipset=LegacyClocklessChipset::WS2812B, bool rgbw=false)
fl::unique_ptr< CLEDController > createTyped(CRGB *leds, int numLeds, bool rgbw)
fl::unique_ptr< CLEDController > mController
LegacyClocklessProxy(const LegacyClocklessProxy &)=delete
bool valid() const
Check if the proxy was successfully created.
LegacyClocklessProxy & operator=(const LegacyClocklessProxy &)=delete
~LegacyClocklessProxy()=default
fl::CRGB CRGB
Definition crgb.h:25
fl::enable_if<!fl::is_array< T >::value, unique_ptr< T > >::type make_unique(Args &&... args) FL_NO_EXCEPT
Definition unique_ptr.h:263
unsigned char uint8_t
Definition stdint.h:208