From 0dbefadf1888942a0e0e7b66b23786a4d009281c Mon Sep 17 00:00:00 2001 From: Michael Darr Date: Wed, 6 Dec 2023 14:20:14 -0800 Subject: [PATCH] support eeprom for attiny84a Signed-off-by: Michael Darr --- mcu/attiny-hal/Cargo.toml | 1 + mcu/attiny-hal/src/adc.rs | 1 + mcu/attiny-hal/src/eeprom.rs | 11 +++++++++++ mcu/attiny-hal/src/lib.rs | 12 ++++++++++++ mcu/attiny-hal/src/port.rs | 7 +++++++ 5 files changed, 32 insertions(+) diff --git a/mcu/attiny-hal/Cargo.toml b/mcu/attiny-hal/Cargo.toml index e6929f92fd..4895072b88 100644 --- a/mcu/attiny-hal/Cargo.toml +++ b/mcu/attiny-hal/Cargo.toml @@ -8,6 +8,7 @@ edition = "2018" 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"] diff --git a/mcu/attiny-hal/src/adc.rs b/mcu/attiny-hal/src/adc.rs index 3bb592ec17..331c22fbfe 100644 --- a/mcu/attiny-hal/src/adc.rs +++ b/mcu/attiny-hal/src/adc.rs @@ -68,6 +68,7 @@ pub mod channel { pub struct Temperature; } +#[cfg(not(feature = "attiny84a"))] fn apply_clock(peripheral: &crate::pac::ADC, settings: AdcSettings) { peripheral.adcsra.write(|w| { w.aden().set_bit(); diff --git a/mcu/attiny-hal/src/eeprom.rs b/mcu/attiny-hal/src/eeprom.rs index da42986013..6c13bd9387 100644 --- a/mcu/attiny-hal/src/eeprom.rs +++ b/mcu/attiny-hal/src/eeprom.rs @@ -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, diff --git a/mcu/attiny-hal/src/lib.rs b/mcu/attiny-hal/src/lib.rs index 5dfeddcc58..4bd4677dd6 100644 --- a/mcu/attiny-hal/src/lib.rs +++ b/mcu/attiny-hal/src/lib.rs @@ -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**.")] @@ -25,6 +26,7 @@ compile_error!( Please select one of the following + * attiny84a * attiny85 * attiny88 * attiny167 @@ -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; @@ -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) + }; +} #[cfg(feature = "attiny85")] #[macro_export] macro_rules! pins { diff --git a/mcu/attiny-hal/src/port.rs b/mcu/attiny-hal/src/port.rs index 6b4c8b0fee..21658772a2 100644 --- a/mcu/attiny-hal/src/port.rs +++ b/mcu/attiny-hal/src/port.rs @@ -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], + } +} #[cfg(feature = "attiny85")] avr_hal_generic::impl_port_traditional! {