Skip to content

Commit

Permalink
Add support for atmega328pb
Browse files Browse the repository at this point in the history
  • Loading branch information
jkristell authored and Rahix committed Oct 13, 2020
1 parent d579a49 commit ce03103
Show file tree
Hide file tree
Showing 9 changed files with 1,558 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ atmega168 = []
atmega2560 = []
atmega8 = []
atmega328p = []
atmega328pb = []
atmega48p = []
atmega32u4 = []
atmega64 = []
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 atmega32u4 atmega48p atmega64 atmega644 attiny84 attiny85 attiny88
CHIPS := atmega1280 atmega168 atmega2560 atmega8 atmega328p atmega328pb atmega32u4 atmega48p atmega64 atmega644 attiny84 attiny85 attiny88

RUSTUP_TOOLCHAIN ?= nightly

Expand Down
42 changes: 42 additions & 0 deletions patch/atmega328pb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
_svd: ../svd/atmega328pb.svd

# Remove index suffix from all registers and fields
SPI0:
_strip_end:
- "0"
SPI1:
_strip_end:
- "1"
SPSR:
_strip_end:
- "1"
SPCR:
_strip_end:
- "1"

# Remove index suffix from all registers and fields
TWI0:
_strip_end:
- "0"
TWI1:
_strip_end:
- "1"
TWCR:
_strip_end:
- "1"
TWSR:
_strip_end:
- "1"

_include:
- "common/ac.yaml"
- "common/adc.yaml"
- "common/port.yaml"
- "common/usart.yaml"
- "common/spi.yaml"
- "common/twi.yaml"
- "common/wdt.yaml"

- "timer/atmega328pb.yaml"


2 changes: 1 addition & 1 deletion patch/common/spi.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Patches for the SPI peripheral
#
# Fix the SP2X status register bit to have write access
SPI:
SPI*:
_modify:
SPSR:
access: read-write
Expand Down
2 changes: 1 addition & 1 deletion patch/common/twi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# "Write Collision Flag" being read-only
# - Fix the "Slave Address Mask" description
# - Fix the Prescaler enumerated values
TWI:
TWI*:
_modify:
TWCR:
access: read-write
Expand Down
44 changes: 44 additions & 0 deletions patch/timer/atmega328pb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This intermediate file is needed because peripheral-level includes are not
# supported in top-level files.

TC0:
_include:
- "dev/8bit.yaml"

TC1:
_include:
- "dev/16bit.yaml"

TC2:
_include:
- "dev/8bit-async.yaml"

TC3:
TCCR3B:
# Merge WGM32 and WGM33
_delete:
- "WGM3*"
_add:
WGM3:
description: Waveform Generation Mode
bitOffset: 3
bitWidth: 2
access: read-write
_include:
- "dev/16bit.yaml"

TC4:
TCCR4B:
# Merge WGM42 and WGM43
_delete:
- "WGM4*"
_add:
WGM4:
description: Waveform Generation Mode
bitOffset: 3
bitWidth: 2
access: read-write

_include:
- "dev/16bit.yaml"

20 changes: 20 additions & 0 deletions src/devices/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,26 @@ impl atmega328p::Peripherals {
}
}

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

#[cfg(feature = "atmega328pb")]
impl atmega328pb::Peripherals {
/// Returns all the peripherals *once*
#[inline]
pub fn take() -> Option<Self> {
crate::interrupt::free(|_| {
if unsafe { DEVICE_PERIPHERALS } {
None
} else {
Some(unsafe { atmega328pb::Peripherals::steal() })
}
})
}
}


/// [ATmega32U4](https://www.microchip.com/wwwproducts/en/ATmega32U4)
#[cfg(feature = "atmega32u4")]
pub mod atmega32u4;
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![cfg_attr(feature = "atmega2560", doc = "**atmega2560**,")]
#![cfg_attr(feature = "atmega8", doc = "**atmega8**,")]
#![cfg_attr(feature = "atmega328p", doc = "**atmega328p**,")]
#![cfg_attr(feature = "atmega328pb", doc = "**atmega328pb**,")]
#![cfg_attr(feature = "atmega32u4", doc = "**atmega32u4**,")]
#![cfg_attr(feature = "atmega48p", doc = "**atmega48p**,")]
#![cfg_attr(feature = "atmega64", doc = "**atmega64**,")]
Expand All @@ -20,6 +21,7 @@
//! * `atmega2560`
//! * `atmega8`
//! * `atmega328p`
//! * `atmega328pb`
//! * `atmega32u4`
//! * `atmega48p`
//! * `atmega64`
Expand Down Expand Up @@ -81,6 +83,8 @@ pub use crate::devices::atmega168;
pub use crate::devices::atmega2560;
#[cfg(feature = "atmega328p")]
pub use crate::devices::atmega328p;
#[cfg(feature = "atmega328pb")]
pub use crate::devices::atmega328pb;
#[cfg(feature = "atmega32u4")]
pub use crate::devices::atmega32u4;
#[cfg(feature = "atmega48p")]
Expand All @@ -104,6 +108,7 @@ pub use crate::devices::attiny88;
feature = "atmega2560",
feature = "atmega8",
feature = "atmega328p",
feature = "atmega328pb",
feature = "atmega32u4",
feature = "atmega48p",
feature = "atmega64",
Expand Down
Loading

0 comments on commit ce03103

Please sign in to comment.