diff options
| author | @imrank03 <[email protected]> | 2022-12-21 11:53:55 +0530 |
|---|---|---|
| committer | @imrank03 <[email protected]> | 2022-12-21 11:53:55 +0530 |
| commit | c0f3610581164e12446053706b6dbef98b1f1089 (patch) | |
| tree | ae6682f5c680af533e576abf8abc51feff41b7f8 /examples | |
| parent | 63122f6d7e9b6a3ec9e246a7171444bde41ce9f0 (diff) | |
added interrupt example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32f0/src/bin/button_exti.rs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/examples/stm32f0/src/bin/button_exti.rs b/examples/stm32f0/src/bin/button_exti.rs new file mode 100644 index 000000000..40c0d5848 --- /dev/null +++ b/examples/stm32f0/src/bin/button_exti.rs | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_stm32::exti::ExtiInput; | ||
| 8 | use embassy_stm32::gpio::{Input, Pull}; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 10 | |||
| 11 | #[embassy_executor::main] | ||
| 12 | async fn main(_spawner: Spawner) { | ||
| 13 | // Initialize and create handle for devicer peripherals | ||
| 14 | let p = embassy_stm32::init(Default::default()); | ||
| 15 | // Configure the button pin and obtain handler. | ||
| 16 | // On the Nucleo F091RC there is a button connected to pin PC13. | ||
| 17 | let button = Input::new(p.PC13, Pull::Down); | ||
| 18 | let mut button = ExtiInput::new(button, p.EXTI13); | ||
| 19 | |||
| 20 | info!("Press the USER button..."); | ||
| 21 | loop { | ||
| 22 | button.wait_for_falling_edge().await; | ||
| 23 | info!("Pressed!"); | ||
| 24 | button.wait_for_rising_edge().await; | ||
| 25 | info!("Released!"); | ||
| 26 | } | ||
| 27 | } | ||
