esp-hal/examples/src/bin/etm_timer.rs
Dániel Buga 7f8af8a651
Remove prelude (#2845)
* Remove prelude

* Changelog
2024-12-20 10:24:57 +00:00

65 lines
1.5 KiB
Rust

//! Control LED by the boot button via ETM without involving the CPU.
//! The following wiring is assumed:
//! - LED => GPIO2
//% CHIPS: esp32c6 esp32h2
//% FEATURES: esp-hal/unstable
#![no_std]
#![no_main]
use esp_backtrace as _;
use esp_hal::{
entry,
etm::Etm,
gpio::{
etm::{Channels, OutputConfig},
Level,
Output,
Pull,
},
time::ExtU64,
timer::{
systimer::{etm::Event, SystemTimer},
PeriodicTimer,
},
};
#[entry]
fn main() -> ! {
let peripherals = esp_hal::init(esp_hal::Config::default());
let mut led = Output::new(peripherals.GPIO2, Level::Low);
led.set_high();
let syst = SystemTimer::new(peripherals.SYSTIMER);
let alarm = syst.alarm0;
let timer_event = Event::new(&alarm);
// setup ETM
let gpio_ext = Channels::new(peripherals.GPIO_SD);
let led_task = gpio_ext.channel0_task.toggle(
led,
OutputConfig {
open_drain: false,
pull: Pull::None,
initial_state: Level::Low,
},
);
let etm = Etm::new(peripherals.SOC_ETM);
let channel0 = etm.channel0;
// make sure the configured channel doesn't get dropped - dropping it will
// disable the channel
let _configured_channel = channel0.setup(&timer_event, &led_task);
let mut timer = PeriodicTimer::new(alarm);
timer.start(1u64.secs()).unwrap();
// the LED is controlled by the button without involving the CPU
loop {}
}