diff options
| author | WillaWillNot <[email protected]> | 2025-11-20 16:24:15 -0500 |
|---|---|---|
| committer | WillaWillNot <[email protected]> | 2025-11-21 16:36:15 -0500 |
| commit | 623623a25f213f76de932eaf4458c3120823d205 (patch) | |
| tree | a1039bcdb29488180f4fe669f16ac0b33370404e /examples/stm32f0/src | |
| parent | de4d7f56473df58d9b3fa8ec4917ab86550005ae (diff) | |
Updated documentation, fixed EXTI definition issues with chips that have touch sensing, updated examples, added generation of convenience method to bind_interrupts for easier type erasure
Diffstat (limited to 'examples/stm32f0/src')
| -rw-r--r-- | examples/stm32f0/src/bin/button_controlled_blink.rs | 16 | ||||
| -rw-r--r-- | examples/stm32f0/src/bin/button_exti.rs | 16 |
2 files changed, 28 insertions, 4 deletions
diff --git a/examples/stm32f0/src/bin/button_controlled_blink.rs b/examples/stm32f0/src/bin/button_controlled_blink.rs index 0b678af01..f57d5d200 100644 --- a/examples/stm32f0/src/bin/button_controlled_blink.rs +++ b/examples/stm32f0/src/bin/button_controlled_blink.rs | |||
| @@ -8,13 +8,20 @@ use core::sync::atomic::{AtomicU32, Ordering}; | |||
| 8 | use defmt::info; | 8 | use defmt::info; |
| 9 | use embassy_executor::Spawner; | 9 | use embassy_executor::Spawner; |
| 10 | use embassy_stm32::Peri; | 10 | use embassy_stm32::Peri; |
| 11 | use embassy_stm32::exti::ExtiInput; | 11 | use embassy_stm32::bind_interrupts; |
| 12 | use embassy_stm32::exti::{self, ExtiInput}; | ||
| 12 | use embassy_stm32::gpio::{AnyPin, Level, Output, Pull, Speed}; | 13 | use embassy_stm32::gpio::{AnyPin, Level, Output, Pull, Speed}; |
| 14 | use embassy_stm32::interrupt; | ||
| 13 | use embassy_time::Timer; | 15 | use embassy_time::Timer; |
| 14 | use {defmt_rtt as _, panic_probe as _}; | 16 | use {defmt_rtt as _, panic_probe as _}; |
| 15 | 17 | ||
| 16 | static BLINK_MS: AtomicU32 = AtomicU32::new(0); | 18 | static BLINK_MS: AtomicU32 = AtomicU32::new(0); |
| 17 | 19 | ||
| 20 | bind_interrupts!( | ||
| 21 | pub struct Irqs{ | ||
| 22 | EXTI4_15 => exti::InterruptHandler<interrupt::typelevel::EXTI4_15>; | ||
| 23 | }); | ||
| 24 | |||
| 18 | #[embassy_executor::task] | 25 | #[embassy_executor::task] |
| 19 | async fn led_task(led: Peri<'static, AnyPin>) { | 26 | async fn led_task(led: Peri<'static, AnyPin>) { |
| 20 | // Configure the LED pin as a push pull output and obtain handler. | 27 | // Configure the LED pin as a push pull output and obtain handler. |
| @@ -37,7 +44,12 @@ async fn main(spawner: Spawner) { | |||
| 37 | 44 | ||
| 38 | // Configure the button pin and obtain handler. | 45 | // Configure the button pin and obtain handler. |
| 39 | // On the Nucleo F091RC there is a button connected to pin PC13. | 46 | // On the Nucleo F091RC there is a button connected to pin PC13. |
| 40 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::None); | 47 | let mut button = ExtiInput::new( |
| 48 | p.PC13, | ||
| 49 | p.EXTI13, | ||
| 50 | Pull::None, | ||
| 51 | Irqs::as_any::<interrupt::typelevel::EXTI4_15, exti::InterruptHandler<interrupt::typelevel::EXTI4_15>>(), | ||
| 52 | ); | ||
| 41 | 53 | ||
| 42 | // Create and initialize a delay variable to manage delay loop | 54 | // Create and initialize a delay variable to manage delay loop |
| 43 | let mut del_var = 2000; | 55 | let mut del_var = 2000; |
diff --git a/examples/stm32f0/src/bin/button_exti.rs b/examples/stm32f0/src/bin/button_exti.rs index fd615a215..67ea19215 100644 --- a/examples/stm32f0/src/bin/button_exti.rs +++ b/examples/stm32f0/src/bin/button_exti.rs | |||
| @@ -3,17 +3,29 @@ | |||
| 3 | 3 | ||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::exti::ExtiInput; | 6 | use embassy_stm32::bind_interrupts; |
| 7 | use embassy_stm32::exti::{self, ExtiInput}; | ||
| 7 | use embassy_stm32::gpio::Pull; | 8 | use embassy_stm32::gpio::Pull; |
| 9 | use embassy_stm32::interrupt; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | 10 | use {defmt_rtt as _, panic_probe as _}; |
| 9 | 11 | ||
| 12 | bind_interrupts!( | ||
| 13 | pub struct Irqs{ | ||
| 14 | EXTI4_15 => exti::InterruptHandler<interrupt::typelevel::EXTI4_15>; | ||
| 15 | }); | ||
| 16 | |||
| 10 | #[embassy_executor::main] | 17 | #[embassy_executor::main] |
| 11 | async fn main(_spawner: Spawner) { | 18 | async fn main(_spawner: Spawner) { |
| 12 | // Initialize and create handle for devicer peripherals | 19 | // Initialize and create handle for devicer peripherals |
| 13 | let p = embassy_stm32::init(Default::default()); | 20 | let p = embassy_stm32::init(Default::default()); |
| 14 | // Configure the button pin and obtain handler. | 21 | // Configure the button pin and obtain handler. |
| 15 | // On the Nucleo F091RC there is a button connected to pin PC13. | 22 | // On the Nucleo F091RC there is a button connected to pin PC13. |
| 16 | let mut button = ExtiInput::new(p.PC13, p.EXTI13, Pull::Down); | 23 | let mut button = ExtiInput::new( |
| 24 | p.PC13, | ||
| 25 | p.EXTI13, | ||
| 26 | Pull::Down, | ||
| 27 | Irqs::as_any::<interrupt::typelevel::EXTI4_15, exti::InterruptHandler<interrupt::typelevel::EXTI4_15>>(), | ||
| 28 | ); | ||
| 17 | 29 | ||
| 18 | info!("Press the USER button..."); | 30 | info!("Press the USER button..."); |
| 19 | loop { | 31 | loop { |
