diff options
| author | Daniel Franklin <[email protected]> | 2022-02-11 18:45:23 -0700 |
|---|---|---|
| committer | Daniel Franklin <[email protected]> | 2022-02-11 18:45:23 -0700 |
| commit | 4c5f5f71693600d133d3416634169acdf0042ff7 (patch) | |
| tree | 869798a7e15b95fe21142e35e4ecbb9e9dc08b11 | |
| parent | f2eb4389055ae6cf135168c1e5cb6ccd27800d63 (diff) | |
Add feature defmt-timestamp-uptime
Enabling it adds a timestamp of the number of seconds since startup next
to defmt log messages using `Instant::now`.
| -rw-r--r-- | embassy/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy/src/fmt.rs | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/embassy/Cargo.toml b/embassy/Cargo.toml index d10a8874e..9a5467c6f 100644 --- a/embassy/Cargo.toml +++ b/embassy/Cargo.toml | |||
| @@ -17,6 +17,10 @@ nightly = ["embedded-hal-async"] | |||
| 17 | # Implement embedded-hal-async traits if `nightly` is set as well. | 17 | # Implement embedded-hal-async traits if `nightly` is set as well. |
| 18 | unstable-traits = ["embedded-hal-1"] | 18 | unstable-traits = ["embedded-hal-1"] |
| 19 | 19 | ||
| 20 | # Display a timestamp of the number of seconds since startup next to defmt log messages | ||
| 21 | # To use this you must have a time driver provided. | ||
| 22 | defmt-timestamp-uptime = ["defmt"] | ||
| 23 | |||
| 20 | # Enable `embassy::time` module. | 24 | # Enable `embassy::time` module. |
| 21 | # NOTE: This feature is only intended to be enabled by crates providing the time driver implementation. | 25 | # NOTE: This feature is only intended to be enabled by crates providing the time driver implementation. |
| 22 | # Enabling it directly without supplying a time driver will fail to link. | 26 | # Enabling it directly without supplying a time driver will fail to link. |
diff --git a/embassy/src/fmt.rs b/embassy/src/fmt.rs index 066970813..115febb58 100644 --- a/embassy/src/fmt.rs +++ b/embassy/src/fmt.rs | |||
| @@ -195,6 +195,10 @@ macro_rules! unwrap { | |||
| 195 | } | 195 | } |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | #[cfg(feature = "defmt-timestamp-uptime")] | ||
| 199 | // defmt offers a disply hint for microseconds so we convert from millis | ||
| 200 | defmt::timestamp! {"{=u64:us}", crate::time::Instant::now().as_millis() * 1_000 } | ||
| 201 | |||
| 198 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] | 202 | #[derive(Debug, Copy, Clone, Eq, PartialEq)] |
| 199 | pub struct NoneError; | 203 | pub struct NoneError; |
| 200 | 204 | ||
