// src/wakeup/gpio.rs

use defmt::info;
use embassy_stm32::exti::ExtiInput;
use embassy_stm32::gpio::Pull;
use embassy_stm32::peripherals;
use embassy_time::{Duration, Timer};
use embassy_hal_internal::Peri;

/// GPIO pin as an EXTI wake-up source.
#[embassy_executor::task]
pub async fn gpio_wakeup(
    pin: Peri<'static, peripherals::PA0>,
    ch: Peri<'static, peripherals::EXTI0>
) {
    info!("EXTI wake input on PA0");
    let mut btn = ExtiInput::new(pin, ch, Pull::Up);

    loop {
        info!("Waiting for falling edge on PA0");
        btn.wait_for_falling_edge().await;
        info!("GPIO wake-up");
        Timer::after(Duration::from_millis(50)).await;
    }
}
