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