FastLED 3.9.15
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_NOEXCEPT {
46 return config;
47 }
48
51 static inline SpiEncoder apa102HD(u32 clock_hz = 6000000) FL_NOEXCEPT {
53 return config;
54 }
55
58 static inline SpiEncoder sk9822(u32 clock_hz = 12000000) FL_NOEXCEPT {
60 return config;
61 }
62
65 static inline SpiEncoder sk9822HD(u32 clock_hz = 12000000) FL_NOEXCEPT {
67 return config;
68 }
69
72 static inline SpiEncoder dotstar(u32 clock_hz = 6000000) FL_NOEXCEPT {
74 return config;
75 }
76
79 static inline SpiEncoder dotstarHD(u32 clock_hz = 6000000) FL_NOEXCEPT {
81 return config;
82 }
83
86 static inline SpiEncoder hd107(u32 clock_hz = 40000000) FL_NOEXCEPT {
88 return config;
89 }
90
93 static inline SpiEncoder hd107HD(u32 clock_hz = 40000000) FL_NOEXCEPT {
95 return config;
96 }
97
100 static inline SpiEncoder hd108(u32 clock_hz = 25000000) FL_NOEXCEPT {
102 return config;
103 }
104
107 static inline SpiEncoder ws2801(u32 clock_hz = 1000000) FL_NOEXCEPT {
109 return config;
110 }
111
114 static inline SpiEncoder ws2803(u32 clock_hz = 25000000) FL_NOEXCEPT {
116 return config;
117 }
118
121 static inline SpiEncoder p9813(u32 clock_hz = 10000000) FL_NOEXCEPT {
123 return config;
124 }
125
128 static inline SpiEncoder lpd8806(u32 clock_hz = 12000000) FL_NOEXCEPT {
130 return config;
131 }
132
135 static inline SpiEncoder lpd6803(u32 clock_hz = 12000000) FL_NOEXCEPT {
137 return config;
138 }
139
142 static inline SpiEncoder sm16716(u32 clock_hz = 16000000) FL_NOEXCEPT {
144 return config;
145 }
146
151 static inline SpiEncoder spiEncoderForChipset(SpiChipset chipset, u32 speed_hz_override = 0) FL_NOEXCEPT {
152 SpiEncoder enc = {chipset, 6000000}; // fallback
153 switch (chipset) {
154 case SpiChipset::APA102: enc = apa102(); break;
155 case SpiChipset::APA102HD: enc = apa102HD(); break;
156 case SpiChipset::DOTSTAR: enc = dotstar(); break;
157 case SpiChipset::DOTSTARHD: enc = dotstarHD(); break;
158 case SpiChipset::SK9822: enc = sk9822(); break;
159 case SpiChipset::SK9822HD: enc = sk9822HD(); break;
160 case SpiChipset::HD107: enc = hd107(); break;
161 case SpiChipset::HD107HD: enc = hd107HD(); break;
162 case SpiChipset::HD108: enc = hd108(); break;
163 case SpiChipset::WS2801: enc = ws2801(); break;
164 case SpiChipset::WS2803: enc = ws2803(); break;
165 case SpiChipset::P9813: enc = p9813(); break;
166 case SpiChipset::LPD8806: enc = lpd8806(); break;
167 case SpiChipset::LPD6803: enc = lpd6803(); break;
168 case SpiChipset::SM16716: enc = sm16716(); break;
169 default: break; // unknown chipset: keep fallback
170 }
171 if (speed_hz_override != 0) {
172 enc.clock_hz = speed_hz_override;
173 }
174 return enc;
175 }
176
178 constexpr bool operator==(const SpiEncoder& other) const FL_NOEXCEPT {
179 return chipset == other.chipset &&
180 clock_hz == other.clock_hz;
181 }
182
184 constexpr bool operator!=(const SpiEncoder& other) const FL_NOEXCEPT {
185 return !(*this == other);
186 }
187};
188
189} // namespace fl
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.
@ WS2801
WS2801 LED chipset.
@ HD107HD
Same as APA102HD, but in turbo 40-mhz mode.
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
SPI LED chipset enumeration.
u32 clock_hz
SPI clock frequency in Hz (e.g., 6000000 for 6MHz)
Definition spi.h:40
static SpiEncoder spiEncoderForChipset(SpiChipset chipset, u32 speed_hz_override=0) FL_NOEXCEPT
Look up the default SpiEncoder for a given chipset.
Definition spi.h:151
static SpiEncoder hd108(u32 clock_hz=25000000) FL_NOEXCEPT
Create HD108 encoder configuration.
Definition spi.h:100
constexpr bool operator==(const SpiEncoder &other) const FL_NOEXCEPT
Equality operator (required for hash map key)
Definition spi.h:178
static SpiEncoder ws2803(u32 clock_hz=25000000) FL_NOEXCEPT
Create WS2803 encoder configuration.
Definition spi.h:114
static SpiEncoder lpd8806(u32 clock_hz=12000000) FL_NOEXCEPT
Create LPD8806 encoder configuration.
Definition spi.h:128
SpiChipset chipset
LED chipset type (determines all encoding behavior)
Definition spi.h:39
static SpiEncoder apa102(u32 clock_hz=6000000) FL_NOEXCEPT
Create APA102 encoder configuration.
Definition spi.h:44
static SpiEncoder lpd6803(u32 clock_hz=12000000) FL_NOEXCEPT
Create LPD6803 encoder configuration.
Definition spi.h:135
static SpiEncoder hd107HD(u32 clock_hz=40000000) FL_NOEXCEPT
Create HD107HD encoder configuration.
Definition spi.h:93
static SpiEncoder dotstarHD(u32 clock_hz=6000000) FL_NOEXCEPT
Create DOTSTARHD encoder configuration (alias for APA102HD)
Definition spi.h:79
static SpiEncoder sk9822(u32 clock_hz=12000000) FL_NOEXCEPT
Create SK9822 encoder configuration.
Definition spi.h:58
static SpiEncoder sm16716(u32 clock_hz=16000000) FL_NOEXCEPT
Create SM16716 encoder configuration.
Definition spi.h:142
static SpiEncoder sk9822HD(u32 clock_hz=12000000) FL_NOEXCEPT
Create SK9822HD encoder configuration.
Definition spi.h:65
static SpiEncoder dotstar(u32 clock_hz=6000000) FL_NOEXCEPT
Create DOTSTAR encoder configuration (alias for APA102)
Definition spi.h:72
static SpiEncoder p9813(u32 clock_hz=10000000) FL_NOEXCEPT
Create P9813 encoder configuration.
Definition spi.h:121
static SpiEncoder ws2801(u32 clock_hz=1000000) FL_NOEXCEPT
Create WS2801 encoder configuration.
Definition spi.h:107
static SpiEncoder hd107(u32 clock_hz=40000000) FL_NOEXCEPT
Create HD107 encoder configuration.
Definition spi.h:86
constexpr bool operator!=(const SpiEncoder &other) const FL_NOEXCEPT
Inequality operator.
Definition spi.h:184
static SpiEncoder apa102HD(u32 clock_hz=6000000) FL_NOEXCEPT
Create APA102HD encoder configuration (per-LED brightness via HD gamma)
Definition spi.h:51
SPI encoder configuration for LED protocols.
Definition spi.h:38