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 atmega_hal for additive features #606

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.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"

ravedude:
name: "ravedude"
Expand Down
2 changes: 1 addition & 1 deletion avr-hal-generic/src/simple_pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ macro_rules! impl_simple_pwm {
timer: $TIMER:ty,
init: |$init_timer:ident, $prescaler:ident| $init_block:block,
pins: {$(
$PXi:ident: {
$PXi:ty: {
ocr: $ocr:ident,
$into_pwm:ident: |$pin_timer:ident| if enable
$pin_enable_block:block else $pin_disable_block:block,
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