imxrt: add button example

This commit is contained in:
Felipe Balbi 2025-05-20 10:11:30 -07:00 committed by Felipe Balbi
parent 7134e1a3a5
commit 8e93ae8899

View File

@ -0,0 +1,29 @@
#![no_std]
#![no_main]
use defmt::info;
use embassy_executor::Spawner;
use embassy_futures::select::{select, Either};
use embassy_imxrt::gpio;
use {defmt_rtt as _, embassy_imxrt_examples as _, panic_probe as _};
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_imxrt::init(Default::default());
let mut user1 = gpio::Input::new(p.PIO1_1, gpio::Pull::None, gpio::Inverter::Disabled);
let mut user2 = gpio::Input::new(p.PIO0_10, gpio::Pull::None, gpio::Inverter::Disabled);
loop {
let res = select(user1.wait_for_falling_edge(), user2.wait_for_falling_edge()).await;
match res {
Either::First(()) => {
info!("Button `USER1' pressed");
}
Either::Second(()) => {
info!("Button `USER2' pressed");
}
}
}
}