mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 14:44:42 +00:00

* No longer publicly expose the `PeripheralClockControl` struct * Update examples as needed to get things building again * Update CHANGELOG.md * Address review feedback, fix a warning * Use a critical section for all devices other than the ESP32-C6/H2, as they modify multiple registers * Rebase and update `etm` driver to fix build errors
92 lines
2.3 KiB
Rust
92 lines
2.3 KiB
Rust
//! Demonstrates decoding pulse sequences with RMT
|
|
//! Connect GPIO15 to GPIO4
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use esp32s2_hal::{
|
|
clock::ClockControl,
|
|
gpio::IO,
|
|
peripherals::Peripherals,
|
|
prelude::*,
|
|
rmt::{PulseCode, RxChannel, RxChannelConfig, RxChannelCreator},
|
|
Delay,
|
|
Rmt,
|
|
};
|
|
use esp_backtrace as _;
|
|
use esp_println::println;
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let peripherals = Peripherals::take();
|
|
let system = peripherals.SYSTEM.split();
|
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
let mut out = io.pins.gpio15.into_push_pull_output();
|
|
|
|
let rmt = Rmt::new(peripherals.RMT, 80u32.MHz(), &clocks).unwrap();
|
|
|
|
let mut channel = rmt
|
|
.channel0
|
|
.configure(
|
|
io.pins.gpio4,
|
|
RxChannelConfig {
|
|
clk_divider: 1,
|
|
idle_threshold: 0b111_1111_1111_1111,
|
|
..RxChannelConfig::default()
|
|
},
|
|
)
|
|
.unwrap();
|
|
|
|
let mut delay = Delay::new(&clocks);
|
|
|
|
let mut data = [PulseCode {
|
|
level1: true,
|
|
length1: 1,
|
|
level2: false,
|
|
length2: 1,
|
|
}; 48];
|
|
|
|
loop {
|
|
for x in data.iter_mut() {
|
|
x.length1 = 0;
|
|
x.length2 = 0;
|
|
}
|
|
|
|
let transaction = channel.receive(&mut data).unwrap();
|
|
|
|
// simulate input
|
|
for i in 0u32..5u32 {
|
|
out.set_high().unwrap();
|
|
delay.delay_us(i * 10 + 20);
|
|
out.set_low().unwrap();
|
|
delay.delay_us(i * 20 + 20);
|
|
}
|
|
|
|
match transaction.wait() {
|
|
Ok(channel_res) => {
|
|
channel = channel_res;
|
|
for entry in &data[..data.len()] {
|
|
if entry.length1 == 0 {
|
|
break;
|
|
}
|
|
println!("{} {}", entry.level1, entry.length1);
|
|
|
|
if entry.length2 == 0 {
|
|
break;
|
|
}
|
|
println!("{} {}", entry.level2, entry.length2);
|
|
}
|
|
println!();
|
|
}
|
|
Err((_err, channel_res)) => {
|
|
channel = channel_res;
|
|
println!("Error");
|
|
}
|
|
}
|
|
|
|
delay.delay_ms(1500u32);
|
|
}
|
|
}
|