Repository navigation
Description
Goal
Bring classic ESP32 / esp32dev (IDF 4.x, FASTLED_RMT5 == 0) up to parity with the S3 / C3 / C6 / H2 / P4 family on RX capture. Today, FastLED.addRx(RxChannelConfig(pin, RxBackend::PLATFORM_DEFAULT)) on the classic ESP32 silently returns a DummyRxDevice because the RX channel factory only has an IDF 5.x implementation — every begin() / wait() / decode() is a no-op. AutoResearch loopback validation on the WROOM is therefore unsupported.
This issue backports a real IDF 4.x RMT RX implementation under the same RmtRxChannel interface, gated cleanly against the existing IDF 5.x impl using the same rmt_4 / rmt_5 split pattern that the TX driver already uses.
Survey of the current state
What's there today
src/platforms/esp/32/drivers/rmt_rx/
├── README.md
├── rmt_rx_channel.h -- public RmtRxChannel : public RxDevice interface
├── rmt_rx_channel.cpp.hpp -- impl: ~1620 lines under #if FASTLED_RMT5 + stub for !FASTLED_RMT5
└── _build.cpp.hpp -- unity-build dispatcher
The IDF 4.x branch at the bottom of rmt_rx_channel.cpp.hpp:1624-1639 is:
#else // !FASTLED_RMT5
namespace fl {
fl::shared_ptr<RmtRxChannel> RmtRxChannel::create(int pin) FL_NO_EXCEPT {
(void)pin;
FL_WARN_F("RmtRxChannel::create() requires RMT5 driver (ESP-IDF 5.0+). Returning nullptr.");
return nullptr;
}
} // namespace fl
#endifWhen nullptr is returned, RxDevice::create<RMT>(...) (in src/fl/channels/rx.cpp.hpp:96-98) wraps it as a DummyRxDevice("RMT RX channel creation failed") and every subsequent call is a no-op.
Reference pattern — what the TX driver does
For TX, the rmt_4 vs rmt_5 split is already correctly gated (src/platforms/esp/32/drivers/rmt/):
src/platforms/esp/32/drivers/rmt/
├── _build.cpp.hpp -- includes both sub-dirs unconditionally
├── rmt_4/
│ ├── _build.cpp.hpp
│ ├── channel_driver_rmt4.{h,cpp.hpp} -- gated by #if !FASTLED_RMT5
│ ├── irmt4_peripheral.h -- platform-agnostic header
│ ├── rmt4_peripheral_esp.{h,cpp.hpp} -- gated by #if !FASTLED_RMT5
│ ├── bus_traits.h -- gated by #if !FASTLED_RMT5
│ └── idf4_clockless_rmt_esp32.h -- legacy addLeds<> template path
└── rmt_5/
├── _build.cpp.hpp
├── channel_driver_rmt.{h,cpp.hpp} -- gated by #if FASTLED_RMT5
├── irmt5_peripheral.h
├── rmt5_peripheral_esp.{h,cpp.hpp} -- gated by #if FASTLED_RMT5
├── bus_traits.h -- gated by #if FASTLED_RMT5
└── idf5_clockless.h
Both sub-aggregator _build.cpp.hpp's are included unconditionally by the parent rmt/_build.cpp.hpp — exactly one compiles per build based on FASTLED_RMT5.
The RX backport follows this exact shape, one level deeper.
Plan
Phase 1 — Split the existing rmt_rx/ into rmt_rx/rmt_rx_5/
No semantic change. Just file movement so the directory layout matches the TX precedent:
src/platforms/esp/32/drivers/rmt_rx/
├── README.md -- stays
├── rmt_rx_channel.h -- public interface stays at root
├── _build.cpp.hpp -- now includes the two sub-aggregators
├── rmt_rx_5/
│ ├── _build.cpp.hpp
│ └── rmt_rx_channel_5.cpp.hpp -- the current ~1620-line IDF 5.x impl,
│ guarded by #if FASTLED_RMT5
└── rmt_rx_4/
├── _build.cpp.hpp
└── rmt_rx_channel_4.cpp.hpp -- NEW
The public class fl::RmtRxChannel stays in rmt_rx/rmt_rx_channel.h. Only the create() factory body and the supporting Impl definitions move into the _4/ or _5/ subdirectory.
The current IDF 4.x stub (return nullptr + FL_WARN_F) is removed — it is replaced by the new rmt_rx_4 impl.
Phase 2 — Implement RmtRxChannel against IDF 4.x driver/rmt.h
Concrete API used (all confirmed present in IDF 4.x legacy driver/rmt.h):
| Operation | IDF 4.x call | Notes |
|---|---|---|
| Channel configure | rmt_config(&cfg) with cfg.rmt_mode = RMT_MODE_RX and cfg.rx_config = { idle_threshold, filter_ticks_thresh, filter_en } |
Same rmt_config_t struct as TX, different union member. |
| Driver install (with ring buf) | rmt_driver_install(channel, rx_buf_size, intr_flags) |
rx_buf_size is non-zero for RX — IDF allocates the FreeRTOS ring buffer for us. |
| Get the ring buffer handle | rmt_get_ringbuf_handle(channel, &handle) |
FreeRTOS RingbufHandle_t. |
| Set the GPIO | rmt_set_gpio(channel, RMT_MODE_RX, gpio, invert=false) (IDF ≥ 4.4) or rmt_set_pin(channel, RMT_MODE_RX, gpio) (older 4.x) |
Mirror the same #if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4,4,0) fork the TX impl already uses. |
| Arm receiver | rmt_rx_start(channel, /*rx_idx_rst=*/true) |
|
| Pop symbols | xRingbufferReceive(handle, &item_size, ticks_to_wait) → rmt_item32_t* |
Then vRingbufferReturnItem(handle, raw) after copying. |
| Stop receiver | rmt_rx_stop(channel) |
|
| Teardown | rmt_driver_uninstall(channel) |
Channel allocation strategy: same as the IDF 5.x impl — request a single RX channel from the limited per-chip pool, fail with nullptr if exhausted. Reuse the TX path's channel-pool semantics for consistency.
No custom ISR. The TX path has a custom IRAM ISR because the RMT TX hardware has only ~64 symbols of buffer and needs ISR refill to drive >8 LEDs. RX has the opposite latency profile: the IDF ring buffer absorbs symbols at whatever rate the receiver fires, and the consumer thread (wait() / decode()) pops them at its own pace. Use the IDF-managed ringbuffer. This keeps the code small and side-steps the RMT.int_st.val IRAM ISR plumbing that the TX driver needs.
Phase 3 — Decode and timing shims
The public RmtRxChannel::decode(timing, out) and wait(timeout_ms) semantics are already defined in rmt_rx_channel.h and do not change. The IDF 4.x impl reuses the same ChipsetTiming4Phase math and the same edge-detection convention (first-edge skip, start_low orientation). All of that lives above the IDF layer and is shared.
Phase 4 — Feature-flag gating
The mutually-exclusive guard is exactly the TX precedent:
// rmt_rx_4/rmt_rx_channel_4.cpp.hpp
#if FL_IS_ESP32 && FASTLED_ESP32_HAS_RMT && !FASTLED_ESP32_RMT5_ONLY_PLATFORM && !FASTLED_RMT5
// IDF 4.x impl
#endif// rmt_rx_5/rmt_rx_channel_5.cpp.hpp
#if FL_IS_ESP32 && FASTLED_ESP32_HAS_RMT && FASTLED_RMT5
// IDF 5.x impl (existing code, unchanged semantics)
#endifExactly one definition of RmtRxChannel::create(int) links. Platforms with no RMT at all (ESP32-C2) compile neither. RMT5-only platforms (C6 / H2 / P4 / C5) compile only the _5 path. Classic ESP32 / S2 with IDF 4.x compile only the _4 path.
Phase 5 — Tests + validation
- Host build must still link cleanly (the mock path for RX is a separate question — out of scope for this issue, mirrors the TX mock follow-up Add Rmt4PeripheralMock + unit tests (no threads) — follow-up to #3458 #3462).
bash compile esp32dev --examples AutoResearchmust succeed.- Live WROOM on COM11 with the GPIO 33↔34 jumper:
bash autoresearchshould now capture and decode actual WS2812B waveforms instead of getting aDummyRxDeviceno-op. - Existing RMT5 RX path on S3 / C3 / C6 / H2 / P4 must be unchanged — same source, same emitted binary (the
_5directory is justgit mvof the existing impl).
Files changed (final shape)
src/platforms/esp/32/drivers/rmt_rx/
├── README.md -- updated (note the 4/5 split)
├── rmt_rx_channel.h -- unchanged
├── _build.cpp.hpp -- includes both sub-aggregators
├── rmt_rx_5/
│ ├── _build.cpp.hpp -- NEW, mirrors rmt_4 sub-aggregator
│ └── rmt_rx_channel_5.cpp.hpp -- git mv'd from old rmt_rx_channel.cpp.hpp
│ (IDF 5.x impl, semantics unchanged)
└── rmt_rx_4/
├── _build.cpp.hpp -- NEW
└── rmt_rx_channel_4.cpp.hpp -- NEW, the actual IDF 4.x impl
The IDF-4.x stub at the bottom of the original rmt_rx_channel.cpp.hpp is deleted.
Out of scope
IRmtRxPeripheralvirtual wrapper + host mock. That mirrors what Refactor classic-ESP32 RMT (rmt_4) into the ChannelEngine + Peripheral API-object pattern #3458 / Add Rmt4PeripheralMock + unit tests (no threads) — follow-up to #3458 #3462 did for TX; it's the right next step but not in this PR. RX impl-first, then refactor for testability, same order as TX.- GPIO-ISR RX fallback. The
gpio_isr_rx/directory has a partial skeleton today, gated onFASTLED_RMT5 && SOC_MCPWM_SUPPORTED. Loosening the MCPWM dependency to unblock it on classic ESP32 is a separate, more invasive change — out of scope here. - Bus enum / channel manager changes. RX flows through
RxDevice, notBus; the channel-manager /BusTraitsplumbing is untouched. - API changes. The public
RmtRxChannel::create(int),begin(config),wait(timeout_ms),finished(),decode(timing, out)surface stays bit-for-bit identical. Existing callers (AutoResearch, future user code) require no source change.
Acceptance
-
src/platforms/esp/32/drivers/rmt_rx/rmt_rx_5/exists and contains the unchanged IDF 5.x impl (verified by git history). -
src/platforms/esp/32/drivers/rmt_rx/rmt_rx_4/rmt_rx_channel_4.cpp.hppimplements the fullRmtRxChannelinterface against IDF 4.xdriver/rmt.h. -
RxBackend::PLATFORM_DEFAULTon classic ESP32 returns a realRmtRxChannel(not aDummyRxDevice). -
bash compile esp32dev --examples AutoResearchsucceeds. -
bash test --cpp— host suite stays at 340 / 340. - WROOM live:
bash autoresearchagainst the GPIO 33↔34 jumper successfully decodes a WS2812B / SK6812 transmission. - RMT5 RX path on S3 / C3 / C6 / H2 / P4 emits identical code (no regression in unit tests / device tests).
Plan drafted with assistance from Claude Code.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat(rmt_rx): backport RmtRxChannel to IDF 4.x (#3465) (#3467)