Repository navigation
feat(channels): one-shot affinity-miss diagnostic + normalized driver names (closes #2455) - #2456
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (14)
✅ Files skipped from review due to trivial changes (5)
🚧 Files skipped from review as they are similar to previous changes (8)
📝 WalkthroughWalkthroughThis PR normalizes driver name strings to match C++ enumerator spellings (FLEX_IO, OBJECT_FLED, BIT_BANG), adds isKnownBusName(), introduces a silent ChannelManager lookup, implements one-shot per-channel affinity-miss diagnostics with graceful fallback, and updates drivers and tests to the new names. ChangesBus Name Normalization & Affinity-Miss Diagnostics
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
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)
Warning Review ran into problems🔥 ProblemsTimed out fetching pipeline failures after 30000ms 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.
Actionable comments posted: 4
🤖 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.
Inline comments:
In `@src/fl/channels/channel.cpp.hpp`:
- Around line 334-346: The fallback log incorrectly treats any affinity mismatch
(driver->getName() != mAffinity) as "not instantiated"; update the conditional
and messages to distinguish "no registered/enabled driver" from "registered
driver incompatible." Specifically, instead of using (driver->getName() !=
mAffinity) alone, query the channel/driver registry (e.g.,
ChannelManager::hasDriver or equivalent) to detect whether mAffinity is actually
registered/enabled; if the affinity is not registered, emit the existing "wasn't
instantiated — call fl::enableDrivers<fl::Bus::...>()" message; otherwise, if a
driver for mAffinity exists but is incompatible (driver exists but reports it
cannot handle the channel, e.g., via driver->canHandle(...) or
driver->getName()==mAffinity && !driver->canHandle(...)), emit a
mismatch/incompatibility warning and default to AUTO/priority dispatch. Ensure
the checks reference mDriverPreBound, mAffinity, mAffinityWarned, driver and
isKnownBusName so the correct branch is chosen.
In `@src/fl/channels/manager.cpp.hpp`:
- Around line 291-305: The affinity-miss path is still noisy because
getDriverByName(affinity) emits diagnostics; change the manager to use a
non-diagnostic lookup here by calling a new/overloaded silent lookup (e.g.,
getDriverByNameSilent or getDriverByName(affinity, /*suppressDiagnostics*/
true)) instead of getDriverByName so misses return nullptr without emitting
FL_ERROR, and implement the silent variant to perform the same lookup but not
emit any logs; update the call in the do-block that currently references
getDriverByName(affinity) to use this silent API.
In `@tests/fl/channels/all_drivers.cpp`:
- Around line 51-52: The comment next to the call to mgr.getDriverByName using
the string literal "BIT_BANG" is incorrect; update the comment to match the
literal by removing "(no underscore)" or changing it to "(with underscore)" so
it accurately describes "BIT_BANG" used in the call to
mgr.getDriverByName(fl::string::from_literal("BIT_BANG")).
In `@tests/fl/channels/channel.cpp`:
- Around line 538-566: The test currently triggers an extra FL_ERROR by calling
mgr.getDriverByName("RMT") and never asserts the one-shot affinity diagnostic;
change the test to avoid provoking that extra error and explicitly capture logs
around the two showLeds() calls and assert exactly one affinity-miss FL_ERROR
was emitted. Concretely: remove or replace the call to getDriverByName("RMT")
(which causes an unwanted error) and wrap the first and second
channel->showLeds(0) calls with the test log-capture utility (e.g., captureLogs
or the project test logger), then assert the captured logs contain one and only
one FL_ERROR message mentioning the affinity miss for the channel (and assert
driver binding stability as before using channel->getEngineName()).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: cec8abc2-535d-4593-8f6d-4bf5dfed3363
📒 Files selected for processing (13)
src/fl/channels/bus.hsrc/fl/channels/channel.cpp.hppsrc/fl/channels/channel.hsrc/fl/channels/manager.cpp.hppsrc/fl/log/async_logger.hsrc/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.hsrc/platforms/arm/teensy/teensy4_common/drivers/objectfled/channel_engine_objectfled.hsrc/platforms/shared/bitbang/bitbang_channel_driver.cpp.hpptests/fl/channels/all_drivers.cpptests/fl/channels/channel.cpptests/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.cpptests/platforms/arm/teensy/teensy4_common/drivers/objectfled/channel_engine_objectfled.cpptests/platforms/shared/bitbang/bitbang_channel_driver.cpp
| if (!mDriverPreBound && !mAffinity.empty() && !mAffinityWarned) { | ||
| const bool affinityMiss = !driver || | ||
| (driver->getName() != mAffinity); | ||
| if (affinityMiss) { | ||
| if (isKnownBusName(mAffinity)) { | ||
| FL_ERROR("Channel '" << mName << "': Driver '" << mAffinity | ||
| << "' wasn't instantiated — call fl::enableDrivers<fl::Bus::" | ||
| << mAffinity | ||
| << ">() (or fl::enableAllDrivers()) before adding the channel. " | ||
| << "Defaulting to AUTO/priority dispatch."); | ||
| } else { | ||
| FL_ERROR("Channel '" << mName << "': Affinity '" << mAffinity | ||
| << "' has no registered driver. Defaulting to AUTO/priority dispatch."); |
There was a problem hiding this comment.
Affinity diagnostic currently mislabels incompatibility as “not instantiated.”
Lines 335-346 treat any fallback (driver->getName() != mAffinity) as a registration miss. That also catches the “affinity driver exists but canHandle() failed” path, so the enableDrivers<fl::Bus::...>() guidance is incorrect in that case.
Please gate this message on an explicit “not found/not enabled” reason from ChannelManager (or equivalent), and keep incompatibility on the mismatch warning path.
🤖 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/channels/channel.cpp.hpp` around lines 334 - 346, The fallback log
incorrectly treats any affinity mismatch (driver->getName() != mAffinity) as
"not instantiated"; update the conditional and messages to distinguish "no
registered/enabled driver" from "registered driver incompatible." Specifically,
instead of using (driver->getName() != mAffinity) alone, query the
channel/driver registry (e.g., ChannelManager::hasDriver or equivalent) to
detect whether mAffinity is actually registered/enabled; if the affinity is not
registered, emit the existing "wasn't instantiated — call
fl::enableDrivers<fl::Bus::...>()" message; otherwise, if a driver for mAffinity
exists but is incompatible (driver exists but reports it cannot handle the
channel, e.g., via driver->canHandle(...) or driver->getName()==mAffinity &&
!driver->canHandle(...)), emit a mismatch/incompatibility warning and default to
AUTO/priority dispatch. Ensure the checks reference mDriverPreBound, mAffinity,
mAffinityWarned, driver and isKnownBusName so the correct branch is chosen.
There was a problem hiding this comment.
Fixed in a48c3ec. The channel-side diagnostic now probes the registry directly via the new silent ChannelManager::findDriverByName(mAffinity). Branches: registry returns null → "wasn't instantiated, call enableDriversBus::X()"; registry returns a driver (so the priority fallback fired because canHandle() rejected this chipset) → "registered but cannot handle this channel's chipset (bus/chipset mismatch)". Resolution paths are now distinct.
There was a problem hiding this comment.
@zackees, confirmed — the updated logic in the file_content correctly implements both branches:
findDriverByNamereturnsnull→ driver was never instantiated → emits theenableDrivers<fl::Bus::X>()/enableAllDrivers()hint (gated onisKnownBusName).findDriverByNamereturns a driver → it exists butcanHandle()rejected the chipset → emits the "registered but cannot handle this channel's chipset (bus/chipset mismatch)" message.
The mAffinityWarned = true guard is still set after either branch, so the one-shot behavior is preserved. The original concern is fully addressed. ✅
If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
| FL_TEST_CASE("Affinity miss to unregistered known Bus falls back and still renders") { | ||
| auto& mgr = freshBusTestManager(); | ||
| FL_REQUIRE(mgr.getDriverCount() == 0); | ||
|
|
||
| // Register ONLY the host fallbacks (STUB + BIT_BANG via enableAllDrivers). | ||
| // We do not register Bus::RMT, so an affinity = "RMT" must miss. | ||
| fl::enableAllDrivers(); | ||
| FL_CHECK(mgr.getDriverByName(fl::string::from_literal("RMT")) == nullptr); | ||
|
|
||
| CRGB leds[8] = {}; | ||
| ChannelConfig cfg = makeBusTestConfig(fl::span<CRGB>(leds, 8)); | ||
| // Forge a runtime affinity for a Bus whose driver is NOT registered. | ||
| cfg.options.mAffinity = fl::string::from_literal("RMT"); | ||
|
|
||
| auto channel = Channel::create(cfg); | ||
| FL_REQUIRE(channel != nullptr); | ||
| channel->addToDrawList(); | ||
|
|
||
| // First show: the diagnostic fires AND priority dispatch picks a host | ||
| // driver (STUB or BIT_BANG). Channel still renders. | ||
| channel->showLeds(0); | ||
| auto bound = channel->getEngineName(); | ||
| FL_CHECK(bound == fl::string::from_literal("STUB") || | ||
| bound == fl::string::from_literal("BIT_BANG")); | ||
|
|
||
| // Second show: mAffinityWarned suppresses the duplicate diagnostic. | ||
| // Driver binding is unchanged. | ||
| channel->showLeds(0); | ||
| FL_CHECK(channel->getEngineName() == bound); |
There was a problem hiding this comment.
One-shot diagnostic behavior isn’t actually asserted in this test.
Lines 563-566 only check driver stability; they don’t verify that the affinity-miss FL_ERROR occurs exactly once. Also, Line 545 currently triggers an extra FL_ERROR via getDriverByName("RMT"), which can interfere with a future log-count assertion.
Please capture logs around the two showLeds() calls and assert exactly one affinity-miss error for this channel.
🤖 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 `@tests/fl/channels/channel.cpp` around lines 538 - 566, The test currently
triggers an extra FL_ERROR by calling mgr.getDriverByName("RMT") and never
asserts the one-shot affinity diagnostic; change the test to avoid provoking
that extra error and explicitly capture logs around the two showLeds() calls and
assert exactly one affinity-miss FL_ERROR was emitted. Concretely: remove or
replace the call to getDriverByName("RMT") (which causes an unwanted error) and
wrap the first and second channel->showLeds(0) calls with the test log-capture
utility (e.g., captureLogs or the project test logger), then assert the captured
logs contain one and only one FL_ERROR message mentioning the affinity miss for
the channel (and assert driver binding stability as before using
channel->getEngineName()).
There was a problem hiding this comment.
Partially fixed in a48c3ec. Removed the getDriverByName("RMT") call that was emitting its own FL_ERROR (now uses the new silent findDriverByName). Did NOT add the log-count assertion — the project log macros have no capture/intercept hook today, so a count assertion isn't feasible without new test infrastructure. Added a comment in the test explaining the behavioural proxy (dispatch falls back to a host driver; bound driver stable across shows; mAffinityWarned latches unconditionally). If a follow-up adds an FL_LOG_CAPTURE utility, this test can be tightened.
There was a problem hiding this comment.
@zackees, thanks for the update. The two parts break down cleanly:
getDriverByName→findDriverByName— fully resolved. The silent lookup eliminates the spuriousFL_ERRORthat would have polluted any future log-count assertion.- Log-count assertion — the deferral is reasonable. Without a capture/intercept hook on
FL_ERROR, a count assertion would either require invasive changes to the logging layer or a test-only global side-channel, neither of which belongs in this PR. The behavioral proxy (stable bound-driver across twoshowLeds()calls + the unconditionalmAffinityWarnedlatch documented in the comment) is a sound substitute for now.
Would you like me to open a follow-up GitHub issue to track adding an FL_LOG_CAPTURE / log-intercept test utility so this test can be tightened later?
… names (closes #2455) When a runtime affinity is set but the named driver isn't registered with ChannelManager (e.g., the user wrote FastLED.add(fl::Bus::RMT, cfg) without calling enableAllDrivers() / enableDrivers<Bus::RMT>() first), Channel:: showPixels now emits exactly one FL_ERROR on the first show() of that channel: Channel 'Channel_3': Driver 'RMT' wasn't instantiated -- call fl::enableDrivers<fl::Bus::RMT>() (or fl::enableAllDrivers()) before adding the channel. Defaulting to AUTO/priority dispatch. The new mAffinityWarned per-channel flag suppresses duplicates on every subsequent show. Dispatch still falls through to ChannelManager's priority search so LEDs still light up. For unknown / third-party affinity strings (not one of fl::Bus's canonical names) the message drops the fl::Bus::X hint and just reports the missing driver. The per-frame ERROR-level log in ChannelManager::selectDriverForChannel is now silent in the affinity-miss path -- the Channel layer carries the actionable message. canHandle() mismatches are demoted to FL_WARN_ONCE. Also normalized three driver getName() returns + their log categories to match the C++ enumerator spelling (with underscores) -- no more divergence: Bus::FLEX_IO -> "FLEX_IO" (was "FLEXIO") Bus::OBJECT_FLED -> "OBJECT_FLED" (was "OBJECTFLED") Bus::BIT_BANG -> "BIT_BANG" (was "BITBANG") The previous busEnumSpelling() helper is gone -- single source of truth in bus.h's busName() table now matches getName() everywhere, so isKnownBusName() is a flat string compare and the FL_ERROR message embeds mAffinity verbatim without translation. Tests cover: - Known Bus miss: actionable FL_ERROR + priority fallback + render success. - Unknown affinity miss: generic FL_ERROR + priority fallback. - Repeat shows do not re-log (mAffinityWarned guard works). Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
724f79f to
a48c3ec
Compare
…bleAllDrivers + diagnostics) (#2458) The channels README hadn't been updated since #2435 (Phase 3a) while the real API surface grew through #2437/2438/2441/2448/2449/2450/2451/2454/ 2456. This refresh aligns the docs with what the code actually does today. Reviewed in three independent sub-agent passes: - Pass 1 (broad accuracy): added the new dual-mode dispatch architecture section (compile-time `fl::Bus` binding vs runtime `ChannelManager`), the templated `Channel::create<Bus B>(cfg)` / `FastLED.add<Bus B>(cfg)` examples, the `ChannelConfigOf<Chipset>` + `TypedChannel<Bus, Chipset>` Phase 3b API, the `enableDrivers<>()` / `enableAllDrivers()` opt-in registry, the `FASTLED_DISABLE_LEGACY_DRIVER_REGISTRY` binary-size macro, the one-shot affinity-miss diagnostic (#2456), and the driver-name rename callout (BITBANG -> BIT_BANG, FLEXIO -> FLEX_IO, OBJECTFLED -> OBJECT_FLED). Updated the registration example to the current 2-arg `addDriver(priority, driver)` signature; the name comes from `driver->getName()`. Expanded the Reference section to list the new headers (`bus.h`, `bus_traits.h`, `all_drivers.h`, `channel_typed.h`, `ichannel.h`) and to include `findDriverByName` / `clearAllDrivers` on `manager.h`. - Pass 2 (independent verification): fixed two real bugs the first pass left in place. (a) DMA wait-pattern snippet referenced a nonexistent `EngineState::READY` — corrected to `IChannelDriver::DriverState::READY`. (b) "Overriding Engine Selection" examples called a nonexistent `FastLED.setDriverPriority(...)` — the method lives only on `ChannelManager::setDriverPriority`; rewrote both call sites to `fl::ChannelManager::instance().setDriverPriority(...)` with an explanatory comment about the API asymmetry vs the `setDriverEnabled` / `setExclusiveDriver` helpers that DO have CFastLED forwarders. - Pass 3 (polish): added missing file-scope `CRGB leds[60];` declarations to two example snippets that referenced `leds` without anchoring it. Inserted an "alternatives, not a sequence" clarifier above the three Override Methods so a careful reader doesn't think calling all three in order is intended. Verified the `Bus::AUTO` story end-to-end: `FastLED.add<fl::Bus::AUTO>(cfg)` never appears as an example (the static_assert from #2451 rejects it); only `FastLED.add(cfg)` (implicit default via `ChannelConfigOf`) and `FastLED.add(fl::Bus::AUTO, cfg)` (runtime form, clears affinity) are shown. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Closes #2455. Follow-up to #2454 — when a runtime-selected driver isn't registered, give the user an actionable diagnostic instead of silently falling through to priority dispatch.
```cpp
// User forgets to enroll RMT:
FastLED.add(fl::Bus::RMT, cfg);
// On the first show(), one-shot:
// [ERROR] Channel 'Channel_3': Driver 'RMT' wasn't instantiated --
// call fl::enableDriversfl::Bus::RMT() (or fl::enableAllDrivers())
// before adding the channel. Defaulting to AUTO/priority dispatch.
// LEDs still light up via priority fallback. Subsequent shows are silent.
```
What changed
Diagnostic
Normalization
Per user request — get rid of the busName/getName divergence entirely. The C++ enumerator spelling is now the single source of truth:
No back-compat path because all of this code shipped within the past few PRs (#2451 / #2454 / #2448) — there is no caller in the wild relying on the old spellings.
Tests
Two new host-side cases in `tests/fl/channels/channel.cpp`:
Plus name updates in the three driver tests + `all_drivers.cpp` for the spelling normalization.
Test plan
Files changed (13)
Implementation:
Tests:
Related
🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests