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

atmega-hal: Add support for ATmega8U2 v2 #568

Open
wants to merge 8 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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ jobs:
name: attiny88
spec: attiny88
crate: attiny-hal
- type: mcu
name: atmega8u2
spec: atmega8u2
crate: atmega-hal
- type: mcu
name: attiny167
spec: attiny167
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ exclude = [
# The RAVEDUDE! Yeah!
"ravedude",
]
resolver = "2"
resolver = "2"
27 changes: 27 additions & 0 deletions avr-specs/avr-atmega8u2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"arch": "avr",
"atomic-cas": false,
"cpu": "atmega8u2",
"data-layout": "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8",
"eh-frame-header": false,
"exe-suffix": ".elf",
"executables": true,
"late-link-args": {
"gcc": [
"-lgcc"
]
},
"linker": "avr-gcc",
"linker-is-gnu": true,
"llvm-target": "avr-unknown-unknown",
"max-atomic-width": 8,
"no-default-libraries": false,
"pre-link-args": {
"gcc": [
"-mmcu=atmega8u2",
"-Wl,--as-needed"
]
},
"target-c-int-width": "16",
"target-pointer-width": "16"
}
3 changes: 3 additions & 0 deletions avr-specs/sync-from-upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import subprocess

SPECS = {
"atmega8u2": {
"cpu": "atmega8u2",
},
"atmega32u4": {
"cpu": "atmega32u4",
},
Expand Down
2 changes: 2 additions & 0 deletions mcu/atmega-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ categories = ["no-std", "embedded", "hardware-support"]
rt = ["avr-device/rt"]
device-selected = []
enable-extra-adc = []
disable-adc = []
atmega48p = ["avr-device/atmega48p", "device-selected"]
atmega164pa = ["avr-device/atmega164pa", "device-selected"]
atmega168 = ["avr-device/atmega168", "device-selected"]
Expand All @@ -26,6 +27,7 @@ atmega128a = ["avr-device/atmega128a", "device-selected"]
atmega1280 = ["avr-device/atmega1280", "device-selected"]
atmega1284p = ["avr-device/atmega1284p", "device-selected"]
atmega8 = ["avr-device/atmega8", "device-selected"]
atmega8u2 = ["avr-device/atmega8u2", "device-selected", "disable-adc"]

critical-section-impl = ["avr-device/critical-section-impl"]

Expand Down
3 changes: 3 additions & 0 deletions mcu/atmega-hal/src/adc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct AdcSettings {
pub ref_voltage: ReferenceVoltage,
}

#[cfg(not(feature = "disable-adc"))]
fn apply_settings(peripheral: &crate::pac::ADC, settings: AdcSettings) {
peripheral.adcsra.write(|w| {
w.aden().set_bit();
Expand All @@ -52,9 +53,11 @@ fn apply_settings(peripheral: &crate::pac::ADC, settings: AdcSettings) {
}

/// Check the [`avr_hal_generic::adc::Adc`] documentation.
#[cfg(not(feature = "disable-adc"))]
pub type Adc<CLOCK> = avr_hal_generic::adc::Adc<crate::Atmega, crate::pac::ADC, CLOCK>;

/// Check the [`avr_hal_generic::adc::Channel`] documentation.
#[cfg(not(feature = "disable-adc"))]
pub type Channel = avr_hal_generic::adc::Channel<crate::Atmega, crate::pac::ADC>;

/// Additional channels
Expand Down
14 changes: 12 additions & 2 deletions mcu/atmega-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ compile_error!(

Please select one of the following

* atmega8u2
* atmega48p
* atmega164pa
* atmega168
Expand Down Expand Up @@ -95,6 +96,10 @@ pub use avr_device::atmega48p as pac;
///
#[cfg(feature = "atmega8")]
pub use avr_device::atmega8 as pac;
/// Reexport of `atmega8u2` from `avr-device`
///
#[cfg(feature = "atmega8u2")]
pub use avr_device::atmega8u2 as pac;

/// See [`avr_device::entry`](https://docs.rs/avr-device/latest/avr_device/attr.entry.html).
#[cfg(feature = "rt")]
Expand All @@ -109,7 +114,7 @@ pub use avr_hal_generic::prelude;

#[cfg(feature = "device-selected")]
pub mod adc;
#[cfg(feature = "device-selected")]
#[cfg(all(feature = "device-selected", not(feature = "disable-adc")))]
pub use adc::Adc;

#[cfg(feature = "device-selected")]
Expand Down Expand Up @@ -147,7 +152,12 @@ pub use eeprom::Eeprom;

pub struct Atmega;

#[cfg(any(feature = "atmega48p", feature = "atmega168", feature = "atmega328p"))]
#[cfg(any(
feature = "atmega8u2",
feature = "atmega48p",
feature = "atmega168",
feature = "atmega328p"
))]
#[macro_export]
macro_rules! pins {
($p:expr) => {
Expand Down
20 changes: 10 additions & 10 deletions mcu/atmega-hal/src/port.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub use avr_hal_generic::port::{mode, PinMode, PinOps};

#[cfg(any(feature = "atmega48p", feature = "atmega168", feature = "atmega328p"))]
#[cfg(any(feature = "atmega48p", feature = "atmega168", feature = "atmega328p", feature="atmega8"))]
avr_hal_generic::impl_port_traditional! {
enum Ports {
B: crate::pac::PORTB = [0, 1, 2, 3, 4, 5, 6, 7],
Expand All @@ -19,6 +19,15 @@ avr_hal_generic::impl_port_traditional! {
}
}

#[cfg(feature = "atmega8u2")]
avr_hal_generic::impl_port_traditional! {
enum Ports {
B: crate::pac::PORTB = [0, 1, 2, 3, 4, 5, 6, 7],
C: crate::pac::PORTC = [0, 1, 2, 3, 4, 5, 6, 7],
D: crate::pac::PORTD = [0, 1, 2, 3, 4, 5, 6, 7],
}
}

#[cfg(feature = "atmega328pb")]
avr_hal_generic::impl_port_traditional! {
enum Ports {
Expand Down Expand Up @@ -79,12 +88,3 @@ avr_hal_generic::impl_port_traditional! {
D: crate::pac::PORTD = [0, 1, 2, 3, 4, 5, 6, 7],
}
}

#[cfg(any(feature = "atmega8"))]
avr_hal_generic::impl_port_traditional! {
enum Ports {
B: crate::pac::PORTB = [0, 1, 2, 3, 4, 5, 6, 7],
C: crate::pac::PORTC = [0, 1, 2, 3, 4, 5, 6],
D: crate::pac::PORTD = [0, 1, 2, 3, 4, 5, 6, 7],
}
}
2 changes: 2 additions & 0 deletions mcu/atmega-hal/src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub use avr_hal_generic::spi::*;
feature = "atmega128a",
feature = "atmega1280",
feature = "atmega2560",
feature = "atmega8u2",
feature = "atmega32u4"
))]
pub type Spi = avr_hal_generic::spi::Spi<
Expand All @@ -20,6 +21,7 @@ pub type Spi = avr_hal_generic::spi::Spi<
feature = "atmega128a",
feature = "atmega1280",
feature = "atmega2560",
feature = "atmega8u2",
feature = "atmega32u4"
))]
avr_hal_generic::impl_spi! {
Expand Down
2 changes: 2 additions & 0 deletions mcu/atmega-hal/src/usart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ avr_hal_generic::impl_usart_traditional! {
}

#[cfg(any(
feature = "atmega8u2",
feature = "atmega32u4",
feature = "atmega128a",
feature = "atmega1280",
Expand All @@ -68,6 +69,7 @@ pub type Usart1<CLOCK> = Usart<
CLOCK,
>;
#[cfg(any(
feature = "atmega8u2",
feature = "atmega32u4",
feature = "atmega1280",
feature = "atmega2560",
Expand Down