From 0b81ff0da43974544266483e785a47588849f918 Mon Sep 17 00:00:00 2001 From: Andriy <30056636+West14@users.noreply.github.com> Date: Tue, 18 Apr 2023 01:52:59 +0300 Subject: [PATCH] atmega32a: Basic support --- .github/workflows/ci.yml | 3 +++ mcu/atmega-hal/Cargo.toml | 1 + mcu/atmega-hal/src/adc.rs | 30 ++++++++++++++++++++++++++++++ mcu/atmega-hal/src/eeprom.rs | 16 +++++++++++++++- mcu/atmega-hal/src/i2c.rs | 4 ++-- mcu/atmega-hal/src/lib.rs | 6 +++++- mcu/atmega-hal/src/port.rs | 2 +- mcu/atmega-hal/src/spi.rs | 4 ++-- mcu/atmega-hal/src/usart.rs | 4 ++-- mcu/atmega-hal/src/wdt.rs | 4 ++-- 10 files changed, 63 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7e35c4f969..69ee8e9fb4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,6 +49,9 @@ jobs: name: atmega1280 spec: atmega1280 crate: atmega-hal + - type: mcu + name: atmega32a + spec: atmega32a - type: mcu name: atmega128a spec: atmega128a diff --git a/mcu/atmega-hal/Cargo.toml b/mcu/atmega-hal/Cargo.toml index 6a9a6787f6..032bbfa961 100644 --- a/mcu/atmega-hal/Cargo.toml +++ b/mcu/atmega-hal/Cargo.toml @@ -12,6 +12,7 @@ atmega48p = ["avr-device/atmega48p", "device-selected"] atmega168 = ["avr-device/atmega168", "device-selected"] atmega328p = ["avr-device/atmega328p", "device-selected"] atmega328pb = ["avr-device/atmega328pb", "device-selected"] +atmega32a = ["avr-device/atmega32a", "device-selected"] atmega32u4 = ["avr-device/atmega32u4", "device-selected"] atmega2560 = ["avr-device/atmega2560", "device-selected"] atmega128a = ["avr-device/atmega128a", "device-selected"] diff --git a/mcu/atmega-hal/src/adc.rs b/mcu/atmega-hal/src/adc.rs index 21db51fdc2..f7aa1a929f 100644 --- a/mcu/atmega-hal/src/adc.rs +++ b/mcu/atmega-hal/src/adc.rs @@ -73,6 +73,7 @@ pub mod channel { #[cfg(all( any( feature = "atmega168", + feature = "atmega32a", feature = "atmega328p", feature = "atmega328pb", feature = "atmega48p", @@ -86,6 +87,7 @@ pub mod channel { #[cfg(all( any( feature = "atmega168", + feature = "atmega32a", feature = "atmega328p", feature = "atmega328pb", feature = "atmega48p", @@ -100,6 +102,7 @@ pub mod channel { feature = "atmega1280", feature = "atmega168", feature = "atmega2560", + feature = "atmega32a", feature = "atmega328p", feature = "atmega328pb", feature = "atmega32u4", @@ -113,6 +116,7 @@ pub mod channel { feature = "atmega1280", feature = "atmega168", feature = "atmega2560", + feature = "atmega32a", feature = "atmega328p", feature = "atmega328pb", feature = "atmega32u4", @@ -166,6 +170,32 @@ avr_hal_generic::impl_adc! { }, } +#[cfg(any(feature = "atmega32a"))] +avr_hal_generic::impl_adc! { + hal: crate::Atmega, + peripheral: crate::pac::ADC, + settings: AdcSettings, + apply_settings: |peripheral, settings| { apply_settings(peripheral, settings) }, + channel_id: crate::pac::adc::admux::MUX_A, + set_channel: |peripheral, id| { + peripheral.admux.modify(|_, w| w.mux().variant(id)); + }, + pins: { + port::PA0: (crate::pac::adc::admux::MUX_A::ADC0), + port::PA1: (crate::pac::adc::admux::MUX_A::ADC1), + port::PA2: (crate::pac::adc::admux::MUX_A::ADC2), + port::PA3: (crate::pac::adc::admux::MUX_A::ADC3), + port::PA4: (crate::pac::adc::admux::MUX_A::ADC4), + port::PA5: (crate::pac::adc::admux::MUX_A::ADC5), + port::PA6: (crate::pac::adc::admux::MUX_A::ADC6), + port::PA7: (crate::pac::adc::admux::MUX_A::ADC7), + }, + channels: { + channel::Vbg: crate::pac::adc::admux::MUX_A::ADC_VBG, + channel::Gnd: crate::pac::adc::admux::MUX_A::ADC_GND, + }, +} + #[cfg(feature = "atmega32u4")] avr_hal_generic::impl_adc! { hal: crate::Atmega, diff --git a/mcu/atmega-hal/src/eeprom.rs b/mcu/atmega-hal/src/eeprom.rs index 6623813193..c167fa5c1c 100644 --- a/mcu/atmega-hal/src/eeprom.rs +++ b/mcu/atmega-hal/src/eeprom.rs @@ -68,6 +68,19 @@ avr_hal_generic::impl_eeprom_atmega_old! { }, } +#[cfg(any( + feature = "atmega32a" +))] +avr_hal_generic::impl_eeprom_atmega_old! { + hal: crate::Atmega, + peripheral: crate::pac::EEPROM, + capacity: 1024, + addr_width: u16, + set_address: |peripheral, address| { + peripheral.eear.write(|w| w.bits(address)); + }, +} + #[cfg(any( feature = "atmega128a", ))] @@ -79,4 +92,5 @@ avr_hal_generic::impl_eeprom_atmega_old! { set_address: |peripheral, address| { peripheral.eear.write(|w| w.bits(address)); }, -} \ No newline at end of file +} + diff --git a/mcu/atmega-hal/src/i2c.rs b/mcu/atmega-hal/src/i2c.rs index e97903d772..456ebfe9b5 100644 --- a/mcu/atmega-hal/src/i2c.rs +++ b/mcu/atmega-hal/src/i2c.rs @@ -65,7 +65,7 @@ avr_hal_generic::impl_i2c_twi! { scl: port::PE1, } -#[cfg(any(feature = "atmega1284p"))] +#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))] pub type I2c = avr_hal_generic::i2c::I2c< crate::Atmega, crate::pac::TWI, @@ -73,7 +73,7 @@ pub type I2c = avr_hal_generic::i2c::I2c< port::Pin, CLOCK, >; -#[cfg(any(feature = "atmega1284p"))] +#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))] avr_hal_generic::impl_i2c_twi! { hal: crate::Atmega, peripheral: crate::pac::TWI, diff --git a/mcu/atmega-hal/src/lib.rs b/mcu/atmega-hal/src/lib.rs index b13c102651..49fab63741 100644 --- a/mcu/atmega-hal/src/lib.rs +++ b/mcu/atmega-hal/src/lib.rs @@ -9,6 +9,7 @@ #![cfg_attr(feature = "atmega168", doc = "**ATmega168**.")] #![cfg_attr(feature = "atmega328p", doc = "**ATmega328P**.")] #![cfg_attr(feature = "atmega328pb", doc = "**ATmega328PB**.")] +#![cfg_attr(feature = "atmega32a", doc = "**ATmega32a**.")] #![cfg_attr(feature = "atmega32u4", doc = "**ATmega32U4**.")] #![cfg_attr(feature = "atmega2560", doc = "**ATmega2560**.")] #![cfg_attr(feature = "atmega128a", doc = "**ATmega128A**.")] @@ -59,6 +60,9 @@ pub use avr_device::atmega328p as pac; /// Reexport of `atmega328pb` from `avr-device` #[cfg(feature = "atmega328pb")] pub use avr_device::atmega328pb as pac; +/// Reexport of `atmega32a` from `avr-device` +#[cfg(feature = "atmega32a")] +pub use avr_device::atmega32a as pac; /// Reexport of `atmega32u4` from `avr-device` #[cfg(feature = "atmega32u4")] pub use avr_device::atmega32u4 as pac; @@ -170,7 +174,7 @@ macro_rules! pins { }; } -#[cfg(any(feature = "atmega1284p"))] +#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))] #[macro_export] macro_rules! pins { ($p:expr) => { diff --git a/mcu/atmega-hal/src/port.rs b/mcu/atmega-hal/src/port.rs index e0e3149584..9cf4561df6 100644 --- a/mcu/atmega-hal/src/port.rs +++ b/mcu/atmega-hal/src/port.rs @@ -292,7 +292,7 @@ avr_hal_generic::impl_port_traditional! { } } -#[cfg(any(feature = "atmega1284p"))] +#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))] avr_hal_generic::impl_port_traditional! { enum Ports { PORTA: (crate::pac::PORTA, porta, pina, ddra), diff --git a/mcu/atmega-hal/src/spi.rs b/mcu/atmega-hal/src/spi.rs index ae391dfbce..ae72c08528 100644 --- a/mcu/atmega-hal/src/spi.rs +++ b/mcu/atmega-hal/src/spi.rs @@ -77,7 +77,7 @@ avr_hal_generic::impl_spi! { cs: port::PE2, } -#[cfg(any(feature = "atmega1284p"))] +#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))] pub type Spi = avr_hal_generic::spi::Spi< crate::Atmega, crate::pac::SPI, @@ -86,7 +86,7 @@ pub type Spi = avr_hal_generic::spi::Spi< port::PB6, port::PB4, >; -#[cfg(any(feature = "atmega1284p"))] +#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))] avr_hal_generic::impl_spi! { hal: crate::Atmega, peripheral: crate::pac::SPI, diff --git a/mcu/atmega-hal/src/usart.rs b/mcu/atmega-hal/src/usart.rs index df64e5641b..02f6a6565e 100644 --- a/mcu/atmega-hal/src/usart.rs +++ b/mcu/atmega-hal/src/usart.rs @@ -105,7 +105,7 @@ avr_hal_generic::impl_usart_traditional! { tx: port::PJ1, } -#[cfg(any(feature = "atmega8"))] +#[cfg(any(feature = "atmega8", feature = "atmega32a"))] pub type Usart0 = Usart< crate::pac::USART, port::Pin, @@ -120,7 +120,7 @@ pub type Usart0 = Usart< // or 0 (for UBRRH). Because of the same address, // these two are exposed as functions instead of // fields. -#[cfg(any(feature = "atmega8"))] +#[cfg(any(feature = "atmega8", feature = "atmega32a"))] impl crate::usart::UsartOps< crate::Atmega, crate::port::Pin, diff --git a/mcu/atmega-hal/src/wdt.rs b/mcu/atmega-hal/src/wdt.rs index 70a656f0a5..434189a82e 100644 --- a/mcu/atmega-hal/src/wdt.rs +++ b/mcu/atmega-hal/src/wdt.rs @@ -3,7 +3,7 @@ pub use avr_hal_generic::wdt::{Timeout, WdtOps}; pub type Wdt = avr_hal_generic::wdt::Wdt; -#[cfg(not(any(feature = "atmega128a", feature = "atmega8")))] +#[cfg(not(any(feature = "atmega8", feature = "atmega32a", feature = "atmega128a")))] avr_hal_generic::impl_wdt! { hal: crate::Atmega, peripheral: crate::pac::WDT, @@ -23,7 +23,7 @@ avr_hal_generic::impl_wdt! { }, } -#[cfg(any(feature = "atmega128a", feature = "atmega8"))] +#[cfg(any(feature = "atmega8", feature = "atmega32a", feature = "atmega128a"))] avr_hal_generic::impl_wdt! { hal: crate::Atmega, peripheral: crate::pac::WDT,