Module esp32_hal::rmt

source ·
Expand description

§Remote Control Peripheral (RMT)

§Overview

Some ESP32 variants include a remote control peripheral (RMT) that is designed to handle infrared remote control signals. For that purpose, it can convert bitstreams of data (from the RAM) into pulse codes and even modulate those codes into a carrier wave.

It can also convert received pulse codes (again, with carrier wave support) into data bits.

A secondary use case for this peripheral is to drive RGB(W) LEDs that bear an internal IC and use a pulse code protocol.

§Channels

The RMT peripheral has the following channels available on individual chips:

  • The ESP32 has 8 channels, each of them can be either receiver or transmitter
  • The ESP32-C3 has 4 channels, Channel<0> and Channel<1> hardcoded for transmitting signals and Channel<2> and Channel<3> hardcoded for receiving signals.
  • The ESP32-C6 has 4 channels, Channel<0> and Channel<1> hardcoded for transmitting signals and Channel<2> and Channel<3> hardcoded for receiving signals.
  • The ESP32-H2 has 4 channels, Channel<0> and Channel<1> hardcoded for transmitting signals and Channel<2> and Channel<3> hardcoded for receiving signals.
  • The ESP32-S2 has 4 channels, each of them can be either receiver or transmitter.
  • The ESP32-S3 has 8 channels, Channel<0>-Channel<3> hardcoded for transmitting signals and Channel<4>-Channel<7> hardcoded for receiving signals.

For more information, please refer to the ESP-IDF documentation: https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/rmt.html

§Examples

§Initialization

let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &mut clock_control, &clocks).unwrap();
let mut channel = rmt
    .channel0
    .configure(
        io.pins.gpio1.into_push_pull_output(),
        TxChannelConfig {
            clk_divider: 1,
            idle_output_level: false,
            idle_output: false,
            carrier_modulation: false,
            carrier_high: 1,
            carrier_low: 1,
            carrier_level: false,
        },
    )
    .unwrap();

(on ESP32 and ESP32-S2 you cannot specify a base frequency other than 80 MHz)

§Sending a pulse sequence

let data = [
    PulseCode {
        level1: true,
        length1: 100,
        level2: false,
        length2: 300,
    },
    PulseCode {
        level1: true,
        length1: 100,
        level2: false,
        length2: 0, // a zero-length pulse marks the end of the sequence
    },
];

let transaction = channel.transmit(&data);
channel = transaction.wait().unwrap();

Structs§

Enums§

Traits§