Repository navigation
fix: stream ESP32-S3 LCD clockless chunks - #2703
Conversation
📝 WalkthroughWalkthroughThis PR makes FbuildDriver the default for AutoResearch builds (install_packages no longer calls PlatformIO), adds a staged build_dir/src/sketch fallback, switches the AutoResearch example filter from platform: to board:, and refactors the ESP32 LCD SPI stack to a worker-task driven multi-chunk DMA flow with queued transmits and pending-transfer tracking. ChangesAutoResearch Build System & Filter Updates
LCD SPI Worker-Task Chunked DMA Architecture
Sequence Diagram(s)sequenceDiagram
participant Task as Task/Poll
participant ISR as ISR\nisrChunkDone
participant Worker as Worker Task
participant Peripheral as LcdSpiPeripheral
Task->>Peripheral: submitChunk(0, true)\nqueueTransmit buffer
Peripheral->>Peripheral: mPendingTransmits++
Peripheral->>ISR: DMA complete interrupt
ISR->>ISR: mCompletedChunks++
alt more chunks remain
ISR->>Worker: notifyWorkerFromIsr()
Worker->>Peripheral: submitChunk(i, false)
Peripheral->>ISR: DMA complete
ISR->>Worker: notify for next chunk
else all chunks done
ISR->>ISR: mStreamComplete=true
end
Task->>Worker: processWorkerQueue()\nduring poll
Worker->>Task: submit remaining chunks
Task->>Task: poll(): stream complete +\nidle peripheral → ready
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 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)
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 |
6c0fca7 to
fa79f3f
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
ci/tests/test_sketch_filter.py (1)
731-763: ⚡ Quick winMove the new local imports to module scope.
These imports are deterministic test dependencies, so keeping them at the top of the file will match the repo's Python import rule and keep the new test class cleaner. As per coding guidelines, "All system imports must be at the top of the file in proper order: standard library, third-party, local".
🤖 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 `@ci/tests/test_sketch_filter.py` around lines 731 - 763, Move the deterministic test imports out of the test methods and place them at module scope: import get_example_ino_path from ci.compiler.board_example_utils and import create_board and should_skip_example_for_board from ci.boards/ci.compiler.board_example_utils at the top of the file; then remove the local imports inside test_autoresearch_filter_parsing, test_autoresearch_supported_boards_compile, and test_autoresearch_incompatible_boards_stay_filtered so those functions reference the module-level symbols instead.tests/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp (1)
214-215: ⚡ Quick winKeep an explicit
DRAININGassertion before the first completion.These updates now only check transmit counts after
show(). Ifpoll()regresses toREADYwhile the initially queued DMA transfers are still pending, all of these tests would still pass, which leaves the new pending-transmit contract under-covered. Add a pre-completion state check in each case.Suggested pattern
driver.show(); +FL_CHECK(driver.poll() == IChannelDriver::DriverState::DRAINING); FL_CHECK(mock.getTransmitCount() == 2); mock.simulateTransmitComplete();Also applies to: 233-244, 273-276, 387-394
🤖 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/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp` around lines 214 - 215, The tests only assert transmit counts after calling show() and completions, missing a pre-completion check that the channel has entered the DRAINING state; add an explicit assertion that poll() (or the channel/driver poll method used in these tests) returns/indicates DRAINING immediately after show() and before simulating the first completion so the pending-transmit contract is exercised — update the test locations that currently call show(), then later check mock.getTransmitCount() (the blocks around the current mock.getTransmitCount() assertions and usages at the other noted ranges) to insert a DRAINING-state assertion right after show() and before any completion simulation.
🤖 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/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp`:
- Around line 343-353: The code currently clears mIsrCtx and releases
mTransmittingChannels as soon as mIsrCtx.mStreamError is set, which can race
with an earlier queued DMA chunk still completing; change the branch in
channel_driver_lcd_clockless.cpp.hpp so we only clear state and release channels
once the peripheral is actually idle — i.e. require peripheralIdle for the error
path as well (replace the condition if ((streamDone && peripheralIdle) ||
mIsrCtx.mStreamError) with logic that requires peripheralIdle when
mIsrCtx.mStreamError is true, or alternatively track outstanding chunks (e.g.
mIsrCtx.mPendingChunks) and only clear mIsrCtx.mStreamError/mStreamComplete and
set mBusy=false after peripheral->isBusy() is false or pendingChunks == 0),
ensuring mIsrCtx.mStreamComplete/mStreamError are not reset until the last DMA
callback can no longer run.
In `@src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.h`:
- Around line 101-102: Replace the volatile fields with ISR-safe atomics and use
atomic operations everywhere they’re touched: change mPendingTransmits to
std::atomic<size_t> and mBusy to std::atomic<bool>, then update
transmitInternal(), waitTransmitDone(), isBusy() to use
.fetch_add(1)/.fetch_sub(1) and .load() (with appropriate memory_order or
defaults), and modify the ISR routine lcd_spi_flush_ready() to use .fetch_sub(1)
and .store(...) instead of plain reads/writes; this ensures
increments/decrements and reads are atomic across the ISR and task contexts and
prevents lost updates during panel IO recreation.
---
Nitpick comments:
In `@ci/tests/test_sketch_filter.py`:
- Around line 731-763: Move the deterministic test imports out of the test
methods and place them at module scope: import get_example_ino_path from
ci.compiler.board_example_utils and import create_board and
should_skip_example_for_board from ci.boards/ci.compiler.board_example_utils at
the top of the file; then remove the local imports inside
test_autoresearch_filter_parsing, test_autoresearch_supported_boards_compile,
and test_autoresearch_incompatible_boards_stay_filtered so those functions
reference the module-level symbols instead.
In `@tests/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp`:
- Around line 214-215: The tests only assert transmit counts after calling
show() and completions, missing a pre-completion check that the channel has
entered the DRAINING state; add an explicit assertion that poll() (or the
channel/driver poll method used in these tests) returns/indicates DRAINING
immediately after show() and before simulating the first completion so the
pending-transmit contract is exercised — update the test locations that
currently call show(), then later check mock.getTransmitCount() (the blocks
around the current mock.getTransmitCount() assertions and usages at the other
noted ranges) to insert a DRAINING-state assertion right after show() and before
any completion simulation.
🪄 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: c987a0ec-ea43-4cde-b002-090b5eddc762
📒 Files selected for processing (13)
ci/autoresearch/build_driver.pyci/autoresearch/phases.pyci/tests/test_autoresearch_phases.pyci/tests/test_fbuild_default_selection.pyci/tests/test_sketch_filter.pyexamples/AutoResearch/AutoResearch.inosrc/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hppsrc/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.hsrc/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_spi.cpp.hppsrc/platforms/esp/32/drivers/lcd_spi/ilcd_spi_peripheral.hsrc/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.cpp.hppsrc/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.htests/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp
| volatile bool mBusy; | ||
| volatile size_t mPendingTransmits; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify that mPendingTransmits/mBusy are touched from both ISR and task paths,
# and that those accesses are not protected by an ISR-safe critical section or atomic primitive.
rg -n -C2 'mPendingTransmits|mBusy' \
src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.h \
src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.cpp.hpp
rg -n -C2 'portENTER_CRITICAL|portEXIT_CRITICAL|portENTER_CRITICAL_ISR|portEXIT_CRITICAL_ISR|std::atomic|atomic_' \
src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.h \
src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.cpp.hppRepository: FastLED/FastLED
Length of output: 7407
Make mPendingTransmits/mBusy ISR-safe (don’t rely on volatile).
mPendingTransmits and mBusy are modified/consumed across ISR + task contexts: the ISR (lcd_spi_flush_ready() in src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.cpp.hpp) decrements mPendingTransmits and sets mBusy, while task code (transmitInternal(), waitTransmitDone(), and isBusy()) increments/reads the same members. The counter updates are plain read-modify-write (mPendingTransmits = mPendingTransmits +/- 1), and there’s no ISR-safe critical section/atomic primitive guarding these accesses—so an ISR preempting a task update can lose increments/decrements and leave the count wrong, breaking isBusy()/waitTransmitDone() and potentially bypassing the mPendingTransmits > 0 guard before esp_lcd_panel_io_del() during panel-IO recreation.
🤖 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/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.h` around lines
101 - 102, Replace the volatile fields with ISR-safe atomics and use atomic
operations everywhere they’re touched: change mPendingTransmits to
std::atomic<size_t> and mBusy to std::atomic<bool>, then update
transmitInternal(), waitTransmitDone(), isBusy() to use
.fetch_add(1)/.fetch_sub(1) and .load() (with appropriate memory_order or
defaults), and modify the ISR routine lcd_spi_flush_ready() to use .fetch_sub(1)
and .store(...) instead of plain reads/writes; this ensures
increments/decrements and reads are atomic across the ISR and task contexts and
prevents lost updates during panel IO recreation.
There was a problem hiding this comment.
Flagging for human review: ISR/task race on volatile mPendingTransmits/mBusy is real, but converting to std::atomic touches the singleton's IRAM-safe hot path and warrants a maintainer's call on memory_order and the broader recreation-during-IO scenario. Deferring per the address-reviews security-flag policy — not auto-fixing in this PR.
There was a problem hiding this comment.
@zackees, understood — the rationale is solid: std::atomic on IRAM-resident paths requires careful memory_order selection (likely memory_order_relaxed for the ISR decrement + memory_order_release/acquire for the task-side load, but that warrants deliberate review), and the panel-IO recreation guard interacts with it in a non-trivial way.
Would you like me to open a follow-up GitHub issue to track this so it doesn't get lost? I can file it with the relevant details (affected fields, affected methods, and the IRAM/atomic constraint) as a backlink to this PR and comment.
🧠 Learnings used
Learnt from: zackees
Repo: FastLED/FastLED PR: 0
File: :0-0
Timestamp: 2026-05-24T15:31:46.546Z
Learning: In the FastLED repository, the `running-process` dependency bump from 3.4.1 to 4.0.0 (PR `#2506`) is a Rust-side mono-crate consolidation only. The Python (`pip install running-process`) ABI is explicitly unchanged in the 4.0.0 CHANGELOG. All tests passed locally (6/6 and 27/27). The author of running-process is also the maintainer of this PR (zackees).
CodeRabbit flagged that queueTransmit() keeps up to two LCD transactions in flight, so a failed follow-up submission could leave an earlier chunk still completing asynchronously inside LcdSpiPeripheralEsp. The previous poll() branch released mIsrCtx and the transmitting channels as soon as mStreamError was set, allowing the trailing ISR callback to land on a torn-down or newly-started stream. Require peripheralIdle for both the streamDone and mStreamError paths so state is only cleared after the final DMA callback has run. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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 (1)
src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp (1)
349-367:⚠️ Potential issue | 🟠 Major | ⚡ Quick winKeep the errored stream in
DRAININGuntil the last queued DMA completes.This cleanup guard is correct, but the state machine still reopens too early because
processWorkerQueue()clearsmBusyon aqueueTransmit()failure before the already-queued chunk has finished.poll()then falls through toREADY, andshow()can overwritemTransmittingChannels/ resetmIsrCtxwhile the stale completion callback is still in flight.Suggested fix
diff --git a/src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp b/src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp @@ if (!submitChunk(submitted, false)) { ctx.mStreamError = true; ctx.mStreamComplete = true; - mBusy = false; break; }If you want extra belt-and-suspenders protection,
poll()can also returnDRAININGwhenevermTransmittingChannelsis still non-empty and cleanup has not executed yet.🤖 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/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp` around lines 349 - 367, The poll() path must keep the driver in DRAINING while any previously-queued DMA can still complete; update poll() so it returns DriverState::DRAINING not only when mBusy is true but also when mTransmittingChannels is non-empty or cleanup hasn’t run yet (i.e., when an errored stream may still have pending callbacks), so that show()/processWorkerQueue()/queueTransmit() cannot clear mIsrCtx or reset mTransmittingChannels prematurely; also ensure processWorkerQueue() does not clear mBusy on queueTransmit() failure (leave mBusy until the final DMA completion/cleanup sets it false) so the combined check in poll() (mBusy || !mTransmittingChannels.empty()) prevents reopening the stream.
🤖 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 `@src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp`:
- Around line 349-367: The poll() path must keep the driver in DRAINING while
any previously-queued DMA can still complete; update poll() so it returns
DriverState::DRAINING not only when mBusy is true but also when
mTransmittingChannels is non-empty or cleanup hasn’t run yet (i.e., when an
errored stream may still have pending callbacks), so that
show()/processWorkerQueue()/queueTransmit() cannot clear mIsrCtx or reset
mTransmittingChannels prematurely; also ensure processWorkerQueue() does not
clear mBusy on queueTransmit() failure (leave mBusy until the final DMA
completion/cleanup sets it false) so the combined check in poll() (mBusy ||
!mTransmittingChannels.empty()) prevents reopening the stream.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 2c02ac54-a827-4bf1-9b7a-e6546e9a444c
📒 Files selected for processing (1)
src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp
Summary
board:instead ofplatform:Tests
uv run python -m pytest ci/tests/test_autoresearch_phases.py ci/tests/test_fbuild_default_selection.py ci/tests/test_sketch_filter.py ci/tests/test_filter_examples.py -q(130 passed)bash test --cpp tests/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cppbash test --cpp tests/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_spi.cppgit diff --checkfirmware.bin/firmware.elfHardware Validation
Blocked before serial AutoResearch results: fbuild deploy hangs while writing ESP partitions after the bootloader write succeeds. Tracked upstream as FastLED/fbuild#379.
Closes #2690
Closes #2693
Summary by CodeRabbit
New Features
Improvements
Tests