diff options
| author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-06-28 11:40:51 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-06-28 11:40:51 +0000 |
| commit | e0e675042bde3f0d6fbdf42c777d8963282a3e44 (patch) | |
| tree | b71c1ac30edc78d3172e2a2e35cfbd8ab9d1dd5b | |
| parent | c7703ba17c5da3d294544c3a4f451bb7bd04ccfb (diff) | |
| parent | d1d07cd9e3b86b2d387b26b652e3caebe114e36b (diff) | |
Merge #803
803: Initial independent watchdog implementation r=FrozenDroid a=FrozenDroid
Co-authored-by: Vincent Stakenburg <[email protected]>
| -rw-r--r-- | embassy-stm32/src/lib.rs | 3 | ||||
| -rw-r--r-- | embassy-stm32/src/wdg/mod.rs | 53 |
2 files changed, 56 insertions, 0 deletions
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 717ebb95e..7be0c77ea 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -55,6 +55,9 @@ pub mod usb; | |||
| 55 | #[cfg(any(otgfs, otghs))] | 55 | #[cfg(any(otgfs, otghs))] |
| 56 | pub mod usb_otg; | 56 | pub mod usb_otg; |
| 57 | 57 | ||
| 58 | #[cfg(iwdg)] | ||
| 59 | pub mod wdg; | ||
| 60 | |||
| 58 | #[cfg(feature = "subghz")] | 61 | #[cfg(feature = "subghz")] |
| 59 | pub mod subghz; | 62 | pub mod subghz; |
| 60 | 63 | ||
diff --git a/embassy-stm32/src/wdg/mod.rs b/embassy-stm32/src/wdg/mod.rs new file mode 100644 index 000000000..da25692ab --- /dev/null +++ b/embassy-stm32/src/wdg/mod.rs | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | use core::marker::PhantomData; | ||
| 2 | |||
| 3 | use embassy_hal_common::{unborrow, Unborrow}; | ||
| 4 | use stm32_metapac::iwdg::vals::Key; | ||
| 5 | pub use stm32_metapac::iwdg::vals::Pr as Prescaler; | ||
| 6 | |||
| 7 | pub struct IndependentWatchdog<'d, T: Instance> { | ||
| 8 | wdg: PhantomData<&'d mut T>, | ||
| 9 | } | ||
| 10 | |||
| 11 | impl<'d, T: Instance> IndependentWatchdog<'d, T> { | ||
| 12 | pub fn new(_instance: impl Unborrow<Target = T> + 'd, presc: Prescaler) -> Self { | ||
| 13 | unborrow!(_instance); | ||
| 14 | |||
| 15 | let wdg = T::regs(); | ||
| 16 | unsafe { | ||
| 17 | wdg.kr().write(|w| w.set_key(Key::ENABLE)); | ||
| 18 | wdg.pr().write(|w| w.set_pr(presc)); | ||
| 19 | } | ||
| 20 | |||
| 21 | IndependentWatchdog { | ||
| 22 | wdg: PhantomData::default(), | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | pub unsafe fn unleash(&mut self) { | ||
| 27 | T::regs().kr().write(|w| w.set_key(Key::START)); | ||
| 28 | } | ||
| 29 | |||
| 30 | pub unsafe fn pet(&mut self) { | ||
| 31 | T::regs().kr().write(|w| w.set_key(Key::RESET)); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | mod sealed { | ||
| 36 | pub trait Instance { | ||
| 37 | fn regs() -> crate::pac::iwdg::Iwdg; | ||
| 38 | } | ||
| 39 | } | ||
| 40 | |||
| 41 | pub trait Instance: sealed::Instance {} | ||
| 42 | |||
| 43 | foreach_peripheral!( | ||
| 44 | (iwdg, $inst:ident) => { | ||
| 45 | impl sealed::Instance for crate::peripherals::$inst { | ||
| 46 | fn regs() -> crate::pac::iwdg::Iwdg { | ||
| 47 | crate::pac::$inst | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | impl Instance for crate::peripherals::$inst {} | ||
| 52 | }; | ||
| 53 | ); | ||
