Skip to content

Commit

Permalink
Merge stm32-rs#136
Browse files Browse the repository at this point in the history
136: Add conversions from us/ns to Hertz r=richardeoin a=mattico



Co-authored-by: Matt Ickstadt <mattico8@gmail.com>
  • Loading branch information
bors[bot] and mattico committed Sep 24, 2020
2 parents bb9df8c + 3ca687c commit 418971b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/time.rs
Expand Up @@ -181,6 +181,38 @@ impl Into<Hertz> for MilliSeconds {
}
}

// MicroSeconds <-> Hertz
impl Into<MicroSeconds> for Hertz {
fn into(self) -> MicroSeconds {
let freq = self.0;
assert!(freq != 0 && freq <= 1_000_000);
MicroSeconds(1_000_000 / freq)
}
}
impl Into<Hertz> for MicroSeconds {
fn into(self) -> Hertz {
let period = self.0;
assert!(period != 0 && period <= 1_000_000);
Hertz(1_000_000 / period)
}
}

// NanoSeconds <-> Hertz
impl Into<NanoSeconds> for Hertz {
fn into(self) -> NanoSeconds {
let freq = self.0;
assert!(freq != 0 && freq <= 1_000_000_000);
NanoSeconds(1_000_000_000 / freq)
}
}
impl Into<Hertz> for NanoSeconds {
fn into(self) -> Hertz {
let period = self.0;
assert!(period != 0 && period <= 1_000_000_000);
Hertz(1_000_000_000 / period)
}
}

// Into core::time::Duration
impl Into<Duration> for MilliSeconds {
fn into(self) -> Duration {
Expand Down

0 comments on commit 418971b

Please sign in to comment.