Repository navigation
feat(rmt4): port RmtMemoryManager — WiFi-resistant TX + TX/RX ledger (#3469) - #3470
Conversation
#3469) Ports the RMT5 `RmtMemoryManager` accounting ledger + adaptive buffer-block strategy to the classic-ESP32 / IDF 4.x RMT driver, following the rmt_4/rmt_5 split precedent from #3461 and #3467. ## What's in - `rmt/rmt_4/rmt_memory_manager_4.h` - header-inline class body - `rmt/rmt_4/rmt_memory_manager_4.cpp.hpp` - platform-default singleton - `rmt/rmt_4/network_state_tracker_4.{h,cpp.hpp}` - v1 stub returning `false`. Follow-up PR wires this to the shared network detector once it's lifted out of the FASTLED_RMT5 guard. The manager tracks: - Global word-pool (512 words on classic ESP32, 256 on S2 — 8 or 4 channels × 64 words per block). - Per-channel allocations (TX or RX distinguished by `is_tx` flag). - `hasActiveRxChannels()` for TX-side coordination. - Adaptive `calculateMemoryBlocks(network_active)` that returns 3 when the network is active AND the pool has room for the extra 64-word block, else 2 (RMT4 historic default). ## What's out (deliberately) - No DMA accounting: RMT4 hardware has no DMA channel. The RMT5 manager's DMA slot ledger is not ported. - No dedicated TX/RX pools: RMT4 is always a global-pool platform. - Real network detection: `NetworkStateTracker4::isActive()` is a stub `return false` for v1. That means today's behaviour is bit-for-bit identical to pre-#3469 — the manager plumbing is in place, but the driver still allocates 2 mem blocks per TX channel. Follow-up PR flips the stub to poll the (shared) network detector. - No ISR-side refactor: the `PULSES_PER_FILL_RMT4` refill threshold stays fixed. Higher `mem_block_num` values in `rmt_config()` give the ISR more headroom before it misses its deadline; the reactive `checkTime` truncation in `fillNextBuffer` stays as a belt-and- braces safety net. ## Wiring - `ChannelEngineRMT4Impl::configureChannel`: calls the manager's free-then-tryAllocateTx idiom. Failure returns false; caller (acquireChannel) treats this the same as HW-channel-count-miss and defers the strip to the pending queue. Uses `calculateMemoryBlocks(network_active)` to fill in `Rmt4ChannelConfig::mMemBlocks`. - `ChannelEngineRMT4Impl::~ChannelEngineRMT4Impl`: releases every in-use channel's allocation. - `rmt_rx_4/RmtRxChannelImpl` constructor: pre-registers a 64-symbol RX reservation with channel-id `128 + (pin & 0x7F)` so TX (using raw 0..N-1 IDs) never collides. - `rmt_rx_4/RmtRxChannelImpl` destructor: releases the RX reservation. ## Tests 19 host `FL_TEST_CASE`s in `tests/platforms/esp/32/drivers/rmt/rmt_4/rmt_memory_manager_4.cpp`, covering: - pool starts empty - TX idle allocation = 128 words, network-active = 192 words - graceful demotion to 128 when 192 doesn't fit - pool-exhausted refusals - duplicate-alloc refusals - RX symbol-count recording, zero-symbol rejection - free() releases correctly; wrong is_tx and unknown-channel misses - free-then-realloc reconfigure idiom - hasActiveRxChannels tracks RX lifetime, ignores TX - calculateMemoryBlocks 2/3 selection + fallback when the extra block doesn't fit - reset() clears the ledger - 4 concurrent TX up to pool limit, 5th refused Local results: - `bash test rmt_memory_manager_4 --cpp --clean`: [doctest] test cases: 19 | 19 passed | 0 failed - `bash test --cpp`: 342/342 pass (no regression). - `clang-format --dry-run --Werror` clean on every touched file. The manager class body is header-inline on purpose so host tests build it directly without needing the ESP-IDF headers. Only the platform-default `instance()` singleton lives in the .cpp.hpp behind the usual `FL_IS_ESP32 && !FASTLED_RMT5` guard. `bash compile esp32dev` is still blocked on the pre-existing fbuild Windows spec-file backslash regression (`cc1plus: fatal error: C:Usersniteris.fbuild...`) that reproduces on plain master, so on-device WROOM validation of the network-active bump rides on that blocker as before. CI on Linux exercises the cross-compile. Closes #3469. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📝 WalkthroughWalkthroughAdds a ChangesRMT4 Memory Manager Port
Sequence Diagram(s)sequenceDiagram
participant ChannelDriverRMT4
participant NetworkStateTracker4
participant RmtMemoryManager4
participant Peripheral
ChannelDriverRMT4->>RmtMemoryManager4: free(prior TX allocation)
ChannelDriverRMT4->>NetworkStateTracker4: isActive()
ChannelDriverRMT4->>RmtMemoryManager4: tryAllocateTx(channel_id, network_active)
RmtMemoryManager4-->>ChannelDriverRMT4: out_words or refusal
ChannelDriverRMT4->>ChannelDriverRMT4: compute mem_blocks
ChannelDriverRMT4->>Peripheral: configure(mem_blocks)
Peripheral-->>ChannelDriverRMT4: success or failure
ChannelDriverRMT4->>RmtMemoryManager4: free(allocation) on failure
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related issues
Possibly related PRs
Poem
✨ 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 |
Summary
Ports the RMT5
RmtMemoryManageraccounting ledger + adaptive buffer-block strategy to the classic-ESP32 / IDF 4.x RMT driver. Follows thermt_4/rmt_5split precedent from #3461 and #3467.The manager:
hasActiveRxChannels()calculateMemoryBlocks(network_active)returning 3 (triple-buffer) when the network is active AND the pool has room for the extra 64-word block, else 2 (RMT4 historic default)Closes #3469.
What's out (deliberate)
NetworkStateTracker4::isActive()returnsfalsein v1. That means today's behaviour is bit-for-bit identical to pre-Port RmtMemoryManager to RMT4 — WiFi-resistant TX + central TX/RX ledger for classic ESP32 #3469 — the manager plumbing is in place, but TX still gets 2 mem blocks per channel. Follow-up PR flips the stub to poll a shared network detector.PULSES_PER_FILL_RMT4stays fixed. Highermem_block_numvalues inrmt_config()give the ISR more headroom before it misses its deadline; the reactivecheckTimetruncation infillNextBufferstays as a belt-and-braces safety net.Wiring
ChannelEngineRMT4Impl::configureChannel— free-then-tryAllocateTx idiom. Failure returnsfalse; the caller (acquireChannel) treats this the same as a HW-channel-count miss and defers the strip to the pending queue. UsescalculateMemoryBlocks(network_active)to fillRmt4ChannelConfig::mMemBlocks.ChannelEngineRMT4Impldestructor — releases every in-use channel's allocation.rmt_rx_4/RmtRxChannelImplconstructor — pre-registers a 64-symbol RX reservation with channel-id128 + (pin & 0x7F)so TX (raw 0..N-1 IDs) never collides.rmt_rx_4/RmtRxChannelImpldestructor — releases the RX reservation.Tests
19 host
FL_TEST_CASEs intests/platforms/esp/32/drivers/rmt/rmt_4/rmt_memory_manager_4.cppcover:free()releases correctly; wrongis_txand unknown-channel misseshasActiveRxChannels()tracks RX lifetime, ignores TXcalculateMemoryBlocks()2/3 selection + fallback when the extra block doesn't fitreset()clears the ledgerTest plan
bash test rmt_memory_manager_4 --cpp --clean— 19 / 19 pass on a fresh build.bash test --cpp— full host suite 342 / 342 pass (no regression).clang-format --dry-run --Werrorclean on every touched file.bash compile esp32dev --examples AutoResearch— blocked on the pre-existing fbuild Windows spec-file backslash regression that also reproduces on plain master. Not introduced by this PR. CI on Linux exercises the cross-compile.The manager class body is header-inline on purpose so host tests build it directly without needing the ESP-IDF headers. Only the platform-default
instance()singleton lives in the.cpp.hppbehind the usualFL_IS_ESP32 && !FASTLED_RMT5guard.Follow-ups called out in the file docblocks
NetworkStateTracker4::isActive()to a real detector once the RMT5NetworkDetectoris lifted out of its#if FASTLED_RMT5guard to a shared location.PULSES_PER_FILL_RMT4threshold to a per-channelstate->mem_blocks * 32computation so the ISR actually exploits the extra buffer headroom during network bursts. Requires ISR path touch — separate PR.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes
Tests