Skip to content

Add ATtiny84A support #459

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 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
1 change: 1 addition & 0 deletions mcu/attiny-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2021"
rt = ["avr-device/rt"]
device-selected = []
attiny84 = ["avr-device/attiny84", "device-selected"]
attiny84a = ["avr-device/attiny84a", "device-selected"]
attiny85 = ["avr-device/attiny85", "device-selected"]
attiny88 = ["avr-device/attiny88", "device-selected"]
attiny167 = ["avr-device/attiny167", "device-selected"]
Expand Down
1 change: 1 addition & 0 deletions mcu/attiny-hal/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub mod channel {
pub struct Temperature;
}

#[cfg(not(feature = "attiny84a"))]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this is a multi-level issue:

First of all, to not build the ADC module for this chip, it would be better to disable it at crate level. Here:

// ATtiny2313 does not have ADC and will not compile with this module
#[cfg(all(feature = "device-selected", not(feature = "attiny2313")))]
pub mod adc;
#[cfg(all(feature = "device-selected", not(feature = "attiny2313")))]
pub use adc::Adc;

However, the chip does have an ADC so this code shouldn't fail to compile. The reason it does is probably that registers in avr-device are not correctly defined. I've already investigated this and opened Rahix/avr-device#151 to fix it.

So I think the best course of action is to wait for the change to land in avr-device and then things should just work without the #[cfg(not())] line.

fn apply_clock(peripheral: &crate::pac::ADC, settings: AdcSettings) {
peripheral.adcsra.write(|w| {
w.aden().set_bit();
Expand Down
11 changes: 11 additions & 0 deletions mcu/attiny-hal/src/eeprom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ avr_hal_generic::impl_eeprom_attiny! {
},
}

#[cfg(feature = "attiny84a")]
avr_hal_generic::impl_eeprom_attiny! {
hal: crate::Attiny,
peripheral: crate::pac::EEPROM,
capacity: 512,
addr_width: u16,
set_address: |peripheral, address| {
peripheral.eear.write(|w| w.bits(address));
},
}

#[cfg(feature = "attiny88")]
avr_hal_generic::impl_eeprom_attiny! {
hal: crate::Attiny,
Expand Down
12 changes: 12 additions & 0 deletions mcu/attiny-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! Common HAL (hardware abstraction layer) for ATtiny* microcontrollers.
//!
//! **Note**: This version of the documentation was built for
#![cfg_attr(feature = "attiny84a", doc = "**ATtiny84a**.")]
#![cfg_attr(feature = "attiny85", doc = "**ATtiny85**.")]
#![cfg_attr(feature = "attiny88", doc = "**ATtiny88**.")]
#![cfg_attr(feature = "attiny167", doc = "**ATtiny167**.")]
Expand All @@ -25,6 +26,7 @@ compile_error!(

Please select one of the following

* attiny84a
* attiny85
* attiny88
* attiny167
Expand All @@ -35,6 +37,9 @@ compile_error!(
#[cfg(feature = "attiny84")]
pub use avr_device::attiny84 as pac;

#[cfg(feature = "attiny84a")]
pub use avr_device::attiny84a as pac;

/// Reexport of `attiny85` from `avr-device`
#[cfg(feature = "attiny85")]
pub use avr_device::attiny85 as pac;
Expand Down Expand Up @@ -96,6 +101,13 @@ macro_rules! pins {
$crate::Pins::new($p.PORTA, $p.PORTB)
};
}
#[cfg(feature = "attiny84a")]
#[macro_export]
macro_rules! pins {
($p:expr) => {
$crate::Pins::new($p.PORTA, $p.PORTB)
};
}
Comment on lines +104 to +110
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, just augment the attiny84 block:

-#[cfg(feature = "attiny84")]
+#[cfg(any(feature = "attiny84", feature = "attiny84a"))]
 #[macro_export]
 macro_rules! pins {
     ($p:expr) => {

#[cfg(feature = "attiny85")]
#[macro_export]
macro_rules! pins {
Expand Down
7 changes: 7 additions & 0 deletions mcu/attiny-hal/src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ avr_hal_generic::impl_port_traditional! {
B: crate::pac::PORTB = [0, 1, 2, 3],
}
}
#[cfg(feature = "attiny84a")]
avr_hal_generic::impl_port_traditional! {
enum Ports {
A: crate::pac::PORTA = [0, 1, 2, 3, 4, 5, 6, 7],
B: crate::pac::PORTB = [0, 1, 2, 3],
}
}
Comment on lines +27 to +33
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating the values from attiny84, you can also reuse the block by extending the #[cfg] above like this:

-#[cfg(feature = "attiny84")]
+#[cfg(any(feature = "attiny84", feature = "attiny84a"))]
 avr_hal_generic::impl_port_traditional! {


#[cfg(feature = "attiny85")]
avr_hal_generic::impl_port_traditional! {
Expand Down