Skip to content
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

Add ATmega16 support #645

Open
wants to merge 1 commit 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/atmega-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ rt = ["avr-device/rt"]
device-selected = []
enable-extra-adc = []
atmega48p = ["avr-device/atmega48p", "device-selected"]
atmega16 = ["avr-device/atmega16", "device-selected"]
atmega164pa = ["avr-device/atmega164pa", "device-selected"]
atmega168 = ["avr-device/atmega168", "device-selected"]
atmega328p = ["avr-device/atmega328p", "device-selected"]
Expand Down
5 changes: 4 additions & 1 deletion mcu/atmega-hal/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ pub mod channel {
pub struct ADC7;
#[cfg(any(
feature = "atmega1280",
feature = "atmega16",
feature = "atmega168",
feature = "atmega2560",
feature = "atmega32a",
Expand All @@ -136,6 +137,7 @@ pub mod channel {
feature = "atmega128a",
feature = "atmega1284p",
feature = "atmega8",
feature = "atmega16",
feature = "atmega164pa",
feature = "atmega88p"
))]
Expand All @@ -152,6 +154,7 @@ pub mod channel {
feature = "atmega128a",
feature = "atmega1284p",
feature = "atmega8",
feature = "atmega16",
feature = "atmega164pa",
feature = "atmega88p"
))]
Expand Down Expand Up @@ -202,7 +205,7 @@ avr_hal_generic::impl_adc! {
},
}

#[cfg(any(feature = "atmega32a"))]
#[cfg(any(feature = "atmega16", feature = "atmega32a"))]
avr_hal_generic::impl_adc! {
hal: crate::Atmega,
peripheral: crate::pac::ADC,
Expand Down
2 changes: 1 addition & 1 deletion mcu/atmega-hal/src/eeprom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ avr_hal_generic::impl_eeprom_atmega! {
},
}

#[cfg(any(feature = "atmega8"))]
#[cfg(any(feature = "atmega8", feature = "atmega8"))]
avr_hal_generic::impl_eeprom_atmega_old! {
hal: crate::Atmega,
peripheral: crate::pac::EEPROM,
Expand Down
4 changes: 2 additions & 2 deletions mcu/atmega-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ avr_hal_generic::impl_i2c_twi! {
scl: port::PD0,
}

#[cfg(any(feature = "atmega164pa"))]
#[cfg(any(feature = "atmega16", feature = "atmega164pa"))]
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 = "atmega164pa"))]
#[cfg(any(feature = "atmega16", feature = "atmega164pa"))]
avr_hal_generic::impl_i2c_twi! {
hal: crate::Atmega,
peripheral: crate::pac::TWI,
Expand Down
8 changes: 7 additions & 1 deletion mcu/atmega-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//!
//! **Note**: This version of the documentation was built for
#![cfg_attr(feature = "atmega48p", doc = "**ATmega48P**.")]
#![cfg_attr(feature = "atmega16", doc = "**ATmega16**.")]
#![cfg_attr(feature = "atmega164pa", doc = "**ATmega164PA**.")]
#![cfg_attr(feature = "atmega168", doc = "**ATmega168**.")]
#![cfg_attr(feature = "atmega328p", doc = "**ATmega328P**.")]
Expand Down Expand Up @@ -35,6 +36,7 @@ compile_error!(
Please select one of the following

* atmega48p
* atmega16
* atmega164pa
* atmega168
* atmega328p
Expand All @@ -61,6 +63,10 @@ pub use avr_device::atmega1284p as pac;
///
#[cfg(feature = "atmega128a")]
pub use avr_device::atmega128a as pac;
/// Reexport of `atmega16` from `avr-device`
///
#[cfg(feature = "atmega16")]
pub use avr_device::atmega16 as pac;
/// Reexport of `atmega164pa` from `avr-device`
///
#[cfg(feature = "atmega164pa")]
Expand Down Expand Up @@ -165,7 +171,7 @@ macro_rules! pins {
$crate::Pins::new($p.PORTB, $p.PORTC, $p.PORTD)
};
}
#[cfg(any(feature = "atmega164pa"))]
#[cfg(any(feature = "atmega16", feature = "atmega164pa"))]
#[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 @@ -33,7 +33,7 @@ avr_hal_generic::impl_port_traditional! {
}
}

#[cfg(any(feature = "atmega164pa"))]
#[cfg(any(feature = "atmega16", feature = "atmega164pa"))]
avr_hal_generic::impl_port_traditional! {
enum Ports {
A: crate::pac::PORTA = [0, 1, 2, 3, 4, 5, 6 ,7],
Expand Down
11 changes: 10 additions & 1 deletion mcu/atmega-hal/src/simple_pwm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,7 @@ avr_hal_generic::impl_simple_pwm! {
}
}

#[cfg(any(feature = "atmega164pa"))]
#[cfg(any(feature = "atmega16", feature = "atmega164pa"))]
avr_hal_generic::impl_simple_pwm! {
/// Use `TC1` for PWM (pins `PD4`, `PD5`)
///
Expand All @@ -1150,13 +1150,22 @@ avr_hal_generic::impl_simple_pwm! {
tim.tccr1a.modify(|_r, w| w.wgm1().bits(0b01));
tim.tccr1a.modify(|_r, w| w.com1a().bits(0b00));
tim.tccr1a.modify(|_r, w| w.com1b().bits(0b00));
#[cfg(any(feature = "atmega164pa"))]
tim.tccr1b.modify(|_r, w| match prescaler {
Prescaler::Direct => w.cs1().running_no_prescaling(),
Prescaler::Prescale8 => w.cs1().running_clk_8(),
Prescaler::Prescale64 => w.cs1().running_clk_64(),
Prescaler::Prescale256 => w.cs1().running_clk_256(),
Prescaler::Prescale1024 => w.cs1().running_clk_1024(),
});
#[cfg(any(feature = "atmega16"))]
tim.tccr1b.modify(|_r, w| match prescaler {
Prescaler::Direct => w.cs1().val_0x01(),
Prescaler::Prescale8 => w.cs1().val_0x02(),
Prescaler::Prescale64 => w.cs1().val_0x03(),
Prescaler::Prescale256 => w.cs1().val_0x04(),
Prescaler::Prescale1024 => w.cs1().val_0x05(),
});
},
pins: {
PD4: {
Expand Down
7 changes: 7 additions & 0 deletions mcu/atmega-hal/src/usart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ pub type UsartWriter<USART, RX, TX, CLOCK> =
pub type UsartReader<USART, RX, TX, CLOCK> =
avr_hal_generic::usart::UsartReader<crate::Atmega, USART, RX, TX, CLOCK>;

#[cfg(any(feature = "atmega16"))]
pub type Usart0<CLOCK> = Usart<
crate::pac::USART,
port::Pin<port::mode::Input, port::PD0>,
port::Pin<port::mode::Output, port::PD1>,
CLOCK,
>;
#[cfg(any(
feature = "atmega88p",
feature = "atmega168",
Expand Down
2 changes: 1 addition & 1 deletion 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 = "atmega8", feature = "atmega32a", feature = "atmega128a")))]
#[cfg(not(any(feature = "atmega8", feature = "atmega16", feature = "atmega32a", feature = "atmega128a")))]
avr_hal_generic::impl_wdt! {
hal: crate::Atmega,
peripheral: crate::pac::WDT,
Expand Down