@@ -4,7 +4,7 @@ use core::marker;
4
4
use embedded_hal:: delay:: DelayNs ;
5
5
use embedded_hal_v0:: blocking:: delay as delay_v0;
6
6
7
- #[ cfg( all ( target_arch = "avr" , avr_hal_asm_macro ) ) ]
7
+ #[ cfg( target_arch = "avr" ) ]
8
8
use core:: arch:: asm;
9
9
10
10
/// A busy-loop delay implementation
@@ -44,38 +44,24 @@ impl<SPEED> Delay<SPEED> {
44
44
45
45
// based on https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/wiring.c
46
46
47
- cfg_if:: cfg_if! {
48
- if #[ cfg( all( target_arch = "avr" , avr_hal_asm_macro) ) ] {
49
- #[ allow( unused_assignments) ]
50
- fn busy_loop( mut c: u16 ) {
51
- unsafe {
52
- asm!(
53
- "1:" ,
54
- "sbiw {c}, 1" ,
55
- "brne 1b" ,
56
- c = inout( reg_iw) c,
57
- ) ;
58
- }
59
- }
60
- } else if #[ cfg( target_arch = "avr" ) ] {
61
- #[ allow( unused_assignments) ]
62
- fn busy_loop( mut c: u16 ) {
63
- unsafe {
64
- llvm_asm!( "1: sbiw $0,1\n \t brne 1b"
65
- : "=w" ( c)
66
- : "0" ( c)
67
- :
68
- : "volatile"
69
- ) ;
70
- }
71
- }
72
- } else {
73
- fn busy_loop( _c: u16 ) {
74
- unimplemented!( "Implementation is only available for avr targets!" )
75
- }
47
+ #[ cfg( target_arch = "avr" ) ]
48
+ #[ allow( unused_assignments) ]
49
+ fn busy_loop ( mut c : u16 ) {
50
+ unsafe {
51
+ asm ! (
52
+ "1:" ,
53
+ "sbiw {c}, 1" ,
54
+ "brne 1b" ,
55
+ c = inout( reg_iw) c,
56
+ ) ;
76
57
}
77
58
}
78
59
60
+ #[ cfg( not( target_arch = "avr" ) ) ]
61
+ fn busy_loop ( _c : u16 ) {
62
+ unimplemented ! ( "Implementation is only available for avr targets!" )
63
+ }
64
+
79
65
// Clock-Specific Delay Implementations ----------------------------------- {{{
80
66
impl delay_v0:: DelayUs < u16 > for Delay < crate :: clock:: MHz24 > {
81
67
fn delay_us ( & mut self , mut us : u16 ) {
@@ -106,16 +92,11 @@ impl delay_v0::DelayUs<u16> for Delay<crate::clock::MHz20> {
106
92
107
93
// for a one-microsecond delay, simply return. the overhead
108
94
// of the function call takes 18 (20) cycles, which is 1us
109
- #[ cfg( all ( target_arch = "avr" , avr_hal_asm_macro ) ) ]
95
+ #[ cfg( target_arch = "avr" ) ]
110
96
unsafe {
111
97
asm ! ( "nop" , "nop" , "nop" , "nop" ) ;
112
98
}
113
99
114
- #[ cfg( all( target_arch = "avr" , not( avr_hal_asm_macro) ) ) ]
115
- unsafe {
116
- llvm_asm ! ( "nop\n nop\n nop\n nop" :: :: "volatile" ) ;
117
- }
118
-
119
100
if us <= 1 {
120
101
return ;
121
102
} // = 3 cycles, (4 when true)
0 commit comments