2021-05-12 16:46:18 +02:00
|
|
|
//! Time units
|
|
|
|
|
2023-04-06 18:53:51 +02:00
|
|
|
use core::ops::{Div, Mul};
|
|
|
|
|
2021-05-12 16:46:18 +02:00
|
|
|
/// Hertz
|
2023-04-06 18:53:51 +02:00
|
|
|
#[derive(Eq, PartialEq, Ord, PartialOrd, Clone, Copy, Debug)]
|
2023-01-20 16:31:04 +01:00
|
|
|
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
2021-05-12 16:46:18 +02:00
|
|
|
pub struct Hertz(pub u32);
|
|
|
|
|
2022-07-11 00:36:10 +02:00
|
|
|
impl Hertz {
|
2023-04-13 00:04:44 +02:00
|
|
|
pub const fn hz(hertz: u32) -> Self {
|
2022-07-11 00:36:10 +02:00
|
|
|
Self(hertz)
|
2021-05-12 16:46:18 +02:00
|
|
|
}
|
|
|
|
|
2023-04-13 00:04:44 +02:00
|
|
|
pub const fn khz(kilohertz: u32) -> Self {
|
2022-07-11 00:36:10 +02:00
|
|
|
Self(kilohertz * 1_000)
|
2021-05-12 16:46:18 +02:00
|
|
|
}
|
|
|
|
|
2023-04-13 00:04:44 +02:00
|
|
|
pub const fn mhz(megahertz: u32) -> Self {
|
2022-07-11 00:36:10 +02:00
|
|
|
Self(megahertz * 1_000_000)
|
2021-05-12 16:46:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-11 00:36:10 +02:00
|
|
|
/// This is a convenience shortcut for [`Hertz::hz`]
|
2023-04-13 00:04:44 +02:00
|
|
|
pub const fn hz(hertz: u32) -> Hertz {
|
2022-07-11 00:36:10 +02:00
|
|
|
Hertz::hz(hertz)
|
2021-05-12 16:46:18 +02:00
|
|
|
}
|
|
|
|
|
2022-07-11 00:36:10 +02:00
|
|
|
/// This is a convenience shortcut for [`Hertz::khz`]
|
2023-04-13 00:04:44 +02:00
|
|
|
pub const fn khz(kilohertz: u32) -> Hertz {
|
2022-07-11 00:36:10 +02:00
|
|
|
Hertz::khz(kilohertz)
|
2021-05-12 16:46:18 +02:00
|
|
|
}
|
|
|
|
|
2022-07-11 00:36:10 +02:00
|
|
|
/// This is a convenience shortcut for [`Hertz::mhz`]
|
2023-04-13 00:04:44 +02:00
|
|
|
pub const fn mhz(megahertz: u32) -> Hertz {
|
2022-07-11 00:36:10 +02:00
|
|
|
Hertz::mhz(megahertz)
|
2021-05-14 16:11:43 +02:00
|
|
|
}
|
2023-04-06 18:53:51 +02:00
|
|
|
|
|
|
|
impl Mul<u32> for Hertz {
|
|
|
|
type Output = Hertz;
|
|
|
|
fn mul(self, rhs: u32) -> Self::Output {
|
|
|
|
Hertz(self.0 * rhs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Div<u32> for Hertz {
|
|
|
|
type Output = Hertz;
|
|
|
|
fn div(self, rhs: u32) -> Self::Output {
|
|
|
|
Hertz(self.0 / rhs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Mul<u16> for Hertz {
|
|
|
|
type Output = Hertz;
|
|
|
|
fn mul(self, rhs: u16) -> Self::Output {
|
|
|
|
self * (rhs as u32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Div<u16> for Hertz {
|
|
|
|
type Output = Hertz;
|
|
|
|
fn div(self, rhs: u16) -> Self::Output {
|
|
|
|
self / (rhs as u32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Mul<u8> for Hertz {
|
|
|
|
type Output = Hertz;
|
|
|
|
fn mul(self, rhs: u8) -> Self::Output {
|
|
|
|
self * (rhs as u32)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Div<u8> for Hertz {
|
|
|
|
type Output = Hertz;
|
|
|
|
fn div(self, rhs: u8) -> Self::Output {
|
|
|
|
self / (rhs as u32)
|
|
|
|
}
|
|
|
|
}
|
2023-10-11 00:12:33 +02:00
|
|
|
|
|
|
|
impl Div<Hertz> for Hertz {
|
|
|
|
type Output = u32;
|
|
|
|
fn div(self, rhs: Hertz) -> Self::Output {
|
|
|
|
self.0 / rhs.0
|
|
|
|
}
|
|
|
|
}
|