embassy/embassy-stm32/src/time.rs
Grant Miller 5ecbe5c918 embassy-stm32: Simplify time
- Remove unused `MilliSeconds`, `MicroSeconds`, and `NanoSeconds` types
- Remove `Bps`, `KiloHertz`, and `MegaHertz` types that were only used
for converting to `Hertz`
- Replace all instances of `impl Into<Hertz>` with `Hertz`
- Add `hz`, `khz`, and `mhz` methods to `Hertz`, as well as
free function shortcuts
- Remove `U32Ext` extension trait
2022-07-10 21:46:45 -05:00

34 lines
704 B
Rust

//! Time units
/// Hertz
#[derive(PartialEq, PartialOrd, Clone, Copy, Debug, Eq)]
pub struct Hertz(pub u32);
impl Hertz {
pub fn hz(hertz: u32) -> Self {
Self(hertz)
}
pub fn khz(kilohertz: u32) -> Self {
Self(kilohertz * 1_000)
}
pub fn mhz(megahertz: u32) -> Self {
Self(megahertz * 1_000_000)
}
}
/// This is a convenience shortcut for [`Hertz::hz`]
pub fn hz(hertz: u32) -> Hertz {
Hertz::hz(hertz)
}
/// This is a convenience shortcut for [`Hertz::khz`]
pub fn khz(kilohertz: u32) -> Hertz {
Hertz::khz(kilohertz)
}
/// This is a convenience shortcut for [`Hertz::mhz`]
pub fn mhz(megahertz: u32) -> Hertz {
Hertz::mhz(megahertz)
}