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 = "cmsdk")]
27pub mod driver_cmsdk;
28#[cfg(feature = "std")]
29mod driver_std;
30#[cfg(feature = "wasm")]
31mod driver_wasm;
32
33pub use delay::{Delay, block_for, try_block_for};
34pub use duration::Duration;
35pub use embassy_time_driver::TICK_HZ;
36pub use instant::Instant;
37pub use timer::{Ticker, TimeoutError, Timer, WithTimeout, try_with_timeout, with_deadline, with_timeout};
38
39const fn gcd(a: u64, b: u64) -> u64 {
40 if b == 0 { a } else { gcd(b, a % b) }
41}
42
43pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000);
44pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000);
45pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000);
46
47#[cfg(feature = "defmt-timestamp-uptime-s")]
48defmt::timestamp! {"{=u64}", Instant::now().as_secs() }
49
50#[cfg(feature = "defmt-timestamp-uptime-ms")]
51defmt::timestamp! {"{=u64:ms}", Instant::now().as_millis() }
52
53#[cfg(any(feature = "defmt-timestamp-uptime", feature = "defmt-timestamp-uptime-us"))]
54defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() }
55
56#[cfg(feature = "defmt-timestamp-uptime-ts")]
57defmt::timestamp! {"{=u64:ts}", Instant::now().as_secs() }
58
59#[cfg(feature = "defmt-timestamp-uptime-tms")]
60defmt::timestamp! {"{=u64:tms}", Instant::now().as_millis() }
61
62#[cfg(feature = "defmt-timestamp-uptime-tus")]
63defmt::timestamp! {"{=u64:tus}", Instant::now().as_micros() }