gd32e2_hal/time.rs
1//! Typed units for frequencies and durations, aliased from `fugit`.
2//!
3//! This module names the `u32` instances of [`fugit`]; `u64` is not aliased.
4//!
5//! The generic [`Duration`] and [`Rate`] are re-exported for signatures that
6//! stay open to any scale, as are the suffix traits: [`ExtU32`] for durations
7//! and [`RateExtU32`] for frequencies, joined by [`BpsExtU32`] for bit rates,
8//! which `fugit` has no suffix for. The whole crate is re-exported too, so
9//! `Instant`, the tick-based `TimerDuration` and the `u64` widths are reachable
10//! without adding a matching dependency downstream.
11//!
12//! ```ignore
13//! use gd32e2_hal::time::ExtU32;
14//! let period = 5.secs();
15//! ```
16
17pub use fugit;
18pub use fugit::{Duration, ExtU32, Rate, RateExtU32};
19
20/// Frequency in hertz.
21pub type Hertz = fugit::HertzU32;
22/// Frequency in kilohertz.
23pub type Kilohertz = fugit::KilohertzU32;
24/// Frequency in megahertz.
25pub type Megahertz = fugit::MegahertzU32;
26/// Frequency in gigahertz.
27pub type Gigahertz = fugit::GigahertzU32;
28
29/// Bit rate in symbols per second.
30///
31/// The very same type as [`Hertz`], a bit rate being a rate on the one-second
32/// scale: the name reads right in a signature but checks nothing, and a clock
33/// frequency passed as a bit rate still compiles.
34pub type Bps = fugit::Rate<u32, 1, 1>;
35
36/// Duration in picoseconds.
37pub type PicosDuration = fugit::PicosDurationU32;
38/// Duration in nanoseconds.
39pub type NanosDuration = fugit::NanosDurationU32;
40/// Duration in microseconds.
41pub type MicrosDuration = fugit::MicrosDurationU32;
42/// Duration in milliseconds.
43pub type MillisDuration = fugit::MillisDurationU32;
44/// Duration in seconds.
45pub type SecsDuration = fugit::SecsDurationU32;
46/// Duration in minutes.
47pub type MinutesDuration = fugit::MinutesDurationU32;
48/// Duration in hours.
49pub type HoursDuration = fugit::HoursDurationU32;
50
51/// Suffix for bit rates: `115_200.bps()`.
52pub trait BpsExtU32 {
53 /// Reads the number as symbols per second.
54 fn bps(self) -> Bps;
55}
56
57impl BpsExtU32 for u32 {
58 fn bps(self) -> Bps {
59 Bps::from_raw(self)
60 }
61}