Skip to content

Commit

Permalink
atmega32a: Basic support
Browse files Browse the repository at this point in the history
  • Loading branch information
West14 committed Aug 10, 2023
1 parent d5beacb commit 0b81ff0
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ jobs:
name: atmega1280
spec: atmega1280
crate: atmega-hal
- type: mcu
name: atmega32a
spec: atmega32a
- type: mcu
name: atmega128a
spec: atmega128a
Expand Down
1 change: 1 addition & 0 deletions mcu/atmega-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
30 changes: 30 additions & 0 deletions mcu/atmega-hal/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub mod channel {
#[cfg(all(
any(
feature = "atmega168",
feature = "atmega32a",
feature = "atmega328p",
feature = "atmega328pb",
feature = "atmega48p",
Expand All @@ -86,6 +87,7 @@ pub mod channel {
#[cfg(all(
any(
feature = "atmega168",
feature = "atmega32a",
feature = "atmega328p",
feature = "atmega328pb",
feature = "atmega48p",
Expand All @@ -100,6 +102,7 @@ pub mod channel {
feature = "atmega1280",
feature = "atmega168",
feature = "atmega2560",
feature = "atmega32a",
feature = "atmega328p",
feature = "atmega328pb",
feature = "atmega32u4",
Expand All @@ -113,6 +116,7 @@ pub mod channel {
feature = "atmega1280",
feature = "atmega168",
feature = "atmega2560",
feature = "atmega32a",
feature = "atmega328p",
feature = "atmega328pb",
feature = "atmega32u4",
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 15 additions & 1 deletion mcu/atmega-hal/src/eeprom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
))]
Expand All @@ -79,4 +92,5 @@ avr_hal_generic::impl_eeprom_atmega_old! {
set_address: |peripheral, address| {
peripheral.eear.write(|w| w.bits(address));
},
}
}

4 changes: 2 additions & 2 deletions mcu/atmega-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ avr_hal_generic::impl_i2c_twi! {
scl: port::PE1,
}

#[cfg(any(feature = "atmega1284p"))]
#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
pub type I2c<CLOCK> = avr_hal_generic::i2c::I2c<
crate::Atmega,
crate::pac::TWI,
port::Pin<port::mode::Input, port::PC1>,
port::Pin<port::mode::Input, port::PC0>,
CLOCK,
>;
#[cfg(any(feature = "atmega1284p"))]
#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
avr_hal_generic::impl_i2c_twi! {
hal: crate::Atmega,
peripheral: crate::pac::TWI,
Expand Down
6 changes: 5 additions & 1 deletion mcu/atmega-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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**.")]
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -170,7 +174,7 @@ macro_rules! pins {
};
}

#[cfg(any(feature = "atmega1284p"))]
#[cfg(any(feature = "atmega1284p", feature = "atmega32a"))]
#[macro_export]
macro_rules! pins {
($p:expr) => {
Expand Down
2 changes: 1 addition & 1 deletion mcu/atmega-hal/src/port.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions mcu/atmega-hal/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions mcu/atmega-hal/src/usart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CLOCK> = Usart<
crate::pac::USART,
port::Pin<port::mode::Input, port::PD0>,
Expand All @@ -120,7 +120,7 @@ pub type Usart0<CLOCK> = 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<crate::port::mode::Input, port::PD0>,
Expand Down
4 changes: 2 additions & 2 deletions mcu/atmega-hal/src/wdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub use avr_hal_generic::wdt::{Timeout, WdtOps};

pub type Wdt = avr_hal_generic::wdt::Wdt<crate::Atmega, crate::pac::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,
Expand All @@ -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,
Expand Down

0 comments on commit 0b81ff0

Please sign in to comment.