Skip to content

Commit 164c56e

Browse files
committed
add fugit for Countdown
1 parent d9a66bb commit 164c56e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ features = ["stm32h743v", "rt", "xspi", "sdmmc", "fmc", "usb_hs", "rtc", "ethern
2525
targets = ["thumbv7em-none-eabihf"]
2626

2727
[dependencies]
28+
fugit = "0.3.3"
2829
embedded-hal = "0.2.6"
2930
embedded-dma = "0.1.2"
3031
cortex-m = "^0.7.4"

src/delay.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,14 @@ pub struct Delay {
6464
}
6565

6666
/// Implements [CountDown](embedded_hal::timer::CountDown) for the System timer (SysTick).
67-
/// Time is measured in microseconds
68-
pub struct CountdownUs<'a> {
67+
pub struct Countdown<'a> {
6968
clocks: CoreClocks,
7069
syst: &'a mut SYST,
7170
total_rvr: u64,
7271
finished: bool,
7372
}
7473

75-
impl<'a> CountdownUs<'a> {
74+
impl<'a> Countdown<'a> {
7675
/// Create a new [CountDown] measured in microseconds.
7776
pub fn new(syst: &'a mut SYST, clocks: CoreClocks) -> Self {
7877
Self {
@@ -107,14 +106,14 @@ impl<'a> CountdownUs<'a> {
107106
}
108107
}
109108

110-
impl<'a> CountDown for CountdownUs<'a> {
111-
type Time = u32;
109+
impl<'a> CountDown for Countdown<'a> {
110+
type Time = fugit::MicrosDurationU32;
112111

113112
fn start<T>(&mut self, count: T)
114113
where
115114
T: Into<Self::Time>,
116115
{
117-
let us = count.into();
116+
let us = count.into().ticks();
118117

119118
// With c_ck up to 480e6, we need u64 for delays > 8.9s
120119

@@ -189,7 +188,7 @@ impl DelayUs<u32> for Delay {
189188
// See errata ES0392 §2.2.3. Revision Y does not have the /8 divider
190189
u64::from(us) * u64::from(self.clocks.c_ck().0 / 1_000_000)
191190
} else if cfg!(feature = "cm4") {
192-
// CM4 dervived from HCLK
191+
// CM4 derived from HCLK
193192
u64::from(us) * u64::from(self.clocks.hclk().0 / 8_000_000)
194193
} else {
195194
// Normally divide by 8

0 commit comments

Comments
 (0)