Skip to content

Commit 43a5bba

Browse files
authored
Merge pull request #18 from mbuesch/use_rust_asm
Fix build: Use the new rust asm! available in rustc 1.63.0-nightly
2 parents 7925367 + aea1a4b commit 43a5bba

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/lib.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
#![feature(llvm_asm)]
1+
#![feature(asm_experimental_arch)]
22

33
#![no_std]
44

55
#![crate_name = "avr_delay"]
66

7+
use core::arch::asm;
8+
79
/// This library is intended to provide a busy-wait delay
810
/// similar to the one provided by the arduino c++ utilities
911
/// If you need accurate time keeping you should consider a
@@ -31,19 +33,20 @@ pub fn delay(count: u32) {
3133
let last_count = ((count % 65536)+1) as u16;
3234
for _ in 0..outer_count {
3335
// Each loop through should be 4 cycles.
34-
unsafe {llvm_asm!("1: sbiw $0,1
35-
brne 1b"
36-
:
37-
: "w" (0)
38-
:
39-
:)}
36+
let zero = 0u16;
37+
unsafe {
38+
asm!("1: sbiw {i}, 1",
39+
"brne 1b",
40+
i = inout(reg_iw) zero => _,
41+
)
42+
}
43+
}
44+
unsafe {
45+
asm!("1: sbiw {i}, 1",
46+
"brne 1b",
47+
i = inout(reg_iw) last_count => _,
48+
)
4049
}
41-
unsafe {llvm_asm!("1: sbiw $0,1
42-
brne 1b"
43-
:
44-
: "w" (last_count)
45-
:
46-
:)}
4750
}
4851

4952
///delay for N miliseconds

0 commit comments

Comments
 (0)