diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4596a452e3..7eeb111562 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Cargo.toml b/Cargo.toml index ca159ee2b2..fafb798d74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,4 +41,4 @@ exclude = [ # The RAVEDUDE! Yeah! "ravedude", ] -resolver = "2" +resolver = "2" \ No newline at end of file diff --git a/avr-specs/avr-atmega8u2.json b/avr-specs/avr-atmega8u2.json new file mode 100644 index 0000000000..30dc533ffe --- /dev/null +++ b/avr-specs/avr-atmega8u2.json @@ -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" +} diff --git a/avr-specs/sync-from-upstream.py b/avr-specs/sync-from-upstream.py index 3d04e7471f..58349e192a 100755 --- a/avr-specs/sync-from-upstream.py +++ b/avr-specs/sync-from-upstream.py @@ -4,6 +4,9 @@ import subprocess SPECS = { + "atmega8u2": { + "cpu": "atmega8u2", + }, "atmega32u4": { "cpu": "atmega32u4", }, diff --git a/mcu/atmega-hal/Cargo.toml b/mcu/atmega-hal/Cargo.toml index ebe5a12a4b..c5c179c799 100644 --- a/mcu/atmega-hal/Cargo.toml +++ b/mcu/atmega-hal/Cargo.toml @@ -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"] @@ -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"] diff --git a/mcu/atmega-hal/src/adc.rs b/mcu/atmega-hal/src/adc.rs index d79f5866ec..e784358320 100644 --- a/mcu/atmega-hal/src/adc.rs +++ b/mcu/atmega-hal/src/adc.rs @@ -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(); @@ -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 = avr_hal_generic::adc::Adc; /// Check the [`avr_hal_generic::adc::Channel`] documentation. +#[cfg(not(feature = "disable-adc"))] pub type Channel = avr_hal_generic::adc::Channel; /// Additional channels diff --git a/mcu/atmega-hal/src/lib.rs b/mcu/atmega-hal/src/lib.rs index e2ce9bf2e1..ae7f99cfd9 100644 --- a/mcu/atmega-hal/src/lib.rs +++ b/mcu/atmega-hal/src/lib.rs @@ -33,6 +33,7 @@ compile_error!( Please select one of the following + * atmega8u2 * atmega48p * atmega164pa * atmega168 @@ -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")] @@ -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")] @@ -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) => { diff --git a/mcu/atmega-hal/src/port.rs b/mcu/atmega-hal/src/port.rs index a4abf776c0..235edce2da 100644 --- a/mcu/atmega-hal/src/port.rs +++ b/mcu/atmega-hal/src/port.rs @@ -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], @@ -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 { @@ -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], - } -} diff --git a/mcu/atmega-hal/src/spi.rs b/mcu/atmega-hal/src/spi.rs index 62c7988011..1cc518b8ce 100644 --- a/mcu/atmega-hal/src/spi.rs +++ b/mcu/atmega-hal/src/spi.rs @@ -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< @@ -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! { diff --git a/mcu/atmega-hal/src/usart.rs b/mcu/atmega-hal/src/usart.rs index 3fbd8514cc..43b87f2c81 100644 --- a/mcu/atmega-hal/src/usart.rs +++ b/mcu/atmega-hal/src/usart.rs @@ -54,6 +54,7 @@ avr_hal_generic::impl_usart_traditional! { } #[cfg(any( + feature = "atmega8u2", feature = "atmega32u4", feature = "atmega128a", feature = "atmega1280", @@ -68,6 +69,7 @@ pub type Usart1 = Usart< CLOCK, >; #[cfg(any( + feature = "atmega8u2", feature = "atmega32u4", feature = "atmega1280", feature = "atmega2560",