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

* Unify the system peripheral Whilst the PCR, SYSTEM and DPORT peripherals are different, we currently use them all in the same way. This PR unifies the peripheral name in the hal to `SYSTEM`. The idea is that they all do the same sort of thing, so we can collect them under the same name, and later down the line we can being to expose differences under an extended API. The benifits to this are imo quite big, the examples now are all identical, which makes things easier for esp-wifi, and paves a path towards the multichip hal. Why not do this in the PAC? Imo the pac should be as close to the hardware as possible, and the HAL is where we should abstractions such as this. * changelog
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 esp32_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);
|
|
}
|
|
}
|