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 11//! Delay devices and providers
22use crate :: register:: mcycle;
3- use embedded_hal:: delay:: DelayUs ;
3+ use embedded_hal:: delay:: DelayNs ;
44
55/// Machine mode cycle counter (`mcycle`) as a delay provider
66#[ derive( Copy , Clone ) ]
@@ -19,12 +19,17 @@ impl McycleDelay {
1919 }
2020}
2121
22- impl DelayUs for McycleDelay {
22+ impl DelayNs for McycleDelay {
2323 #[ inline]
2424 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 ) {
2530 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 ;
2833 while mcycle:: read64 ( ) . wrapping_sub ( t0) <= clock { }
29- }
34+ }
3035}
You can’t perform that action at this time.
0 commit comments