aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres O. Vela <[email protected]>2024-05-30 22:16:56 +0200
committerAndres O. Vela <[email protected]>2024-05-30 22:16:56 +0200
commit6eaa25934226ee5ff2038a34e6d32b5d69559c1d (patch)
treeb732407ca438eaae2b017c5a107c499f81539853
parent694ac3a51573421c90e350c6253e2f42b4ab0bb1 (diff)
embassy-time: add timestamp features
-rw-r--r--embassy-time/Cargo.toml10
-rw-r--r--embassy-time/src/lib.rs17
2 files changed, 25 insertions, 2 deletions
diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml
index ca7ad2d09..ce3f3d8c2 100644
--- a/embassy-time/Cargo.toml
+++ b/embassy-time/Cargo.toml
@@ -27,9 +27,17 @@ features = ["defmt", "std"]
27std = ["tick-hz-1_000_000", "critical-section/std"] 27std = ["tick-hz-1_000_000", "critical-section/std"]
28wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-hz-1_000_000"] 28wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-hz-1_000_000"]
29 29
30## Display a timestamp of the number of seconds since startup next to defmt log messages 30## Display the time since startup next to defmt log messages.
31## At most 1 `defmt-timestamp-uptime-*` feature can be used.
32## `defmt-timestamp-uptime` is provided for backwards compatibility (provides the same format as `uptime-us`).
31## To use this you must have a time driver provided. 33## To use this you must have a time driver provided.
32defmt-timestamp-uptime = ["defmt"] 34defmt-timestamp-uptime = ["defmt"]
35defmt-timestamp-uptime-s = ["defmt"]
36defmt-timestamp-uptime-ms = ["defmt"]
37defmt-timestamp-uptime-us = ["defmt"]
38defmt-timestamp-uptime-ts = ["defmt"]
39defmt-timestamp-uptime-tms = ["defmt"]
40defmt-timestamp-uptime-tus = ["defmt"]
33 41
34## Create a `MockDriver` that can be manually advanced for testing purposes. 42## Create a `MockDriver` that can be manually advanced for testing purposes.
35mock-driver = ["tick-hz-1_000_000"] 43mock-driver = ["tick-hz-1_000_000"]
diff --git a/embassy-time/src/lib.rs b/embassy-time/src/lib.rs
index 3c8575ee9..24ee51be7 100644
--- a/embassy-time/src/lib.rs
+++ b/embassy-time/src/lib.rs
@@ -46,5 +46,20 @@ pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000);
46pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000); 46pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000);
47pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000); 47pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000);
48 48
49#[cfg(feature = "defmt-timestamp-uptime")] 49#[cfg(feature = "defmt-timestamp-uptime-s")]
50defmt::timestamp! {"{=u64}", Instant::now().as_secs() }
51
52#[cfg(feature = "defmt-timestamp-uptime-ms")]
53defmt::timestamp! {"{=u64:ms}", Instant::now().as_millis() }
54
55#[cfg(any(feature = "defmt-timestamp-uptime", feature = "defmt-timestamp-uptime-us"))]
50defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } 56defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() }
57
58#[cfg(feature = "defmt-timestamp-uptime-ts")]
59defmt::timestamp! {"{=u64:ts}", Instant::now().as_secs() }
60
61#[cfg(feature = "defmt-timestamp-uptime-tms")]
62defmt::timestamp! {"{=u64:tms}", Instant::now().as_millis() }
63
64#[cfg(feature = "defmt-timestamp-uptime-tus")]
65defmt::timestamp! {"{=u64:tus}", Instant::now().as_micros() }