Skip to content

Commit 8805c2f

Browse files
committed
Refactor attiny-hal using separate modules per device
1 parent 297d3db commit 8805c2f

21 files changed

+1080
-765
lines changed

mcu/attiny-hal/Cargo.toml

Lines changed: 9 additions & 5 deletions
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"
@@ -13,10 +13,10 @@ categories = ["no-std", "embedded", "hardware-support"]
1313
[features]
1414
rt = ["avr-device/rt"]
1515
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"]
16+
attiny84 = ["avr-device/attiny84", "device-selected", "_peripheral-simple-pwm"]
17+
attiny85 = ["avr-device/attiny85", "device-selected", "_peripheral-adc", "_peripheral-simple-pwm"]
18+
attiny88 = ["avr-device/attiny88", "device-selected", "_peripheral-adc", "_peripheral-spi", "_peripheral-simple-pwm"]
19+
attiny167 = ["avr-device/attiny167", "device-selected", "_peripheral-adc", "_peripheral-spi"]
2020
attiny2313 = ["avr-device/attiny2313", "device-selected"]
2121

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

30+
_peripheral-adc = []
31+
_peripheral-spi = []
32+
_peripheral-simple-pwm = []
33+
3034
[dependencies]
3135
avr-hal-generic = { path = "../../avr-hal-generic/" }
3236

mcu/attiny-hal/src/adc.rs

Lines changed: 0 additions & 209 deletions
This file was deleted.

mcu/attiny-hal/src/attiny167.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use crate::r#impl::avr_hal;
2+
3+
avr_hal! {
4+
device: attiny167,
5+
eeprom: {
6+
capacity: 512,
7+
addr_width: u16,
8+
addr_reg: eear,
9+
},
10+
port: {
11+
ports: {
12+
A: [0, 1, 2, 3, 4, 5, 6, 7],
13+
B: [0, 1, 2, 3, 4, 5, 6, 7],
14+
},
15+
impl!: avr_hal_generic::impl_port_traditional,
16+
},
17+
spi: {
18+
interfaces: {
19+
Spi: {
20+
peripheral: SPI,
21+
sclk: PA5,
22+
mosi: PA4,
23+
miso: PA2,
24+
cs: PA6,
25+
impl!: avr_hal_generic::impl_spi,
26+
},
27+
},
28+
},
29+
adc: {
30+
references: {
31+
/// Voltage applied to AREF pin.
32+
Aref: |peripheral| {
33+
peripheral.amiscr.write(|w| w.arefen().set_bit());
34+
peripheral.admux.write(|w| w.refs().avcc());
35+
},
36+
/// Default reference voltage (default).
37+
AVcc: |peripheral| {
38+
peripheral.amiscr.write(|w| w.arefen().clear_bit());
39+
peripheral.admux.write(|w| w.refs().avcc());
40+
},
41+
/// Internal 1.1V reference.
42+
Internal1_1: |peripheral| {
43+
peripheral.amiscr.write(|w| w.arefen().clear_bit());
44+
peripheral.admux.write(|w| w.refs().internal_11());
45+
},
46+
/// Internal 2.56V reference.
47+
Internal2_56: |peripheral| {
48+
peripheral.amiscr.write(|w| w.arefen().clear_bit());
49+
peripheral.admux.write(|w| w.refs().internal_256());
50+
},
51+
},
52+
pins: {
53+
PA0: (hal::pac::adc::admux::MUX_A::ADC0, didr0::adc0d),
54+
PA1: (hal::pac::adc::admux::MUX_A::ADC1, didr0::adc1d),
55+
PA2: (hal::pac::adc::admux::MUX_A::ADC2, didr0::adc2d),
56+
PA3: (hal::pac::adc::admux::MUX_A::ADC3, didr0::adc3d),
57+
PA4: (hal::pac::adc::admux::MUX_A::ADC4, didr0::adc4d),
58+
PA5: (hal::pac::adc::admux::MUX_A::ADC5, didr0::adc5d),
59+
PA6: (hal::pac::adc::admux::MUX_A::ADC6, didr0::adc6d),
60+
PA7: (hal::pac::adc::admux::MUX_A::ADC7, didr0::adc7d),
61+
PB5: (hal::pac::adc::admux::MUX_A::ADC8, didr1::adc8d),
62+
PB6: (hal::pac::adc::admux::MUX_A::ADC9, didr1::adc9d),
63+
PB7: (hal::pac::adc::admux::MUX_A::ADC10, didr1::adc10d),
64+
},
65+
channels: {
66+
AVcc_4: hal::pac::adc::admux::MUX_A::ADC_AVCC_4,
67+
Vbg: hal::pac::adc::admux::MUX_A::ADC_VBG,
68+
Gnd: hal::pac::adc::admux::MUX_A::ADC_GND,
69+
Temperature: hal::pac::adc::admux::MUX_A::TEMPSENS,
70+
},
71+
},
72+
wdt: {
73+
wdtcsr_name: wdtcr,
74+
},
75+
}

mcu/attiny-hal/src/attiny2313.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::r#impl::avr_hal;
2+
3+
avr_hal! {
4+
device: attiny2313,
5+
eeprom: {
6+
capacity: 128,
7+
addr_width: u8,
8+
addr_reg: eear,
9+
},
10+
port: {
11+
ports: {
12+
A: [0, 1, 2],
13+
B: [0, 1, 2, 3, 4, 5, 6, 7],
14+
D: [0, 1, 2, 3, 4, 5, 6],
15+
},
16+
impl!: avr_hal_generic::impl_port_traditional,
17+
},
18+
wdt: {
19+
wdtcsr_name: wdtcr,
20+
},
21+
}

mcu/attiny-hal/src/attiny84.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
use crate::r#impl::avr_hal;
2+
3+
avr_hal! {
4+
device: attiny84,
5+
eeprom: {
6+
capacity: 512,
7+
addr_width: u16,
8+
addr_reg: eear,
9+
},
10+
port: {
11+
ports: {
12+
A: [0, 1, 2, 3, 4, 5, 6, 7],
13+
B: [0, 1, 2, 3],
14+
},
15+
impl!: avr_hal_generic::impl_port_traditional,
16+
},
17+
pwm: {
18+
timers: {
19+
Timer0Pwm: {
20+
peripheral: TC0,
21+
tccr: tccr0,
22+
pins: {
23+
PB2: {
24+
ocr: ocr0a,
25+
com: com0a,
26+
},
27+
PA7: {
28+
ocr: ocr0b,
29+
com: com0b,
30+
},
31+
},
32+
impl!: crate::r#impl::timer_8bit_impl,
33+
},
34+
Timer1Pwm: {
35+
peripheral: TC1,
36+
tccr: tccr1,
37+
pins: {
38+
PA6: {
39+
ocr: ocr1a,
40+
com: com1a,
41+
},
42+
PA5: {
43+
ocr: ocr1b,
44+
com: com1b,
45+
},
46+
},
47+
impl!: crate::r#impl::timer_16bit_impl,
48+
},
49+
},
50+
},
51+
wdt: {
52+
wdtcsr_name: wdtcsr,
53+
},
54+
}

0 commit comments

Comments
 (0)