Skip to content

Fix doctests in attiny-hal #616

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

Open
wants to merge 5 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 @@ -123,6 +123,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: Compile doctests for an ATtiny MCU
if: "${{ matrix.m.crate == 'attiny-hal' }}"
run: >-
cd "mcu/${{ matrix.m.crate }}" &&
cargo test --doc --features "${{ matrix.m.name }}" -Z build-std=core --target "../../avr-specs/avr-${{ matrix.m.spec }}.json"

ravedude:
name: "ravedude"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Build documentation (atmega-hal)
run: cd mcu/atmega-hal/ && cargo doc --features atmega328p
- name: Build documentation (attiny-hal)
run: cd mcu/attiny-hal/ && cargo doc --features attiny85
run: cd mcu/attiny-hal/ && cargo doc --features docsrs
- name: Deploy to GH-Pages
uses: peaceiris/actions-gh-pages@v4
with:
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
25 changes: 18 additions & 7 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 @@ -13,19 +13,30 @@ 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"]

# Allow certain downstream crates to overwrite the device selection error by themselves.
disable-device-selection-error = []

# We must select a microcontroller to build on docs.rs
docsrs = ["attiny85"]
default = []
all = ["attiny84", "attiny85", "attiny88", "attiny167", "attiny2313", "no-globals"]
docsrs = ["all"]

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


[dev-dependencies]
ufmt = "0.2.0"
embedded-hal = "1.0"

[dependencies]
avr-hal-generic = { path = "../../avr-hal-generic/" }
Expand Down
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