Repository navigation
Description
Goal
Bring the classic-ESP32 RMT driver (src/platforms/esp/32/drivers/rmt/rmt_4/) in line with the canonical ChannelEngine + Peripheral API-object pattern that the rest of the channel-driver registry now uses. This is the last clockless-TX driver on esp32dev that pre-dates the #2428 channel-manager refactor and still carries Phase-3B stubs.
This is a refactor + completion task, not a feature add. No new Bus enum, no SPI mode. RMT stays clockless-only.
Survey of the current state
What's there today
src/platforms/esp/32/drivers/rmt/rmt_4/
├── channel_driver_rmt4.h -- IChannelDriver impl (mostly shaped)
├── channel_driver_rmt4.cpp.hpp -- has Phase-3B stubs
├── bus_traits.h -- BusTraits<Bus::RMT> + addDriver(priority=2)
├── idf4_clockless_rmt_esp32.h -- legacy ClocklessIdf4<PIN, TIMING> template
└── _build.cpp.hpp -- unity-build dispatcher
Feature flags (src/platforms/esp/32/feature_flags/enabled.h):
FASTLED_ESP32_HAS_RMT = SOC_RMT_SUPPORTEDFASTLED_RMT5 = 0on classic ESP32 → rmt_4 is the active impl
Legacy template path (addLeds<WS2812B, PIN>) → ClocklessIdf4<PIN, TIMING> → ODR-uses BusTraits<Bus::RMT>::instancePtr() directly (Phase 5c #2441 / #2450), bypassing ChannelManager. The legacy fast-path stays — this refactor only fixes the modern FastLED.add<>() / Channel::create<>() path.
Reference template
Use src/platforms/arm/teensy/teensy4_common/drivers/flexio/channel_engine_flexio.h as the shape model. RMT4 should mirror:
- Factory
create(...)returningshared_ptr<ChannelEngineRMT> - Abstract base + concrete impl split (header/cpp.hpp)
- Peripheral injected via constructor —
explicit ChannelEngineRMT(fl::shared_ptr<IRmtPeripheral>) enqueue()/poll()/show()state machine:READY → BUSY → DRAINING → READY- Clean
canHandle()vetting
Differences from FlexIO (so we don't blindly copy):
- RMT is not a parallel-IO peripheral, so the unified-clockless+SPI rule from
agents/docs/cpp-standards.mddoes not apply.Capabilitiesstays(true, false). - RMT uses ISR-driven double-buffer refill, not DMA completion. Keep that.
- TX and RX are separate peripherals (rmt_4 TX + rmt_rx RX). Don't merge — that's a separate future question.
Gap list
| # | Severity | Gap | Where |
|---|---|---|---|
| 1 | HIGH | acquireChannel() is a Phase-3B stub — allocates pool slots but never calls rmt_driver_install() or configures hardware. New-API channels can't actually transmit through the ChannelManager path. |
channel_driver_rmt4.cpp.hpp:172 |
| 2 | HIGH | fillNextBuffer() ISR-refill skeleton has placeholder memPtr and pixel iteration. No actual byte→symbol encoding wired up. |
same file, ISR section |
| 3 | MEDIUM | No IRmtPeripheral abstraction. Driver directly touches RMT.* register struct, soc/rmt_struct.h, and the inline spinlock. Tightly couples driver to silicon. |
channel_driver_rmt4.{h,cpp.hpp} |
| 4 | LOW | No unit tests for symbol-encoding math (makeZeroSymbol, makeOneSymbol, NS_TO_ESP_CYCLES, ESP_TO_RMT_CYCLES). WS2812B / SK6812 timing not verified post-refactor. |
tests/ |
| 5 | INFO | TX (rmt_4) and RX (rmt_rx) drivers are independent. Not a blocker — flag only. | — |
Plan
Phase 1 — Peripheral wrapper
Extract IRmtPeripheral (analogous to IUartPeripheral at src/platforms/esp/32/drivers/uart/iuart_peripheral.h). Surface:
class IRmtPeripheral {
public:
virtual ~IRmtPeripheral() = default;
virtual bool initialize(const RmtPeripheralConfig& cfg) = 0;
virtual void deinitialize() = 0;
virtual bool isInitialized() const = 0;
// Channel allocation (returns -1 on failure)
virtual int allocateChannel(int gpio_pin, uint32_t clk_div) = 0;
virtual void releaseChannel(int channel) = 0;
// Symbol-buffer access for ISR refill
virtual void writeSymbols(int channel, const rmt_item32_t* symbols, size_t count, size_t offset) = 0;
// ISR registration
virtual bool installIsr(rmt_isr_handler_t handler, void* arg) = 0;
virtual void startTransmission(int channel) = 0;
virtual void stopTransmission(int channel) = 0;
};Concrete RmtPeripheralEsp implements this against driver/rmt.h + the RMT.* register struct. Singleton lifetime via a RmtBusHolder struct (mirror UartBusHolder at src/platforms/esp/32/drivers/uart/bus_traits.h:30-37).
Phase 2 — Finish acquireChannel() and fillNextBuffer()
Replace the Phase-3B stubs with real hardware init. Reference the working RMT timing path from idf4_clockless_rmt_esp32.h (the legacy template) — that code already encodes WS2812-family symbols correctly. Lift its symbol-encode + refill logic into ChannelEngineRMT::fillNextBuffer() behind the new IRmtPeripheral surface.
Phase 3 — ChannelEngineRMT shape cleanup
Mirror ChannelEngineFlexIO:
create(fl::shared_ptr<IRmtPeripheral>)factoryenqueue(ChannelDataPtr)pushes tomEnqueuedChannelsshow()iterates, callsmPeripheral->startTransmission(), returnspoll()returnsDriverStatefrom peripheral statusgetCapabilities()returnsCapabilities(true, false)— no SPI (RMT isn't a parallel-IO peripheral, peragents/docs/cpp-standards.mdrule clarification)getName()returns"RMT"(matchesBus::RMTdispatch — must not change)
BusTraits<Bus::RMT> becomes:
struct RmtBusHolder {
fl::shared_ptr<RmtPeripheralEsp> peripheral;
fl::shared_ptr<ChannelEngineRMT> driver;
RmtBusHolder() FL_NO_EXCEPT
: peripheral(fl::make_shared<RmtPeripheralEsp>()),
driver(fl::make_shared<ChannelEngineRMT>(peripheral)) {}
};Priority stays at 2 (see src/fl/channels/bus_priorities.h) so RMT keeps the same dispatch ranking; no other drivers move.
Phase 4 — Tests
Add unit tests under tests/ for symbol-encoding math, independent of hardware:
makeZeroSymbol(timing)produces correctrmt_item32_tbit pattern for WS2812B/SK6812 T0H/T0LmakeOneSymbol(timing)likewise for T1H/T1L- Round-trip
NS_TO_ESP_CYCLES → ESP_TO_RMT_CYCLESfor the documented APB clock divisors
Phase 5 — Validation
bash compile esp32dev --examples AutoResearch— must still linkbash test --cpp— no regression- AutoResearch on the live WROOM (COM11) — RMT driver should still report
connected:trueon the user's GPIO 33↔34 jumper, identical to today bash autoresearchend-to-end on classic ESP32 — used to be blocked by AutoResearch on classic ESP32-WROOM: device boots + emits , but RPC ingest is silent (blocks #3446 follow-up) #3452 (now fixed in fix(autoresearch): use GPIO18/19 as default TX/RX on classic ESP32 (#3452) #3455), so this should run cleanly post-refactor
Out of scope
- RMT5 (S3/C3/C6/H2/P4) — separate driver, separate refactor if needed
- Merging TX (rmt_4) + RX (rmt_rx) into one
IRmtPeripheral— flagged in survey but not in this issue - Legacy
ClocklessIdf4<PIN, TIMING>template path — already optimized via Phase 5c (feat(channels): pre-bind legacy clockless to BusTraits singleton (Phase 5b of #2428) #2441/feat(channels): gate driver aggregator + pre-bind remaining legacy clockless (Phase 5c of #2428) #2450), don't disturb - Any Bus enum changes
- Any SPI mode work — RMT is not a parallel-IO peripheral; the
agents/docs/cpp-standards.mdunified-engine rule does not apply
Acceptance
-
IRmtPeripheralexists;ChannelEngineRMTtakes it via constructor -
acquireChannel()andfillNextBuffer()are no longer Phase-3B stubs -
bash compile esp32dev --examples AutoResearchpasses -
bash test --cpppasses (including new symbol-encoding unit tests) - Legacy
addLeds<WS2812B, PIN>path still works on classic ESP32 (no behavioral change there) - AutoResearch on the live WROOM board still reports the GPIO 33↔34 short
Survey source: code grep across src/platforms/esp/32/drivers/rmt/, src/fl/channels/, src/platforms/esp/32/drivers/uart/, src/platforms/arm/teensy/teensy4_common/drivers/flexio/, and src/platforms/esp/32/feature_flags/enabled.h. No prior issues filed for rmt_4 refactor (no hits for rmt_4 in agents/ or docs/). Last related work: #2441 / #2450 (Phase 5c pre-bind), #2247 / #2252 (ISR contention fixes, 2023).
Plan drafted with assistance from Claude Code.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
refactor(rmt4): extract IRMT4Peripheral lifecycle wrapper (#3458) (#3461
test(rmt4): Rmt4PeripheralMock + 22 host unit tests, no threads (#3462)…