From d029f651fada0b998f6899b92d93ff175fd74571 Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 1 Mar 2021 11:47:55 -0600 Subject: [PATCH 1/2] add us delays --- embassy/src/time/duration.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/embassy/src/time/duration.rs b/embassy/src/time/duration.rs index 8135961ea..2d78c06b2 100644 --- a/embassy/src/time/duration.rs +++ b/embassy/src/time/duration.rs @@ -38,6 +38,15 @@ impl Duration { } } + /* + NOTE: us delays may not be as accurate + */ + pub const fn from_us(millis: u64) -> Duration { + Duration { + ticks: millis * TICKS_PER_SECOND / 1_000_000, + } + } + pub fn checked_add(self, rhs: Duration) -> Option { self.ticks .checked_add(rhs.ticks) From a7549108a8b3ae32273ec3bcc25f8a5c48b7fc98 Mon Sep 17 00:00:00 2001 From: xoviat Date: Mon, 1 Mar 2021 11:59:40 -0600 Subject: [PATCH 2/2] rename methods --- embassy/src/time/duration.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/embassy/src/time/duration.rs b/embassy/src/time/duration.rs index 2d78c06b2..ba8960606 100644 --- a/embassy/src/time/duration.rs +++ b/embassy/src/time/duration.rs @@ -22,6 +22,10 @@ impl Duration { self.ticks * 1000 / TICKS_PER_SECOND } + pub const fn as_micros(&self) -> u64 { + self.ticks * 1_000_000 / TICKS_PER_SECOND + } + pub const fn from_ticks(ticks: u64) -> Duration { Duration { ticks } } @@ -41,7 +45,7 @@ impl Duration { /* NOTE: us delays may not be as accurate */ - pub const fn from_us(millis: u64) -> Duration { + pub const fn from_micros(millis: u64) -> Duration { Duration { ticks: millis * TICKS_PER_SECOND / 1_000_000, }