dashboard/
btn_mod.rs

1//! Module for Handling Buttons
2//! Uses external interrupts to handle button input.
3//!
4//! Note that the documentation and examples for `embassy-stm32` version "0.4.0" does
5//! not match the actual source code for the `exti` module. The `exti` module
6//! is actually the same as version "0.3.0".
7//!
8//! Note that **Non-Blocking** delays are used to handle signal bouncing.
9//!
10use defmt::info;
11use embassy_stm32::exti::ExtiInput;
12use embassy_time::Timer;
13
14/// A delay to handle signal bounce. Default at 50ms.
15pub const BOUNCE_DELAY: u64 = 50;
16
17#[embassy_executor::task]
18pub async fn btn1_task(mut btn1: ExtiInput<'static>) {
19    let mut i = 0;
20    loop {
21        btn1.wait_for_falling_edge().await;
22        info!("Btn 1 Pressed!");
23        Timer::after_millis(BOUNCE_DELAY).await;
24
25        i += 1;
26        btn1.wait_for_high().await;
27        Timer::after_millis(BOUNCE_DELAY).await;
28        info!("Btn 1 Released {} times!", i);
29    }
30}
31
32#[embassy_executor::task]
33pub async fn btn2_task(mut btn2: ExtiInput<'static>) {
34    let mut i = 0;
35    loop {
36        btn2.wait_for_falling_edge().await;
37        info!("Btn 2 Pressed!");
38        Timer::after_millis(BOUNCE_DELAY).await;
39
40        i += 1;
41        btn2.wait_for_high().await;
42        Timer::after_millis(BOUNCE_DELAY).await;
43        info!("Btn 2 Released {} times!", i);
44    }
45}