use embassy_time::{Duration, Timer};
use crate::core_traits::Runnable;
#[cfg(feature = "_esp_ble")]
mod esp32;
#[cfg(any(feature = "_nrf_ble", feature = "dfu_nrf"))]
#[cfg(not(any(feature = "nrf54l15_ble", feature = "nrf54lm20_ble")))]
mod nrf52;
#[cfg(feature = "rp2040")]
mod rp2040;
#[cfg(feature = "_esp_ble")]
pub use esp32::Esp32Watchdog;
#[cfg(any(feature = "_nrf_ble", feature = "dfu_nrf"))]
#[cfg(not(any(feature = "nrf54l15_ble", feature = "nrf54lm20_ble")))]
pub use nrf52::Nrf52Watchdog;
#[cfg(feature = "rp2040")]
pub use rp2040::Rp2040Watchdog;
pub trait WatchdogFeed: Send {
fn feed(&mut self);
}
pub struct WatchdogRunner<W: WatchdogFeed> {
watchdog: W,
interval: Duration,
}
impl<W: WatchdogFeed> WatchdogRunner<W> {
pub fn new(watchdog: W, interval: Duration) -> Self {
Self { watchdog, interval }
}
}
impl<W: WatchdogFeed> Runnable for WatchdogRunner<W> {
async fn run(&mut self) -> ! {
loop {
self.watchdog.feed();
Timer::after(self.interval).await;
}
}
}