1#![cfg_attr(not(any(feature = "std", feature = "wasm", test)), no_std)]
2#![allow(async_fn_in_trait)]
3#![allow(unsafe_op_in_unsafe_fn)]
4#![doc = include_str!("../README.md")]
5#![allow(clippy::new_without_default)]
6#![warn(missing_docs)]
7#![deny(missing_debug_implementations)]
8
9#![doc = document_features::document_features!(feature_label = r#"<span class="stab portability"><code>{feature}</code></span>"#)]
11
12pub(crate) mod fmt;
14
15mod delay;
16mod duration;
17mod instant;
18mod timer;
19
20#[cfg(feature = "mock-driver")]
21mod driver_mock;
22
23#[cfg(feature = "mock-driver")]
24pub use driver_mock::MockDriver;
25
26#[cfg(feature = "std")]
27mod driver_std;
28#[cfg(feature = "wasm")]
29mod driver_wasm;
30
31pub use delay::{Delay, block_for};
32pub use duration::Duration;
33pub use embassy_time_driver::TICK_HZ;
34pub use instant::Instant;
35pub use timer::{Ticker, TimeoutError, Timer, WithTimeout, with_deadline, with_timeout};
36
37const fn gcd(a: u64, b: u64) -> u64 {
38 if b == 0 { a } else { gcd(b, a % b) }
39}
40
41pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000);
42pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000);
43pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000);
44
45#[cfg(feature = "defmt-timestamp-uptime-s")]
46defmt::timestamp! {"{=u64}", Instant::now().as_secs() }
47
48#[cfg(feature = "defmt-timestamp-uptime-ms")]
49defmt::timestamp! {"{=u64:ms}", Instant::now().as_millis() }
50
51#[cfg(any(feature = "defmt-timestamp-uptime", feature = "defmt-timestamp-uptime-us"))]
52defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() }
53
54#[cfg(feature = "defmt-timestamp-uptime-ts")]
55defmt::timestamp! {"{=u64:ts}", Instant::now().as_secs() }
56
57#[cfg(feature = "defmt-timestamp-uptime-tms")]
58defmt::timestamp! {"{=u64:tms}", Instant::now().as_millis() }
59
60#[cfg(feature = "defmt-timestamp-uptime-tus")]
61defmt::timestamp! {"{=u64:tus}", Instant::now().as_micros() }