From ce321a918d719cca2e998de7562b1c4a46200ac8 Mon Sep 17 00:00:00 2001 From: jaxter184 Date: Mon, 7 Dec 2020 13:52:02 -0600 Subject: [PATCH 1/4] Fix atmega328pb AC patch --- patch/atmega328pb.yaml | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/patch/atmega328pb.yaml b/patch/atmega328pb.yaml index 71e7a13..aaedc63 100644 --- a/patch/atmega328pb.yaml +++ b/patch/atmega328pb.yaml @@ -28,8 +28,27 @@ TWI1: _strip_end: - "1" +# the svd has a register called ACSRA with no fields that +# messes up the patch when using `common/ac.yaml`, so the +# ac has to be patched here instead. +AC: + _modify: + ACSR: + access: read-write + ACSR: + _modify: + ACIS: + description: "Analog Comparator Interrupt Mode Select" + ACO: + access: read-only + ACIS: + _replace_enum: + ON_TOGGLE: [0, "Interrupt on Toggle"] + # Leaving [1, 'Reserved'] out + ON_FALLING_EDGE: [2, "Interrupt on Falling Edge"] + ON_RISING_EDGE: [3, "Interrupt on Rising Edge"] + _include: - - "common/ac.yaml" - "common/adc.yaml" - "common/port.yaml" - "common/usart.yaml" From 9df485e03419782dbde2160a20415b9845fd4d95 Mon Sep 17 00:00:00 2001 From: jaxter184 Date: Fri, 27 Nov 2020 01:44:39 -0600 Subject: [PATCH 2/4] Add attiny841 and attiny861 --- Cargo.toml | 2 + Makefile | 2 +- README.md | 2 + patch/attiny841.yaml | 51 ++ patch/attiny861.yaml | 11 + patch/common/ac.yaml | 8 +- patch/timer/attiny841.yaml | 18 + patch/timer/attiny861.yaml | 16 + patch/timer/dev/16bit-tiny861-tc0.yaml | 19 + src/devices/mod.rs | 38 + src/lib.rs | 10 + vendor/attiny841.atdf | 1125 ++++++++++++++++++++++++ vendor/attiny861.atdf | 939 ++++++++++++++++++++ 13 files changed, 2236 insertions(+), 5 deletions(-) create mode 100644 patch/attiny841.yaml create mode 100644 patch/attiny861.yaml create mode 100644 patch/timer/attiny841.yaml create mode 100644 patch/timer/attiny861.yaml create mode 100644 patch/timer/dev/16bit-tiny861-tc0.yaml create mode 100644 vendor/attiny841.atdf create mode 100644 vendor/attiny861.atdf diff --git a/Cargo.toml b/Cargo.toml index 60b2e25..e71b1c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,9 @@ atmega32u4 = [] atmega64 = [] atmega644 = [] attiny84 = [] +attiny841 = [] attiny85 = [] +attiny861 = [] attiny88 = [] rt = ["avr-device-macros"] diff --git a/Makefile b/Makefile index 65b6a95..a216b06 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: deps chips -CHIPS := atmega1280 atmega168 atmega2560 atmega8 atmega328p atmega328pb atmega32u4 atmega4809 atmega48p atmega64 atmega644 attiny84 attiny85 attiny88 +CHIPS := atmega1280 atmega168 atmega2560 atmega8 atmega328p atmega328pb atmega32u4 atmega4809 atmega48p atmega64 atmega644 attiny84 attiny85 attiny88 attiny841 attiny861 RUSTUP_TOOLCHAIN ?= nightly diff --git a/README.md b/README.md index 0f97e3e..f7d4196 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,9 @@ Via the feature you can select which chip you want the register specifications f * `atmega64` * `atmega644` * `attiny84` +* `attiny841` * `attiny85` +* `attiny861` * `attiny88` ## Build Instructions diff --git a/patch/attiny841.yaml b/patch/attiny841.yaml new file mode 100644 index 0000000..eea5686 --- /dev/null +++ b/patch/attiny841.yaml @@ -0,0 +1,51 @@ +_svd: ../svd/attiny841.svd + +_include: + - "common/ac.yaml" + - "common/port.yaml" + - "common/spi.yaml" + - "common/usart.yaml" + - "common/wdt.yaml" + + - "timer/attiny841.yaml" + +ADC: + _modify: + ADCSRA: + access: read-write + 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"] + ADMUXB: + REFS: + _replace_enum: + VCC: [0, "Vcc"] + INTERNAL_1: [1, "Internal 1.1V Voltage Reference with AREF disconnected"] + INTERNAL_2: [2, "Internal 2.2V Voltage Reference with AREF disconnected"] + INTERNAL_4: [3, "Internal 4.096V Voltage Reference with AREF disconnected"] + AREF: [4, "AREF with internal reference off"] + AREF_INTERNAL_1: [5, "Internal 1.1V Voltage Reference with external capacitor at AREF pin"] + AREF_INTERNAL_2: [6, "Internal 2.2V Voltage Reference with external capacitor at AREF pin"] + AREF_INTERNAL_4: [7, "Internal 4.096V Voltage Reference with external capacitor at AREF pin"] + +# While this chip does have a TWI peripheral, it only performs as a +# slave, so it doesn't have many of the fields that the common peripheral +# does, like TWWC, TWAMR, and TWPS +TWI*: + _modify: + TWCR: + access: read-write + TWSCRB: + TWAA: + _replace_enum: + ACK_WRITE: [0, "Send ACK when TWCMD is written as 10 or 11"] + ACK_READ: [1, "Send ACK when TWSD is read"] + NACK_WRITE: [2, "Send NACK when TWCMD is written as 10 or 11"] + NACK_READ: [3, "Send NACK when TWSD is read"] diff --git a/patch/attiny861.yaml b/patch/attiny861.yaml new file mode 100644 index 0000000..a0c2000 --- /dev/null +++ b/patch/attiny861.yaml @@ -0,0 +1,11 @@ +_svd: ../svd/attiny861.svd + +_include: + - "common/ac.yaml" + - "common/adc.yaml" + - "common/port.yaml" + - "common/tiny/usi.yaml" + - "common/wdt.yaml" + + - "timer/attiny861.yaml" + diff --git a/patch/common/ac.yaml b/patch/common/ac.yaml index 0e73a4a..c8cf890 100644 --- a/patch/common/ac.yaml +++ b/patch/common/ac.yaml @@ -6,15 +6,15 @@ # - Fix the "Interrupt Mode Select" enumerated values AC: _modify: - ACSR: + ACSR,ACSR?A,ACSRA: access: read-write - ACSR: + ACSR,ACSR?A,ACSRA: _modify: - ACIS: + ACIS,ACIS?: description: "Analog Comparator Interrupt Mode Select" ACO: access: read-only - ACIS: + ACIS,ACIS?: _replace_enum: ON_TOGGLE: [0, "Interrupt on Toggle"] # Leaving [1, 'Reserved'] out diff --git a/patch/timer/attiny841.yaml b/patch/timer/attiny841.yaml new file mode 100644 index 0000000..1964cca --- /dev/null +++ b/patch/timer/attiny841.yaml @@ -0,0 +1,18 @@ +# This intermediate file is needed because peripheral-level includes are not +# supported in top-level files. + +_modify: + TC0: + description: "Timer/Counter0, 8-bit, PWM" + TC1: + description: "Timer/Counter1, 16-bit" + TC2: + description: "Timer/Counter2, 16-bit" + +TC0: + _include: + - "dev/8bit-tiny8n-tc0.yaml" + +TC1,TC2: + _include: + - "dev/16bit.yaml" diff --git a/patch/timer/attiny861.yaml b/patch/timer/attiny861.yaml new file mode 100644 index 0000000..2af6ba4 --- /dev/null +++ b/patch/timer/attiny861.yaml @@ -0,0 +1,16 @@ +# This intermediate file is needed because peripheral-level includes are not +# supported in top-level files. + +_modify: + TC0: + description: "Timer/Counter0" + TC1: + description: "Timer/Counter1, 10-bit" + +TC0: + _include: + - "dev/16bit-tiny861-tc0.yaml" + +TC1: + _include: + - "dev/10bit.yaml" diff --git a/patch/timer/dev/16bit-tiny861-tc0.yaml b/patch/timer/dev/16bit-tiny861-tc0.yaml new file mode 100644 index 0000000..21050b7 --- /dev/null +++ b/patch/timer/dev/16bit-tiny861-tc0.yaml @@ -0,0 +1,19 @@ +_modify: + TIFR?: + access: read-write + +TCCR?B: + _modify: + CS?: + _write_constraint: enum + CS?: + _replace_enum: + NO_CLOCK: [0, "No clock source (Timer/Counter stopped)"] + DIRECT: [1, "Running, No Prescaling"] + PRESCALE_8: [2, "Running, CLK/8"] + PRESCALE_64: [3, "Running, CLK/64"] + PRESCALE_256: [4, "Running, CLK/256"] + PRESCALE_1024: [5, "Running, CLK/1024"] + EXT_FALLING: [6, "Running, ExtClk Tx Falling Edge"] + EXT_RISING: [7, "Running, ExtClk Tx Rising Edge"] + diff --git a/src/devices/mod.rs b/src/devices/mod.rs index 56059bb..8722d6c 100644 --- a/src/devices/mod.rs +++ b/src/devices/mod.rs @@ -231,6 +231,25 @@ impl attiny84::Peripherals { } } +/// [ATtiny841](https://www.microchip.com/wwwproducts/en/ATtiny841) +#[cfg(feature = "attiny841")] +pub mod attiny841; + +#[cfg(feature = "attiny841")] +impl attiny841::Peripherals { + /// Returns all the peripherals *once* + #[inline] + pub fn take() -> Option { + crate::interrupt::free(|_| { + if unsafe { DEVICE_PERIPHERALS } { + None + } else { + Some(unsafe { attiny841::Peripherals::steal() }) + } + }) + } +} + /// [ATtiny85](https://www.microchip.com/wwwproducts/en/ATtiny85) #[cfg(feature = "attiny85")] pub mod attiny85; @@ -250,6 +269,25 @@ impl attiny85::Peripherals { } } +/// [ATtiny861](https://www.microchip.com/wwwproducts/en/ATtiny861) +#[cfg(feature = "attiny861")] +pub mod attiny861; + +#[cfg(feature = "attiny861")] +impl attiny861::Peripherals { + /// Returns all the peripherals *once* + #[inline] + pub fn take() -> Option { + crate::interrupt::free(|_| { + if unsafe { DEVICE_PERIPHERALS } { + None + } else { + Some(unsafe { attiny861::Peripherals::steal() }) + } + }) + } +} + /// [ATtiny88](https://www.microchip.com/wwwproducts/en/ATtiny88) #[cfg(feature = "attiny88")] pub mod attiny88; diff --git a/src/lib.rs b/src/lib.rs index 712e75e..0f45da3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,9 @@ #![cfg_attr(feature = "atmega64", doc = "**atmega64**,")] #![cfg_attr(feature = "atmega644", doc = "**atmega644**,")] #![cfg_attr(feature = "attiny84", doc = "**attiny84**,")] +#![cfg_attr(feature = "attiny841", doc = "**attiny841**,")] #![cfg_attr(feature = "attiny85", doc = "**attiny85**,")] +#![cfg_attr(feature = "attiny861", doc = "**attiny861**,")] #![cfg_attr(feature = "attiny88", doc = "**attiny88**,")] //! and a few things which apply to AVR microcontrollers generally. //! @@ -27,7 +29,9 @@ //! * `atmega4809` //! * `atmega48p` //! * `atmega64` +//! * `attiny841` //! * `attiny85` +//! * `attiny861` //! * `attiny88` #![no_std] #![feature(llvm_asm)] @@ -101,8 +105,12 @@ pub use crate::devices::atmega644; pub use crate::devices::atmega8; #[cfg(feature = "attiny84")] pub use crate::devices::attiny84; +#[cfg(feature = "attiny841")] +pub use crate::devices::attiny841; #[cfg(feature = "attiny85")] pub use crate::devices::attiny85; +#[cfg(feature = "attiny861")] +pub use crate::devices::attiny861; #[cfg(feature = "attiny88")] pub use crate::devices::attiny88; @@ -119,7 +127,9 @@ pub use crate::devices::attiny88; feature = "atmega64", feature = "atmega644", feature = "attiny84", + feature = "attiny841", feature = "attiny85", + feature = "attiny861", feature = "attiny88", )))] compile_error!("You need to select at least one chip as a feature!"); diff --git a/vendor/attiny841.atdf b/vendor/attiny841.atdf new file mode 100644 index 0000000..543a061 --- /dev/null +++ b/vendor/attiny841.atdf @@ -0,0 +1,1125 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vendor/attiny861.atdf b/vendor/attiny861.atdf new file mode 100644 index 0000000..50f9371 --- /dev/null +++ b/vendor/attiny861.atdf @@ -0,0 +1,939 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 3de96c1b8937b1b89d2fcfd0ee6487eb05c173e3 Mon Sep 17 00:00:00 2001 From: jaxter184 Date: Sat, 5 Dec 2020 19:20:32 -0600 Subject: [PATCH 3/4] Fix 16bit timer patch --- patch/timer/attiny84.yaml | 2 +- patch/timer/dev/16bit-tiny84-tc1.yaml | 30 --------------------------- patch/timer/dev/16bit.yaml | 4 ++-- 3 files changed, 3 insertions(+), 33 deletions(-) delete mode 100644 patch/timer/dev/16bit-tiny84-tc1.yaml diff --git a/patch/timer/attiny84.yaml b/patch/timer/attiny84.yaml index f04b576..1550fc0 100644 --- a/patch/timer/attiny84.yaml +++ b/patch/timer/attiny84.yaml @@ -11,4 +11,4 @@ TC0: TC1: _include: - - "dev/16bit-tiny84-tc1.yaml" + - "dev/16bit.yaml" diff --git a/patch/timer/dev/16bit-tiny84-tc1.yaml b/patch/timer/dev/16bit-tiny84-tc1.yaml deleted file mode 100644 index 7033632..0000000 --- a/patch/timer/dev/16bit-tiny84-tc1.yaml +++ /dev/null @@ -1,30 +0,0 @@ -TCCR?A: - _modify: - COM??: - _write_constraint: enum - COM??: - _replace_enum: - DISCONNECTED: [0, "Normal port operation, OCix disconnected"] - MATCH_TOGGLE: [1, "Toggle OCix on Compare Match (Might depend on WGM)"] - MATCH_CLEAR: [2, "Clear OCix on Compare Match (If PWM is enabled, OCix is set at BOTTOM)"] - MATCH_SET: [3, "Set OCix on Compare Match (If PWM is enabled, OCix is cleared at BOTTOM)"] - -TCCR?B: - _modify: - CS?: - _write_constraint: enum - CS?: - _replace_enum: - NO_CLOCK: [0, "No clock source (Timer/Counter stopped)"] - DIRECT: [1, "Running, No Prescaling"] - PRESCALE_8: [2, "Running, CLK/8"] - PRESCALE_64: [3, "Running, CLK/64"] - PRESCALE_256: [4, "Running, CLK/256"] - PRESCALE_1024: [5, "Running, CLK/1024"] - EXT_FALLING: [6, "Running, ExtClk Tx Falling Edge"] - EXT_RISING: [7, "Running, ExtClk Tx Rising Edge"] - -TCCR?C: - _modify: - FOC??: - access: write-only diff --git a/patch/timer/dev/16bit.yaml b/patch/timer/dev/16bit.yaml index 33846c5..d719df8 100644 --- a/patch/timer/dev/16bit.yaml +++ b/patch/timer/dev/16bit.yaml @@ -10,8 +10,8 @@ TCCR?A: _replace_enum: DISCONNECTED: [0, "Normal port operation, OCix disconnected"] MATCH_TOGGLE: [1, "Toggle OCix on Compare Match (Might depend on WGM)"] - MATCH_CLEAR: [2, "Clear OCix on Compare Match (If PWM is enabled, OCix is set at TOP)"] - MATCH_SET: [3, "Set OCix on Compare Match (If PWM is enabled, OCix is cleared at TOP)"] + MATCH_CLEAR: [2, "Clear OCix on Compare Match (If PWM is enabled, OCix is set at BOTTOM)"] + MATCH_SET: [3, "Set OCix on Compare Match (If PWM is enabled, OCix is cleared at BOTTOM)"] TCCR?B: _modify: From cce853a47931327196aa492375b68bf18a9dfe63 Mon Sep 17 00:00:00 2001 From: jaxter184 Date: Sat, 5 Dec 2020 19:21:40 -0600 Subject: [PATCH 4/4] Add attiny84 and atmega644 to `src/lib.rs` --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0f45da3..7c105b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -29,6 +29,8 @@ //! * `atmega4809` //! * `atmega48p` //! * `atmega64` +//! * `atmega644` +//! * `attiny84` //! * `attiny841` //! * `attiny85` //! * `attiny861`