FastLED 3.10.8
Loading...
Searching...
No Matches
spi.h
Go to the documentation of this file.
1
7
8#pragma once
9
10#include "fl/stl/stdint.h"
12#include "fl/stl/noexcept.h"
13
14namespace fl {
15
38struct SpiEncoder {
41
44 static inline SpiEncoder apa102(u32 clock_hz = 6000000) FL_NO_EXCEPT {
46 return config;
47 }
48
51 static inline SpiEncoder apa102HD(u32 clock_hz = 6000000) FL_NO_EXCEPT {
53 return config;
54 }
55
58 static inline SpiEncoder sk9822(u32 clock_hz = 12000000) FL_NO_EXCEPT {
60 return config;
61 }
62
65 static inline SpiEncoder sk9822HD(u32 clock_hz = 12000000) FL_NO_EXCEPT {
67 return config;
68 }
69
72 static inline SpiEncoder dotstar(u32 clock_hz = 6000000) FL_NO_EXCEPT {
74 return config;
75 }
76
79 static inline SpiEncoder dotstarHD(u32 clock_hz = 6000000) FL_NO_EXCEPT {
81 return config;
82 }
83
86 static inline SpiEncoder hd107(u32 clock_hz = 40000000) FL_NO_EXCEPT {
88 return config;
89 }
90
93 static inline SpiEncoder hd107HD(u32 clock_hz = 40000000) FL_NO_EXCEPT {
95 return config;
96 }
97
100 static inline SpiEncoder hd108(u32 clock_hz = 25000000) FL_NO_EXCEPT {
102 return config;
103 }
104
107 static inline SpiEncoder ws2801(u32 clock_hz = 1000000) FL_NO_EXCEPT {
109 return config;
110 }
111
114 static inline SpiEncoder ws2803(u32 clock_hz = 25000000) FL_NO_EXCEPT {
116 return config;
117 }
118
121 static inline SpiEncoder p9813(u32 clock_hz = 10000000) FL_NO_EXCEPT {
123 return config;
124 }
125
128 static inline SpiEncoder lpd8806(u32 clock_hz = 12000000) FL_NO_EXCEPT {
130 return config;
131 }
132
135 static inline SpiEncoder lpd6803(u32 clock_hz = 12000000) FL_NO_EXCEPT {
137 return config;
138 }
139
142 static inline SpiEncoder sm16716(u32 clock_hz = 16000000) FL_NO_EXCEPT {
144 return config;
145 }
146
152 static inline SpiEncoder my9221(u32 clock_hz = 1000000) FL_NO_EXCEPT {
154 return config;
155 }
156
161 static inline SpiEncoder spiEncoderForChipset(SpiChipset chipset, u32 speed_hz_override = 0) FL_NO_EXCEPT {
162 SpiEncoder enc = {chipset, 6000000}; // fallback
163 switch (chipset) {
164 case SpiChipset::APA102: enc = apa102(); break;
165 case SpiChipset::APA102HD: enc = apa102HD(); break;
166 case SpiChipset::DOTSTAR: enc = dotstar(); break;
167 case SpiChipset::DOTSTARHD: enc = dotstarHD(); break;
168 case SpiChipset::SK9822: enc = sk9822(); break;
169 case SpiChipset::SK9822HD: enc = sk9822HD(); break;
170 case SpiChipset::HD107: enc = hd107(); break;
171 case SpiChipset::HD107HD: enc = hd107HD(); break;
172 case SpiChipset::HD108: enc = hd108(); break;
173 case SpiChipset::WS2801: enc = ws2801(); break;
174 case SpiChipset::WS2803: enc = ws2803(); break;
175 case SpiChipset::P9813: enc = p9813(); break;
176 case SpiChipset::LPD8806: enc = lpd8806(); break;
177 case SpiChipset::LPD6803: enc = lpd6803(); break;
178 case SpiChipset::SM16716: enc = sm16716(); break;
179 case SpiChipset::MY9221: enc = my9221(); break;
180 default: break; // unknown chipset: keep fallback
181 }
182 if (speed_hz_override != 0) {
183 enc.clock_hz = speed_hz_override;
184 }
185 return enc;
186 }
187
189 constexpr bool operator==(const SpiEncoder& other) const FL_NO_EXCEPT {
190 return chipset == other.chipset &&
191 clock_hz == other.clock_hz;
192 }
193
195 constexpr bool operator!=(const SpiEncoder& other) const FL_NO_EXCEPT {
196 return !(*this == other);
197 }
198};
199
200} // namespace fl
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
SpiChipset
LED chipsets with SPI interface (clocked protocols) Modern type-safe enum class - prefer this for new...
@ SM16716
SM16716 LED chipset.
@ LPD6803
LPD6803 LED chipset.
@ APA102HD
APA102 LED chipset with 5-bit gamma correction.
@ HD107
Same as APA102, but in turbo 40-mhz mode.
@ DOTSTARHD
APA102HD LED chipset alias.
@ SK9822HD
SK9822 LED chipset with 5-bit gamma correction.
@ SK9822
SK9822 LED chipset.
@ DOTSTAR
APA102 LED chipset alias.
@ P9813
P9813 LED chipset.
@ APA102
APA102 LED chipset.
@ HD108
16-bit variant of HD107, always gamma corrected. No SD (standard definition) option available - all H...
@ LPD8806
LPD8806 LED chipset.
@ WS2803
WS2803 LED chipset.
@ MY9221
MY9221 12-channel LED driver (dual-edge clocked; 4 RGB LEDs per chip)
@ WS2801
WS2801 LED chipset.
@ HD107HD
Same as APA102HD, but in turbo 40-mhz mode.
Base definition for an LED controller.
Definition crgb.hpp:179
SPI LED chipset enumeration.
u32 clock_hz
SPI clock frequency in Hz (e.g., 6000000 for 6MHz)
Definition spi.h:40
static SpiEncoder sm16716(u32 clock_hz=16000000) FL_NO_EXCEPT
Create SM16716 encoder configuration.
Definition spi.h:142
static SpiEncoder my9221(u32 clock_hz=1000000) FL_NO_EXCEPT
Create MY9221 encoder configuration.
Definition spi.h:152
SpiChipset chipset
LED chipset type (determines all encoding behavior)
Definition spi.h:39
static SpiEncoder dotstarHD(u32 clock_hz=6000000) FL_NO_EXCEPT
Create DOTSTARHD encoder configuration (alias for APA102HD)
Definition spi.h:79
static SpiEncoder spiEncoderForChipset(SpiChipset chipset, u32 speed_hz_override=0) FL_NO_EXCEPT
Look up the default SpiEncoder for a given chipset.
Definition spi.h:161
static SpiEncoder hd108(u32 clock_hz=25000000) FL_NO_EXCEPT
Create HD108 encoder configuration.
Definition spi.h:100
static SpiEncoder apa102(u32 clock_hz=6000000) FL_NO_EXCEPT
Create APA102 encoder configuration.
Definition spi.h:44
static SpiEncoder sk9822(u32 clock_hz=12000000) FL_NO_EXCEPT
Create SK9822 encoder configuration.
Definition spi.h:58
static SpiEncoder p9813(u32 clock_hz=10000000) FL_NO_EXCEPT
Create P9813 encoder configuration.
Definition spi.h:121
static SpiEncoder apa102HD(u32 clock_hz=6000000) FL_NO_EXCEPT
Create APA102HD encoder configuration (per-LED brightness via HD gamma)
Definition spi.h:51
static SpiEncoder hd107HD(u32 clock_hz=40000000) FL_NO_EXCEPT
Create HD107HD encoder configuration.
Definition spi.h:93
constexpr bool operator==(const SpiEncoder &other) const FL_NO_EXCEPT
Equality operator (required for hash map key)
Definition spi.h:189
static SpiEncoder lpd6803(u32 clock_hz=12000000) FL_NO_EXCEPT
Create LPD6803 encoder configuration.
Definition spi.h:135
constexpr bool operator!=(const SpiEncoder &other) const FL_NO_EXCEPT
Inequality operator.
Definition spi.h:195
static SpiEncoder lpd8806(u32 clock_hz=12000000) FL_NO_EXCEPT
Create LPD8806 encoder configuration.
Definition spi.h:128
static SpiEncoder dotstar(u32 clock_hz=6000000) FL_NO_EXCEPT
Create DOTSTAR encoder configuration (alias for APA102)
Definition spi.h:72
static SpiEncoder hd107(u32 clock_hz=40000000) FL_NO_EXCEPT
Create HD107 encoder configuration.
Definition spi.h:86
static SpiEncoder ws2801(u32 clock_hz=1000000) FL_NO_EXCEPT
Create WS2801 encoder configuration.
Definition spi.h:107
static SpiEncoder sk9822HD(u32 clock_hz=12000000) FL_NO_EXCEPT
Create SK9822HD encoder configuration.
Definition spi.h:65
static SpiEncoder ws2803(u32 clock_hz=25000000) FL_NO_EXCEPT
Create WS2803 encoder configuration.
Definition spi.h:114
SPI encoder configuration for LED protocols.
Definition spi.h:38