Repository navigation
refactor(channels): separate ClocklessEncoder from ChipsetTimingConfig (#2467) - #2468
Conversation
#2467) Bit-period timing and the byte-level encoding pipeline are two concerns that were merged into ChipsetTimingConfig. The codebase already signaled the mismatch by having ChipsetTimingConfig::operator== deliberately ignore the encoder field — a clear sign the field wasn't really part of "timing" identity. Changes: - New header src/fl/chipsets/clockless_encoder.h owns ClocklessEncoder enum + has_encoder / get_encoder SFINAE + encoder_for<TIMING>(). - ChipsetTimingConfig drops its encoder field; operator== now honestly compares every field it carries. - ClocklessChipset gains encoder as a peer field alongside pin/timing. Constructors are now constexpr. - New makeClockless<TIMING>(pin) helper collapses the historical two-step "auto timing = makeTimingConfig<X>(); ClocklessChipset(pin, timing);" idiom into a single expression and carries the encoder selector through automatically. - channel.cpp.hpp dispatch site reads clockless->encoder (peer field) instead of clockless->timing.encoder. - led_timing.h no longer hosts the ClocklessEncoder enum (it includes clockless_encoder.h so UCS7604 timing structs' static ENCODER members keep compiling). - AutoResearch infrastructure (NamedTimingConfig, AutoResearchConfig, isUCS7604, buildExpectedUCS7604) threads the encoder selector alongside the timing reference so runtime-named chipset variants preserve their encoder end-to-end. - README + UCS7604 tests + UCS7604 example paths migrated to makeClockless<>() so they don't silently regress to WS2812 encoding. Closes #2467
📝 WalkthroughWalkthroughThis PR refactors the FastLED chipset model to separate byte-level encoder selection from timing configuration. A new ChangesEncoder/Timing Separation Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
examples/AutoResearch/AutoResearchTest.cpp (1)
1033-1040:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winCritical: Encoder not passed when re-creating
ChannelConfigfor clockless chipsets.The code re-creates
ChannelConfigwithconfig.timingbut doesn't passconfig.encoderwhen constructing theClocklessChipset. This causes UCS7604 and other non-WS2812 chipsets to default to WS2812 encoding on the TX side, even thoughconfig.encoderis correctly set and used for RX-side comparison.This breaks the encoder propagation chain established in
testDriver(AutoResearchHelpers.cpp line 52) whereClocklessChipsetis constructed with all three parameters.🐛 Proposed fix to propagate encoder
} else { // Clockless chipset: re-create with runtime timing - fl::ChannelConfig channel_config(config.tx_configs[i].getDataPin(), config.timing, config.tx_configs[i].mLeds, config.tx_configs[i].rgb_order); + fl::ClocklessChipset chipset(config.tx_configs[i].getDataPin(), config.timing, config.encoder); + fl::ChannelConfig channel_config(chipset, config.tx_configs[i].mLeds, config.tx_configs[i].rgb_order); channel = FastLED.add(channel_config); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/AutoResearch/AutoResearchTest.cpp` around lines 1033 - 1040, When re-creating ChannelConfig for clockless chipsets the encoder is not being propagated, so the TX side falls back to WS2812 encoding; update the Clockless/ChannelConfig construction in the else branch that builds fl::ChannelConfig (currently using getDataPin(), config.timing, mLeds, rgb_order) to also pass config.encoder (or otherwise set the encoder on the new ChannelConfig) before calling FastLED.add, ensuring the encoder value from config.tx_configs[i] / config.encoder is forwarded just like testDriver does when constructing ClocklessChipset.examples/AutoResearch/AutoResearchRemote.cpp (1)
345-350:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winMissing encoder when constructing
ChannelConfigfor clockless chipsets.For UCS7604 and other non-WS2812 chipsets, the encoder must be explicitly passed when creating
ClocklessChipset. The current code uses theChannelConfig(pin, timing, leds, order)constructor, which will default the encoder to WS2812 even whentiming_config.encoderspecifies UCS7604.🐛 Proposed fix to propagate encoder
} else { + fl::ClocklessChipset chipset(pin_tx + i, timing_config.timing, timing_config.encoder); tx_configs.push_back(fl::ChannelConfig( - pin_tx + i, // Consecutive pins for multi-lane - timing_config.timing, + chipset, fl::span<CRGB>(leds->data(), leds->size()), - RGB // Default color order + RGB )); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/AutoResearch/AutoResearchRemote.cpp` around lines 345 - 350, The ChannelConfig being constructed in tx_configs uses the constructor that omits the encoder, causing default WS2812 encoding even when timing_config.encoder (for UCS7604 or other clockless chipsets) should be used; update the ChannelConfig construction in the tx_configs push (where tx_configs.push_back(fl::ChannelConfig(...)) is called) to pass timing_config.encoder (or the appropriate encoder field) into the ChannelConfig/ClocklessChipset constructor so the encoder from timing_config is propagated to the channel.
♻️ Duplicate comments (2)
examples/AutoResearch/AutoResearchRemote.cpp (2)
679-685:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winSame encoder propagation issue in parallel test path.
This has the same issue as line 346:
ChannelConfigis constructed without passingtiming_config.encoderto theClocklessChipset. Apply the same fix pattern.🐛 Proposed fix
+ fl::ClocklessChipset chipset(de.pin_tx + (int)li, timing_config.timing, timing_config.encoder); fl::ChannelConfig channel_config( - de.pin_tx + (int)li, // Consecutive pins per lane - timing_config.timing, + chipset, fl::span<CRGB>(leds->data(), leds->size()), RGB, opts );🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/AutoResearch/AutoResearchRemote.cpp` around lines 679 - 685, The ChannelConfig construction in AutoResearchRemote.cpp omits passing timing_config.encoder into the ClocklessChipset for the parallel test path; update the ChannelConfig call that constructs fl::ChannelConfig (the block creating channel_config with de.pin_tx + (int)li, timing_config.timing, fl::span<CRGB>(leds->data(), leds->size()), RGB, opts) to include timing_config.encoder in the ClocklessChipset initialization using the same pattern you applied at the earlier occurrence (i.e., pass timing_config.encoder into the ClocklessChipset constructor used by ChannelConfig).
749-756:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winSame encoder propagation issue in RX validation path.
Another instance of the same pattern. The encoder must be passed for correct UCS7604 behavior.
🐛 Proposed fix
for (fl::size li = 0; li < primary_driver.lane_sizes.size(); li++) { + fl::ClocklessChipset chipset(primary_driver.pin_tx + (int)li, + timing_config.timing, + timing_config.encoder); tx_configs.push_back(fl::ChannelConfig( - primary_driver.pin_tx + (int)li, - timing_config.timing, + chipset, fl::span<CRGB>(all_led_arrays[led_array_offset + li]->data(), all_led_arrays[led_array_offset + li]->size()), RGB )); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/AutoResearch/AutoResearchRemote.cpp` around lines 749 - 756, The RX validation path repeats the ChannelConfig construction without passing the encoder, causing incorrect UCS7604 behavior; update the fl::ChannelConfig call that builds tx_configs (the one using primary_driver.pin_tx + (int)li, timing_config.timing, fl::span<CRGB>(all_led_arrays[led_array_offset + li]->data(), all_led_arrays[led_array_offset + li]->size()), RGB) to include the encoder parameter (same encoder used in the matching TX path) so the constructor receives the encoder argument for correct UCS7604 operation.
🧹 Nitpick comments (2)
src/fl/chipsets/chipset_timing_config.h (1)
13-13: ⚡ Quick winRemove unnecessary include.
The
clockless_encoder.hinclude is no longer needed sinceChipsetTimingConfigno longer contains aClocklessEncoderfield. The encoder concern now lives entirely onClocklessChipset(inconfig.h).♻️ Proposed fix to remove unused include
`#include` "fl/stl/stdint.h" `#include` "fl/chipsets/led_timing.h" -#include "fl/chipsets/clockless_encoder.h" `#include` "fl/stl/noexcept.h"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/fl/chipsets/chipset_timing_config.h` at line 13, Remove the now-unused include of "fl/chipsets/clockless_encoder.h" from the header where ChipsetTimingConfig is defined: delete the `#include` "fl/chipsets/clockless_encoder.h" line in chipset_timing_config.h because ChipsetTimingConfig no longer contains a ClocklessEncoder field and encoder logic has moved to ClocklessChipset (config.h); ensure no other symbols from clockless_encoder.h are referenced in chipset_timing_config.h after removal.examples/AutoResearch/AutoResearchRemote.cpp (1)
303-315: 💤 Low valueEncoder resolution logic looks correct but has minor duplication.
The pattern of resolving
timing+encoderfromtiming_nameis duplicated at lines 534-542 inrunParallelTestImpl. Consider extracting to a helper function to reduce duplication and improve maintainability.♻️ Optional refactor to reduce duplication
// Add helper function struct ResolvedTimingConfig { fl::ChipsetTimingConfig timing; fl::ClocklessEncoder encoder; fl::string name; }; static ResolvedTimingConfig resolveTimingByName(const fl::string& timing_name, bool use_legacy_api) { fl::ChipsetTimingConfig resolved_timing; fl::ClocklessEncoder resolved_encoder = fl::ClocklessEncoder::CLOCKLESS_ENCODER_WS2812; fl::string resolved_name = timing_name; if (use_legacy_api) { resolved_timing = fl::makeTimingConfig<fl::TIMING_WS2812_800KHZ>(); resolved_encoder = fl::encoder_for<fl::TIMING_WS2812_800KHZ>(); resolved_name = "WS2812-800KHZ"; } else if (timing_name == "UCS7604-800KHZ") { resolved_timing = fl::makeTimingConfig<fl::TIMING_UCS7604_800KHZ>(); resolved_encoder = fl::encoder_for<fl::TIMING_UCS7604_800KHZ>(); } else { resolved_timing = fl::makeTimingConfig<fl::TIMING_WS2812B_V5>(); resolved_encoder = fl::encoder_for<fl::TIMING_WS2812B_V5>(); } return {resolved_timing, resolved_encoder, resolved_name}; } // Then use at lines 303-315: auto resolved = resolveTimingByName(timing_name, use_legacy_api); fl::NamedTimingConfig timing_config(resolved.timing, resolved.name.c_str(), resolved.encoder);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/AutoResearch/AutoResearchRemote.cpp` around lines 303 - 315, Extract the duplicated timing+encoder resolution into a helper (e.g., a static resolveTimingByName function returning a small ResolvedTimingConfig struct with fields timing, encoder, name) and replace both sites (the block that creates fl::NamedTimingConfig and the similar logic in runParallelTestImpl) to call it; inside the helper use fl::makeTimingConfig<...>() and fl::encoder_for<...>() for the three cases (legacy use_legacy_api -> TIMING_WS2812_800KHZ, timing_name == "UCS7604-800KHZ" -> TIMING_UCS7604_800KHZ, else -> TIMING_WS2812B_V5) and return values to construct fl::NamedTimingConfig at the call sites.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@examples/AutoResearch/AutoResearchRemote.cpp`:
- Around line 345-350: The ChannelConfig being constructed in tx_configs uses
the constructor that omits the encoder, causing default WS2812 encoding even
when timing_config.encoder (for UCS7604 or other clockless chipsets) should be
used; update the ChannelConfig construction in the tx_configs push (where
tx_configs.push_back(fl::ChannelConfig(...)) is called) to pass
timing_config.encoder (or the appropriate encoder field) into the
ChannelConfig/ClocklessChipset constructor so the encoder from timing_config is
propagated to the channel.
In `@examples/AutoResearch/AutoResearchTest.cpp`:
- Around line 1033-1040: When re-creating ChannelConfig for clockless chipsets
the encoder is not being propagated, so the TX side falls back to WS2812
encoding; update the Clockless/ChannelConfig construction in the else branch
that builds fl::ChannelConfig (currently using getDataPin(), config.timing,
mLeds, rgb_order) to also pass config.encoder (or otherwise set the encoder on
the new ChannelConfig) before calling FastLED.add, ensuring the encoder value
from config.tx_configs[i] / config.encoder is forwarded just like testDriver
does when constructing ClocklessChipset.
---
Duplicate comments:
In `@examples/AutoResearch/AutoResearchRemote.cpp`:
- Around line 679-685: The ChannelConfig construction in AutoResearchRemote.cpp
omits passing timing_config.encoder into the ClocklessChipset for the parallel
test path; update the ChannelConfig call that constructs fl::ChannelConfig (the
block creating channel_config with de.pin_tx + (int)li, timing_config.timing,
fl::span<CRGB>(leds->data(), leds->size()), RGB, opts) to include
timing_config.encoder in the ClocklessChipset initialization using the same
pattern you applied at the earlier occurrence (i.e., pass timing_config.encoder
into the ClocklessChipset constructor used by ChannelConfig).
- Around line 749-756: The RX validation path repeats the ChannelConfig
construction without passing the encoder, causing incorrect UCS7604 behavior;
update the fl::ChannelConfig call that builds tx_configs (the one using
primary_driver.pin_tx + (int)li, timing_config.timing,
fl::span<CRGB>(all_led_arrays[led_array_offset + li]->data(),
all_led_arrays[led_array_offset + li]->size()), RGB) to include the encoder
parameter (same encoder used in the matching TX path) so the constructor
receives the encoder argument for correct UCS7604 operation.
---
Nitpick comments:
In `@examples/AutoResearch/AutoResearchRemote.cpp`:
- Around line 303-315: Extract the duplicated timing+encoder resolution into a
helper (e.g., a static resolveTimingByName function returning a small
ResolvedTimingConfig struct with fields timing, encoder, name) and replace both
sites (the block that creates fl::NamedTimingConfig and the similar logic in
runParallelTestImpl) to call it; inside the helper use
fl::makeTimingConfig<...>() and fl::encoder_for<...>() for the three cases
(legacy use_legacy_api -> TIMING_WS2812_800KHZ, timing_name == "UCS7604-800KHZ"
-> TIMING_UCS7604_800KHZ, else -> TIMING_WS2812B_V5) and return values to
construct fl::NamedTimingConfig at the call sites.
In `@src/fl/chipsets/chipset_timing_config.h`:
- Line 13: Remove the now-unused include of "fl/chipsets/clockless_encoder.h"
from the header where ChipsetTimingConfig is defined: delete the `#include`
"fl/chipsets/clockless_encoder.h" line in chipset_timing_config.h because
ChipsetTimingConfig no longer contains a ClocklessEncoder field and encoder
logic has moved to ClocklessChipset (config.h); ensure no other symbols from
clockless_encoder.h are referenced in chipset_timing_config.h after removal.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 386333db-291e-44c7-860e-c4d8c1edbd61
📒 Files selected for processing (12)
examples/AutoResearch/AutoResearchHelpers.cppexamples/AutoResearch/AutoResearchRemote.cppexamples/AutoResearch/AutoResearchTest.cppexamples/AutoResearch/AutoResearchTest.hexamples/AutoResearch/Common.hsrc/fl/channels/README.mdsrc/fl/channels/channel.cpp.hppsrc/fl/channels/config.hsrc/fl/chipsets/chipset_timing_config.hsrc/fl/chipsets/clockless_encoder.hsrc/fl/chipsets/led_timing.htests/fl/chipsets/ucs7604.cpp
Closes #2467.
Summary
ChipsetTimingConfigis now pure bit-period timing (T1/T2/T3/RESET). Itsoperator==no longer silently ignores any field.ClocklessEncoder) is lifted toClocklessChipsetas a peer ofpin/timing.fl::makeClockless<TIMING>(pin)helper collapses the historical two-stepauto t = makeTimingConfig<X>(); ClocklessChipset(PIN, t);idiom into one expression — and carries the encoder selector through automatically.ClocklessEncoderenum moves out ofled_timing.h(a "T1/T2/T3 timing" header per its own comment) into a focusedclockless_encoder.h.AutoResearchinfrastructure threads the encoder selector alongside the timing reference (viaNamedTimingConfig/AutoResearchConfig) so runtime-named chipset variants like"UCS7604-800KHZ"preserve their encoder end-to-end through the test harness.makeClockless<>()so they don't silently regress to WS2812 encoding when the timing struct no longer drags its encoder along.Why
ChipsetTimingConfig::operator==deliberately ignored theencoderfield — the codebase's own confession that the merge of timing + encoder wasn't really a single concept. This split makes the equality contract honest, givesled_timing.hback its single responsibility, and shrinks the ~80 two-line call-site dances to one-linemakeClockless<>(pin)invocations.Test plan
bash test --cpp— 304/304 passedbash lint— cleanbash test ucs7604— passes; verifies encoder propagation via the newencoder_for<>()/makeClockless<>()helpers and that the UCS7604 preamble is still emitted end-to-end via the channel APIBackward compatibility
fl::makeTimingConfig<TIMING>()still works (returns pure-timingChipsetTimingConfig).ClocklessChipset(pin, timing)2-arg constructor still works — encoder defaults to WS2812. Call sites that need non-WS2812 encoding should switch tomakeClockless<TIMING>(pin); this PR migrates the UCS7604 sites that would otherwise silently regress.🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
makeClockless<>()helper function for more streamlined configuration construction.Documentation