diff options
| author | Bob McWhirter <[email protected]> | 2021-08-16 15:03:29 -0400 |
|---|---|---|
| committer | Bob McWhirter <[email protected]> | 2021-08-16 15:15:07 -0400 |
| commit | a93ed2bed6311450b2a8f17a07346eff3c9b6667 (patch) | |
| tree | abfbb7c5d952d128277a2b3b3f9d0d381312862e /examples | |
| parent | cbff0398bb8d59f881e6649e2b3776d9e00af671 (diff) | |
Add H7 exti button example using correct EXTI reg block offsets.
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32h7/src/bin/button_exti.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/examples/stm32h7/src/bin/button_exti.rs b/examples/stm32h7/src/bin/button_exti.rs new file mode 100644 index 000000000..ee43fa7d9 --- /dev/null +++ b/examples/stm32h7/src/bin/button_exti.rs | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(trait_alias)] | ||
| 4 | #![feature(type_alias_impl_trait)] | ||
| 5 | #![allow(incomplete_features)] | ||
| 6 | |||
| 7 | #[path = "../example_common.rs"] | ||
| 8 | mod example_common; | ||
| 9 | use embassy::executor::Spawner; | ||
| 10 | use embassy_stm32::dbgmcu::Dbgmcu; | ||
| 11 | use embassy_stm32::exti::ExtiInput; | ||
| 12 | use embassy_stm32::gpio::{Input, Pull}; | ||
| 13 | use embassy_stm32::Peripherals; | ||
| 14 | use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge}; | ||
| 15 | use example_common::*; | ||
| 16 | |||
| 17 | #[embassy::main] | ||
| 18 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 19 | info!("Hello World!"); | ||
| 20 | |||
| 21 | unsafe { | ||
| 22 | Dbgmcu::enable_all(); | ||
| 23 | } | ||
| 24 | |||
| 25 | let button = Input::new(p.PC13, Pull::Down); | ||
| 26 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 27 | |||
| 28 | info!("Press the USER button..."); | ||
| 29 | |||
| 30 | loop { | ||
| 31 | button.wait_for_rising_edge().await; | ||
| 32 | info!("Pressed!"); | ||
| 33 | button.wait_for_falling_edge().await; | ||
| 34 | info!("Released!"); | ||
| 35 | } | ||
| 36 | } | ||
