use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use rmk_config::resolved::Hardware;
#[cfg(feature = "watchdog")]
use rmk_config::resolved::hardware::ChipSeries;
#[cfg(feature = "watchdog")]
pub(crate) fn expand_watchdog_init(hardware: &Hardware) -> (TokenStream2, Option<TokenStream2>) {
let init = match hardware.chip.series {
ChipSeries::Rp2040 => quote! {
let mut watchdog_runner = ::rmk::watchdog::Rp2040Watchdog::default_runner(
::embassy_rp::watchdog::Watchdog::new(p.WATCHDOG),
);
},
ChipSeries::Nrf52 => quote! {
let mut watchdog_runner =
::rmk::watchdog::Nrf52Watchdog::default_runner(p.WDT);
},
ChipSeries::Esp32 => quote! {
let timg1 = ::esp_hal::timer::timg::TimerGroup::new(p.TIMG1);
let mut esp_wdt_inner = timg1.wdt;
esp_wdt_inner.set_timeout(
::esp_hal::timer::timg::MwdtStage::Stage0,
::esp_hal::time::Duration::from_secs(10),
);
esp_wdt_inner.enable();
let esp_wdt = ::rmk::watchdog::Esp32Watchdog::new(esp_wdt_inner);
let mut watchdog_runner = ::rmk::watchdog::WatchdogRunner::new(
esp_wdt,
::rmk::embassy_time::Duration::from_secs(5),
);
},
ChipSeries::Stm32 => quote! {},
};
if init.is_empty() {
(init, None)
} else {
(init, Some(quote! { watchdog_runner.run() }))
}
}
#[cfg(not(feature = "watchdog"))]
pub(crate) fn expand_watchdog_init(_hardware: &Hardware) -> (TokenStream2, Option<TokenStream2>) {
(quote! {}, None)
}