1
1
use crate :: register:: mcycle;
2
- use embedded_hal:: blocking:: delay:: { DelayMs , DelayUs } ;
2
+ use core:: convert:: Infallible ;
3
+ use embedded_hal:: delay:: blocking:: DelayUs ;
3
4
4
5
/// Machine mode cycle counter (`mcycle`) as a delay provider
5
6
#[ derive( Copy , Clone ) ]
@@ -15,71 +16,14 @@ impl McycleDelay {
15
16
}
16
17
}
17
18
18
- impl DelayUs < u64 > for McycleDelay {
19
+ impl DelayUs for McycleDelay {
20
+ type Error = Infallible ;
21
+
19
22
#[ inline]
20
- fn delay_us ( & mut self , us : u64 ) {
23
+ fn delay_us ( & mut self , us : u32 ) -> Result < ( ) , Self :: Error > {
21
24
let t0 = mcycle:: read64 ( ) ;
22
- let clock = ( us * ( self . ticks_second as u64 ) ) / 1_000_000 ;
25
+ let clock = ( ( us as u64 ) * ( self . ticks_second as u64 ) ) / 1_000_000 ;
23
26
while mcycle:: read64 ( ) . wrapping_sub ( t0) <= clock { }
24
- }
25
- }
26
-
27
- impl DelayUs < u32 > for McycleDelay {
28
- #[ inline( always) ]
29
- fn delay_us ( & mut self , us : u32 ) {
30
- self . delay_us ( us as u64 )
31
- }
32
- }
33
-
34
- // Implemented for constructions like `delay.delay_us(50_000);`
35
- impl DelayUs < i32 > for McycleDelay {
36
- #[ inline( always) ]
37
- fn delay_us ( & mut self , us : i32 ) {
38
- assert ! ( us >= 0 ) ;
39
- self . delay_us ( us as u32 ) ;
40
- }
41
- }
42
-
43
- impl DelayUs < u16 > for McycleDelay {
44
- #[ inline( always) ]
45
- fn delay_us ( & mut self , us : u16 ) {
46
- self . delay_us ( us as u32 )
47
- }
48
- }
49
-
50
- impl DelayUs < u8 > for McycleDelay {
51
- #[ inline( always) ]
52
- fn delay_us ( & mut self , us : u8 ) {
53
- self . delay_us ( us as u32 )
54
- }
55
- }
56
-
57
- impl DelayMs < u32 > for McycleDelay {
58
- #[ inline]
59
- fn delay_ms ( & mut self , ms : u32 ) {
60
- self . delay_us ( ( ms as u64 ) * 1000 )
61
- }
62
- }
63
-
64
- // Implemented for constructions like `delay.delay_ms(50_000);`
65
- impl DelayMs < i32 > for McycleDelay {
66
- #[ inline( always) ]
67
- fn delay_ms ( & mut self , ms : i32 ) {
68
- assert ! ( ms >= 0 ) ;
69
- self . delay_ms ( ms as u32 ) ;
70
- }
71
- }
72
-
73
- impl DelayMs < u16 > for McycleDelay {
74
- #[ inline( always) ]
75
- fn delay_ms ( & mut self , ms : u16 ) {
76
- self . delay_ms ( ms as u32 )
77
- }
78
- }
79
-
80
- impl DelayMs < u8 > for McycleDelay {
81
- #[ inline( always) ]
82
- fn delay_ms ( & mut self , ms : u8 ) {
83
- self . delay_ms ( ms as u32 )
27
+ Ok ( ( ) )
84
28
}
85
29
}
0 commit comments