aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-06-28 11:40:51 +0000
committerGitHub <[email protected]>2022-06-28 11:40:51 +0000
commite0e675042bde3f0d6fbdf42c777d8963282a3e44 (patch)
treeb71c1ac30edc78d3172e2a2e35cfbd8ab9d1dd5b
parentc7703ba17c5da3d294544c3a4f451bb7bd04ccfb (diff)
parentd1d07cd9e3b86b2d387b26b652e3caebe114e36b (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.rs3
-rw-r--r--embassy-stm32/src/wdg/mod.rs53
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))]
56pub mod usb_otg; 56pub mod usb_otg;
57 57
58#[cfg(iwdg)]
59pub mod wdg;
60
58#[cfg(feature = "subghz")] 61#[cfg(feature = "subghz")]
59pub mod subghz; 62pub 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 @@
1use core::marker::PhantomData;
2
3use embassy_hal_common::{unborrow, Unborrow};
4use stm32_metapac::iwdg::vals::Key;
5pub use stm32_metapac::iwdg::vals::Pr as Prescaler;
6
7pub struct IndependentWatchdog<'d, T: Instance> {
8 wdg: PhantomData<&'d mut T>,
9}
10
11impl<'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
35mod sealed {
36 pub trait Instance {
37 fn regs() -> crate::pac::iwdg::Iwdg;
38 }
39}
40
41pub trait Instance: sealed::Instance {}
42
43foreach_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);