Skip to main content

Module rmt

Module rmt 

Source
Available on crate feature unstable only.
Expand description

§Remote Control Peripheral (RMT)

§Overview

The RMT (Remote Control) module is designed to send and receive infrared remote control signals. A variety of remote control protocols can be encoded/decoded via software based on the RMT module. The RMT module converts pulse codes stored in the module’s built-in RAM into output signals, or converts input signals into pulse codes and stores them in RAM. In addition, the RMT module optionally modulates its output signals with a carrier wave, or optionally demodulates and filters its input signals.

Typically, the RMT peripheral can be used in the following scenarios:

  • Transmit or receive infrared signals, with any IR protocols, e.g., NEC
  • General-purpose sequence generator
  • Transmit signals in a hardware-controlled loop, with a finite or infinite number of times
  • Modulate the carrier to the output signal or demodulate the carrier from the input signal

§Channels

There are 4 channels, each of them can be either receiver or transmitter. Each channel is a peripheral singleton (RMT_CH0, …).

A channel can use the RAM of the channels that follow it: pass a tuple of adjacent channel singletons, such as (RMT_CH0, RMT_CH1). See TxInstance and RxInstance for the combinations of the chip.

For more information, please refer to the ESP-IDF documentation

§Configuration

Rmt holds the settings that all channels share: the clock source and the group clock (RmtConfig). The channels come from Rmt::tx_channel and Rmt::rx_channel, and each channel selects its own tick rate (TxConfig, RxConfig).

§Examples

§TX operation

let rmt = Rmt::new(peripherals.RMT, RmtConfig::default())?;

let tx_config = TxConfig::default().with_tick_rate(Rate::from_mhz(1));
let mut channel = rmt
    .tx_channel(peripherals.RMT_CH0, tx_config)?
    .with_pin(peripherals.GPIO4);

let delay = Delay::new();

let mut data = [PulseCode::new(Level::High, 200, Level::Low, 50); 20];
data[data.len() - 1] = PulseCode::new(Level::High, 3000, Level::Low, 500);

loop {
    channel.transmit(&data)?;
    delay.delay_millis(500);
}

§RX operation

let rmt = Rmt::new(peripherals.RMT, RmtConfig::default())?;

let rx_config = RxConfig::default()
    .with_tick_rate(Rate::from_mhz(1))
    .with_idle_ns(10_000_000);
let mut channel = rmt
    .rx_channel(peripherals.RMT_CH1, rx_config)?
    .with_pin(peripherals.GPIO4);

let mut data = [PulseCode::default(); 48];
let count = channel.receive(&mut data)?;
for code in &data[..count] {
    println!("{:?}", code);
}

Structs§

AnyRmtRxChannel
Any RMT channel that can receive.
AnyRmtTxChannel
Any RMT channel that can transmit.
CarrierConfig
Carrier of a transmit channel, or the carrier that a receive channel removes.
PulseCode
Convenience newtype to work with pulse codes.
Rmt
Shared RMT setup: clock source and group clock.
RmtConfig
Configuration of Rmt: the settings that all channels share.
RxChannel
A receive channel.
RxConfig
Configuration of a receive channel.
RxReception
A reception in progress, see RxChannel::start_receive.
TxChannel
A transmit channel.
TxConfig
Configuration of a transmit channel.
TxLoop
A loop transmission in progress, see TxChannel::transmit_loop.

Enums§

ClockSource
RMT clock source. The list of clock signals that the RMT_SCLK multiplexer can output.
ConfigError
Errors of Rmt and of the channel constructors.
LoopMode
Loop mode of TxChannel::transmit_loop.
PulseCodeError
Error of PulseCode::try_new.
RxError
Errors of a reception.
RxProgress
Progress of an RxReception, see RxReception::poll.
TxError
Errors of a transmission.

Constants§

CHANNEL_RAM_SIZE
Per-channel size of the RMT hardware buffer (number of PulseCodes).
HAS_RX_WRAP
Whether the channel supports wrapping rx (wrapping tx is supported on all devices)
MAX_RX_IDLE_THRESHOLD
The largest idle threshold of a receive channel, in ticks.
MAX_TX_LOOPCOUNT
The largest valid value for loopcounts in LoopMode.

Traits§

RxInstance
A receive channel, alone or with the RAM blocks of the channels that follow it.
TxInstance
A transmit channel, alone or with the RAM blocks of the channels that follow it.