FastLED 3.10.8
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1#pragma once
2
3#include "crgb.h" // IWYU pragma: keep
4#include "fl/gfx/rgbw.h" // IWYU pragma: keep
5#include "fl/stl/span.h"
6#include "fl/stl/vector.h"
7#include "fl/stl/shared_ptr.h"
8#include "fl/stl/variant.h"
9#include "fl/math/screenmap.h"
12#include "fl/chipsets/spi.h"
13#include "fl/gfx/eorder.h"
14#include "fl/channels/options.h"
15#include "fl/spi_bus.h"
16#include "fl/stl/optional.h"
17#include "fl/stl/string.h" // fl::string must be complete for Optional<fl::string> below // IWYU pragma: keep
18#include "color.h" // IWYU pragma: keep
19#include "dither_mode.h" // IWYU pragma: keep
20#include "fl/stl/noexcept.h"
21
22namespace fl {
23
34 int pin;
37
42
46
50
53
56
58 ClocklessChipset& operator=(const ClocklessChipset&) FL_NO_EXCEPT = default;
59
62
64 bool operator==(const ClocklessChipset& other) const FL_NO_EXCEPT {
65 return pin == other.pin &&
66 timing == other.timing &&
67 encoder == other.encoder;
68 }
69
71 bool operator!=(const ClocklessChipset& other) const FL_NO_EXCEPT {
72 return !(*this == other);
73 }
74};
75
94template <typename TIMING>
98
108
113
117
120
123
125 SpiChipsetConfig& operator=(const SpiChipsetConfig&) FL_NO_EXCEPT = default;
126
129
131 bool operator==(const SpiChipsetConfig& other) const FL_NO_EXCEPT {
132 return dataPin == other.dataPin &&
133 clockPin == other.clockPin &&
134 timing == other.timing &&
135 spiBus == other.spiBus;
136 }
137
139 bool operator!=(const SpiChipsetConfig& other) const FL_NO_EXCEPT {
140 return !(*this == other);
141 }
142};
143
157using ChipsetVariant = fl::variant<ClocklessChipset, SpiChipsetConfig>;
158
168
169 // ========== New Variant-Based Constructors ==========
170
179
187
195
203
204 // ========== Backwards-Compatible Constructors (Deprecated) ==========
205
209 template<typename TIMING>
212 FL_NO_EXCEPT : ChannelConfig(makeClockless<TIMING>(pin), leds, rgbOrder, options) {}
213
219
220 // Copy constructor (needed because of variant)
222
223 // Move constructor (needed because of variant)
225
226 // Note: Assignment operators deleted because const members cannot be reassigned
227 ChannelConfig& operator=(const ChannelConfig&) FL_NO_EXCEPT = delete;
229
230 // ========== Accessors ==========
231
234
236 bool isClockless() const FL_NO_EXCEPT { return chipset.is<ClocklessChipset>(); }
237
239 bool isSpi() const FL_NO_EXCEPT { return chipset.is<SpiChipsetConfig>(); }
240
243
246
248 int getDataPin() const FL_NO_EXCEPT;
249
251 int getClockPin() const FL_NO_EXCEPT;
252
256
260
263 bool hasScreenMap() const FL_NO_EXCEPT { return mScreenMap.getLength() > 0; }
264
265 // ========== Data Members ==========
266
269
272
275
278
281
284};
285
287
306template<typename Chipset>
313
315 ChannelConfigOf(const fl::string& name, const Chipset& chipset,
316 fl::span<CRGB> leds, EOrder rgbOrder = RGB,
318 : chipset(chipset), mLeds(leds), rgb_order(rgbOrder), options(options), mName(name) {}
319
323 operator ChannelConfig() const FL_NO_EXCEPT {
326 if (mName.has_value()) {
327 cfg.mName = mName;
328 }
329 return cfg;
330 }
331
334 ChannelConfig toErased() const FL_NO_EXCEPT { return static_cast<ChannelConfig>(*this); }
335
336 // ---- Data members (mirror ChannelConfig, but with typed `chipset`) ----
337
340 Chipset chipset;
341
344
347
350
353
356};
357
398
399}
CRGB leds[1]
Runtime chipset timing configuration for clockless LED drivers.
SPI encoder configuration for clocked LED chipsets.
Encoding pipeline selector for clockless LED chipsets.
Declares dithering options and types.
Functions for red, green, blue, white (RGBW) output.
constexpr T * end(T(&array)[N]) FL_NO_EXCEPT
constexpr T * begin(T(&array)[N]) FL_NO_EXCEPT
Esp32SpiBus
ESP-IDF SPI host selection for an individual clocked LED controller.
Definition spi_bus.h:18
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
ClocklessEncoder
Identifies which encoder to use for clockless chipsets in the Channel API.
@ CLOCKLESS_ENCODER_WS2812
Default, no preamble (WS2812 and compatible)
constexpr ChipsetTimingConfig makeTimingConfig() FL_NO_EXCEPT
Convert compile-time CHIPSET type to runtime timing config.
MapRedBlackTree< Key, T, Compare, fl::allocator_slab< char > > map
Definition map.h:283
Optional< T > optional
Definition optional.h:16
fl::variant< ClocklessChipset, SpiChipsetConfig > ChipsetVariant
Definition config.h:157
EOrder
RGB color channel orderings, used when instantiating controllers to determine what order the controll...
Definition eorder.h:15
constexpr ClocklessEncoder encoder_for() FL_NO_EXCEPT
Extract the encoder selector from a compile-time TIMING type.
constexpr ClocklessChipset makeClockless(int pin) FL_NO_EXCEPT
Build a ClocklessChipset from a compile-time TIMING trait.
Definition config.h:95
@ APA102
APA102 LED chipset.
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_SHARED_PTR_STRUCT(type)
Definition shared_ptr.h:582
void setScreenMap(const fl::ScreenMap &map) FL_NO_EXCEPT
Set screen map for JS canvas visualization.
Definition config.h:255
bool isClockless() const FL_NO_EXCEPT
Check if this is a clockless chipset.
Definition config.h:236
ChannelConfig(const fl::string &name, const ChipsetVariant &chipset, fl::span< CRGB > leds, EOrder rgbOrder=RGB, const ChannelOptions &options=ChannelOptions()) FL_NO_EXCEPT
Named constructor with chipset variant.
fl::optional< fl::string > mName
Optional user-specified name (if not set, Channel generates one automatically)
Definition config.h:283
int getDataPin() const FL_NO_EXCEPT
Get data pin (works for both clockless and SPI)
const SpiChipsetConfig * getSpiChipset() const FL_NO_EXCEPT
Get SPI chipset (returns nullptr if not SPI)
Definition config.h:245
const fl::ScreenMap & getScreenMap() const FL_NO_EXCEPT
Get screen map for JS canvas visualization.
Definition config.h:259
int getClockPin() const FL_NO_EXCEPT
Get clock pin (returns -1 for clockless chipsets)
const ChipsetVariant & getChipset() const FL_NO_EXCEPT
Get the chipset configuration variant.
Definition config.h:233
fl::ScreenMap mScreenMap
Screen mapping.
Definition config.h:280
bool isSpi() const FL_NO_EXCEPT
Check if this is an SPI chipset.
Definition config.h:239
bool hasScreenMap() const FL_NO_EXCEPT
Check if screen map is configured.
Definition config.h:263
ChannelOptions options
Optional channel settings (correction, temperature, dither, rgbw, affinity)
Definition config.h:277
fl::span< CRGB > mLeds
LED data array.
Definition config.h:271
ChannelConfig(int pin, fl::span< CRGB > leds, EOrder rgbOrder=RGB, const ChannelOptions &options=ChannelOptions()) FL_NO_EXCEPT
Template constructor with TIMING type (backwards compatibility)
Definition config.h:210
const ClocklessChipset * getClocklessChipset() const FL_NO_EXCEPT
Get clockless chipset (returns nullptr if not clockless)
Definition config.h:242
ChipsetVariant chipset
Chipset configuration (clockless or SPI)
Definition config.h:268
EOrder rgb_order
RGB channel ordering.
Definition config.h:274
Configuration for a single LED channel.
Definition config.h:167
fl::ScreenMap mScreenMap
Screen mapping (for JS canvas visualization).
Definition config.h:352
ChannelConfigOf(const Chipset &chipset, fl::span< CRGB > leds, EOrder rgbOrder=RGB, const ChannelOptions &options=ChannelOptions()) FL_NO_EXCEPT
Construct from a typed chipset, LEDs span, and optional metadata.
Definition config.h:309
fl::span< CRGB > mLeds
LED data span.
Definition config.h:343
ChannelOptions options
Optional channel settings (correction, temperature, dither, rgbw, affinity).
Definition config.h:349
fl::optional< fl::string > mName
Optional user-specified name. If unset, Channel auto-generates one.
Definition config.h:355
EOrder rgb_order
RGB channel ordering.
Definition config.h:346
Chipset chipset
Typed chipset configuration.
Definition config.h:340
ChannelConfigOf(const fl::string &name, const Chipset &chipset, fl::span< CRGB > leds, EOrder rgbOrder=RGB, const ChannelOptions &options=ChannelOptions()) FL_NO_EXCEPT
Named-channel constructor.
Definition config.h:315
ChannelConfig toErased() const FL_NO_EXCEPT
Convenience: build the erased form by value (handy in templates where the implicit conversion is supp...
Definition config.h:334
Optional channel configuration parameters All fields have sensible defaults and can be overridden as ...
Definition options.h:92
Runtime bit-period timing for a clockless chipset.
ChipsetTimingConfig timing
T1/T2/T3 timing parameters.
Definition config.h:35
bool operator!=(const ClocklessChipset &other) const FL_NO_EXCEPT
Inequality operator.
Definition config.h:71
int pin
GPIO data pin.
Definition config.h:34
ClocklessChipset(ClocklessChipset &&) FL_NO_EXCEPT=default
Move constructor.
ClocklessChipset(const ClocklessChipset &) FL_NO_EXCEPT=default
Copy constructor.
constexpr ClocklessChipset() FL_NO_EXCEPT
Default constructor.
Definition config.h:48
ClocklessEncoder encoder
Byte-level encoding pipeline (default: WS2812)
Definition config.h:36
constexpr ClocklessChipset(int pin, const ChipsetTimingConfig &timing, ClocklessEncoder encoder) FL_NO_EXCEPT
Constructor with explicit encoder.
Definition config.h:39
constexpr ClocklessChipset(int pin, const ChipsetTimingConfig &timing) FL_NO_EXCEPT
Constructor (encoder defaults to WS2812)
Definition config.h:44
Clockless chipset configuration (single data pin)
Definition config.h:33
MultiChannelConfig & operator=(const MultiChannelConfig &) FL_NO_EXCEPT=default
MultiChannelConfig & add(ChannelConfigPtr channel) FL_NO_EXCEPT
Add a channel configuration to the multi-channel config.
fl::vector< ChannelConfigPtr > mChannels
Vector of shared pointers to channel configurations.
Definition config.h:396
MultiChannelConfig() FL_NO_EXCEPT=default
MultiChannelConfig(fl::initializer_list< ChannelConfigPtr > channels) FL_NO_EXCEPT
Definition config.h:376
MultiChannelConfig & operator=(MultiChannelConfig &&) FL_NO_EXCEPT=default
SpiEncoder timing
SPI encoder configuration.
Definition config.h:106
SpiChipsetConfig(int dataPin, int clockPin, const SpiEncoder &timing, Esp32SpiBus spiBus=Esp32SpiBus::AUTO) FL_NO_EXCEPT
Constructor.
Definition config.h:110
bool operator!=(const SpiChipsetConfig &other) const FL_NO_EXCEPT
Inequality operator.
Definition config.h:139
SpiChipsetConfig() FL_NO_EXCEPT
Default constructor (requires explicit protocol specification)
Definition config.h:116
Esp32SpiBus spiBus
ESP-IDF host override, or AUTO.
Definition config.h:107
SpiChipsetConfig(const SpiChipsetConfig &) FL_NO_EXCEPT=default
Copy constructor.
int clockPin
GPIO clock pin (SCK)
Definition config.h:105
int dataPin
GPIO data pin (MOSI)
Definition config.h:104
SpiChipsetConfig(SpiChipsetConfig &&) FL_NO_EXCEPT=default
Move constructor.
SPI chipset configuration (data + clock pins)
Definition config.h:103
SPI encoder configuration for LED protocols.
Definition spi.h:38