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

Refactor ATtiny HAL to use a separate module for each MCU #643

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion avr-hal-generic/src/simple_pwm.rs
Original file line number Diff line number Diff line change
@@ -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,
14 changes: 9 additions & 5 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"
@@ -13,10 +13,10 @@ 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"]
attiny84 = ["avr-device/attiny84", "device-selected", "_peripheral-simple-pwm"]
attiny85 = ["avr-device/attiny85", "device-selected", "_peripheral-adc", "_peripheral-simple-pwm"]
attiny88 = ["avr-device/attiny88", "device-selected", "_peripheral-adc", "_peripheral-spi", "_peripheral-simple-pwm"]
attiny167 = ["avr-device/attiny167", "device-selected", "_peripheral-adc", "_peripheral-spi"]
attiny2313 = ["avr-device/attiny2313", "device-selected"]

critical-section-impl = ["avr-device/critical-section-impl"]
@@ -27,6 +27,10 @@ disable-device-selection-error = []
# We must select a microcontroller to build on docs.rs
docsrs = ["attiny85"]

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

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

209 changes: 0 additions & 209 deletions mcu/attiny-hal/src/adc.rs

This file was deleted.

75 changes: 75 additions & 0 deletions mcu/attiny-hal/src/attiny167.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
use crate::r#impl::avr_hal;

avr_hal! {
device: attiny167,
eeprom: {
capacity: 512,
addr_width: u16,
addr_reg: eear,
},
port: {
ports: {
A: [0, 1, 2, 3, 4, 5, 6, 7],
B: [0, 1, 2, 3, 4, 5, 6, 7],
},
impl!: avr_hal_generic::impl_port_traditional,
},
spi: {
interfaces: {
Spi: {
peripheral: SPI,
sclk: PA5,
mosi: PA4,
miso: PA2,
cs: PA6,
impl!: avr_hal_generic::impl_spi,
},
},
},
adc: {
references: {
/// Voltage applied to AREF pin.
Aref: |peripheral| {
peripheral.amiscr.write(|w| w.arefen().set_bit());
peripheral.admux.write(|w| w.refs().avcc());
},
/// Default reference voltage (default).
AVcc: |peripheral| {
peripheral.amiscr.write(|w| w.arefen().clear_bit());
peripheral.admux.write(|w| w.refs().avcc());
},
/// Internal 1.1V reference.
Internal1_1: |peripheral| {
peripheral.amiscr.write(|w| w.arefen().clear_bit());
peripheral.admux.write(|w| w.refs().internal_11());
},
/// Internal 2.56V reference.
Internal2_56: |peripheral| {
peripheral.amiscr.write(|w| w.arefen().clear_bit());
peripheral.admux.write(|w| w.refs().internal_256());
},
},
pins: {
PA0: (hal::pac::adc::admux::MUX_A::ADC0, didr0::adc0d),
PA1: (hal::pac::adc::admux::MUX_A::ADC1, didr0::adc1d),
PA2: (hal::pac::adc::admux::MUX_A::ADC2, didr0::adc2d),
PA3: (hal::pac::adc::admux::MUX_A::ADC3, didr0::adc3d),
PA4: (hal::pac::adc::admux::MUX_A::ADC4, didr0::adc4d),
PA5: (hal::pac::adc::admux::MUX_A::ADC5, didr0::adc5d),
PA6: (hal::pac::adc::admux::MUX_A::ADC6, didr0::adc6d),
PA7: (hal::pac::adc::admux::MUX_A::ADC7, didr0::adc7d),
PB5: (hal::pac::adc::admux::MUX_A::ADC8, didr1::adc8d),
PB6: (hal::pac::adc::admux::MUX_A::ADC9, didr1::adc9d),
PB7: (hal::pac::adc::admux::MUX_A::ADC10, didr1::adc10d),
},
channels: {
AVcc_4: hal::pac::adc::admux::MUX_A::ADC_AVCC_4,
Vbg: hal::pac::adc::admux::MUX_A::ADC_VBG,
Gnd: hal::pac::adc::admux::MUX_A::ADC_GND,
Temperature: hal::pac::adc::admux::MUX_A::TEMPSENS,
},
},
wdt: {
wdtcsr_name: wdtcr,
},
}
21 changes: 21 additions & 0 deletions mcu/attiny-hal/src/attiny2313.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::r#impl::avr_hal;

avr_hal! {
device: attiny2313,
eeprom: {
capacity: 128,
addr_width: u8,
addr_reg: eear,
},
port: {
ports: {
A: [0, 1, 2],
B: [0, 1, 2, 3, 4, 5, 6, 7],
D: [0, 1, 2, 3, 4, 5, 6],
},
impl!: avr_hal_generic::impl_port_traditional,
},
wdt: {
wdtcsr_name: wdtcr,
},
}
Loading