* Rework hal initialization * Turn sw interrupt control into a virtual peripheral * Return a tuple instead of a named struct * Fix docs * Remove SystemClockControl * Move software interrupts under interrupt * Re-document what's left in system * Update time docs * Update sw int docs * Introduce Config * Fix tests * Remove redundant inits * Doc * Clean up examples&tests * Update tests * Add changelog entry * Start migration guide * Restore some convenience-imports * Remove Config from prelude
67 lines
1.5 KiB
Rust
67 lines
1.5 KiB
Rust
//! Demonstrates generating pulse sequences with RMT
|
|
//!
|
|
//! Connect a logic analyzer to GPIO4 to see the generated pulses.
|
|
//!
|
|
//! The following wiring is assumed:
|
|
//! - generated pulses => GPIO4
|
|
|
|
//% CHIPS: esp32 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use esp_backtrace as _;
|
|
use esp_hal::{
|
|
delay::Delay,
|
|
gpio::Io,
|
|
prelude::*,
|
|
rmt::{PulseCode, Rmt, TxChannel, TxChannelConfig, TxChannelCreator},
|
|
};
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let (peripherals, clocks) = esp_hal::init(esp_hal::Config::default());
|
|
|
|
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
|
|
cfg_if::cfg_if! {
|
|
if #[cfg(feature = "esp32h2")] {
|
|
let freq = 32.MHz();
|
|
} else {
|
|
let freq = 80.MHz();
|
|
}
|
|
};
|
|
|
|
let rmt = Rmt::new(peripherals.RMT, freq, &clocks).unwrap();
|
|
|
|
let tx_config = TxChannelConfig {
|
|
clk_divider: 255,
|
|
..TxChannelConfig::default()
|
|
};
|
|
|
|
let mut channel = rmt.channel0.configure(io.pins.gpio4, tx_config).unwrap();
|
|
|
|
let delay = Delay::new(&clocks);
|
|
|
|
let mut data = [PulseCode {
|
|
level1: true,
|
|
length1: 200,
|
|
level2: false,
|
|
length2: 50,
|
|
}; 20];
|
|
|
|
data[data.len() - 2] = PulseCode {
|
|
level1: true,
|
|
length1: 3000,
|
|
level2: false,
|
|
length2: 500,
|
|
};
|
|
data[data.len() - 1] = PulseCode::default();
|
|
|
|
loop {
|
|
let transaction = channel.transmit(&data);
|
|
channel = transaction.wait().unwrap();
|
|
delay.delay_millis(500);
|
|
}
|
|
}
|