From f287eed0406b609fce3d1e97d16b6fde4d6aaf39 Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Tue, 27 Jul 2021 15:40:21 -0400 Subject: [PATCH] Add ATtiny167 support --- Cargo.toml | 1 + Makefile | 2 +- patch/attiny167.yaml | 85 ++++ src/devices/mod.rs | 19 + src/lib.rs | 5 + vendor/attiny167.atdf | 888 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 999 insertions(+), 1 deletion(-) create mode 100644 patch/attiny167.yaml create mode 100644 vendor/attiny167.atdf diff --git a/Cargo.toml b/Cargo.toml index 1743d43..c86921f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ atmega48p = ["device-selected"] atmega32u4 = ["device-selected"] atmega64 = ["device-selected"] atmega644 = ["device-selected"] +attiny167 = ["device-selected"] attiny202 = ["device-selected"] attiny84 = ["device-selected"] attiny841 = ["device-selected"] diff --git a/Makefile b/Makefile index 680e452..9b78a14 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 attiny84 attiny85 attiny88 attiny841 attiny861 +CHIPS := at90usb1286 atmega1280 atmega168 atmega2560 atmega8 atmega8u2 atmega328p atmega328pb atmega32u4 atmega4809 atmega48p atmega64 atmega644 attiny202 attiny84 attiny85 attiny88 attiny841 attiny861 attiny167 RUSTUP_TOOLCHAIN ?= nightly diff --git a/patch/attiny167.yaml b/patch/attiny167.yaml new file mode 100644 index 0000000..3311574 --- /dev/null +++ b/patch/attiny167.yaml @@ -0,0 +1,85 @@ +_svd: ../svd/attiny167.svd + +_include: + - "common/ac.yaml" + - "common/eeprom.yaml" + - "common/spi.yaml" +# - "common/twi.yaml" + - "common/wdt.yaml" + - "common/tiny/usi.yaml" + + +# - "timer/attiny88.yaml" + +ADC: + ADMUX: + _modify: + MUX: + description: "Analog Channel Selection Bits" + MUX: + _replace_enum: + ADC0: [0, "ADC Single Ended Input pin 0"] + ADC1: [1, "ADC Single Ended Input pin 1"] + ADC2: [2, "ADC Single Ended Input pin 2"] + ADC3: [3, "ADC Single Ended Input pin 3"] + ADC4: [4, "ADC Single Ended Input pin 4"] + ADC5: [5, "ADC Single Ended Input pin 5"] + ADC6: [6, "ADC Single Ended Input pin 6"] + ADC7: [7, "ADC Single Ended Input pin 7"] + ADC8: [8, "ADC Single Ended Input pin 8"] + ADC9: [9, "ADC Single Ended Input pin 9"] + ADC10: [10, "ADC Single Ended Input pin 10"] + TEMPSENS: [11, "Temperature sensor"] + ADC_VBG: [12, "Internal Reference (VBG)"] + ADC_AVCC_4: [13, "AVcc/4"] + ADC_GND: [14, "0V (GND)"] + REFS: + _replace_enum: + AVCC: [0, "AVcc or External Reference"] + INTERNAL_11: [1, "Internal 1.1V Voltage Reference"] + INTERNAL_256: [3, "Internal 2.56V Voltage Reference"] + 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"] + TC1_CMB: [5, "Timer/Counter1 Compare Match B"] + TC1_CE: [6, "Timer/Counter1 Capture Event"] + WDT: [7, "Watchdog Interrupt Request"] +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"] +EXINT: + EICRA: + ISC?: + _replace_enum: + LOW: [0, "The low level of INTx generates an interrupt request"] + TOGGLE: [1, "Any logical change on INTx generates an interrupt request"] + FALLING: [2, "The falling edge of INTx generates an interrupt request"] + RISING: [3, "The rising edge of INTx generates an interrupt request"] + _modify: + PCICR: + description: "Pin Change Interrupt Control Register" diff --git a/src/devices/mod.rs b/src/devices/mod.rs index a055eaa..3731c6b 100644 --- a/src/devices/mod.rs +++ b/src/devices/mod.rs @@ -250,6 +250,25 @@ impl atmega644::Peripherals { } } +/// [ATtiny167](https://www.microchip.com/wwwproducts/en/ATtiny167) +#[cfg(feature = "attiny167")] +pub mod attiny167; + +#[cfg(feature = "attiny167")] +impl attiny167::Peripherals { + /// Returns all the peripherals *once* + #[inline] + pub fn take() -> Option { + crate::interrupt::free(|_| { + if unsafe { DEVICE_PERIPHERALS } { + None + } else { + Some(unsafe { attiny167::Peripherals::steal() }) + } + }) + } +} + /// [ATtiny202](https://www.microchip.com/wwwproducts/en/ATtiny202) #[cfg(feature = "attiny202")] pub mod attiny202; diff --git a/src/lib.rs b/src/lib.rs index f695e81..be61c56 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ #![cfg_attr(feature = "atmega48p", doc = "**atmega48p**,")] #![cfg_attr(feature = "atmega64", doc = "**atmega64**,")] #![cfg_attr(feature = "atmega644", doc = "**atmega644**,")] +#![cfg_attr(feature = "attiny167", doc = "**attiny167**,")] #![cfg_attr(feature = "attiny202", doc = "**attiny202**,")] #![cfg_attr(feature = "attiny84", doc = "**attiny84**,")] #![cfg_attr(feature = "attiny841", doc = "**attiny841**,")] @@ -35,6 +36,7 @@ //! * `atmega48p` //! * `atmega64` //! * `atmega644` +//! * `attiny167` //! * `attiny202` //! * `attiny84` //! * `attiny841` @@ -104,6 +106,7 @@ compile_error!( * atmega644 * atmega8 * atmega8u2 + * attiny167 * attiny202 * attiny84 * attiny841 @@ -142,6 +145,8 @@ pub use crate::devices::atmega644; pub use crate::devices::atmega8; #[cfg(feature = "atmega8u2")] pub use crate::devices::atmega8u2; +#[cfg(feature = "attiny167")] +pub use crate::devices::attiny167; #[cfg(feature = "attiny202")] pub use crate::devices::attiny202; #[cfg(feature = "attiny84")] diff --git a/vendor/attiny167.atdf b/vendor/attiny167.atdf new file mode 100644 index 0000000..abf9af7 --- /dev/null +++ b/vendor/attiny167.atdf @@ -0,0 +1,888 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.49.0