Skip to content

fix(esp32-s3): LCD_CLOCKLESS chunk-ISR IRAM/ISR-safety + equal-chunk (#2647 WIP) - #2648

Merged
zackees merged 4 commits into
masterfrom
fix/lcd-clockless-isr-iram-2026-05-30
May 31, 2026
Merged

zackees merged 4 commits into
masterfrom
fix/lcd-clockless-isr-iram-2026-05-30

Conversation

@zackees

@zackees zackees commented May 31, 2026 •

Copy link
Copy Markdown
Member

Summary

Defense-in-depth fixes plus a chunk-sizing workaround for the LCD_CLOCKLESS ISR-driven chunked DMA path discussed in #2647. With this PR the typical-frame case (RGB frames that fit in a single DMA chunk) now passes the autoresearch RX-loopback matrix on a XIAO ESP32-S3; the multi-chunk corruption (chunks 2..N of an ISR-driven stream) is tracked separately as a #2647 follow-up.

Commits

  • 7bfb1bb53f — fix(esp32-s3): make LCD_CLOCKLESS chunk-ISR path IRAM/ISR-safe
    • Mark isrChunkDone, encodeChunk, LcdSpiPeripheralEsp::transmit, and the EspWrapper::transmit thunk FL_IRAM (matches the PARLIO workerIsrCallback convention).
    • Route LcdSpiPeripheralEsp::transmit's completion-semaphore take through xSemaphoreTakeFromISR when xPortInIsrContext(), keeping the existing 2 s blocking take on the task path.
    • Bump runSingleTest's laneSizes upper bound 8 → 16 so autoresearch can exercise the full LCD_CAM 16-bit bus.
  • 821fd8919a — fix(esp32-s3): force LCD_CLOCKLESS chunks to equal DMA size
    • Pick numChunks so maxSize / numChunks is exact, preventing the variable-size last chunk that forces an ISR-time esp_lcd_panel_io_del + esp_lcd_new_panel_io_i80 round-trip.
  • eb59d1b491 — fix(esp32-s3): bump LCD I80 trans_queue_depth 1 → 2 (#2647 IWDT fix)
    • With trans_queue_depth=1 the ISR-driven re-arm in isrChunkDone blocked waiting for a free queue slot — from ISR context — and tripped the 300 ms watchdog. Depth = 2 leaves room for the re-arm.
  • 8d791ad125 — fix(esp32-s3): default LCD_CLOCKLESS chunk to 1024 B (workaround for #2647 corruption)
    • Bump kDefaultChunkInputBytes 90 → 1024 so a typical RGB frame (≤ 341 LEDs/lane) fits in one DMA chunk and the still-broken ISR re-arm path is never exercised. Worst-case ring-buffer PSRAM for 16-lane wave8: 1024 × 128 × 3 = 384 KB (XIAO ESP32-S3 has 8 MB PSRAM).

Status

  • Builds clean for esp32s3; CI green for all configured platforms.
  • Hardware-verified on Seeed XIAO ESP32-S3 (GPIO 1 → GPIO 2 jumper):
    bash autoresearch esp32s3 --lcd --upload-port COM<x> --lanes 16 --strip-sizes 256 --skip-lint
    TEST LCD_CLOCKLESS lanes=16 leds=4096 PASS 1694ms
    Tests: 4/4 passed
    
  • Known limitation (tracked as a ESP32-S3 LCD_CLOCKLESS: interrupt watchdog timeout in ISR context with 8+ lanes × 256 LEDs WS2812 #2647 follow-up): the chunked-streaming ISR re-arm path still emits 87–92 % corrupted bytes for chunks 2..N when a frame is split across multiple DMA chunks. The 1024 B default keeps typical RGB frames inside a single chunk; users running very long strips on many lanes that would force multi-chunk streaming should track that follow-up rather than relying on this driver path.

Test plan

  • Hardware: bash autoresearch esp32s3 --lcd --upload-port COM<x> --lanes 16 --strip-sizes 256 --skip-lint completes with TEST_COMPLETED_EXIT_OK — verified.
  • Host: tests/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp mocks keep passing (CI: unit tests linux ✓).
  • No regression in --lanes 1..8 --strip-sizes 100,300 (smaller, previously-tested matrix) — recommended sanity check; not run in this PR but the kDefaultChunkInputBytes bump to 1024 only enlarges the single-chunk regime, so smaller frames remain in single-chunk mode and should be unaffected.

🤖 Generated with Claude Code

zackees and others added 2 commits May 30, 2026 19:40
LCD_CLOCKLESS uses an ISR-driven 3-buffer ring (see issue #2258) where
on_color_trans_done re-encodes and re-arms the next DMA chunk inside
the interrupt callback. The original implementation had two latent
bugs that would deadlock the chip under flash-cache pressure:

1. ISR path lived in flash. isrChunkDone, encodeChunk, and
   LcdSpiPeripheralEsp::transmit (plus the EspWrapper thunk) were all
   compiled into the default .text section. When any concurrent flash
   operation suspended the cache (NVS commit, esp_flash_erase_region,
   etc.), the ISR could not fetch its own code, interrupts stayed
   masked past the 300 ms IWDT window, and the device panicked with
   "Interrupt wdt timeout on CPU1" in ISR context with PC inside
   spi_flash_chip_generic_erase_block.

   Fix: mark every function on the ISR re-arm path FL_IRAM (matches the
   PARLIO worker-ISR convention).

2. transmit() called the regular xSemaphoreTake from ISR context.
   lcd_spi_flush_ready already did xSemaphoreGiveFromISR before
   invoking the user callback so the take was guaranteed non-blocking,
   but xSemaphoreTake (not the FromISR variant) asserts when invoked
   from an interrupt — undefined behavior in release builds, panic
   in debug.

   Fix: route through xSemaphoreTakeFromISR when xPortInIsrContext()
   returns true; keep the existing 2 s blocking take on the task path.

Test infrastructure: bump runSingleTest laneSizes upper bound from 8
to 16 so autoresearch can exercise LCD_CAM's full 16-bit parallel bus
(matching the wave8Transpose_16 path the driver already supports).

Repro before the fix:
  bash autoresearch esp32s3 --lcd --lanes 16 --strip-sizes 256
  → Guru Meditation Error: Interrupt wdt timeout on CPU1
  → PC inside spi_flash_chip_generic_erase_block, ISR context

Co-Authored-By: Claude Opus 4.7 <[email protected]>
LcdSpiPeripheralEsp::transmit() tears down and recreates the ESP-IDF
panel_io handle whenever the transaction size changes — its GDMA
descriptor chain is sized per transaction. The teardown calls
esp_lcd_panel_io_del, which lives in flash; performing it from
isrChunkDone (ISR context) deadlocks the chip with "Interrupt wdt
timeout on CPU1" if any concurrent flash op has suspended the cache.

Round numChunks up from ceil(maxSize / requested) until it evenly
divides maxSize so every ISR-driven transmit uses the same DMA byte
count and the panel_io recreate path is never taken from ISR.

For typical RGB LED counts (n × 3 bytes per pixel) this terminates in
a couple of iterations: e.g. 16 lanes × 256 LEDs (maxSize=768) with
requested=90 → numChunks walks 9→10→11→12, settles on 12 × 64 input
bytes (8192 DMA bytes per chunk).

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@coderabbitai

coderabbitai Bot commented May 31, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR hardens the ESP32 LCD driver stack against ISR and flash-cache suspension failures by adding IRAM safety annotations to critical DMA and completion handlers, implementing ISR-aware semaphore logic in the transmit path, increasing the default chunk size to 1024 bytes, and refactoring chunk calculation to ensure exact divisor boundaries. A separate change extends AutoResearch lane validation to 16 lanes.

Changes

AutoResearch Lane Count Extension

Layer / File(s) Summary
Lane count validation increase
examples/AutoResearch/AutoResearchRemote.cpp
The runSingleTestImpl validation for laneSizes is updated to permit up to 16 lanes (instead of 8) and adjusts the InvalidLaneCount error message accordingly.

ESP32 LCD Driver ISR/IRAM Hardening

Layer / File(s) Summary
Headers and constants: IRAM markers and chunk sizing
src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.h, src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.h
Header files declare the increased default chunk size (kDefaultChunkInputBytes from 90 to 1024 bytes), mark critical ISR-linked methods encodeChunk() and isrChunkDone() with FL_IRAM, update the LcdSpiPeripheralEsp::transmit() method signature with FL_IRAM, reorder includes to place compiler_control.h before noexcept.h, and add inline documentation emphasizing IRAM residency requirements during ISR-context re-arming.
Chunk calculation and queue depth adjustment
src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp, src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.cpp.hpp
The beginTransmission() chunk-sizing calculation is refactored to compute numChunks so that chunkInputBytes becomes an exact divisor of maxSize, eliminating remainder-induced splits and adding bounds handling. The I80 panel IO trans_queue_depth is increased from 1 to 2 to prevent blocking when isrChunkDone() re-arms from the on_color_trans_done callback.
ISR-aware DMA completion synchronization
src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.cpp.hpp
The LcdSpiPeripheralEsp::transmit() method is annotated FL_IRAM and uses xPortInIsrContext() to select ISR-safe xSemaphoreTakeFromISR() with portYIELD_FROM_ISR() (ISR context) or timed xSemaphoreTake() with a 2000ms timeout (task context). On failure, it clears mBusy and returns false.
IRAM-resident DMA and ISR completion handlers
src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp
The encodeChunk() method and isrChunkDone() completion handler are marked FL_IRAM with documentation emphasizing execution from IRAM when invoked during ISR context and flash-cache suspension. The embedded EspWrapper::transmit() override inside the peripheral factory is also annotated FL_IRAM with comments clarifying that IRAM coverage must include the vtable-dispatched thunk entry point.

Sequence Diagram

sequenceDiagram
  participant Caller
  participant LcdSpiPeripheralEsp
  participant RTOS as FreeRTOS
  Caller->>LcdSpiPeripheralEsp: transmit(buffer, size)
  LcdSpiPeripheralEsp->>RTOS: xPortInIsrContext()
  alt ISR Context
    RTOS-->>LcdSpiPeripheralEsp: true
    LcdSpiPeripheralEsp->>RTOS: xSemaphoreTakeFromISR()
    RTOS->>RTOS: portYIELD_FROM_ISR()
  else Task Context
    RTOS-->>LcdSpiPeripheralEsp: false
    LcdSpiPeripheralEsp->>RTOS: xSemaphoreTake(2000ms)
  end
  alt Semaphore Available
    RTOS-->>LcdSpiPeripheralEsp: acquired
    LcdSpiPeripheralEsp-->>Caller: transmit DMA
  else Timeout/Fail
    LcdSpiPeripheralEsp->>LcdSpiPeripheralEsp: clear mBusy
    LcdSpiPeripheralEsp-->>Caller: false
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • FastLED/FastLED#2647: Directly addresses the same ISR/IRAM, semaphore-from-ISR, chunk-size re-arm, and laneSizes problems reported in that issue, targeting the exact same functions and classes.
  • FastLED/FastLED#2270: Related through modifications to the ESP I80 LCD driver stack (ChannelDriverLcdClockless and LcdSpiPeripheralEsp), including ISR/IRAM annotations and transmit/semaphore handling that address the singleton-driven transmit/ISR code paths described in that issue.

Possibly related PRs

  • FastLED/FastLED#2251: Modifies the ESP32 LcdSpiPeripheralEsp::transmit() path in lcd_spi_peripheral_esp.cpp.hpp around DMA-completion and semaphore handling with ISR-context behavior, directly related to this PR's transmit synchronization changes.
  • FastLED/FastLED#2273: Modifies the ESP32-S3 LCD_CLOCKLESS stack including ChannelDriverLcdClockless::beginTransmission(), directly related to this PR's IRAM/chunking fixes.

Poem

🐰 A chunky hop through IRAM's lane,
Where ISR dances without pain,
Sixteen lanes now lead the way,
No watchdog barks on this fine day!
Flash cache sleeps while drivers gleam, ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 69.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(esp32-s3): LCD_CLOCKLESS chunk-ISR IRAM/ISR-safety + equal-chunk (#2647 WIP)' accurately reflects the main changes: marking ISR functions as IRAM, making ISR operations safe, implementing equal-chunk sizing, and fixing LCD_CLOCKLESS on ESP32-S3.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/lcd-clockless-isr-iram-2026-05-30

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

zackees and others added 2 commits May 30, 2026 20:20
ChannelDriverLcdClockless::isrChunkDone calls back into
esp_lcd_panel_io_tx_color() from the on_color_trans_done callback to
re-arm the next chunk in the ring. With trans_queue_depth=1 the
currently-running transaction has not yet been retired from the I80
queue when the user callback fires, so the re-arm blocks waiting for
a free queue slot — from ISR context — and trips the 300 ms interrupt
watchdog.

Bumping the depth to 2 leaves room for the ISR-driven re-arm and
eliminates the "Guru Meditation Error: Interrupt wdt timeout on CPU1"
panic at every multi-chunk LCD_CLOCKLESS frame size (verified on
16 lanes × 256 LEDs WS2812B-V5 on XIAO ESP32-S3).

Caveat: with this fix the device stays alive but ISR-driven chunks
2..N still emit garbled data on the wire (87.5–91.8 % byte corruption
in RMT-RX loopback validation). The first chunk — encoded and submitted
from task context in beginTransmission() — is correct. Tracking the
correctness issue as a follow-up on #2647; this commit just gets the
chip past the IWDT panic so the correctness work can proceed.

Co-Authored-By: Claude Opus 4.7 <[email protected]>
…2647 corruption)

Bump kDefaultChunkInputBytes 90 → 1024 so a typical RGB frame fits in
one DMA chunk and the ISR re-arm path is not exercised.

Background. The ISR-driven re-arm path in
ChannelDriverLcdClockless::isrChunkDone currently emits garbled data
for chunks 2..N — only the first chunk (encoded + submitted from
beginTransmission() in task context) lands correctly on the wire. The
defense-in-depth fixes earlier in this PR (FL_IRAM on the ISR path,
xSemaphoreTakeFromISR, trans_queue_depth=2, equal-chunk sizing) all
prevent the IWDT panic that previously occurred, but the multi-chunk
output is still 87–92 % corrupted in RX-loopback validation. The
correctness fix for multi-chunk streaming is tracked separately.

This change makes 16 lanes × 256 LEDs WS2812B-V5 actually work on
hardware today by selecting a chunk size that fits a 768-byte/lane
frame in a single transaction. Worst-case PSRAM for 16-lane wave8 with
1024-byte chunks: 1024 × 128 × 3 ring buffers = 384 KB (XIAO ESP32-S3
has 8 MB PSRAM, plenty).

Verified on hardware (Seeed XIAO ESP32-S3, GPIO 1 → GPIO 2 jumper):
  bash autoresearch esp32s3 --lcd --upload-port COM13 \
      --lanes 16 --strip-sizes 256 --skip-lint
  TEST LCD_CLOCKLESS lanes=16 leds=4096 PASS 1694ms
  Tests: 4/4 passed

Co-Authored-By: Claude Opus 4.7 <[email protected]>
@zackees
zackees marked this pull request as ready for review May 31, 2026 13:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.h (1)

98-101: ⚡ Quick win

Use text-only warning prefixes in these comments.

⚠️ is now present in C++ source comments. Please switch those to a text prefix like WARNING: to match repo style.

As per coding guidelines, "Avoid emoticons and emoji characters in C++ source files - use text-based prefixes instead"

Also applies to: 113-118

🤖 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.h` around
lines 98 - 101, Replace the emoji warning prefixes in the hot-path comment
blocks with a text-only prefix: change the leading "⚠️" to "WARNING:" in the
ISR/IRAM comment that mentions IRAM, FL_IRAM and the interrupt watchdog (the
comment immediately above the hot-path/ISR note) and do the same for the similar
comment later (the block that spans the second occurrence around the FL_IRAM/ISR
explanation). Keep the rest of the wording intact (retain references to IRAM,
FL_IRAM, ISR context, flash cache suspension, and interrupt watchdog) but use
"WARNING:" as the prefix to comply with coding guidelines.
🤖 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 `@examples/AutoResearch/AutoResearchRemote.cpp`:
- Around line 162-165: The remote's laneSizes upper bound change to 16 is
inconsistent with firmware validation (src/fl/channels/validation.cpp.hpp which
enforces max 8), unit tests (tests/fl/channels/validation.cpp), docs
(AutoResearchTest.h), and CI (ci/autoresearch/phases.py); either revert the
change in AutoResearchRemote.cpp (reset the laneSizes upper bound to 8 in the
validation block that sets "InvalidLaneCount") or update the firmware validation
function in validation.cpp.hpp, the unit test expectations in
tests/fl/channels/validation.cpp, the documentation in AutoResearchTest.h, and
the CI phase limits in ci/autoresearch/phases.py to accept up to 16 lanes so the
contract matches end-to-end.

In `@src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp`:
- Around line 369-385: The current loop increases numChunks until maxSize %
numChunks == 0 which can shrink chunkInputBytes unnecessarily; instead compute
chunkInputBytes by rounding up so we don't force many small chunks. Replace the
divisor-seeking loop logic around numChunks/chunkInputBytes: keep the initial
numChunks = ceil(maxSize / requestedChunkInputBytes), then set chunkInputBytes =
ceil_div(maxSize, numChunks) (i.e. (maxSize + numChunks - 1) / numChunks) and do
not increment numChunks to force an exact divisor; fall back to chunkInputBytes
= maxSize only if that computed chunkInputBytes is 0. Reference variables:
numChunks, chunkInputBytes, maxSize, requestedChunkInputBytes.

---

Nitpick comments:
In `@src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.h`:
- Around line 98-101: Replace the emoji warning prefixes in the hot-path comment
blocks with a text-only prefix: change the leading "⚠️" to "WARNING:" in the
ISR/IRAM comment that mentions IRAM, FL_IRAM and the interrupt watchdog (the
comment immediately above the hot-path/ISR note) and do the same for the similar
comment later (the block that spans the second occurrence around the FL_IRAM/ISR
explanation). Keep the rest of the wording intact (retain references to IRAM,
FL_IRAM, ISR context, flash cache suspension, and interrupt watchdog) but use
"WARNING:" as the prefix to comply with coding guidelines.
🪄 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: ad9af0bc-e53f-41f7-b422-4c05d60e4a79

📥 Commits

Reviewing files that changed from the base of the PR and between 25e444c and 8d791ad.

📒 Files selected for processing (5)
  • examples/AutoResearch/AutoResearchRemote.cpp
  • src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.cpp.hpp
  • src/platforms/esp/32/drivers/lcd_spi/channel_driver_lcd_clockless.h
  • src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.cpp.hpp
  • src/platforms/esp/32/drivers/lcd_spi/lcd_spi_peripheral_esp.h

Comment on lines +162 to +165
if (lane_sizes_json.size() == 0 || lane_sizes_json.size() > 16) {
response.set("success", false);
response.set("error", "InvalidLaneCount");
response.set("message", "laneSizes must have 1-8 elements");
response.set("message", "laneSizes must have 1-16 elements");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Contract mismatch: remote accepts 1–16 lanes, but firmware rejects > 8.

The remote now validates laneSizes with an upper bound of 16, but the firmware-side validation in src/fl/channels/validation.cpp.hpp still rejects lane_sizes.size() > 8 with error "Lane count cannot exceed 8" (context snippet 1). This creates a broken contract: RPC calls with 9–16 lanes will pass remote validation but fail at the firmware layer with a confusing error message.

Additional mismatches:

  • Unit test in tests/fl/channels/validation.cpp explicitly expects failure at 9 lanes (context snippet 2).
  • Documentation in AutoResearchTest.h still describes lane count as 1-8 (context snippet 3).
  • CI script ci/autoresearch/phases.py hard-limits --lane-counts to 1-8 and cannot generate 9–16 lane test cases (context snippet 4).

Either revert this change until the full stack (firmware validation, tests, docs, CI) supports 16 lanes, or ensure those layers are updated in the same PR to maintain contract consistency.

🤖 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 162 - 165, The
remote's laneSizes upper bound change to 16 is inconsistent with firmware
validation (src/fl/channels/validation.cpp.hpp which enforces max 8), unit tests
(tests/fl/channels/validation.cpp), docs (AutoResearchTest.h), and CI
(ci/autoresearch/phases.py); either revert the change in AutoResearchRemote.cpp
(reset the laneSizes upper bound to 8 in the validation block that sets
"InvalidLaneCount") or update the firmware validation function in
validation.cpp.hpp, the unit test expectations in
tests/fl/channels/validation.cpp, the documentation in AutoResearchTest.h, and
the CI phase limits in ci/autoresearch/phases.py to accept up to 16 lanes so the
contract matches end-to-end.

Comment on lines +369 to 385
// Pick numChunks so chunkInputBytes = maxSize / numChunks is exact (the
// remainder must be 0). Walk numChunks upward from
// ceil(maxSize / requested) until we hit a divisor; in the worst case we
// fall back to numChunks = maxSize (single-byte chunks). For typical LED
// counts (powers of two × 3 bytes per RGB pixel) the loop terminates in
// a couple of iterations.
size_t numChunks =
(maxSize + requestedChunkInputBytes - 1) / requestedChunkInputBytes;
if (numChunks == 0) {
numChunks = 1;
}
while (numChunks < maxSize && (maxSize % numChunks) != 0) {
++numChunks;
}
size_t chunkInputBytes = maxSize / numChunks;
if (chunkInputBytes == 0) {
chunkInputBytes = maxSize;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Round chunkInputBytes up instead of shrinking it via numChunks.

This loop can collapse a near-1024-byte request into many small ISR-driven chunks. For example, maxSize = 1025 yields 5 chunks of 205 bytes, even though a single 1025-byte chunk would satisfy the equal-size requirement. That defeats the fallback meant to avoid the ISR re-arm path and raises interrupt load on awkward frame sizes.

Possible fix
-    size_t numChunks =
-        (maxSize + requestedChunkInputBytes - 1) / requestedChunkInputBytes;
-    if (numChunks == 0) {
-        numChunks = 1;
-    }
-    while (numChunks < maxSize && (maxSize % numChunks) != 0) {
-        ++numChunks;
-    }
-    size_t chunkInputBytes = maxSize / numChunks;
-    if (chunkInputBytes == 0) {
-        chunkInputBytes = maxSize;
-    }
+    size_t chunkInputBytes = requestedChunkInputBytes;
+    while (chunkInputBytes < maxSize &&
+           (maxSize % chunkInputBytes) != 0) {
+        ++chunkInputBytes;
+    }
🤖 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 369 - 385, The current loop increases numChunks until maxSize %
numChunks == 0 which can shrink chunkInputBytes unnecessarily; instead compute
chunkInputBytes by rounding up so we don't force many small chunks. Replace the
divisor-seeking loop logic around numChunks/chunkInputBytes: keep the initial
numChunks = ceil(maxSize / requestedChunkInputBytes), then set chunkInputBytes =
ceil_div(maxSize, numChunks) (i.e. (maxSize + numChunks - 1) / numChunks) and do
not increment numChunks to force an exact divisor; fall back to chunkInputBytes
= maxSize only if that computed chunkInputBytes is 0. Reference variables:
numChunks, chunkInputBytes, maxSize, requestedChunkInputBytes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant