embedded-time
provides a comprehensive library implementing duration, rate, instant, and software timer types as well as a clock trait for abstracting over hardware timers/clocks.
Units | Extension |
---|---|
Hours | hours |
Minutes | minutes |
Seconds | seconds |
Milliseconds | milliseconds |
Microseconds | microseconds |
Nanoseconds | nanoseconds |
-
Conversion from
Rate
typesMicroseconds::<u32>::try_from_rate(Kilohertz(2_u32)) -> Ok(Microseconds(500_u32))
-
Conversion to/from
Generic
Duration
typeSeconds(2_u64).try_into_generic(Fraction::new(1, 2_000)) -> Ok(Generic::new(4_000_u32, Fraction::new(1, 2_000)))) Seconds::<u64>::try_from(Generic::new(2_000_u32, Fraction::new(1, 1_000))) -> Ok(Seconds(2_u64))
- Conversion to/from
core::time::Duration
let duration = Milliseconds::<u64>(ms); // 8 bytes
let count = duration.count();
(the size of embedded-time
duration types is only the size of the inner type)
let core_duration = Duration::from_millis(ms); // 12 bytes
let count = core_duration.as_millis();
(the size of core
duration type is 12 B)
Units | Extension |
---|---|
Megahertz | MHz |
Kilohertz | kHz |
Hertz | Hz |
MebibytePerSecond | MiBps |
MegabytePerSecond | MBps |
KibibytePerSecond | KiBps |
KiloBytePerSecond | KBps |
BytePerSecond | Bps |
MebibitPerSecond | Mibps |
MegabitPerSecond | Mbps |
KibibitPerSecond | Kibps |
KilobitPerSecond | kbps |
BitPerSecond | bps |
Mebibaud | MiBd |
Megabaud | MBd |
Kibibaud | KiBd |
Kilobaud | kBd |
Baud | Bd |
-
Conversion from
Duration
typesKilohertz::<u32>::try_from_duration(Microseconds(2_u32)) -> Ok(Kilohertz(500_u32))
-
Conversion to/from
Generic
Rate
typeHertz(2_u64).try_into_generic(Fraction::new(1,2_000)) -> Ok(Generic::new(4_000_u32, Fraction::new(1,2_000)))) Hertz::<u64>::try_from(Generic::new(2_000_u32, Fraction::new(1,1_000))) -> Ok(Hertz(2_u64))
Clock
trait allowing abstraction of hardware timers/clocks for timekeeping.
- Software timers spawned from a
Clock
impl object. - One-shot or periodic/continuous
- Blocking delay
- Poll for expiration
- Read elapsed/remaining duration
- Extensive tests
- Thorough documentation with examples
- Example for the nRF52_DK board
This project is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in embedded-time
by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.