FastLED 3.10.10
Loading...
Searching...
No Matches
bus.h
Go to the documentation of this file.
1#pragma once
2
5
7#include "fl/stl/noexcept.h"
9#include "fl/stl/stdint.h"
10#include "platforms/is_platform.h"
11
12#if defined(FL_IS_ESP32)
13#include "platforms/esp/32/feature_flags/enabled.h" // ok platform headers // IWYU pragma: keep
14#endif
15
16// Platform CMSIS/Arduino headers may define peripheral pointer macros that
17// collide with Bus enumerators and qualified names such as Bus::SPI.
18#pragma push_macro("UART")
19#pragma push_macro("SPI")
20#pragma push_macro("I2S")
21#undef UART
22#undef SPI
23#undef I2S
24
25namespace fl {
26
27struct ClocklessChipset;
28struct SpiChipsetConfig;
29
42
43template<typename Chipset> struct DefaultBus;
44
45#if defined(FL_IS_STUB) || defined(FL_IS_WASM)
46
47template<> struct DefaultBus<ClocklessChipset> {
48 static constexpr Bus value = Bus::BIT_BANG;
49};
50
51template<> struct DefaultBus<SpiChipsetConfig> {
52 static constexpr Bus value = Bus::BIT_BANG;
53};
54
55#elif defined(FL_IS_ESP32)
56
57#if defined(FL_IS_ESP_32P4) || defined(FL_IS_ESP_32C6) || \
58 defined(FL_IS_ESP_32H2) || defined(FL_IS_ESP_32C5)
59template<> struct DefaultBus<ClocklessChipset> {
60 static constexpr Bus value = Bus::FLEX_IO;
61};
62#elif FASTLED_ESP32_HAS_RMT
63template<> struct DefaultBus<ClocklessChipset> {
64 static constexpr Bus value = Bus::RMT;
65};
66#endif
67// No RMT (ESP32-C2) or no soc_caps.h (IDF 3.x): there is no BusTraits<Bus::RMT>
68// (see rmt_4/rmt_5 bus_traits.h, gated on the same flag), so
69// DefaultBus<ClocklessChipset> stays unspecialized and the add(cfg) fallback
70// binds nothing instead of naming a missing driver.
71
72#if defined(FL_IS_ESP_32S3) || defined(FL_IS_ESP_32DEV) || \
73 defined(FL_IS_ESP_32P4) || defined(FL_IS_ESP_32C6) || \
74 defined(FL_IS_ESP_32H2) || defined(FL_IS_ESP_32C5)
75template<> struct DefaultBus<SpiChipsetConfig> {
76 static constexpr Bus value = Bus::FLEX_IO;
77};
78#else
79template<> struct DefaultBus<SpiChipsetConfig> {
80 static constexpr Bus value = Bus::BIT_BANG;
81};
82#endif
83
84#elif defined(FL_IS_TEENSY_4X)
85
86template<> struct DefaultBus<ClocklessChipset> {
87 static constexpr Bus value = Bus::FLEX_IO;
88};
89
90template<> struct DefaultBus<SpiChipsetConfig> {
91 static constexpr Bus value = Bus::FLEX_IO;
92};
93
94#elif defined(FL_IS_ARM_LPC)
95
96// Only LPC845 has a channels-API clockless engine: USART+DMA by default
97// (Bus::UART), or SCT+DMA under FASTLED_LPC_PWM_DMA (Bus::BIT_BANG, see
98// drivers/sct_dma/bus_traits.h). LPC804 / LPC11xx / LPC15xx clockless output
99// is the cycle-counted ClocklessController in clockless_arm_lpc.h, which is
100// not a channel driver, and the shared BitBangChannelDriver cannot meet WS2812
101// timing there, so DefaultBus<ClocklessChipset> stays unspecialized: the
102// add(cfg) fallback then binds nothing instead of naming a missing BusTraits.
103#if defined(FL_IS_ARM_LPC_845) && FASTLED_LPC_UART_DMA
104template<> struct DefaultBus<ClocklessChipset> {
105 static constexpr Bus value = Bus::UART;
106};
107#elif defined(FL_IS_ARM_LPC_845) && defined(FASTLED_LPC_PWM_DMA)
108template<> struct DefaultBus<ClocklessChipset> {
109 static constexpr Bus value = Bus::BIT_BANG;
110};
111#endif
112
113// No LPC family has a channels-API SPI driver (no BusTraits<Bus::SPI>): the
114// LPC8xx hardware SPI in spi_arm_lpc.h is a legacy SPIOutput, not a channel
115// driver. DefaultBus<SpiChipsetConfig> stays unspecialized for the same reason.
116
117#elif defined(FL_IS_RP2040) || defined(FL_IS_RP2350)
118
119template<> struct DefaultBus<SpiChipsetConfig> {
120 static constexpr Bus value = Bus::SPI;
121};
122
123#elif defined(FL_IS_ESP8266)
124
125// ESP8266 has no peripheral engine wired through the channel API yet, so both
126// chipset families resolve to the shared GPIO bit-bang driver
127// (`src/platforms/shared/bitbang/bus_traits.h`). A native engine (I2S, see
128// #4943) can replace the clockless default later. This is a template selection,
129// not a code-enabling define: naming `Bus::AUTO` is what keeps the driver's
130// translation unit, and the selection is fully type-checked either way.
131template<> struct DefaultBus<ClocklessChipset> {
132 static constexpr Bus value = Bus::BIT_BANG;
133};
134
135template<> struct DefaultBus<SpiChipsetConfig> {
136 static constexpr Bus value = Bus::BIT_BANG;
137};
138
139#endif
140
141template<Bus B> struct BusInstanceCount {
142 static constexpr fl::u8 value = 1;
143};
144
145#if defined(FL_IS_TEENSY_4X)
146template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 2; };
147template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 4; };
148template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 1; };
149#elif defined(FL_IS_ESP_32S3)
150template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 2; };
151template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 2; };
152template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 3; };
153#elif defined(FL_IS_ESP_32C6)
154template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 2; };
155template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 1; };
156template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 2; };
157#elif defined(FL_IS_ESP_32DEV)
158// Classic ESP32 (FastLED#3576 Phase 1): FLEX_IO instance 0 = I2S1
159// primary clockless bank, instance 1 = I2S0 second bank ("I2S0",
160// contended with the clocked-SPI driver via the port-claim registry).
161template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 2; };
162template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 2; };
163template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 2; };
164#elif defined(FL_IS_ARM_LPC_845)
165template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 1; };
166#elif defined(FL_IS_RP2350)
167template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 3; };
168template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 2; };
169template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 2; };
170#elif defined(FL_IS_RP2040)
171template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 2; };
172template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 2; };
173template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 2; };
174#endif
175
176inline const char* busName(Bus b, fl::u8 which = 0) FL_NO_EXCEPT {
177 (void)which;
178 switch (b) {
179 case Bus::AUTO: return "AUTO";
180 case Bus::BIT_BANG: return "BIT_BANG";
181 case Bus::UART: return "UART";
182 case Bus::SPI: return "SPI";
183 case Bus::DUAL_SPI: return "DUAL_SPI";
184 case Bus::QUAD_SPI: return "QUAD_SPI";
185 case Bus::OCTAL_SPI: return "OCTAL_SPI";
186 case Bus::RMT: return "RMT";
187 case Bus::FLEX_IO: return "FLEX_IO";
188 }
189 return "";
190}
191
193inline const char* busDriverName(Bus b, fl::u8 which = 0, bool spi = false) FL_NO_EXCEPT {
194 switch (b) {
195 case Bus::FLEX_IO:
196#if defined(FL_IS_TEENSY_4X)
197 (void)spi;
198 return which == 0 ? "OBJECT_FLED" : "FLEX_IO";
199#elif defined(FL_IS_ESP8266)
200 // ESP8266 has no parallel-I/O bank; `Bus::FLEX_IO` names its native
201 // I2S output engine (#4943), matching ESP32's I2S naming.
202 (void)which;
203 (void)spi;
204 return "I2S";
205#elif defined(FL_IS_RP2040) || defined(FL_IS_RP2350)
206 (void)spi;
207 if (which == 0) return "PIO0";
208 if (which == 1) return "PIO1";
209 #if defined(FL_IS_RP2350)
210 if (which == 2) return "PIO2";
211 #endif
212 return "FLEX_IO_UNAVAILABLE";
213#elif defined(FL_IS_ESP32)
214#if FASTLED_HAS_PARLIO
215 (void)which;
216 (void)spi;
217 return "PARLIO";
218#elif FASTLED_HAS_LCD_SPI || FASTLED_HAS_LCD_CAM_CLOCKLESS
219 (void)which;
220 return spi ? "LCD_SPI" : "LCD_CLOCKLESS";
221#elif FASTLED_HAS_I2S_SPI || FASTLED_HAS_I2S_LED
222 (void)which;
223 return spi ? "I2S_SPI" : "I2S";
224#else
225 (void)which;
226 (void)spi;
227 return "FLEX_IO";
228#endif
229#else
230 (void)which;
231 (void)spi;
232 return "FLEX_IO";
233#endif
234 case Bus::AUTO:
235 case Bus::BIT_BANG:
236 case Bus::DUAL_SPI:
237 case Bus::QUAD_SPI:
238 case Bus::OCTAL_SPI:
239 case Bus::RMT:
240 (void)spi;
241 return busName(b, which);
242 case Bus::SPI:
243#if defined(FL_IS_RP2040) || defined(FL_IS_RP2350)
244 (void)spi;
245 return which == 0 ? "SPI0" : "SPI1";
246#else
247 (void)spi;
248 return busName(b, which);
249#endif
250 case Bus::UART:
251 (void)spi;
252#if defined(FL_IS_RP2040) || defined(FL_IS_RP2350)
253 return which == 0 ? "UART0" : "UART1";
254#elif defined(FL_IS_TEENSY_4X)
255 (void)which;
256 return "LPUART";
257#else
258 (void)which;
259 return "UART";
260#endif
261 }
262 return "";
263}
264
266 "Bus changed: update busName() and busDriverName()");
267
268} // namespace fl
269
270#pragma pop_macro("I2S")
271#pragma pop_macro("SPI")
272#pragma pop_macro("UART")
Zero-filled feature macros for portable bus selection.
unsigned char u8
Definition s16x16x4.h:132
unsigned char u8
Definition stdint.h:132
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
constexpr int type_rank< T >::value
const char * busName(Bus b, fl::u8 which=0) FL_NO_EXCEPT
Definition bus.h:176
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
Bus
Portable public bus selector.
Definition bus.h:31
@ FLEX_IO
Definition bus.h:40
@ DUAL_SPI
Definition bus.h:36
@ QUAD_SPI
Definition bus.h:37
@ SPI
Definition bus.h:35
@ OCTAL_SPI
Definition bus.h:38
@ BIT_BANG
Definition bus.h:33
@ RMT
Definition bus.h:39
@ UART
Definition bus.h:34
@ AUTO
Definition bus.h:32
Base definition for an LED controller.
#define FL_STATIC_ASSERT(...)
Portable compile-time assertion wrapper.
static constexpr fl::u8 value
Definition bus.h:142
Clockless chipset configuration (single data pin)
Definition config.h:33
SPI chipset configuration (data + clock pins)
Definition config.h:103