Repository navigation
Description
Motivation
fl::ChipsetTimingConfig (src/fl/chipsets/chipset_timing_config.h:16) currently bundles bit-period timing (t1_ns, t2_ns, t3_ns, reset_us) with an unrelated concern: ClocklessEncoder encoder (the byte-level pipeline selector used to dispatch WS2812 vs UCS7604 encoding).
The codebase already signals that these fields aren't peers of the same nature:
ChipsetTimingConfig::operator==deliberately ignoresencoder(chipset_timing_config.h:36-41). A field that doesn't participate in identity isn't really part of the type's concept.ClocklessEncoderlives insrc/fl/chipsets/led_timing.h, whose own header comment declares it as "nanosecond-based T1, T2, T3 timing model" — the enum is a misfit there.- The encoder field is read in exactly one place (
src/fl/channels/channel.cpp.hpp:378-388) to dispatch betweenwriteWS2812()andwriteUCS7604().
Call sites pay a small ergonomic tax for the merged design:
auto timing = fl::makeTimingConfig<fl::TIMING_WS2812_800KHZ>();
fl::ChannelConfig cfg("left_strip", fl::ClocklessChipset(PIN1, timing), leds, RGB);This two-line dance appears in ~80 sites across tests/, examples/, and src/platforms/.
Proposal (Design 2)
Separate the concerns and add an ergonomic helper.
1. Pure-timing ChipsetTimingConfig
Drop the encoder field. operator== then means exactly what it says.
struct ChipsetTimingConfig {
u32 t1_ns, t2_ns, t3_ns, reset_us;
const char* name;
// encoder removed
};2. Encoder lifted to ClocklessChipset as a peer field
struct ClocklessChipset {
int pin;
ChipsetTimingConfig timing;
ClocklessEncoder encoder; // peer concern, not a sub-field of timing
};3. New helper collapses the two-step pattern
template<typename TIMING>
constexpr ClocklessChipset makeClockless(int pin) FL_NOEXCEPT {
return { pin, makeTimingConfig<TIMING>(),
detail::get_encoder<TIMING, has_encoder<TIMING>::value>::value };
}Call sites become one line:
fl::ChannelConfig cfg("left_strip", fl::makeClockless<fl::TIMING_WS2812_800KHZ>(PIN1), leds, RGB);4. Move ClocklessEncoder enum out of led_timing.h
New header src/fl/chipsets/clockless_encoder.h owns the enum. led_timing.h returns to bit-timing only, matching its documented purpose.
Migration plan
- Add
clockless_encoder.h; moveenum class ClocklessEncoderand thehas_encoder/get_encoderSFINAE helpers there. - Update
ChipsetTimingConfig: removeencoderfield, ctor argument, and the equality-ignore comment. - Add
encodertoClocklessChipset(withCLOCKLESS_ENCODER_WS2812default for backward-compat constructors). - Add
makeClockless<TIMING>(pin)inchipset_timing_config.h(or a newclockless_chipset.h). - Update the single consumer at
channel.cpp.hpp:378(clockless->timing.encoder→clockless->encoder). - Migrate call sites in
tests/,examples/,src/platforms/tomakeClockless<>()opportunistically (not a hard requirement —makeTimingConfig<>()still works for the timing-only path). - Update
src/fl/channels/README.mdandFastLED.hdoc examples.
Acceptance criteria
bash testpassesbash lintcleanChipsetTimingConfig::operator==compares all fields (no ignored field)led_timing.hno longer mentionsClocklessEncoder- README and FastLED.h examples use
fl::makeClockless<>()for one-liner clockless construction - Existing
makeTimingConfig<>()continues to work;ClocklessChipset(pin, timing)two-arg form continues to work (defaults encoder to WS2812)
Out of scope
- Compile-time-only chipset typing via
ClocklessChipsetT<TIMING>(that was "Design 1" in the design discussion — too invasive for the variant/driver layer to be worth doing right now).
Activity
refactor(channels): separate ClocklessEncoder from ChipsetTimingConfig (
docs(channels): document makeClockless<>() + reframe addLeds<> as Eas…