Skip to content

Commit 674f0ed

Browse files
committed
Refactor attiny-hal for opt-out deprecated globals
1 parent 949130a commit 674f0ed

23 files changed

+1076
-784
lines changed

.github/workflows/ci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ jobs:
119119
- name: Test-compile HAL crate for an MCU
120120
if: "${{ matrix.m.type == 'mcu' }}"
121121
run: cd "mcu/${{ matrix.m.crate }}" && cargo build --features "${{ matrix.m.name }}" -Z build-std=core --target "../../avr-specs/avr-${{ matrix.m.spec }}.json"
122+
- name: Test-compile HAL crate for an MCU (no deprecated globals)
123+
if: "${{ matrix.m.crate == 'attiny-hal' }}"
124+
run: >-
125+
cd "mcu/${{ matrix.m.crate }}" &&
126+
cargo build --features "${{ matrix.m.name }}-no-deprecated-globals" -Z build-std=core --target "../../avr-specs/avr-${{ matrix.m.spec }}.json"
122127
123128
ravedude:
124129
name: "ravedude"

avr-hal-generic/src/simple_pwm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ macro_rules! impl_simple_pwm {
123123
timer: $TIMER:ty,
124124
init: |$init_timer:ident, $prescaler:ident| $init_block:block,
125125
pins: {$(
126-
$PXi:ident: {
126+
$PXi:ty: {
127127
ocr: $ocr:ident,
128128
$into_pwm:ident: |$pin_timer:ident| if enable
129129
$pin_enable_block:block else $pin_disable_block:block,

mcu/attiny-hal/Cargo.toml

+51-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "attiny-hal"
3-
version = "0.1.0"
3+
version = "0.2.0"
44

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

1313
[features]
1414
rt = ["avr-device/rt"]
15-
device-selected = []
16-
attiny84 = ["avr-device/attiny84", "device-selected"]
17-
attiny85 = ["avr-device/attiny85", "device-selected"]
18-
attiny88 = ["avr-device/attiny88", "device-selected"]
19-
attiny167 = ["avr-device/attiny167", "device-selected"]
20-
attiny2313 = ["avr-device/attiny2313", "device-selected"]
15+
16+
# MCU-specific targets. Due to use of deprecated globals, only one MCU can be selected at a time
17+
# In attiny-hal 0.30 the defaults will change to no deprecated globals
18+
attiny84 = ["attiny84-deprecated-globals"]
19+
attiny85 = ["attiny85-deprecated-globals"]
20+
attiny88 = ["attiny88-deprecated-globals"]
21+
attiny167 = ["attiny167-deprecated-globals"]
22+
attiny2313 = ["attiny2313-deprecated-globals"]
23+
24+
# MCU-specific targets with deprecated globals. This is the default in attiny-hal <0.3.0
25+
attiny84-deprecated-globals = ["_mcu-attiny84", "deprecated-globals"]
26+
attiny85-deprecated-globals = ["_mcu-attiny85", "deprecated-globals"]
27+
attiny88-deprecated-globals = ["_mcu-attiny88", "deprecated-globals"]
28+
attiny167-deprecated-globals = ["_mcu-attiny167", "deprecated-globals"]
29+
attiny2313-deprecated-globals = ["_mcu-attiny2313", "deprecated-globals"]
30+
31+
# MCU-specific targets without deprecated globals. This will be the default in attiny-hal 0.3.0
32+
attiny84-no-deprecated-globals = ["_mcu-attiny84"]
33+
attiny85-no-deprecated-globals = ["_mcu-attiny85"]
34+
attiny88-no-deprecated-globals = ["_mcu-attiny88"]
35+
attiny167-no-deprecated-globals = ["_mcu-attiny167"]
36+
attiny2313-no-deprecated-globals = ["_mcu-attiny2313"]
2137

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

24-
# Allow certain downstream crates to overwrite the device selection error by themselves.
25-
disable-device-selection-error = []
40+
default = []
41+
42+
docsrs = [
43+
"attiny84-no-deprecated-globals",
44+
"attiny85-no-deprecated-globals",
45+
"attiny88-no-deprecated-globals",
46+
"attiny167-no-deprecated-globals",
47+
"attiny2313-no-deprecated-globals",
48+
]
49+
50+
# Include soon-to-be-deprecated globals in the crate. Only one MCU can be selected if deprecated globals are enabled
51+
deprecated-globals = []
52+
53+
# 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
54+
disable-device-selection-error = ["_mcu-selected"]
55+
56+
# MCU-specific implementation features
57+
# Do not use directly; use either an <mcu>-deprecated-globals feature or any number of <mcu>-no-deprecated-globals features
58+
_mcu-attiny84 = ["_mcu-selected", "_peripheral-simple-pwm", "avr-device/attiny84"]
59+
_mcu-attiny85 = ["_mcu-selected", "_peripheral-adc", "_peripheral-simple-pwm", "avr-device/attiny85"]
60+
_mcu-attiny88 = ["_mcu-selected", "_peripheral-adc", "_peripheral-spi", "_peripheral-simple-pwm", "avr-device/attiny88"]
61+
_mcu-attiny167 = ["_mcu-selected", "_peripheral-adc", "_peripheral-spi", "avr-device/attiny167"]
62+
_mcu-attiny2313 = ["_mcu-selected", "avr-device/attiny2313"]
63+
64+
_mcu-selected = []
65+
_peripheral-adc = []
66+
_peripheral-spi = []
67+
_peripheral-simple-pwm = []
2668

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

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

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

4477
[package.metadata.docs.rs]

mcu/attiny-hal/src/adc.rs

-209
This file was deleted.

0 commit comments

Comments
 (0)