Skip to main content

Module rmt

Module rmt 

Source
Expand description

RMT channels, handed out one consumer at a time.

Two on-board peripherals are driven by the RMT: the DS18B20 1-Wire bus (driver::ds18b20, one TX + one RX channel) and the SK6812 light bars on the M5GO Battery Bottom (driver::sk6812, one TX channel). Both drivers used to take RMT<'static> by value and both configured channel 0, so an application could have temperature sensing or light bars and not both — on hardware whose RMT has eight channels.

This splits the peripheral once and names which channel each consumer gets, so the conflict is resolved where the board knows the answer rather than in every application. esp-hal supports exactly this: a ChannelCreator taken out of the Rmt keeps the peripheral initialised even after the Rmt itself is dropped.

Channel assignment is per chip, because neither RX capability nor channel RAM is uniform:

1-Wire TX1-Wire RXLEDs TXLED blocks
fire27 (ESP32)0244 (256 codes)
cores3 (ESP32-S3)0413 (144 codes)

On the ESP32 every channel can transmit and receive; on the ESP32-S3 channels 0-3 are TX-only and 4-7 RX-only, which is why the RX channel differs. The 1-Wire pair keeps the channels it always used, so that driver’s timing behaviour is unchanged.

§Why the LED channel claims several blocks

An SK6812 frame is one pulse code per bit, so ten LEDs are 242 codes while one RMT block holds 64 (ESP32) or 48 (S3). A frame longer than the channel’s RAM is refilled by the CPU from the threshold interrupt mid-transmission, every ~40 µs — and this firmware has LVGL, BLE and SPI DMA competing for that latency. A late refill clocks out whatever is still in the block, which an SK6812 reads as colour: the strip shows a gradient down its length rather than failing.

The RMT’s block RAM is inside the peripheral (ESP32: 8 x 64 codes, S3: 4 TX + 4 RX x 48), so these blocks cost no DRAM and nothing but channels that are already unused. Four blocks hold a whole ten-LED frame on the ESP32, which removes the refill entirely; the S3 cannot reach 242 codes with four TX blocks total, so there three blocks only make the refill rarer.

Structs§

RmtChannels
The peripheral’s channels, split for the board’s two RMT consumers.

Constants§

ALL_TX_BLOCKS
Blocks a channel-0 owner may claim: every TX block the chip has.
LED_BLOCKS
RMT blocks the LED channel claims, as the module docs explain.
LED_TX
LED TX channel. Named for the same reason as OW_RX.
OW_RX
1-Wire RX channel: any channel on the ESP32, an RX-capable one on the S3.