1use crate::{generics, pac::WDT};
3
4use core::convert::From;
5use core::marker::PhantomData;
6
7pub trait WatchdogState: generics::Sealed {}
9
10pub enum Disabled {}
12pub enum Reset {}
15
16impl generics::Sealed for Disabled {}
17impl WatchdogState for Disabled {}
18impl generics::Sealed for Reset {}
19impl WatchdogState for Reset {}
20
21pub struct Watchdog<S: WatchdogState> {
23 watchdog: WDT,
24 state: PhantomData<S>,
25}
26
27impl Watchdog<Reset> {
28 pub fn new(watchdog: WDT) -> Self {
30 Self {
31 watchdog,
32 state: PhantomData,
33 }
34 }
35
36 pub fn disable(self) -> Watchdog<Disabled> {
38 self.watchdog.mr().write(|w| w.wddis().set_bit());
39 Watchdog {
40 watchdog: self.watchdog,
41 state: PhantomData,
42 }
43 }
44}
45
46impl From<WDT> for Watchdog<Disabled> {
47 fn from(wd: WDT) -> Self {
48 Watchdog::new(wd).disable()
49 }
50}
51
52impl crate::ehal::watchdog::Watchdog for Watchdog<Disabled> {
53 fn feed(&mut self) {}
55}