Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored attiny_hal for additive features #605

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ jobs:
- name: Test-compile HAL crate for an MCU
if: "${{ matrix.m.type == 'mcu' }}"
run: cd "mcu/${{ matrix.m.crate }}" && cargo build --features "${{ matrix.m.name }}" -Z build-std=core --target "../../avr-specs/avr-${{ matrix.m.spec }}.json"
- name: Test-compile HAL crate for an MCU (no deprecated globals)
if: "${{ matrix.m.create == 'attiny-hal' }}"
run: >-
cd "mcu/${{ matrix.m.crate }}" &&
cargo build --features "${{ matrix.m.name }}-no-deprecated-globals" -Z build-std=core --target "../../avr-specs/avr-${{ matrix.m.spec }}.json"

ravedude:
name: "ravedude"
Expand Down
2 changes: 1 addition & 1 deletion avr-hal-generic/src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ macro_rules! impl_port_traditional {

impl Pins {
pub fn new(
$(_: $port,)+
$(_: &$port,)+
) -> Self {
Self {
$($([<p $name:lower $pin>]: $crate::port::Pin::new(
Expand Down
62 changes: 2 additions & 60 deletions mcu/atmega-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,68 +147,10 @@ pub use eeprom::Eeprom;

pub struct Atmega;

#[cfg(any(feature = "atmega48p", feature = "atmega168", feature = "atmega328p"))]
#[macro_export]
macro_rules! pins {
($p:expr) => {
$crate::Pins::new($p.PORTB, $p.PORTC, $p.PORTD)
};
}
#[cfg(any(feature = "atmega164pa"))]
#[macro_export]
macro_rules! pins {
($p:expr) => {
$crate::Pins::new($p.PORTA, $p.PORTB, $p.PORTC, $p.PORTD)
};
}
#[cfg(feature = "atmega328pb")]
#[macro_export]
macro_rules! pins {
($p:expr) => {
$crate::Pins::new($p.PORTB, $p.PORTC, $p.PORTD, $p.PORTE)
};
}
#[cfg(feature = "atmega32u4")]
#[macro_export]
macro_rules! pins {
($p:expr) => {
$crate::Pins::new($p.PORTB, $p.PORTC, $p.PORTD, $p.PORTE, $p.PORTF)
};
}

#[cfg(any(feature = "atmega128a"))]
#[macro_export]
macro_rules! pins {
($p:expr) => {
$crate::Pins::new(
$p.PORTA, $p.PORTB, $p.PORTC, $p.PORTD, $p.PORTE, $p.PORTF, $p.PORTG,
)
};
}

#[cfg(any(feature = "atmega1280", feature = "atmega2560"))]
#[macro_export]
macro_rules! pins {
($p:expr) => {
$crate::Pins::new(
$p.PORTA, $p.PORTB, $p.PORTC, $p.PORTD, $p.PORTE, $p.PORTF, $p.PORTG, $p.PORTH,
$p.PORTJ, $p.PORTK, $p.PORTL,
)
};
}

#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
#[macro_export]
macro_rules! pins {
($p:expr) => {
$crate::Pins::new($p.PORTA, $p.PORTB, $p.PORTC, $p.PORTD)
};
}

#[cfg(any(feature = "atmega8"))]
#[cfg(feature = "device-selected")]
#[macro_export]
macro_rules! pins {
($p:expr) => {
$crate::Pins::new($p.PORTB, $p.PORTC, $p.PORTD)
$crate::port::pins(&$p)
};
}
40 changes: 40 additions & 0 deletions mcu/atmega-hal/src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ avr_hal_generic::impl_port_traditional! {
D: crate::pac::PORTD = [0, 1, 2, 3, 4, 5, 6, 7],
}
}
#[cfg(any(feature = "atmega48p", feature = "atmega168", feature = "atmega328p"))]
pub fn pins(peripherals: &crate::pac::Peripherals) -> Pins {
return Pins::new(&peripherals.PORTB, &peripherals.PORTC, &peripherals.PORTD);
}


#[cfg(any(feature = "atmega164pa"))]
avr_hal_generic::impl_port_traditional! {
Expand All @@ -37,6 +42,11 @@ avr_hal_generic::impl_port_traditional! {
D: crate::pac::PORTD = [0, 1, 2, 3, 4, 5, 6 ,7],
}
}
#[cfg(any(feature = "atmega164pa"))]
pub fn pins(peripherals: &crate::pac::Peripherals) -> Pins {
return Pins::new(&peripherals.PORTA, &peripherals.PORTB, &peripherals.PORTC, &peripherals.PORTD);
}


#[cfg(feature = "atmega328pb")]
avr_hal_generic::impl_port_traditional! {
Expand All @@ -47,6 +57,11 @@ avr_hal_generic::impl_port_traditional! {
E: crate::pac::PORTE = [0, 1, 2, 3],
}
}
#[cfg(feature = "atmega328pb")]
pub fn pins(peripherals: &crate::pac::Peripherals) -> Pins {
return Pins::new(&peripherals.PORTB, &peripherals.PORTC, &peripherals.PORTD, &peripherals.PORTE);
}


#[cfg(feature = "atmega32u4")]
avr_hal_generic::impl_port_traditional! {
Expand All @@ -58,6 +73,11 @@ avr_hal_generic::impl_port_traditional! {
F: crate::pac::PORTF = [0, 1, 4, 5, 6, 7],
}
}
#[cfg(feature = "atmega32u4")]
pub fn pins(peripherals: &crate::pac::Peripherals) -> Pins {
return Pins::new(&peripherals.PORTB, &peripherals.PORTC, &peripherals.PORTD, &peripherals.PORTE, &peripherals.PORTF);
}


#[cfg(any(feature = "atmega128a"))]
avr_hal_generic::impl_port_traditional! {
Expand All @@ -71,6 +91,11 @@ avr_hal_generic::impl_port_traditional! {
G: crate::pac::PORTG = [0, 1, 2, 3, 4],
}
}
#[cfg(any(feature = "atmega128a"))]
pub fn pins(peripherals: &crate::pac::Peripherals) -> Pins {
return Pins::new(&peripherals.PORTA, &peripherals.PORTB, &peripherals.PORTC, &peripherals.PORTD, &peripherals.PORTE, &peripherals.PORTF, &peripherals.PORTG);
}


#[cfg(any(feature = "atmega1280", feature = "atmega2560"))]
avr_hal_generic::impl_port_traditional! {
Expand All @@ -88,6 +113,11 @@ avr_hal_generic::impl_port_traditional! {
L: crate::pac::PORTL = [0, 1, 2, 3, 4, 5, 6, 7],
}
}
#[cfg(any(feature = "atmega1280", feature = "atmega2560"))]
pub fn pins(peripherals: &crate::pac::Peripherals) -> Pins {
return Pins::new(&peripherals.PORTA, &peripherals.PORTB, &peripherals.PORTC, &peripherals.PORTD, &peripherals.PORTE, &peripherals.PORTF, &peripherals.PORTG, &peripherals.PORTH, &peripherals.PORTJ, &peripherals.PORTK, &peripherals.PORTL);
}


#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
avr_hal_generic::impl_port_traditional! {
Expand All @@ -98,6 +128,11 @@ avr_hal_generic::impl_port_traditional! {
D: crate::pac::PORTD = [0, 1, 2, 3, 4, 5, 6, 7],
}
}
#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
pub fn pins(peripherals: &crate::pac::Peripherals) -> Pins {
return Pins::new(&peripherals.PORTA, &peripherals.PORTB, &peripherals.PORTC, &peripherals.PORTD);
}


#[cfg(any(feature = "atmega8"))]
avr_hal_generic::impl_port_traditional! {
Expand All @@ -107,3 +142,8 @@ avr_hal_generic::impl_port_traditional! {
D: crate::pac::PORTD = [0, 1, 2, 3, 4, 5, 6, 7],
}
}
#[cfg(any(feature = "atmega8"))]
pub fn pins(peripherals: &crate::pac::Peripherals) -> Pins {
return Pins::new(&peripherals.PORTB, &peripherals.PORTC, &peripherals.PORTD);
}

66 changes: 48 additions & 18 deletions mcu/attiny-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "attiny-hal"
version = "0.1.0"
version = "0.2.0"

authors = ["Rahix <[email protected]>"]
edition = "2021"
Expand All @@ -12,33 +12,63 @@ categories = ["no-std", "embedded", "hardware-support"]

[features]
rt = ["avr-device/rt"]
device-selected = []
attiny84 = ["avr-device/attiny84", "device-selected"]
attiny85 = ["avr-device/attiny85", "device-selected"]
attiny88 = ["avr-device/attiny88", "device-selected"]
attiny167 = ["avr-device/attiny167", "device-selected"]
attiny2313 = ["avr-device/attiny2313", "device-selected"]

# MCU-specific targets. Due to use of deprecated globals, only one MCU can be selected at a time
# In attiny-hal 0.30 the defaults will change to no deprecated globals
attiny84 = ["attiny84-deprecated-globals"]
attiny85 = ["attiny85-deprecated-globals"]
attiny88 = ["attiny88-deprecated-globals"]
attiny167 = ["attiny167-deprecated-globals"]
attiny2313 = ["attiny2313-deprecated-globals"]

# MCU-specific targets with deprecated globals. This is the default in attiny-hal <0.3.0
attiny84-deprecated-globals = ["_mcu-attiny84", "deprecated-globals"]
attiny85-deprecated-globals = ["_mcu-attiny85", "deprecated-globals"]
attiny88-deprecated-globals = ["_mcu-attiny88", "deprecated-globals"]
attiny167-deprecated-globals = ["_mcu-attiny167", "deprecated-globals"]
attiny2313-deprecated-globals = ["_mcu-attiny2313", "deprecated-globals"]

# MCU-specific targets without deprecated globals. This will be the default in attiny-hal 0.3.0
attiny84-no-deprecated-globals = ["_mcu-attiny84"]
attiny85-no-deprecated-globals = ["_mcu-attiny85"]
attiny88-no-deprecated-globals = ["_mcu-attiny88"]
attiny167-no-deprecated-globals = ["_mcu-attiny167"]
attiny2313-no-deprecated-globals = ["_mcu-attiny2313"]

critical-section-impl = ["avr-device/critical-section-impl"]

# Allow certain downstream crates to overwrite the device selection error by themselves.
disable-device-selection-error = []
default = []

docsrs = [
"attiny84-no-deprecated-globals",
"attiny85-no-deprecated-globals",
"attiny88-no-deprecated-globals",
"attiny167-no-deprecated-globals",
"attiny2313-no-deprecated-globals",
]

# Include soon-to-be-deprecated globals in the crate. Only one MCU can be selected if deprecated globals are enabled
deprecated-globals = []

# When using this crate from another lib crate, you can use this feature to turn suppress the chip selection error in favor of your own error
disable-device-selection-error = ["_mcu-selected"]

# MCU-specific implementation features
# Do not use directly; use either an <mcu>-deprecated-globals feature or any number of <mcu>-no-deprecated-globals features
_mcu-attiny84 = ["_mcu-selected", "avr-device/attiny84"]
_mcu-attiny85 = ["_mcu-selected", "avr-device/attiny85"]
_mcu-attiny88 = ["_mcu-selected", "avr-device/attiny88"]
_mcu-attiny167 = ["_mcu-selected", "avr-device/attiny167"]
_mcu-attiny2313 = ["_mcu-selected", "avr-device/attiny2313"]

_mcu-selected = []

# We must select a microcontroller to build on docs.rs
docsrs = ["attiny85"]

[dependencies]
avr-hal-generic = { path = "../../avr-hal-generic/" }

[dependencies.avr-device]
version = "0.5.4"

# Because this crate has its own check that at least one device is selected, we
# can safely "circumvent" the check in `avr-device`.
#
# Why would we want that? Otherwise, as `avr-device` is compiled first, its
# error will be shown and ours won't which leads to a degraded user experience
# as the displayed error message does not really tell what needs to be done...
features = ["device-selected"]

[package.metadata.docs.rs]
Expand Down
Loading