aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-07-12 03:31:56 +0200
committerDario Nieuwenhuis <[email protected]>2021-07-12 03:45:48 +0200
commit16bb678368c7e781e8f4df867669727fe7988c42 (patch)
tree483e65f11b03764b99e3a2d5587fdb6b50dc89c2
parent35a76c364a90cae23a2a1e72e1d084c226048915 (diff)
Merge BlockingTimer and Delay
-rw-r--r--embassy/src/time/delay.rs29
1 files changed, 13 insertions, 16 deletions
diff --git a/embassy/src/time/delay.rs b/embassy/src/time/delay.rs
index f8b7f8400..c97e8b5c2 100644
--- a/embassy/src/time/delay.rs
+++ b/embassy/src/time/delay.rs
@@ -2,7 +2,13 @@ use core::future::Future;
2 2
3use super::{Duration, Instant, Timer}; 3use super::{Duration, Instant, Timer};
4 4
5/// Async or blocking delay. 5/// Type implementing async delays and blocking `embedded-hal` delays.
6///
7/// For this interface to work, the Executor's clock must be correctly initialized before using it.
8/// The delays are implemented in a "best-effort" way, meaning that the cpu will block for at least
9/// the amount provided, but accuracy can be affected by many factors, including interrupt usage.
10/// Make sure to use a suitable tick rate for your use case. The tick rate can be chosen through
11/// features flags of this crate.
6pub struct Delay; 12pub struct Delay;
7 13
8impl crate::traits::delay::Delay for Delay { 14impl crate::traits::delay::Delay for Delay {
@@ -16,46 +22,37 @@ impl crate::traits::delay::Delay for Delay {
16 } 22 }
17} 23}
18 24
19/// Type used for blocking delays through embedded-hal traits. 25impl embedded_hal::blocking::delay::DelayMs<u8> for Delay {
20///
21/// For this interface to work, the Executor's clock must be correctly initialized before using it.
22/// The delays are implemented in a "best-effort" way, meaning that the cpu will block for at least
23/// the amount provided, but accuracy can be affected by many factors, including interrupt usage.
24/// Make sure to use a suitable tick rate for your use case. The tick rate can be chosen through
25/// features flags of this crate.
26pub struct BlockingTimer;
27
28impl embedded_hal::blocking::delay::DelayMs<u8> for BlockingTimer {
29 fn delay_ms(&mut self, ms: u8) { 26 fn delay_ms(&mut self, ms: u8) {
30 block_for(Duration::from_millis(ms as u64)) 27 block_for(Duration::from_millis(ms as u64))
31 } 28 }
32} 29}
33 30
34impl embedded_hal::blocking::delay::DelayMs<u16> for BlockingTimer { 31impl embedded_hal::blocking::delay::DelayMs<u16> for Delay {
35 fn delay_ms(&mut self, ms: u16) { 32 fn delay_ms(&mut self, ms: u16) {
36 block_for(Duration::from_millis(ms as u64)) 33 block_for(Duration::from_millis(ms as u64))
37 } 34 }
38} 35}
39 36
40impl embedded_hal::blocking::delay::DelayMs<u32> for BlockingTimer { 37impl embedded_hal::blocking::delay::DelayMs<u32> for Delay {
41 fn delay_ms(&mut self, ms: u32) { 38 fn delay_ms(&mut self, ms: u32) {
42 block_for(Duration::from_millis(ms as u64)) 39 block_for(Duration::from_millis(ms as u64))
43 } 40 }
44} 41}
45 42
46impl embedded_hal::blocking::delay::DelayUs<u8> for BlockingTimer { 43impl embedded_hal::blocking::delay::DelayUs<u8> for Delay {
47 fn delay_us(&mut self, us: u8) { 44 fn delay_us(&mut self, us: u8) {
48 block_for(Duration::from_micros(us as u64)) 45 block_for(Duration::from_micros(us as u64))
49 } 46 }
50} 47}
51 48
52impl embedded_hal::blocking::delay::DelayUs<u16> for BlockingTimer { 49impl embedded_hal::blocking::delay::DelayUs<u16> for Delay {
53 fn delay_us(&mut self, us: u16) { 50 fn delay_us(&mut self, us: u16) {
54 block_for(Duration::from_micros(us as u64)) 51 block_for(Duration::from_micros(us as u64))
55 } 52 }
56} 53}
57 54
58impl embedded_hal::blocking::delay::DelayUs<u32> for BlockingTimer { 55impl embedded_hal::blocking::delay::DelayUs<u32> for Delay {
59 fn delay_us(&mut self, us: u32) { 56 fn delay_us(&mut self, us: u32) {
60 block_for(Duration::from_micros(us as u64)) 57 block_for(Duration::from_micros(us as u64))
61 } 58 }