Skip to content

Commit

Permalink
Refactor attiny-hal for opt-out deprecated globals
Browse files Browse the repository at this point in the history
  • Loading branch information
innermatrix committed Dec 7, 2024
1 parent e2bebbd commit 40878e2
Show file tree
Hide file tree
Showing 22 changed files with 1,131 additions and 780 deletions.
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
69 changes: 51 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,66 @@ 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", "_peripheral-simple-pwm", "avr-device/attiny84"]
_mcu-attiny85 = ["_mcu-selected", "_peripheral-adc", "_peripheral-simple-pwm", "avr-device/attiny85"]
_mcu-attiny88 = ["_mcu-selected", "_peripheral-adc", "_peripheral-spi", "_peripheral-simple-pwm", "avr-device/attiny88"]
_mcu-attiny167 = ["_mcu-selected", "_peripheral-adc", "_peripheral-spi", "avr-device/attiny167"]
_mcu-attiny2313 = ["_mcu-selected", "avr-device/attiny2313"]

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

# 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
209 changes: 0 additions & 209 deletions mcu/attiny-hal/src/adc.rs

This file was deleted.

Loading

0 comments on commit 40878e2

Please sign in to comment.