Skip to content

Commit cc6652e

Browse files
committed
impl MilliSeconds
1 parent 09bb195 commit cc6652e

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/time.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ pub struct KiloHertz(pub u32);
2020
#[derive(Clone, Copy)]
2121
pub struct MegaHertz(pub u32);
2222

23+
/// Time unit
24+
#[derive(PartialEq, PartialOrd, Clone, Copy)]
25+
pub struct MilliSeconds(pub u32);
26+
2327
/// Extension trait that adds convenience methods to the `u32` type
2428
pub trait U32Ext {
2529
/// Wrap in `Bps`
@@ -33,6 +37,9 @@ pub trait U32Ext {
3337

3438
/// Wrap in `MegaHertz`
3539
fn mhz(self) -> MegaHertz;
40+
41+
/// Wrap in `MilliSeconds`
42+
fn ms(self) -> MilliSeconds;
3643
}
3744

3845
impl U32Ext for u32 {
@@ -51,6 +58,10 @@ impl U32Ext for u32 {
5158
fn mhz(self) -> MegaHertz {
5259
MegaHertz(self)
5360
}
61+
62+
fn ms(self) -> MilliSeconds {
63+
MilliSeconds(self)
64+
}
5465
}
5566

5667
impl Into<Hertz> for KiloHertz {

src/watchdog.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::hal::watchdog::{Watchdog, WatchdogEnable};
22

33
use crate::stm32::{DBGMCU, IWDG};
4+
use crate::time::MilliSeconds;
45

56
const LSI_KHZ: u32 = 40;
67
const MAX_PR: u8 = 8;
@@ -9,13 +10,13 @@ const KR_ACCESS: u16 = 0x5555;
910
const KR_RELOAD: u16 = 0xAAAA;
1011
const KR_START: u16 = 0xCCCC;
1112

12-
struct IndependentWatchDog {
13+
pub struct IndependentWatchDog {
1314
iwdg: IWDG,
1415
}
1516

1617
impl IndependentWatchDog {
1718
pub fn new(iwdg: IWDG) -> Self {
18-
IndependentWatchdog { iwdg }
19+
IndependentWatchDog { iwdg }
1920
}
2021

2122
pub fn stop_on_debug(&self, dbg: &DBGMCU, stop: bool) {
@@ -81,7 +82,7 @@ impl IndependentWatchDog {
8182
}
8283
}
8384

84-
impl WatchdogEnable for IndependentWatchdog {
85+
impl WatchdogEnable for IndependentWatchDog {
8586
type Time = MilliSeconds;
8687

8788
fn start<T: Into<Self::Time>>(&mut self, period: T) {
@@ -91,7 +92,7 @@ impl WatchdogEnable for IndependentWatchdog {
9192
}
9293
}
9394

94-
impl Watchdog for IndependentWatchdog {
95+
impl Watchdog for IndependentWatchDog {
9596
fn feed(&mut self) {
9697
self.iwdg.kr.write(|w| unsafe { w.key().bits(KR_RELOAD) });
9798
}

0 commit comments

Comments
 (0)