File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change 1
1
//! Delay devices and providers
2
2
use crate :: register:: mcycle;
3
- use embedded_hal:: delay:: DelayUs ;
3
+ use embedded_hal:: delay:: DelayNs ;
4
4
5
5
/// Machine mode cycle counter (`mcycle`) as a delay provider
6
6
#[ derive( Copy , Clone ) ]
@@ -19,12 +19,17 @@ impl McycleDelay {
19
19
}
20
20
}
21
21
22
- impl DelayUs for McycleDelay {
22
+ impl DelayNs for McycleDelay {
23
23
#[ inline]
24
24
fn delay_us ( & mut self , us : u32 ) {
25
+ self . delay_ns ( us * 1000 )
26
+ }
27
+
28
+ #[ inline]
29
+ fn delay_ns ( & mut self , ns : u32 ) {
25
30
let t0 = mcycle:: read64 ( ) ;
26
- let us_64: u64 = us . into ( ) ;
27
- let clock = ( us_64 * ( self . ticks_second as u64 ) ) / 1_000_000u64 ;
31
+ let us_64: u64 = ns . into ( ) ;
32
+ let clock = ( us_64 * ( self . ticks_second as u64 ) ) / 1_000_000_000u64 ;
28
33
while mcycle:: read64 ( ) . wrapping_sub ( t0) <= clock { }
29
- }
34
+ }
30
35
}
You can’t perform that action at this time.
0 commit comments