FastLED 3.9.15
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/stl/optional.h"
16#include "fl/stl/string.h" // fl::string must be complete for Optional<fl::string> below // IWYU pragma: keep
17#include "color.h" // IWYU pragma: keep
18#include "dither_mode.h" // IWYU pragma: keep
19#include "fl/stl/noexcept.h"
20
21namespace fl {
22
33 int pin;
36
41
45
49
52
55
57 ClocklessChipset& operator=(const ClocklessChipset&) FL_NOEXCEPT = default;
58
61
63 bool operator==(const ClocklessChipset& other) const FL_NOEXCEPT {
64 return pin == other.pin &&
65 timing == other.timing &&
66 encoder == other.encoder;
67 }
68
70 bool operator!=(const ClocklessChipset& other) const FL_NOEXCEPT {
71 return !(*this == other);
72 }
73};
74
93template <typename TIMING>
97
106
110
114
117
120
122 SpiChipsetConfig& operator=(const SpiChipsetConfig&) FL_NOEXCEPT = default;
123
126
128 bool operator==(const SpiChipsetConfig& other) const FL_NOEXCEPT {
129 return dataPin == other.dataPin &&
130 clockPin == other.clockPin &&
131 timing == other.timing;
132 }
133
135 bool operator!=(const SpiChipsetConfig& other) const FL_NOEXCEPT {
136 return !(*this == other);
137 }
138};
139
153using ChipsetVariant = fl::variant<ClocklessChipset, SpiChipsetConfig>;
154
164
165 // ========== New Variant-Based Constructors ==========
166
175
183
191
199
200 // ========== Backwards-Compatible Constructors (Deprecated) ==========
201
205 template<typename TIMING>
208 FL_NOEXCEPT : ChannelConfig(makeClockless<TIMING>(pin), leds, rgbOrder, options) {}
209
215
216 // Copy constructor (needed because of variant)
218
219 // Move constructor (needed because of variant)
221
222 // Note: Assignment operators deleted because const members cannot be reassigned
223 ChannelConfig& operator=(const ChannelConfig&) FL_NOEXCEPT = delete;
225
226 // ========== Accessors ==========
227
229 const ChipsetVariant& getChipset() const FL_NOEXCEPT { return chipset; }
230
232 bool isClockless() const FL_NOEXCEPT { return chipset.is<ClocklessChipset>(); }
233
235 bool isSpi() const FL_NOEXCEPT { return chipset.is<SpiChipsetConfig>(); }
236
239
242
244 int getDataPin() const FL_NOEXCEPT;
245
247 int getClockPin() const FL_NOEXCEPT;
248
252
256
259 bool hasScreenMap() const FL_NOEXCEPT { return mScreenMap.getLength() > 0; }
260
261 // ========== Data Members ==========
262
265
268
271
274
277
280};
281
283
302template<typename Chipset>
309
311 ChannelConfigOf(const fl::string& name, const Chipset& chipset,
312 fl::span<CRGB> leds, EOrder rgbOrder = RGB,
314 : chipset(chipset), mLeds(leds), rgb_order(rgbOrder), options(options), mName(name) {}
315
319 operator ChannelConfig() const FL_NOEXCEPT {
322 if (mName.has_value()) {
323 cfg.mName = mName;
324 }
325 return cfg;
326 }
327
330 ChannelConfig toErased() const FL_NOEXCEPT { return static_cast<ChannelConfig>(*this); }
331
332 // ---- Data members (mirror ChannelConfig, but with typed `chipset`) ----
333
336 Chipset chipset;
337
340
343
346
349
352};
353
394
395}
fl::CRGB leds[NUM_LEDS]
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.
ClocklessEncoder
Identifies which encoder to use for clockless chipsets in the Channel API.
@ CLOCKLESS_ENCODER_WS2812
Default, no preamble (WS2812 and compatible)
constexpr T * begin(T(&array)[N]) FL_NOEXCEPT
MapRedBlackTree< Key, T, Compare, fl::allocator_slab< char > > map
Definition map.h:283
constexpr ClocklessChipset makeClockless(int pin) FL_NOEXCEPT
Build a ClocklessChipset from a compile-time TIMING trait.
Definition config.h:94
constexpr T * end(T(&array)[N]) FL_NOEXCEPT
Optional< T > optional
Definition optional.h:16
constexpr ChipsetTimingConfig makeTimingConfig() FL_NOEXCEPT
Convert compile-time CHIPSET type to runtime timing config.
fl::variant< ClocklessChipset, SpiChipsetConfig > ChipsetVariant
Definition config.h:153
EOrder
RGB color channel orderings, used when instantiating controllers to determine what order the controll...
Definition eorder.h:13
@ RGB
Red, Green, Blue (0012)
Definition eorder.h:14
constexpr ClocklessEncoder encoder_for() FL_NOEXCEPT
Extract the encoder selector from a compile-time TIMING type.
@ APA102
APA102 LED chipset.
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
#define FASTLED_SHARED_PTR_STRUCT(type)
Definition shared_ptr.h:540
const fl::ScreenMap & getScreenMap() const FL_NOEXCEPT
Get screen map for JS canvas visualization.
Definition config.h:255
fl::optional< fl::string > mName
Optional user-specified name (if not set, Channel generates one automatically)
Definition config.h:279
bool isSpi() const FL_NOEXCEPT
Check if this is an SPI chipset.
Definition config.h:235
const ChipsetVariant & getChipset() const FL_NOEXCEPT
Get the chipset configuration variant.
Definition config.h:229
const ClocklessChipset * getClocklessChipset() const FL_NOEXCEPT
Get clockless chipset (returns nullptr if not clockless)
Definition config.h:238
bool hasScreenMap() const FL_NOEXCEPT
Check if screen map is configured.
Definition config.h:259
const SpiChipsetConfig * getSpiChipset() const FL_NOEXCEPT
Get SPI chipset (returns nullptr if not SPI)
Definition config.h:241
int getDataPin() const FL_NOEXCEPT
Get data pin (works for both clockless and SPI)
void setScreenMap(const fl::ScreenMap &map) FL_NOEXCEPT
Set screen map for JS canvas visualization.
Definition config.h:251
fl::ScreenMap mScreenMap
Screen mapping.
Definition config.h:276
ChannelConfig(int pin, fl::span< CRGB > leds, EOrder rgbOrder=RGB, const ChannelOptions &options=ChannelOptions()) FL_NOEXCEPT
Template constructor with TIMING type (backwards compatibility)
Definition config.h:206
ChannelOptions options
Optional channel settings (correction, temperature, dither, rgbw, affinity)
Definition config.h:273
fl::span< CRGB > mLeds
LED data array.
Definition config.h:267
bool isClockless() const FL_NOEXCEPT
Check if this is a clockless chipset.
Definition config.h:232
ChannelConfig(const fl::string &name, const ChipsetVariant &chipset, fl::span< CRGB > leds, EOrder rgbOrder=RGB, const ChannelOptions &options=ChannelOptions()) FL_NOEXCEPT
Named constructor with chipset variant.
ChipsetVariant chipset
Chipset configuration (clockless or SPI)
Definition config.h:264
int getClockPin() const FL_NOEXCEPT
Get clock pin (returns -1 for clockless chipsets)
EOrder rgb_order
RGB channel ordering.
Definition config.h:270
Configuration for a single LED channel.
Definition config.h:163
ChannelConfig toErased() const FL_NOEXCEPT
Convenience: build the erased form by value (handy in templates where the implicit conversion is supp...
Definition config.h:330
ChannelConfigOf(const Chipset &chipset, fl::span< CRGB > leds, EOrder rgbOrder=RGB, const ChannelOptions &options=ChannelOptions()) FL_NOEXCEPT
Construct from a typed chipset, LEDs span, and optional metadata.
Definition config.h:305
fl::ScreenMap mScreenMap
Screen mapping (for JS canvas visualization).
Definition config.h:348
fl::span< CRGB > mLeds
LED data span.
Definition config.h:339
ChannelOptions options
Optional channel settings (correction, temperature, dither, rgbw, affinity).
Definition config.h:345
fl::optional< fl::string > mName
Optional user-specified name. If unset, Channel auto-generates one.
Definition config.h:351
EOrder rgb_order
RGB channel ordering.
Definition config.h:342
Chipset chipset
Typed chipset configuration.
Definition config.h:336
ChannelConfigOf(const fl::string &name, const Chipset &chipset, fl::span< CRGB > leds, EOrder rgbOrder=RGB, const ChannelOptions &options=ChannelOptions()) FL_NOEXCEPT
Named-channel constructor.
Definition config.h:311
Optional channel configuration parameters All fields have sensible defaults and can be overridden as ...
Definition options.h:43
Runtime bit-period timing for a clockless chipset.
bool operator!=(const ClocklessChipset &other) const FL_NOEXCEPT
Inequality operator.
Definition config.h:70
ChipsetTimingConfig timing
T1/T2/T3 timing parameters.
Definition config.h:34
constexpr ClocklessChipset(int pin, const ChipsetTimingConfig &timing, ClocklessEncoder encoder) FL_NOEXCEPT
Constructor with explicit encoder.
Definition config.h:38
ClocklessChipset(const ClocklessChipset &) FL_NOEXCEPT=default
Copy constructor.
int pin
GPIO data pin.
Definition config.h:33
constexpr ClocklessChipset(int pin, const ChipsetTimingConfig &timing) FL_NOEXCEPT
Constructor (encoder defaults to WS2812)
Definition config.h:43
ClocklessEncoder encoder
Byte-level encoding pipeline (default: WS2812)
Definition config.h:35
ClocklessChipset(ClocklessChipset &&) FL_NOEXCEPT=default
Move constructor.
constexpr ClocklessChipset() FL_NOEXCEPT
Default constructor.
Definition config.h:47
Clockless chipset configuration (single data pin)
Definition config.h:32
MultiChannelConfig & operator=(const MultiChannelConfig &) FL_NOEXCEPT=default
MultiChannelConfig & operator=(MultiChannelConfig &&) FL_NOEXCEPT=default
fl::vector< ChannelConfigPtr > mChannels
Vector of shared pointers to channel configurations.
Definition config.h:392
MultiChannelConfig() FL_NOEXCEPT=default
MultiChannelConfig(fl::initializer_list< ChannelConfigPtr > channels) FL_NOEXCEPT
Definition config.h:372
MultiChannelConfig & add(ChannelConfigPtr channel) FL_NOEXCEPT
Add a channel configuration to the multi-channel config.
SpiEncoder timing
SPI encoder configuration.
Definition config.h:105
bool operator!=(const SpiChipsetConfig &other) const FL_NOEXCEPT
Inequality operator.
Definition config.h:135
SpiChipsetConfig(const SpiChipsetConfig &) FL_NOEXCEPT=default
Copy constructor.
SpiChipsetConfig() FL_NOEXCEPT
Default constructor (requires explicit protocol specification)
Definition config.h:113
SpiChipsetConfig(SpiChipsetConfig &&) FL_NOEXCEPT=default
Move constructor.
int clockPin
GPIO clock pin (SCK)
Definition config.h:104
int dataPin
GPIO data pin (MOSI)
Definition config.h:103
SpiChipsetConfig(int dataPin, int clockPin, const SpiEncoder &timing) FL_NOEXCEPT
Constructor.
Definition config.h:108
SPI chipset configuration (data + clock pins)
Definition config.h:102
SPI encoder configuration for LED protocols.
Definition spi.h:38