Skip to content

Commit

Permalink
Refactor atmega-hal for opt-out deprecated globals
Browse files Browse the repository at this point in the history
  • Loading branch information
innermatrix committed Dec 9, 2024
1 parent 4ffe0b8 commit e83fcd6
Show file tree
Hide file tree
Showing 33 changed files with 3,902 additions and 2,732 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
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.crate == 'attiny-hal' }}"
if: "${{ matrix.m.crate == 'attiny-hal' || matrix.m.crate == 'atmega-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"
Expand Down
143 changes: 126 additions & 17 deletions mcu/atmega-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "atmega-hal"
version = "0.1.0"
version = "0.2.0"

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

[features]
rt = ["avr-device/rt"]
device-selected = []
enable-extra-adc = []
atmega48p = ["avr-device/atmega48p", "device-selected"]
atmega164pa = ["avr-device/atmega164pa", "device-selected"]
atmega168 = ["avr-device/atmega168", "device-selected"]
atmega328p = ["avr-device/atmega328p", "device-selected"]
atmega328pb = ["avr-device/atmega328pb", "device-selected"]
atmega32a = ["avr-device/atmega32a", "device-selected"]
atmega32u4 = ["avr-device/atmega32u4", "device-selected"]
atmega2560 = ["avr-device/atmega2560", "device-selected"]
atmega128a = ["avr-device/atmega128a", "device-selected"]
atmega1280 = ["avr-device/atmega1280", "device-selected"]
atmega1284p = ["avr-device/atmega1284p", "device-selected"]
atmega8 = ["avr-device/atmega8", "device-selected"]

# MCU-specific targets. Due to use of deprecated globals, only one MCU can be selected at a time
# In atmega-hal 0.3.0 the defaults will change to no deprecated globals
atmega48p = ["atmega48p-deprecated-globals"]
atmega164pa = ["atmega164pa-deprecated-globals"]
atmega168 = ["atmega168-deprecated-globals"]
atmega328p = ["atmega328p-deprecated-globals"]
atmega328pb = ["atmega328pb-deprecated-globals"]
atmega32a = ["atmega32a-deprecated-globals"]
atmega32u4 = ["atmega32u4-deprecated-globals"]
atmega2560 = ["atmega2560-deprecated-globals"]
atmega128a = ["atmega128a-deprecated-globals"]
atmega1280 = ["atmega1280-deprecated-globals"]
atmega1284p = ["atmega1284p-deprecated-globals"]
atmega8 = ["atmega8-deprecated-globals"]

# MCU-specific targets with deprecated globals. This is the default in atmega-hal <0.3.0
atmega48p-deprecated-globals = ["_mcu-atmega48p", "deprecated-globals"]
atmega164pa-deprecated-globals = ["_mcu-atmega164pa", "deprecated-globals"]
atmega168-deprecated-globals = ["_mcu-atmega168", "deprecated-globals"]
atmega328p-deprecated-globals = ["_mcu-atmega328p", "deprecated-globals"]
atmega328pb-deprecated-globals = ["_mcu-atmega328pb", "deprecated-globals"]
atmega32a-deprecated-globals = ["_mcu-atmega32a", "deprecated-globals"]
atmega32u4-deprecated-globals = ["_mcu-atmega32u4", "deprecated-globals"]
atmega2560-deprecated-globals = ["_mcu-atmega2560", "deprecated-globals"]
atmega128a-deprecated-globals = ["_mcu-atmega128a", "deprecated-globals"]
atmega1280-deprecated-globals = ["_mcu-atmega1280", "deprecated-globals"]
atmega1284p-deprecated-globals = ["_mcu-atmega1284p", "deprecated-globals"]
atmega8-deprecated-globals = ["_mcu-atmega8", "deprecated-globals"]

# MCU-specific targets without deprecated globals. This will be the default in atmega-hal 0.3.0
atmega48p-no-deprecated-globals = ["_mcu-atmega48p"]
atmega164pa-no-deprecated-globals = ["_mcu-atmega164pa"]
atmega168-no-deprecated-globals = ["_mcu-atmega168"]
atmega328p-no-deprecated-globals = ["_mcu-atmega328p"]
atmega328pb-no-deprecated-globals = ["_mcu-atmega328pb"]
atmega32a-no-deprecated-globals = ["_mcu-atmega32a"]
atmega32u4-no-deprecated-globals = ["_mcu-atmega32u4"]
atmega2560-no-deprecated-globals = ["_mcu-atmega2560"]
atmega128a-no-deprecated-globals = ["_mcu-atmega128a"]
atmega1280-no-deprecated-globals = ["_mcu-atmega1280"]
atmega1284p-no-deprecated-globals = ["_mcu-atmega1284p"]
atmega8-no-deprecated-globals = ["_mcu-atmega8"]

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

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

docsrs = [
"atmega48p-no-deprecated-globals",
"atmega164pa-no-deprecated-globals",
"atmega168-no-deprecated-globals",
"atmega328p-no-deprecated-globals",
"atmega328pb-no-deprecated-globals",
"atmega32a-no-deprecated-globals",
"atmega32u4-no-deprecated-globals",
"atmega2560-no-deprecated-globals",
"atmega128a-no-deprecated-globals",
"atmega1280-no-deprecated-globals",
"atmega1284p-no-deprecated-globals",
"atmega8-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 = []

# If using this crate from another library crate you may want to suppress this error and provide your own
disable-device-selection-error = []

# We must select a microcontroller to build on docs.rs
docsrs = ["atmega328p"]
# 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-atmega48p = ["_mcu-selected", "_peripheral-spi", "_peripheral-simple-pwm", "avr-device/atmega48p"]
_mcu-atmega164pa = ["_mcu-selected", "_peripheral-usart", "_peripheral-simple-pwm", "avr-device/atmega164pa"]
_mcu-atmega168 = [
"_mcu-selected",
"_peripheral-usart",
"_peripheral-spi",
"_peripheral-simple-pwm",
"avr-device/atmega168",
]
_mcu-atmega328p = [
"_mcu-selected",
"_peripheral-usart",
"_peripheral-spi",
"_peripheral-simple-pwm",
"avr-device/atmega328p",
]
_mcu-atmega328pb = [
"_mcu-selected",
"_peripheral-usart",
"_peripheral-spi",
"_peripheral-simple-pwm",
"avr-device/atmega328pb",
]
_mcu-atmega32a = ["_mcu-selected", "_peripheral-usart", "_peripheral-spi", "avr-device/atmega32a"]
_mcu-atmega32u4 = [
"_mcu-selected",
"_peripheral-usart",
"_peripheral-spi",
"_peripheral-simple-pwm",
"avr-device/atmega32u4",
]
_mcu-atmega2560 = [
"_mcu-selected",
"_peripheral-usart",
"_peripheral-spi",
"_peripheral-simple-pwm",
"avr-device/atmega2560",
]
_mcu-atmega128a = ["_mcu-selected", "_peripheral-usart", "_peripheral-spi", "avr-device/atmega128a"]
_mcu-atmega1280 = [
"_mcu-selected",
"_peripheral-usart",
"_peripheral-spi",
"_peripheral-simple-pwm",
"avr-device/atmega1280",
]
_mcu-atmega1284p = [
"_mcu-selected",
"_peripheral-usart",
"_peripheral-spi",
"_peripheral-simple-pwm",
"avr-device/atmega1284p",
]
_mcu-atmega8 = ["_mcu-selected", "_peripheral-usart", "_peripheral-spi", "_peripheral-simple-pwm", "avr-device/atmega8"]

_mcu-selected = []
_peripheral-simple-pwm = []
_peripheral-spi = []
_peripheral-usart = []

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

0 comments on commit e83fcd6

Please sign in to comment.