use crate::pac::WDT;
use hal::watchdog;
pub use hal::watchdog::{WatchdogDisable, WatchdogEnable};
pub struct Watchdog {
wdt: WDT,
}
impl Watchdog {
pub fn new(wdt: WDT) -> Self {
Self { wdt }
}
}
impl watchdog::Watchdog for Watchdog {
fn feed(&mut self) {
self.wdt
.cr
.write_with_zero(|w| w.key().passwd().wdrstt().set_bit());
}
}
impl watchdog::WatchdogDisable for Watchdog {
fn disable(&mut self) {
self.wdt.mr.modify(|_, w| w.wddis().set_bit());
}
}
impl watchdog::WatchdogEnable for Watchdog {
type Time = u16;
fn start<T>(&mut self, period: T)
where
T: Into<Self::Time>,
{
self.wdt.mr.modify(|_, w| unsafe {
w.wdrsten()
.set_bit()
.wdv()
.bits(0x0fff)
.wdd()
.bits(period.into())
});
}
}