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 ATtiny 817 support #144

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ attiny402 = ["device-selected"]
attiny404 = ["device-selected"]
attiny44a = ["device-selected"]
attiny816 = ["device-selected"]
attiny817 = ["device-selected"]
attiny828 = ["device-selected"]
attiny84 = ["device-selected"]
attiny841 = ["device-selected"]
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
all: deps chips

CHIPS := at90usb1286 atmega1280 atmega1284p atmega128a atmega128rfa1 atmega164pa atmega168 atmega2560 atmega8 atmega8u2 atmega324pa atmega328p atmega328pb atmega32a atmega32u4 atmega4808 atmega4809 atmega48p atmega64 atmega644 atmega88p attiny13a attiny202 attiny2313 attiny2313a attiny402 attiny404 attiny44a attiny84 attiny85 attiny88 attiny816 attiny828 attiny841 attiny861 attiny167 attiny1614

CHIPS := at90usb1286 atmega1280 atmega1284p atmega128a atmega128rfa1 atmega164pa atmega168 atmega2560 atmega8 atmega8u2 atmega324pa atmega328p atmega328pb atmega32a atmega32u4 atmega4808 atmega4809 atmega48p atmega64 atmega644 atmega88p attiny13a attiny202 attiny2313 attiny2313a attiny402 attiny404 attiny44a attiny84 attiny85 attiny88 attiny816 attiny817 attiny828 attiny841 attiny861 attiny167 attiny1614
RUSTUP_TOOLCHAIN ?= nightly

PATCHES := $(foreach chip, $(CHIPS), $(wildcard patch/$(chip).yaml))
Expand Down Expand Up @@ -35,7 +34,7 @@ svd/%.svd.patched: svd/%.svd .deps/%.d
src/devices/%/mod.full.rs: svd/%.svd.patched
@mkdir -p $(@D)
@echo -e "\tSVD2RUST\t$*"
@cd $(@D); svd2rust --generic_mod --make_mod --target none -i $(realpath $<)
@cd $(@D); svd2rust --generic_mod --make_mod --target avr -i $(realpath $<)
@mv $(@D)/mod.rs $@
@mv $(@D)/generic.rs $(@D)/../../generic.rs

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ Via the feature you can select which chip you want the register specifications f
| `atmega328p` | | | | `attiny85` |
| `atmega328pb` | | | | `attiny88` |
| `atmega32a` | | | | `attiny816` |
| `atmega1280` | | | | `attiny828` |
| `atmega1284p` | | | | `attiny841` |
| `atmega128a` | | | | `attiny861` |
| `atmega128rfa1` | | | | `attiny1614` |
| `atmega2560` | | | | `attiny2313` |
| `atmega164pa` | | | | `attiny2313a` |
| `atmega1280` | | | | `attiny817` |
| `atmega1284p` | | | | `attiny828` |
| `atmega128a` | | | | `attiny841` |
| `atmega128rfa1` | | | | `attiny861` |
| `atmega2560` | | | | `attiny1614` |
| `atmega164pa` | | | | `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.
Expand Down
107 changes: 107 additions & 0 deletions patch/attiny817.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
_svd: ../svd/attiny817.svd

CRCSCAN:
CTRLB:
SRC:
_replace_enum:
FLASH: [0, "CRC on entire flash"]
BOOTAPP: [1, "CRC on boot and appl section of flash"]
BOOT: [2, "CRC on boot section of flash"]
MODE:
_replace_enum:
PRIORITY: [0, "Priority to flash"]

NVMCTRL:
CTRLA:
CMD:
_replace_enum:
NONE: [0, "No command"]
WP: [1, "Write page"]
ER: [2, "Erase page"]
ERWP: [3, "Erase and write page"]
PBC: [4, "Page buffer clear"]
CHER: [5, "Chip erase"]
EEER: [6, "EEPROM erase"]
WFU: [7, "Write fuse (PDI only)"]

SLPCTRL:
CTRLA:
SMODE:
_replace_enum:
IDLE: [0, "Idle mode"]
STANDBY: [1, "Standby Mode"]
PDOWN: [2, "Power-down Mode"]

TCD0:
EVCTRL?:
CFG:
_replace_enum:
NEITHER: [0, "Neither Filter nor Asynchronous Event is enabled"]
FILTERON: [1, "Input Capture Noise Cancellation Filter enabled"]
ASYNCON: [2, "Asynchronous Event output qualification enabled"]

"PORT?":
DIR:
"P*":
# Make all Pins use the same enum
_replace_enum:
Input: [0, "Input"]
Output: [1, "Output"]

# make PINxCTRL a rust slice
_array:
"PIN?CTRL": {}

"USART?":
STATUS:
_modify:
# The RXSIF bit is actually writable to clear the flag
RXSIF:
access: read-write
# The WFB bit is write-only
WFB:
access: write-only

"SPI?":
CTRLA:
DORD:
# Make it an enum
_replace_enum:
MsbFirst: [0, "Most significant byte first"]
LsbFirst: [1, "Least significant byte first"]

CCL:
_cluster:
"LUT%s":
description: "CCL LUT configuration cluster"
"LUT?CTRLA": {}
"LUT?CTRLB": {}
"LUT?CTRLC": {}
"TRUTH?": {}

# turn all SEQCTRL-registers into slices
_array:
"SEQCTRL?": {}

CPUINT:
CTRLA:
IVSEL:
_replace_enum:
AFTERBOOT: [0, "Interrupt vectors are placed after the BOOT section of the Flash"]
INBOOT: [1, "Interrupt vectors are placed at the start of the BOOT section of the Flash"]
CVT:
_replace_enum:
NORMAL: [0, "Compact Vector Table function is disabled"]
COMPACT: [1, "Compact Vector Table function is enabled"]
LVL0RR:
_replace_enum:
FIXED: [0, "Priority is fixed for priority level 0 interrupt requests: The lowest interrupt vector address has the highest priority."]
ROUNDROBIN: [1, "The round robin priority scheme is enabled for priority level 0 interrupt requests"]

EVSYS:
# make ASYNCCHx, SYNCCHx, ASYNCUSERx and SYNCUSERx a rust slice
_array:
"ASYNCCH*": {}
"SYNCCH*": {}
"ASYNCUSER*": {}
"SYNCUSER*": {}
41 changes: 41 additions & 0 deletions src/ccp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//! Configuration change protected (CCP) register definitions

pub use crate::generic::ProtectedWritable;

#[cfg(feature = "attiny817")]
pub mod attiny817 {
use crate::generic::{UnlockRegister, Protected};

// Mark the CPU.CCP register with the UnlockRegister trait so that it can be used to unlock the below defined registers
impl UnlockRegister for crate::attiny817::cpu::ccp::CCP_SPEC { const PTR: *mut u8 = 0x34 as *mut u8; }

// Configuration change protected registers in NVMCTRL
impl Protected for crate::attiny817::nvmctrl::ctrla::CTRLA_SPEC { const MAGIC: u8 = 0x9D; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }
impl Protected for crate::attiny817::nvmctrl::ctrlb::CTRLB_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }

// Configuration change protected registers in CLKCTRL
impl Protected for crate::attiny817::clkctrl::mclkctrlb::MCLKCTRLB_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }
impl Protected for crate::attiny817::clkctrl::mclklock::MCLKLOCK_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }
impl Protected for crate::attiny817::clkctrl::xosc32kctrla::XOSC32KCTRLA_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }
impl Protected for crate::attiny817::clkctrl::mclkctrla::MCLKCTRLA_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }
impl Protected for crate::attiny817::clkctrl::osc20mctrla::OSC20MCTRLA_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }
impl Protected for crate::attiny817::clkctrl::osc20mcaliba::OSC20MCALIBA_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }
impl Protected for crate::attiny817::clkctrl::osc20mcalibb::OSC20MCALIBB_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }
impl Protected for crate::attiny817::clkctrl::osc32kctrla::OSC32KCTRLA_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }

// Configuration change protected registers in RSTCTRL
impl Protected for crate::attiny817::rstctrl::swrr::SWRR_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }

// Configuration change protected registers in CPUINT
impl Protected for crate::attiny817::cpuint::ctrla::CTRLA_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }

// Configuration change protected registers in BOD
impl Protected for crate::attiny817::bod::ctrla::CTRLA_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }

// Configuration change protected registers in WDT
impl Protected for crate::attiny817::wdt::ctrla::CTRLA_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }
impl Protected for crate::attiny817::wdt::status::STATUS_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }

// Configuration change protected registers in TCD0
impl Protected for crate::attiny817::tcd0::faultctrl::FAULTCTRL_SPEC { const MAGIC: u8 = 0xD8; type CcpReg = crate::attiny817::cpu::ccp::CCP_SPEC; }
}
4 changes: 4 additions & 0 deletions src/devices/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ pub mod attiny44a;
#[cfg(feature = "attiny816")]
pub mod attiny816;

/// [ATtiny817](https://www.microchip.com/wwwproducts/en/ATtiny817)
#[cfg(feature = "attiny817")]
pub mod attiny817;

/// [ATtiny828](https://www.microchip.com/wwwproducts/en/ATtiny828)
#[cfg(feature = "attiny828")]
pub mod attiny828;
Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! This crate contains register definitions for
#![feature(asm_const)]

#![cfg_attr(feature = "at90usb1286", doc = "**at90usb1286**,")]
#![cfg_attr(feature = "atmega1280", doc = "**atmega1280**,")]
Expand Down Expand Up @@ -30,6 +31,7 @@
#![cfg_attr(feature = "attiny404", doc = "**attiny404**,")]
#![cfg_attr(feature = "attiny44a", doc = "**attiny44a**,")]
#![cfg_attr(feature = "attiny816", doc = "**attiny816**,")]
#![cfg_attr(feature = "attiny817", doc = "**attiny817**,")]
#![cfg_attr(feature = "attiny828", doc = "**attiny828**,")]
#![cfg_attr(feature = "attiny84", doc = "**attiny84**,")]
#![cfg_attr(feature = "attiny841", doc = "**attiny841**,")]
Expand Down Expand Up @@ -74,6 +76,7 @@
//! `attiny404`,
//! `attiny44a`,
//! `attiny816`,
//! `attiny817`,
//! `attiny828`,
//! `attiny84`,
//! `attiny841`,
Expand Down Expand Up @@ -231,6 +234,7 @@ compile_error!(
* attiny402
* attiny44a
* attiny816
* attiny817
* attiny828
* attiny84
* attiny841
Expand Down Expand Up @@ -303,6 +307,8 @@ pub use crate::devices::attiny404;
pub use crate::devices::attiny44a;
#[cfg(feature = "attiny816")]
pub use crate::devices::attiny816;
#[cfg(feature = "attiny817")]
pub use crate::devices::attiny817;
#[cfg(feature = "attiny828")]
pub use crate::devices::attiny828;
#[cfg(feature = "attiny84")]
Expand All @@ -315,3 +321,9 @@ pub use crate::devices::attiny85;
pub use crate::devices::attiny861;
#[cfg(feature = "attiny88")]
pub use crate::devices::attiny88;

#[allow(non_camel_case_types, unused_attributes, unreachable_patterns)]
pub mod ccp;

#[cfg(feature = "attiny817")]
pub use crate::ccp::attiny817 as attiny817_ccp;
Loading