aboutsummaryrefslogtreecommitdiff
path: root/embassy-time/src
diff options
context:
space:
mode:
authorGustav Toft <[email protected]>2024-04-04 15:52:44 +0200
committerGustav Toft <[email protected]>2024-04-04 15:52:44 +0200
commita373633d0dbc352de1b488bf15e383f8ef1d4a8c (patch)
treea4590f26bd3252445e2adfa6d271a6f1cf74d54b /embassy-time/src
parent0427c442ea531673e18da304c7402927589b8d0b (diff)
parent067e422863674762c0ee20178f3671ce16a5986c (diff)
Merge branch 'main' of https://github.com/GustavToft/embassy
Diffstat (limited to 'embassy-time/src')
-rw-r--r--embassy-time/src/fmt.rs3
-rw-r--r--embassy-time/src/timer.rs14
2 files changed, 14 insertions, 3 deletions
diff --git a/embassy-time/src/fmt.rs b/embassy-time/src/fmt.rs
index 78e583c1c..2ac42c557 100644
--- a/embassy-time/src/fmt.rs
+++ b/embassy-time/src/fmt.rs
@@ -1,5 +1,5 @@
1#![macro_use] 1#![macro_use]
2#![allow(unused_macros)] 2#![allow(unused)]
3 3
4use core::fmt::{Debug, Display, LowerHex}; 4use core::fmt::{Debug, Display, LowerHex};
5 5
@@ -229,7 +229,6 @@ impl<T, E> Try for Result<T, E> {
229 } 229 }
230} 230}
231 231
232#[allow(unused)]
233pub(crate) struct Bytes<'a>(pub &'a [u8]); 232pub(crate) struct Bytes<'a>(pub &'a [u8]);
234 233
235impl<'a> Debug for Bytes<'a> { 234impl<'a> Debug for Bytes<'a> {
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs
index daa4c1699..757c3ff00 100644
--- a/embassy-time/src/timer.rs
+++ b/embassy-time/src/timer.rs
@@ -190,8 +190,20 @@ impl Ticker {
190 self.expires_at = Instant::now() + self.duration; 190 self.expires_at = Instant::now() + self.duration;
191 } 191 }
192 192
193 /// Reset the ticker at the deadline.
194 /// If the deadline is in the past, the ticker will fire instantly.
195 pub fn reset_at(&mut self, deadline: Instant) {
196 self.expires_at = deadline + self.duration;
197 }
198
199 /// Resets the ticker, after the specified duration has passed.
200 /// If the specified duration is zero, the next tick will be after the duration of the ticker.
201 pub fn reset_after(&mut self, after: Duration) {
202 self.expires_at = Instant::now() + after + self.duration;
203 }
204
193 /// Waits for the next tick. 205 /// Waits for the next tick.
194 pub fn next(&mut self) -> impl Future<Output = ()> + '_ { 206 pub fn next(&mut self) -> impl Future<Output = ()> + Send + Sync + '_ {
195 poll_fn(|cx| { 207 poll_fn(|cx| {
196 if self.expires_at <= Instant::now() { 208 if self.expires_at <= Instant::now() {
197 let dur = self.duration; 209 let dur = self.duration;