From 912202c8418d16c740d7e92d82e17554ccda3025 Mon Sep 17 00:00:00 2001 From: the6p4c Date: Sun, 6 Mar 2022 23:04:17 +1000 Subject: [PATCH] Add ATmega128RFA1 support Adds basic ATmega128RFA1 support. Adjusts the common USART patches for UCSZ? slightly to work with the ATmega128RFA1's ATDF. --- Cargo.toml | 1 + Makefile | 2 +- README.md | 26 +- patch/atmega128rfa1.yaml | 18 + patch/common/usart.yaml | 9 +- src/devices/mod.rs | 19 + src/lib.rs | 5 + vendor/atmega128rfa1.atdf | 2217 +++++++++++++++++++++++++++++++++++++ 8 files changed, 2279 insertions(+), 18 deletions(-) create mode 100644 patch/atmega128rfa1.yaml create mode 100644 vendor/atmega128rfa1.atdf diff --git a/Cargo.toml b/Cargo.toml index afeb44f..a728961 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ all-features = true device-selected = [] at90usb1286 = ["device-selected"] atmega1280 = ["device-selected"] +atmega128rfa1 = ["device-selected"] atmega168 = ["device-selected"] atmega2560 = ["device-selected"] atmega8 = ["device-selected"] diff --git a/Makefile b/Makefile index 83266e1..79a04b2 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: deps chips -CHIPS := at90usb1286 atmega1280 atmega168 atmega2560 atmega8 atmega8u2 atmega328p atmega328pb atmega32u4 atmega4809 atmega48p atmega64 atmega644 attiny202 attiny2313 attiny2313a attiny84 attiny85 attiny88 attiny816 attiny841 attiny861 attiny167 attiny1614 +CHIPS := at90usb1286 atmega1280 atmega128rfa1 atmega168 atmega2560 atmega8 atmega8u2 atmega328p atmega328pb atmega32u4 atmega4809 atmega48p atmega64 atmega644 attiny202 attiny2313 attiny2313a attiny84 attiny85 attiny88 attiny816 attiny841 attiny861 attiny167 attiny1614 RUSTUP_TOOLCHAIN ?= nightly diff --git a/README.md b/README.md index 8e43a08..956d929 100644 --- a/README.md +++ b/README.md @@ -12,19 +12,19 @@ features = ["atmega32u4"] Via the feature you can select which chip you want the register specifications for. The following list is what is currently supported: -| ATmega | ATmega USB | ATmega 0,1 Series | AT90 | ATtiny | -|:-------------:|:------------:|:-----------------:|:-------------:|:-------------:| -| `atmega8` | `atmega8u2` | `atmega4809` | `at90usb1286` | `attiny167` | -| `atmega48p` | `atmega32u4` | | | `attiny202` | -| `atmega64` | | | | `attiny84` | -| `atmega644` | | | | `attiny85` | -| `atmega168` | | | | `attiny88` | -| `atmega328p` | | | | `attiny816` | -| `atmega328pb` | | | | `attiny841` | -| `atmega1280` | | | | `attiny861` | -| `atmega2560` | | | | `attiny1614` | -| | | | | `attiny2313` | -| | | | | `attiny2313a` | +| ATmega | ATmega USB | ATmega 0,1 Series | AT90 | ATtiny | +|:---------------:|:------------:|:-----------------:|:-------------:|:-------------:| +| `atmega8` | `atmega8u2` | `atmega4809` | `at90usb1286` | `attiny167` | +| `atmega48p` | `atmega32u4` | | | `attiny202` | +| `atmega64` | | | | `attiny84` | +| `atmega644` | | | | `attiny85` | +| `atmega168` | | | | `attiny88` | +| `atmega328p` | | | | `attiny816` | +| `atmega328pb` | | | | `attiny841` | +| `atmega1280` | | | | `attiny861` | +| `atmega128rfa1` | | | | `attiny1614` | +| `atmega2560` | | | | `attiny2313` | +| | | | | `attiny2313a` | ## Build Instructions The version on `crates.io` is pre-built. The following is only necessary when trying to build this crate from source. diff --git a/patch/atmega128rfa1.yaml b/patch/atmega128rfa1.yaml new file mode 100644 index 0000000..c82be77 --- /dev/null +++ b/patch/atmega128rfa1.yaml @@ -0,0 +1,18 @@ +_svd: ../svd/atmega128rfa1.svd + +# this isn't complete, but the MAN_ID_0 field is broken into bits, and has an +# associated 8-bit wide enum which is associated with bit 0 rather than the +# entire register. many other registers within the TRX24 are incorrectly split +# into bits, however they have not been patched yet as this is the only one +# which causes a build failure. +TRX24: + MAN_ID_0: + _merge: + - "*" + +_include: + - "common/adc.yaml" + - "common/spi.yaml" + - "common/twi.yaml" + - "common/usart.yaml" + - "common/wdt.yaml" diff --git a/patch/common/usart.yaml b/patch/common/usart.yaml index c18f0fa..ed4ebee 100644 --- a/patch/common/usart.yaml +++ b/patch/common/usart.yaml @@ -33,10 +33,11 @@ USART?: STOP1: [0, "1-bit"] STOP2: [1, "2-bit"] UCSZ?: - CHR5: [0, "Character Size: 5 bit"] - CHR6: [1, "Character Size: 6 bit"] - CHR7: [2, "Character Size: 7 bit"] - CHR8: [3, "Character Size: 8 bit"] + _replace_enum: + CHR5: [0, "Character Size: 5 bit"] + CHR6: [1, "Character Size: 6 bit"] + CHR7: [2, "Character Size: 7 bit"] + CHR8: [3, "Character Size: 8 bit"] UCPOL?: _replace_enum: RISING_EDGE: [0, "Transmit on Rising XCKn Edge, Receive on Falling XCKn Edge"] diff --git a/src/devices/mod.rs b/src/devices/mod.rs index e12c315..d812ea7 100644 --- a/src/devices/mod.rs +++ b/src/devices/mod.rs @@ -41,6 +41,25 @@ impl atmega1280::Peripherals { } } +/// [ATmega128RFA1](https://www.microchip.com/en-us/product/ATmega128RFA1) +#[cfg(feature = "atmega128rfa1")] +pub mod atmega128rfa1; + +#[cfg(feature = "atmega128rfa1")] +impl atmega128rfa1::Peripherals { + /// Returns all the peripherals *once* + #[inline] + pub fn take() -> Option { + crate::interrupt::free(|_| { + if unsafe { DEVICE_PERIPHERALS } { + None + } else { + Some(unsafe { atmega128rfa1::Peripherals::steal() }) + } + }) + } +} + /// [ATmega168](https://www.microchip.com/wwwproducts/en/ATmega168) #[cfg(feature = "atmega168")] pub mod atmega168; diff --git a/src/lib.rs b/src/lib.rs index b036588..f024878 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ //! This crate contains register definitions for #![cfg_attr(feature = "at90usb1286", doc = "**at90usb1286**,")] #![cfg_attr(feature = "atmega1280", doc = "**atmega1280**,")] +#![cfg_attr(feature = "atmega128rfa1", doc = "**atmega128rfa1**,")] #![cfg_attr(feature = "atmega168", doc = "**atmega168**,")] #![cfg_attr(feature = "atmega2560", doc = "**atmega2560**,")] #![cfg_attr(feature = "atmega8", doc = "**atmega8**,")] @@ -29,6 +30,7 @@ //! The following chips are available (using feature flags of the same name): //! * `at90usb1286` //! * `atmega1280` +//! * `atmega128rfa1` //! * `atmega168` //! * `atmega2560` //! * `atmega8` @@ -103,6 +105,7 @@ compile_error!( Please select one of the following: * atmega1280 + * atmega128rfa1 * atmega168 * atmega2560 * atmega328p @@ -135,6 +138,8 @@ mod devices; pub use crate::devices::at90usb1286; #[cfg(feature = "atmega1280")] pub use crate::devices::atmega1280; +#[cfg(feature = "atmega128rfa1")] +pub use crate::devices::atmega128rfa1; #[cfg(feature = "atmega168")] pub use crate::devices::atmega168; #[cfg(feature = "atmega2560")] diff --git a/vendor/atmega128rfa1.atdf b/vendor/atmega128rfa1.atdf new file mode 100644 index 0000000..7cfe8a8 --- /dev/null +++ b/vendor/atmega128rfa1.atdf @@ -0,0 +1,2217 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.49.0