Skip to content

Commit

Permalink
avr-hal-generic: remove rustc version check
Browse files Browse the repository at this point in the history
The build.rs logic is only used to detect a relatively old compiler
version (Feb 2022). Since a nightly build is required to target AVR it's
unlikely anyone is benefiting from this check.  By removing it we reduce
dependencies and implementation complexity.
  • Loading branch information
tones111 authored and Rahix committed Jan 4, 2025
1 parent 949130a commit b417d5c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 58 deletions.
4 changes: 0 additions & 4 deletions avr-hal-generic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ features = ["docsrs"]
docsrs = ["avr-device/docsrs"]

[dependencies]
cfg-if = "1"
nb = "1.1.0"
ufmt = "0.2.0"
paste = "1.0.0"
Expand All @@ -31,6 +30,3 @@ unwrap-infallible = "0.1.5"
version = "0.2.3"
package = "embedded-hal"
features = ["unproven"]

[build-dependencies]
rustversion = "1.0"
16 changes: 0 additions & 16 deletions avr-hal-generic/build.rs

This file was deleted.

53 changes: 17 additions & 36 deletions avr-hal-generic/src/delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::marker;
use embedded_hal::delay::DelayNs;
use embedded_hal_v0::blocking::delay as delay_v0;

#[cfg(all(target_arch = "avr", avr_hal_asm_macro))]
#[cfg(target_arch = "avr")]
use core::arch::asm;

/// A busy-loop delay implementation
Expand Down Expand Up @@ -44,38 +44,24 @@ impl<SPEED> Delay<SPEED> {

// based on https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/wiring.c

cfg_if::cfg_if! {
if #[cfg(all(target_arch = "avr", avr_hal_asm_macro))] {
#[allow(unused_assignments)]
fn busy_loop(mut c: u16) {
unsafe {
asm!(
"1:",
"sbiw {c}, 1",
"brne 1b",
c = inout(reg_iw) c,
);
}
}
} else if #[cfg(target_arch = "avr")] {
#[allow(unused_assignments)]
fn busy_loop(mut c: u16) {
unsafe {
llvm_asm!("1: sbiw $0,1\n\tbrne 1b"
: "=w"(c)
: "0"(c)
:
: "volatile"
);
}
}
} else {
fn busy_loop(_c: u16) {
unimplemented!("Implementation is only available for avr targets!")
}
#[cfg(target_arch = "avr")]
#[allow(unused_assignments)]
fn busy_loop(mut c: u16) {
unsafe {
asm!(
"1:",
"sbiw {c}, 1",
"brne 1b",
c = inout(reg_iw) c,
);
}
}

#[cfg(not(target_arch = "avr"))]
fn busy_loop(_c: u16) {
unimplemented!("Implementation is only available for avr targets!")
}

// Clock-Specific Delay Implementations ----------------------------------- {{{
impl delay_v0::DelayUs<u16> for Delay<crate::clock::MHz24> {
fn delay_us(&mut self, mut us: u16) {
Expand Down Expand Up @@ -106,16 +92,11 @@ impl delay_v0::DelayUs<u16> for Delay<crate::clock::MHz20> {

// for a one-microsecond delay, simply return. the overhead
// of the function call takes 18 (20) cycles, which is 1us
#[cfg(all(target_arch = "avr", avr_hal_asm_macro))]
#[cfg(target_arch = "avr")]
unsafe {
asm!("nop", "nop", "nop", "nop");
}

#[cfg(all(target_arch = "avr", not(avr_hal_asm_macro)))]
unsafe {
llvm_asm!("nop\nnop\nnop\nnop" :::: "volatile");
}

if us <= 1 {
return;
} // = 3 cycles, (4 when true)
Expand Down
3 changes: 1 addition & 2 deletions avr-hal-generic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![no_std]
#![cfg_attr(avr_hal_asm_macro, feature(asm_experimental_arch))]
#![cfg_attr(not(avr_hal_asm_macro), feature(llvm_asm))]
#![feature(asm_experimental_arch)]

pub use embedded_hal as hal;
pub use embedded_hal_v0 as hal_v0;
Expand Down

0 comments on commit b417d5c

Please sign in to comment.