3
3
use crate :: clock:: Clocks ;
4
4
use crate :: core:: clint:: { MTIME , MTIMECMP } ;
5
5
use core:: convert:: Infallible ;
6
- use embedded_hal:: blocking :: delay :: { DelayMs , DelayUs } ;
6
+ use embedded_hal:: delay :: blocking :: DelayUs ;
7
7
use riscv:: register:: { mie, mip} ;
8
8
9
9
/// Machine timer (mtime) as a busyloop delay provider
@@ -18,10 +18,10 @@ impl Delay {
18
18
}
19
19
}
20
20
21
- impl DelayUs < u32 > for Delay {
21
+ impl DelayUs for Delay {
22
22
type Error = Infallible ;
23
23
24
- fn try_delay_us ( & mut self , us : u32 ) -> Result < ( ) , Infallible > {
24
+ fn delay_us ( & mut self , us : u32 ) -> Result < ( ) , Infallible > {
25
25
let ticks = ( us as u64 ) * TICKS_PER_SECOND / 1_000_000 ;
26
26
27
27
let mtime = MTIME ;
@@ -31,72 +31,6 @@ impl DelayUs<u32> for Delay {
31
31
}
32
32
}
33
33
34
- // This is a workaround to allow `delay_us(42)` construction without specifying a type.
35
- impl DelayUs < i32 > for Delay {
36
- type Error = Infallible ;
37
-
38
- #[ inline( always) ]
39
- fn try_delay_us ( & mut self , us : i32 ) -> Result < ( ) , Infallible > {
40
- assert ! ( us >= 0 ) ;
41
- self . try_delay_us ( us as u32 )
42
- }
43
- }
44
-
45
- impl DelayUs < u16 > for Delay {
46
- type Error = Infallible ;
47
-
48
- #[ inline( always) ]
49
- fn try_delay_us ( & mut self , us : u16 ) -> Result < ( ) , Infallible > {
50
- self . try_delay_us ( u32:: from ( us) )
51
- }
52
- }
53
-
54
- impl DelayUs < u8 > for Delay {
55
- type Error = Infallible ;
56
-
57
- #[ inline( always) ]
58
- fn try_delay_us ( & mut self , us : u8 ) -> Result < ( ) , Infallible > {
59
- self . try_delay_us ( u32:: from ( us) )
60
- }
61
- }
62
-
63
- impl DelayMs < u32 > for Delay {
64
- type Error = Infallible ;
65
-
66
- fn try_delay_ms ( & mut self , ms : u32 ) -> Result < ( ) , Infallible > {
67
- self . try_delay_us ( ms * 1000 )
68
- }
69
- }
70
-
71
- // This is a workaround to allow `delay_ms(42)` construction without specifying a type.
72
- impl DelayMs < i32 > for Delay {
73
- type Error = Infallible ;
74
-
75
- #[ inline( always) ]
76
- fn try_delay_ms ( & mut self , ms : i32 ) -> Result < ( ) , Infallible > {
77
- assert ! ( ms >= 0 ) ;
78
- self . try_delay_ms ( ms as u32 )
79
- }
80
- }
81
-
82
- impl DelayMs < u16 > for Delay {
83
- type Error = Infallible ;
84
-
85
- #[ inline( always) ]
86
- fn try_delay_ms ( & mut self , ms : u16 ) -> Result < ( ) , Infallible > {
87
- self . try_delay_ms ( u32:: from ( ms) )
88
- }
89
- }
90
-
91
- impl DelayMs < u8 > for Delay {
92
- type Error = Infallible ;
93
-
94
- #[ inline( always) ]
95
- fn try_delay_ms ( & mut self , ms : u8 ) -> Result < ( ) , Infallible > {
96
- self . try_delay_ms ( u32:: from ( ms) )
97
- }
98
- }
99
-
100
34
/// Machine timer (mtime) as a sleep delay provider using mtimecmp
101
35
pub struct Sleep {
102
36
clock_freq : u32 ,
@@ -113,11 +47,11 @@ impl Sleep {
113
47
}
114
48
}
115
49
116
- impl DelayMs < u32 > for Sleep {
50
+ impl DelayUs for Sleep {
117
51
type Error = Infallible ;
118
52
119
- fn try_delay_ms ( & mut self , ms : u32 ) -> Result < ( ) , Infallible > {
120
- let ticks = ( ms as u64 ) * ( self . clock_freq as u64 ) / 1000 ;
53
+ fn delay_us ( & mut self , us : u32 ) -> Result < ( ) , Infallible > {
54
+ let ticks = ( us as u64 ) * ( self . clock_freq as u64 ) / 1_000_000 ;
121
55
let t = MTIME . mtime ( ) + ticks;
122
56
123
57
self . mtimecmp . set_mtimecmp ( t) ;
@@ -150,32 +84,3 @@ impl DelayMs<u32> for Sleep {
150
84
Ok ( ( ) )
151
85
}
152
86
}
153
-
154
- // This is a workaround to allow `delay_ms(42)` construction without specifying a type.
155
- impl DelayMs < i32 > for Sleep {
156
- type Error = Infallible ;
157
-
158
- #[ inline( always) ]
159
- fn try_delay_ms ( & mut self , ms : i32 ) -> Result < ( ) , Infallible > {
160
- assert ! ( ms >= 0 ) ;
161
- self . try_delay_ms ( ms as u32 )
162
- }
163
- }
164
-
165
- impl DelayMs < u16 > for Sleep {
166
- type Error = Infallible ;
167
-
168
- #[ inline( always) ]
169
- fn try_delay_ms ( & mut self , ms : u16 ) -> Result < ( ) , Infallible > {
170
- self . try_delay_ms ( u32:: from ( ms) )
171
- }
172
- }
173
-
174
- impl DelayMs < u8 > for Sleep {
175
- type Error = Infallible ;
176
-
177
- #[ inline( always) ]
178
- fn try_delay_ms ( & mut self , ms : u8 ) -> Result < ( ) , Infallible > {
179
- self . try_delay_ms ( u32:: from ( ms) )
180
- }
181
- }
0 commit comments