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 8 channels, RMT_CH0-RMT_CH3 for transmitting signals and RMT_CH4-RMT_CH7 for receiving signals. 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_CH4, 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§
- AnyRmt
RxChannel - Any RMT channel that can receive.
- AnyRmt
TxChannel - Any RMT channel that can transmit.
- Carrier
Config - Carrier of a transmit channel, or the carrier that a receive channel removes.
- Pulse
Code - 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§
- Clock
Source - RMT clock source.
The list of clock signals that the
RMT_SCLKmultiplexer can output. - Config
Error - Errors of
Rmtand of the channel constructors. - Loop
Mode - Loop mode of
TxChannel::transmit_loop. - Pulse
Code Error - Error of
PulseCode::try_new. - RxError
- Errors of a reception.
- RxProgress
- Progress of an
RxReception, seeRxReception::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.