From 16bb678368c7e781e8f4df867669727fe7988c42 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 12 Jul 2021 03:31:56 +0200 Subject: [PATCH] Merge BlockingTimer and Delay --- embassy/src/time/delay.rs | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/embassy/src/time/delay.rs b/embassy/src/time/delay.rs index f8b7f840..c97e8b5c 100644 --- a/embassy/src/time/delay.rs +++ b/embassy/src/time/delay.rs @@ -2,7 +2,13 @@ use core::future::Future; use super::{Duration, Instant, Timer}; -/// Async or blocking delay. +/// Type implementing async delays and blocking `embedded-hal` delays. +/// +/// For this interface to work, the Executor's clock must be correctly initialized before using it. +/// The delays are implemented in a "best-effort" way, meaning that the cpu will block for at least +/// the amount provided, but accuracy can be affected by many factors, including interrupt usage. +/// Make sure to use a suitable tick rate for your use case. The tick rate can be chosen through +/// features flags of this crate. pub struct Delay; impl crate::traits::delay::Delay for Delay { @@ -16,46 +22,37 @@ impl crate::traits::delay::Delay for Delay { } } -/// Type used for blocking delays through embedded-hal traits. -/// -/// For this interface to work, the Executor's clock must be correctly initialized before using it. -/// The delays are implemented in a "best-effort" way, meaning that the cpu will block for at least -/// the amount provided, but accuracy can be affected by many factors, including interrupt usage. -/// Make sure to use a suitable tick rate for your use case. The tick rate can be chosen through -/// features flags of this crate. -pub struct BlockingTimer; - -impl embedded_hal::blocking::delay::DelayMs for BlockingTimer { +impl embedded_hal::blocking::delay::DelayMs for Delay { fn delay_ms(&mut self, ms: u8) { block_for(Duration::from_millis(ms as u64)) } } -impl embedded_hal::blocking::delay::DelayMs for BlockingTimer { +impl embedded_hal::blocking::delay::DelayMs for Delay { fn delay_ms(&mut self, ms: u16) { block_for(Duration::from_millis(ms as u64)) } } -impl embedded_hal::blocking::delay::DelayMs for BlockingTimer { +impl embedded_hal::blocking::delay::DelayMs for Delay { fn delay_ms(&mut self, ms: u32) { block_for(Duration::from_millis(ms as u64)) } } -impl embedded_hal::blocking::delay::DelayUs for BlockingTimer { +impl embedded_hal::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u8) { block_for(Duration::from_micros(us as u64)) } } -impl embedded_hal::blocking::delay::DelayUs for BlockingTimer { +impl embedded_hal::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u16) { block_for(Duration::from_micros(us as u64)) } } -impl embedded_hal::blocking::delay::DelayUs for BlockingTimer { +impl embedded_hal::blocking::delay::DelayUs for Delay { fn delay_us(&mut self, us: u32) { block_for(Duration::from_micros(us as u64)) }