embassy-time: add timestamp features

This commit is contained in:
Andres O. Vela 2024-05-30 22:16:56 +02:00
parent 694ac3a515
commit 6eaa259342
2 changed files with 25 additions and 2 deletions

View File

@ -27,9 +27,17 @@ features = ["defmt", "std"]
std = ["tick-hz-1_000_000", "critical-section/std"] std = ["tick-hz-1_000_000", "critical-section/std"]
wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-hz-1_000_000"] wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-hz-1_000_000"]
## Display a timestamp of the number of seconds since startup next to defmt log messages ## Display the time since startup next to defmt log messages.
## At most 1 `defmt-timestamp-uptime-*` feature can be used.
## `defmt-timestamp-uptime` is provided for backwards compatibility (provides the same format as `uptime-us`).
## To use this you must have a time driver provided. ## To use this you must have a time driver provided.
defmt-timestamp-uptime = ["defmt"] defmt-timestamp-uptime = ["defmt"]
defmt-timestamp-uptime-s = ["defmt"]
defmt-timestamp-uptime-ms = ["defmt"]
defmt-timestamp-uptime-us = ["defmt"]
defmt-timestamp-uptime-ts = ["defmt"]
defmt-timestamp-uptime-tms = ["defmt"]
defmt-timestamp-uptime-tus = ["defmt"]
## Create a `MockDriver` that can be manually advanced for testing purposes. ## Create a `MockDriver` that can be manually advanced for testing purposes.
mock-driver = ["tick-hz-1_000_000"] mock-driver = ["tick-hz-1_000_000"]

View File

@ -46,5 +46,20 @@ pub(crate) const GCD_1K: u64 = gcd(TICK_HZ, 1_000);
pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000); pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000);
pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000); pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000);
#[cfg(feature = "defmt-timestamp-uptime")] #[cfg(feature = "defmt-timestamp-uptime-s")]
defmt::timestamp! {"{=u64}", Instant::now().as_secs() }
#[cfg(feature = "defmt-timestamp-uptime-ms")]
defmt::timestamp! {"{=u64:ms}", Instant::now().as_millis() }
#[cfg(any(feature = "defmt-timestamp-uptime", feature = "defmt-timestamp-uptime-us"))]
defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() }
#[cfg(feature = "defmt-timestamp-uptime-ts")]
defmt::timestamp! {"{=u64:ts}", Instant::now().as_secs() }
#[cfg(feature = "defmt-timestamp-uptime-tms")]
defmt::timestamp! {"{=u64:tms}", Instant::now().as_millis() }
#[cfg(feature = "defmt-timestamp-uptime-tus")]
defmt::timestamp! {"{=u64:tus}", Instant::now().as_micros() }