diff options
| author | Andres O. Vela <[email protected]> | 2024-05-30 22:16:56 +0200 |
|---|---|---|
| committer | Andres O. Vela <[email protected]> | 2024-05-30 22:16:56 +0200 |
| commit | 6eaa25934226ee5ff2038a34e6d32b5d69559c1d (patch) | |
| tree | b732407ca438eaae2b017c5a107c499f81539853 | |
| parent | 694ac3a51573421c90e350c6253e2f42b4ab0bb1 (diff) | |
embassy-time: add timestamp features
| -rw-r--r-- | embassy-time/Cargo.toml | 10 | ||||
| -rw-r--r-- | embassy-time/src/lib.rs | 17 |
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"] | |||
| 27 | std = ["tick-hz-1_000_000", "critical-section/std"] | 27 | std = ["tick-hz-1_000_000", "critical-section/std"] |
| 28 | wasm = ["dep:wasm-bindgen", "dep:js-sys", "dep:wasm-timer", "tick-hz-1_000_000"] | 28 | wasm = ["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. |
| 32 | defmt-timestamp-uptime = ["defmt"] | 34 | defmt-timestamp-uptime = ["defmt"] |
| 35 | defmt-timestamp-uptime-s = ["defmt"] | ||
| 36 | defmt-timestamp-uptime-ms = ["defmt"] | ||
| 37 | defmt-timestamp-uptime-us = ["defmt"] | ||
| 38 | defmt-timestamp-uptime-ts = ["defmt"] | ||
| 39 | defmt-timestamp-uptime-tms = ["defmt"] | ||
| 40 | defmt-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. |
| 35 | mock-driver = ["tick-hz-1_000_000"] | 43 | mock-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); | |||
| 46 | pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000); | 46 | pub(crate) const GCD_1M: u64 = gcd(TICK_HZ, 1_000_000); |
| 47 | pub(crate) const GCD_1G: u64 = gcd(TICK_HZ, 1_000_000_000); | 47 | pub(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")] |
| 50 | defmt::timestamp! {"{=u64}", Instant::now().as_secs() } | ||
| 51 | |||
| 52 | #[cfg(feature = "defmt-timestamp-uptime-ms")] | ||
| 53 | defmt::timestamp! {"{=u64:ms}", Instant::now().as_millis() } | ||
| 54 | |||
| 55 | #[cfg(any(feature = "defmt-timestamp-uptime", feature = "defmt-timestamp-uptime-us"))] | ||
| 50 | defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } | 56 | defmt::timestamp! {"{=u64:us}", Instant::now().as_micros() } |
| 57 | |||
| 58 | #[cfg(feature = "defmt-timestamp-uptime-ts")] | ||
| 59 | defmt::timestamp! {"{=u64:ts}", Instant::now().as_secs() } | ||
| 60 | |||
| 61 | #[cfg(feature = "defmt-timestamp-uptime-tms")] | ||
| 62 | defmt::timestamp! {"{=u64:tms}", Instant::now().as_millis() } | ||
| 63 | |||
| 64 | #[cfg(feature = "defmt-timestamp-uptime-tus")] | ||
| 65 | defmt::timestamp! {"{=u64:tus}", Instant::now().as_micros() } | ||
