From 8bb15cb1e078609b2f5a324e4eced89c2d4bcffd Mon Sep 17 00:00:00 2001 From: Andelf Date: Tue, 25 Jun 2024 02:18:47 +0800 Subject: [PATCH] feat(gpio): add embassy async button input demo --- README.md | 8 ++++---- examples/embassy_button.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 examples/embassy_button.rs diff --git a/README.md b/README.md index 3ee0c91..e36b829 100644 --- a/README.md +++ b/README.md @@ -9,14 +9,14 @@ This crate is a working-in-progress and not ready for use. - Peripherals: - [x] basic start up code: linker, startup + - [x] Embassy time driver using MCHTMR - [x] SYSCTL init - [x] PLL setting (only PLL0 is supported, since others might be unsafe) - [x] GPIO, Flex, Input, Output + - [x] Async GPIO - [x] RTT support (defmt, defmt-rtt) - - [x] UART support - - [x] blocking TX, RX - - [x] I2C support - - [x] blocking, eh traits + - [x] UART blocking TX, RX + - [x] I2C blocking - MCUs - HPM5300 - currently it's the only supported series diff --git a/examples/embassy_button.rs b/examples/embassy_button.rs new file mode 100644 index 0000000..8951d77 --- /dev/null +++ b/examples/embassy_button.rs @@ -0,0 +1,27 @@ +#![no_main] +#![no_std] +#![feature(type_alias_impl_trait)] + +use embassy_executor::Spawner; +use hpm_hal::gpio::{Input, Level, Output, Pull}; +use {defmt_rtt as _, hpm_hal as hal}; + +#[embassy_executor::main(entry = "hpm_hal::entry")] +async fn main(_spawner: Spawner) -> ! { + let p = hal::init(Default::default()); + + let mut button = Input::new(p.PA03, Pull::Down); // hpm5300evklite, BOOT1_KEY + let mut led = Output::new(p.PA10, Level::Low, Default::default()); + loop { + button.wait_for_falling_edge().await; + defmt::info!("PA03 Button pressed! current={}", button.is_high()); + led.toggle(); + } +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + //let _ = println!("\n\n\n{}", info); + + loop {} +}