FastLED 3.10.8
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// Platform CMSIS/Arduino headers may define peripheral pointer macros that
13// collide with Bus enumerators and qualified names such as Bus::SPI.
14#pragma push_macro("UART")
15#pragma push_macro("SPI")
16#pragma push_macro("I2S")
17#undef UART
18#undef SPI
19#undef I2S
20
21namespace fl {
22
23struct ClocklessChipset;
24struct SpiChipsetConfig;
25
38
39template<typename Chipset> struct DefaultBus;
40
41#if defined(FL_IS_STUB) || defined(FL_IS_WASM)
42
43template<> struct DefaultBus<ClocklessChipset> {
44 static constexpr Bus value = Bus::BIT_BANG;
45};
46
47template<> struct DefaultBus<SpiChipsetConfig> {
48 static constexpr Bus value = Bus::BIT_BANG;
49};
50
51#elif defined(FL_IS_ESP32)
52
53#if defined(FL_IS_ESP_32P4) || defined(FL_IS_ESP_32C6) || \
54 defined(FL_IS_ESP_32H2) || defined(FL_IS_ESP_32C5)
55template<> struct DefaultBus<ClocklessChipset> {
56 static constexpr Bus value = Bus::FLEX_IO;
57};
58#else
59template<> struct DefaultBus<ClocklessChipset> {
60 static constexpr Bus value = Bus::RMT;
61};
62#endif
63
64#if defined(FL_IS_ESP_32S3) || defined(FL_IS_ESP_32DEV) || \
65 defined(FL_IS_ESP_32P4) || defined(FL_IS_ESP_32C6) || \
66 defined(FL_IS_ESP_32H2) || defined(FL_IS_ESP_32C5)
67template<> struct DefaultBus<SpiChipsetConfig> {
68 static constexpr Bus value = Bus::FLEX_IO;
69};
70#else
71template<> struct DefaultBus<SpiChipsetConfig> {
72 static constexpr Bus value = Bus::BIT_BANG;
73};
74#endif
75
76#elif defined(FL_IS_TEENSY_4X)
77
78template<> struct DefaultBus<ClocklessChipset> {
79 static constexpr Bus value = Bus::FLEX_IO;
80};
81
82template<> struct DefaultBus<SpiChipsetConfig> {
83 static constexpr Bus value = Bus::FLEX_IO;
84};
85
86#elif defined(FL_IS_ARM_LPC)
87
88// LPC845 defaults clockless AUTO to the USART DMA engine. Other LPC8xx /
89// LPC11Uxx / LPC15xx targets keep the shared cycle-counted C++ driver
90// (FASTLED_M0_USE_C_IMPLEMENTATION in led_sysdefs_arm_lpc.h), which is
91// what Bus::BIT_BANG names.
92template<> struct DefaultBus<ClocklessChipset> {
93#if defined(FL_IS_ARM_LPC_845) && FASTLED_LPC_UART_DMA
94 static constexpr Bus value = Bus::UART;
95#else
96 static constexpr Bus value = Bus::BIT_BANG;
97#endif
98};
99
100// LPC845 / LPC804 have a hardware SPI driver (spi_arm_lpc.h, UM11029).
101// LPC11xx / LPC15xx do not yet ship one (#2845 Stage 4) — they fall
102// through to the unspecialized DefaultBus, which is intentional: a
103// link error there is the right signal that no SPI driver is wired.
104#if defined(FL_IS_ARM_LPC_845) || defined(FL_IS_ARM_LPC_804)
105template<> struct DefaultBus<SpiChipsetConfig> {
106 static constexpr Bus value = Bus::SPI;
107};
108#endif
109
110#elif defined(FL_IS_RP2040) || defined(FL_IS_RP2350)
111
112template<> struct DefaultBus<SpiChipsetConfig> {
113 static constexpr Bus value = Bus::SPI;
114};
115
116#endif
117
118template<Bus B> struct BusInstanceCount {
119 static constexpr fl::u8 value = 1;
120};
121
122#if defined(FL_IS_TEENSY_4X)
123template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 2; };
124template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 4; };
125template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 1; };
126#elif defined(FL_IS_ESP_32S3)
127template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 2; };
128template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 2; };
129template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 3; };
130#elif defined(FL_IS_ESP_32C6)
131template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 2; };
132template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 1; };
133template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 2; };
134#elif defined(FL_IS_ESP_32DEV)
135// Classic ESP32 (FastLED#3576 Phase 1): FLEX_IO instance 0 = I2S1
136// primary clockless bank, instance 1 = I2S0 second bank ("I2S0",
137// contended with the clocked-SPI driver via the port-claim registry).
138template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 2; };
139template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 2; };
140template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 2; };
141#elif defined(FL_IS_ARM_LPC_845)
142template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 1; };
143#elif defined(FL_IS_RP2350)
144template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 3; };
145template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 2; };
146template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 2; };
147#elif defined(FL_IS_RP2040)
148template<> struct BusInstanceCount<Bus::FLEX_IO> { static constexpr fl::u8 value = 2; };
149template<> struct BusInstanceCount<Bus::SPI> { static constexpr fl::u8 value = 2; };
150template<> struct BusInstanceCount<Bus::UART> { static constexpr fl::u8 value = 2; };
151#endif
152
153inline const char* busName(Bus b, fl::u8 which = 0) FL_NO_EXCEPT {
154 (void)which;
155 switch (b) {
156 case Bus::AUTO: return "AUTO";
157 case Bus::BIT_BANG: return "BIT_BANG";
158 case Bus::UART: return "UART";
159 case Bus::SPI: return "SPI";
160 case Bus::DUAL_SPI: return "DUAL_SPI";
161 case Bus::QUAD_SPI: return "QUAD_SPI";
162 case Bus::OCTAL_SPI: return "OCTAL_SPI";
163 case Bus::RMT: return "RMT";
164 case Bus::FLEX_IO: return "FLEX_IO";
165 }
166 return "";
167}
168
170inline const char* busDriverName(Bus b, fl::u8 which = 0, bool spi = false) FL_NO_EXCEPT {
171 switch (b) {
172 case Bus::FLEX_IO:
173#if defined(FL_IS_TEENSY_4X)
174 (void)spi;
175 return which == 0 ? "OBJECT_FLED" : "FLEX_IO";
176#elif defined(FL_IS_RP2040) || defined(FL_IS_RP2350)
177 (void)spi;
178 if (which == 0) return "PIO0";
179 if (which == 1) return "PIO1";
180 #if defined(FL_IS_RP2350)
181 if (which == 2) return "PIO2";
182 #endif
183 return "FLEX_IO_UNAVAILABLE";
184#elif defined(FL_IS_ESP32)
185#if FASTLED_HAS_PARLIO
186 (void)which;
187 (void)spi;
188 return "PARLIO";
189#elif FASTLED_HAS_LCD_SPI || FASTLED_HAS_LCD_CAM_CLOCKLESS
190 (void)which;
191 return spi ? "LCD_SPI" : "LCD_CLOCKLESS";
192#elif FASTLED_HAS_I2S_SPI || FASTLED_HAS_I2S_LED
193 (void)which;
194 return spi ? "I2S_SPI" : "I2S";
195#else
196 (void)which;
197 (void)spi;
198 return "FLEX_IO";
199#endif
200#else
201 (void)which;
202 (void)spi;
203 return "FLEX_IO";
204#endif
205 case Bus::AUTO:
206 case Bus::BIT_BANG:
207 case Bus::DUAL_SPI:
208 case Bus::QUAD_SPI:
209 case Bus::OCTAL_SPI:
210 case Bus::RMT:
211 (void)spi;
212 return busName(b, which);
213 case Bus::SPI:
214#if defined(FL_IS_RP2040) || defined(FL_IS_RP2350)
215 (void)spi;
216 return which == 0 ? "SPI0" : "SPI1";
217#else
218 (void)spi;
219 return busName(b, which);
220#endif
221 case Bus::UART:
222 (void)spi;
223#if defined(FL_IS_RP2040) || defined(FL_IS_RP2350)
224 return which == 0 ? "UART0" : "UART1";
225#elif defined(FL_IS_TEENSY_4X)
226 (void)which;
227 return "LPUART";
228#else
229 (void)which;
230 return "UART";
231#endif
232 }
233 return "";
234}
235
237 "Bus changed: update busName() and busDriverName()");
238
239} // namespace fl
240
241#pragma pop_macro("I2S")
242#pragma pop_macro("SPI")
243#pragma pop_macro("UART")
Zero-filled feature macros for portable bus selection.
unsigned char u8
Definition stdint.h:131
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:153
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:170
Bus
Portable public bus selector.
Definition bus.h:27
@ FLEX_IO
Definition bus.h:36
@ DUAL_SPI
Definition bus.h:32
@ QUAD_SPI
Definition bus.h:33
@ SPI
Definition bus.h:31
@ OCTAL_SPI
Definition bus.h:34
@ BIT_BANG
Definition bus.h:29
@ RMT
Definition bus.h:35
@ UART
Definition bus.h:30
@ AUTO
Definition bus.h:28
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_STATIC_ASSERT(...)
Portable compile-time assertion wrapper.
static constexpr fl::u8 value
Definition bus.h:119
Clockless chipset configuration (single data pin)
Definition config.h:33
SPI chipset configuration (data + clock pins)
Definition config.h:103