Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attiny841 and attiny861 #67

Merged
merged 4 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ atmega32u4 = []
atmega64 = []
atmega644 = []
attiny84 = []
attiny841 = []
attiny85 = []
attiny861 = []
Rahix marked this conversation as resolved.
Show resolved Hide resolved
attiny88 = []
rt = ["avr-device-macros"]

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion patch/atmega328pb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
51 changes: 51 additions & 0 deletions patch/attiny841.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
_svd: ../svd/attiny841.svd

_include:
- "common/ac.yaml"
- "common/port.yaml"
Rahix marked this conversation as resolved.
Show resolved Hide resolved
- "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"]
11 changes: 11 additions & 0 deletions patch/attiny861.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
_svd: ../svd/attiny861.svd

_include:
- "common/ac.yaml"
- "common/adc.yaml"
- "common/port.yaml"
Rahix marked this conversation as resolved.
Show resolved Hide resolved
- "common/tiny/usi.yaml"
- "common/wdt.yaml"

- "timer/attiny861.yaml"

8 changes: 4 additions & 4 deletions patch/common/ac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion patch/timer/attiny84.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ TC0:

TC1:
_include:
- "dev/16bit-tiny84-tc1.yaml"
- "dev/16bit.yaml"
18 changes: 18 additions & 0 deletions patch/timer/attiny841.yaml
Original file line number Diff line number Diff line change
@@ -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"
16 changes: 16 additions & 0 deletions patch/timer/attiny861.yaml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
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)"]
_modify:
TIFR?:
access: read-write
Rahix marked this conversation as resolved.
Show resolved Hide resolved

TCCR?B:
_modify:
Expand All @@ -24,7 +17,3 @@ TCCR?B:
EXT_FALLING: [6, "Running, ExtClk Tx Falling Edge"]
EXT_RISING: [7, "Running, ExtClk Tx Rising Edge"]

TCCR?C:
_modify:
FOC??:
access: write-only
4 changes: 2 additions & 2 deletions patch/timer/dev/16bit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
38 changes: 38 additions & 0 deletions src/devices/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
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;
Expand All @@ -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<Self> {
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;
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//!
Expand All @@ -27,7 +29,11 @@
//! * `atmega4809`
//! * `atmega48p`
//! * `atmega64`
//! * `atmega644`
//! * `attiny84`
//! * `attiny841`
//! * `attiny85`
//! * `attiny861`
//! * `attiny88`
#![no_std]
#![feature(llvm_asm)]
Expand Down Expand Up @@ -101,8 +107,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;

Expand All @@ -119,7 +129,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!");
Loading