From 0b8c5a8cad9fe77b6632197677de4cfcf3f463a7 Mon Sep 17 00:00:00 2001 From: Alec Deason Date: Wed, 22 Jun 2022 22:12:26 -0700 Subject: [PATCH] Add support for attiny13a --- Cargo.toml | 1 + Makefile | 2 +- README.md | 23 +- patch/attiny13a.yaml | 80 +++++ patch/timer/attiny13a.yaml | 10 + src/devices/mod.rs | 19 ++ src/lib.rs | 5 + vendor/attiny13a.atdf | 632 +++++++++++++++++++++++++++++++++++++ 8 files changed, 760 insertions(+), 12 deletions(-) create mode 100644 patch/attiny13a.yaml create mode 100644 patch/timer/attiny13a.yaml create mode 100644 vendor/attiny13a.atdf diff --git a/Cargo.toml b/Cargo.toml index 17facaa..c8ebdd0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ atmega48p = ["device-selected"] atmega32u4 = ["device-selected"] atmega64 = ["device-selected"] atmega644 = ["device-selected"] +attiny13a = ["device-selected"] attiny167 = ["device-selected"] attiny202 = ["device-selected"] attiny2313 = ["device-selected"] diff --git a/Makefile b/Makefile index b2f7a46..f964a2c 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: deps chips -CHIPS := at90usb1286 atmega1280 atmega1284p atmega128rfa1 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 atmega1284p atmega128rfa1 atmega168 atmega2560 atmega8 atmega8u2 atmega328p atmega328pb atmega32u4 atmega4809 atmega48p atmega64 atmega644 attiny13a attiny202 attiny2313 attiny2313a attiny84 attiny85 attiny88 attiny816 attiny841 attiny861 attiny167 attiny1614 RUSTUP_TOOLCHAIN ?= nightly diff --git a/README.md b/README.md index 578f338..afeebba 100644 --- a/README.md +++ b/README.md @@ -14,17 +14,18 @@ Via the feature you can select which chip you want the register specifications f | 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` | -| `atmega1284p` | | | | `attiny1614` | -| `atmega128rfa1` | | | | `attiny2313` | -| `atmega2560` | | | | `attiny2313a` | +| `atmega8` | `atmega8u2` | `atmega4809` | `at90usb1286` | `attiny13a` | +| `atmega48p` | `atmega32u4` | | | `attiny167` | +| `atmega64` | | | | `attiny202` | +| `atmega644` | | | | `attiny84` | +| `atmega168` | | | | `attiny85` | +| `atmega328p` | | | | `attiny88` | +| `atmega328pb` | | | | `attiny816` | +| `atmega1280` | | | | `attiny841` | +| `atmega1284p` | | | | `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/attiny13a.yaml b/patch/attiny13a.yaml new file mode 100644 index 0000000..b6ce2b5 --- /dev/null +++ b/patch/attiny13a.yaml @@ -0,0 +1,80 @@ +_svd: ../svd/attiny13a.svd + +_include: + - "common/ac.yaml" + - "common/eeprom.yaml" + - "common/wdt.yaml" + + - "common/tiny/exint.yaml" + + - "timer/attiny13a.yaml" + +AC: + _modify: + DIDR0: + description: "Digital Input Disable Register 0" +ADC: + _modify: + ADCSRA: + description: "ADC Control and Status Register A" + ADCSRA: + ADPS: + _replace_enum: + PRESCALER_2: [1, "Prescaler Value 2"] + PRESCALER_4: [2, "Prescaler Value 4"] + PRESCALER_8: [3, "Prescaler Value 8"] + PRESCALER_16: [4, "Prescaler Value 16"] + PRESCALER_32: [5, "Prescaler Value 32"] + PRESCALER_64: [6, "Prescaler Value 64"] + PRESCALER_128: [7, "Prescaler Value 128"] + ADCSRB: + ADTS: + _replace_enum: + FREE: [0, "Free Running mode"] + AC: [1, "Analog Comparator"] + INT0: [2, "External Interrupt Request 0"] + TC0_CMA: [3, "Timer/Counter0 Compare Match A"] + TC0_OVF: [4, "Timer/Counter0 Overflow"] + TC0_CMB: [5, "Timer/Counter0 Compare Match B"] + PCIR: [6, "Pin Change Interrupt Request"] + ADMUX: + _modify: + MUX: + _write_constraint: enum + MUX: + _replace_enum: + ADC0: [0, "Single-ended Input ADC0"] + ADC1: [1, "Single-ended Input ADC1"] + ADC2: [2, "Single-ended Input ADC2"] + ADC3: [3, "Single-ended Input ADC3"] + REFS0: + _replace_enum: + VCC: [0, "Vcc used as Voltage Reference"] + INTERNAL: [1, "Internal Voltage Reference of 1.1V "] +CPU: + CLKPR: + CLKPS: + _replace_enum: + PRESCALER_1: [0, "Prescaler Value 1"] + PRESCALER_2: [1, "Prescaler Value 2"] + PRESCALER_4: [2, "Prescaler Value 4"] + PRESCALER_8: [3, "Prescaler Value 8"] + PRESCALER_16: [4, "Prescaler Value 16"] + PRESCALER_32: [5, "Prescaler Value 32"] + PRESCALER_64: [6, "Prescaler Value 64"] + PRESCALER_128: [7, "Prescaler Value 128"] + PRESCALER_256: [8, "Prescaler Value 256"] + MCUCR: + _delete: + ISC?: + _add: + BODS: + description: "BOD Sleep (available on some devices)" + bitOffset: 7 + bitWidth: 1 + access: read-write + BODSE: + description: "BOD Sleep Enable (available on some devices)" + bitOffset: 2 + bitWidth: 1 + access: read-write diff --git a/patch/timer/attiny13a.yaml b/patch/timer/attiny13a.yaml new file mode 100644 index 0000000..43d8f66 --- /dev/null +++ b/patch/timer/attiny13a.yaml @@ -0,0 +1,10 @@ +# This intermediate file is needed because peripheral-level includes are not +# supported in top-level files. + +_modify: + TC0: + description: "Timer/Counter0, 8-bit, PWM" + +TC0: + _include: + - "dev/8bit-tiny8n-tc0.yaml" diff --git a/src/devices/mod.rs b/src/devices/mod.rs index ad5ad17..646d9b0 100644 --- a/src/devices/mod.rs +++ b/src/devices/mod.rs @@ -288,6 +288,25 @@ impl atmega644::Peripherals { } } +/// [ATtiny13A](https://www.microchip.com/wwwproducts/en/ATtiny13A) +#[cfg(feature = "attiny13a")] +pub mod attiny13a; + +#[cfg(feature = "attiny13a")] +impl attiny13a::Peripherals { + /// Returns all the peripherals *once* + #[inline] + pub fn take() -> Option { + crate::interrupt::free(|_| { + if unsafe { DEVICE_PERIPHERALS } { + None + } else { + Some(unsafe { attiny13a::Peripherals::steal() }) + } + }) + } +} + /// [ATtiny167](https://www.microchip.com/wwwproducts/en/ATtiny167) #[cfg(feature = "attiny167")] pub mod attiny167; diff --git a/src/lib.rs b/src/lib.rs index 2ccbed7..5f8790b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,6 +14,7 @@ #![cfg_attr(feature = "atmega48p", doc = "**atmega48p**,")] #![cfg_attr(feature = "atmega64", doc = "**atmega64**,")] #![cfg_attr(feature = "atmega644", doc = "**atmega644**,")] +#![cfg_attr(feature = "attiny13a", doc = "**attiny13a**,")] #![cfg_attr(feature = "attiny167", doc = "**attiny167**,")] #![cfg_attr(feature = "attiny1614", doc = "**attiny1614**,")] #![cfg_attr(feature = "attiny202", doc = "**attiny202**,")] @@ -44,6 +45,7 @@ //! * `atmega48p` //! * `atmega64` //! * `atmega644` +//! * `attiny13a` //! * `attiny167` //! * `attiny1614` //! * `attiny202` @@ -121,6 +123,7 @@ compile_error!( * atmega644 * atmega8 * atmega8u2 + * attiny13a * attiny167 * attiny1614 * attiny202 @@ -168,6 +171,8 @@ pub use crate::devices::atmega644; pub use crate::devices::atmega8; #[cfg(feature = "atmega8u2")] pub use crate::devices::atmega8u2; +#[cfg(feature = "attiny13a")] +pub use crate::devices::attiny13a; #[cfg(feature = "attiny1614")] pub use crate::devices::attiny1614; #[cfg(feature = "attiny167")] diff --git a/vendor/attiny13a.atdf b/vendor/attiny13a.atdf new file mode 100644 index 0000000..10f7c67 --- /dev/null +++ b/vendor/attiny13a.atdf @@ -0,0 +1,632 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.49.0