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 ATSAMDA1[EGJ] support #1

Merged
merged 1 commit into from
Aug 30, 2022
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions hal/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Unreleased Changes

- Add support for L-Variant of the SAMD21D
- Add support for the SAMDA1[EGJ]

# v0.15.0

Expand Down
26 changes: 25 additions & 1 deletion hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = [
"Michael van Niekerk <mvniekerk@gmail.com>",
"Jesse Braham <jesse@beta7.io>",
]
description = "HAL and Peripheral access API for ATSAMD11, ATSAMD21, ATSAMD51, ATSAME51, ATSAME53 and ATSAME54 microcontrollers"
description = "HAL and Peripheral access API for ATSAMD11, ATSAMD21/ATSAMDA1, ATSAMD51, ATSAME51, ATSAME53 and ATSAME54 microcontrollers"
keywords = ["no-std", "arm", "cortex-m", "embedded-hal"]
categories = ["embedded", "hardware-support", "no-std"]
license = "MIT OR Apache-2.0"
Expand Down Expand Up @@ -60,6 +60,21 @@ version = "1.0"
# Each of the supported chips is listed as an optional dependency here.
# This makes it available when the corresponding feature name is referenced.
# We use a feature named "samdFOO" to pull in the dependency named "atsamdFOO"
[dependencies.atsamda1e]
path = "../pac/atsamda1e"
version = "0.12"
optional = true

[dependencies.atsamda1g]
path = "../pac/atsamda1g"
version = "0.12"
optional = true

[dependencies.atsamda1j]
path = "../pac/atsamda1j"
version = "0.12"
optional = true

[dependencies.atsamd11c]
path = "../pac/atsamd11c"
version = "0.12"
Expand Down Expand Up @@ -165,6 +180,13 @@ device = []
# Bypasses compile-time checks that a specific device is enabled.
library = []

samda1 = ["device"] # Convenience feature for shared configuration of samda1 chips.
samda1e = ["atsamda1e", "samda1"]
samda1e-rt = ["samda1e", "atsamda1e/rt"]
samda1g = ["atsamda1g", "samda1"]
samda1g-rt = ["samda1g", "atsamda1g/rt"]
samda1j = ["atsamda1j", "samda1"]
samda1j-rt = ["samda1j", "atsamda1j/rt"]
samd11 = ["device"] # Convenience feature for shared configuration of samd11 chips.
samd11c = ["atsamd11c", "samd11"]
samd11c-rt = ["samd11c", "atsamd11c/rt"]
Expand Down Expand Up @@ -207,6 +229,8 @@ same54n = ["atsame54n", "same54", "min-samd51n"]
same54n-rt = ["same54n", "atsame54n/rt"]
same54p = ["atsame54p", "same54", "min-samd51p"]
same54p-rt = ["same54p", "atsame54p/rt"]
min-samda1g = []
min-samda1j = ["min-samda1g"]
min-samd21g = []
min-samd21j = ["min-samd21g"]
min-samd51g = []
Expand Down
3 changes: 3 additions & 0 deletions hal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ This crate provides a type-safe API for working with `samd11`, `samd21`, `samd51

## Supported Devices

* `atsamda1e` (via the `samda1e` feature) [[pac]](https://github.com/atsamd-rs/atsamd/tree/master/pac/atsamda1e)
* `atsamda1g` (via the `samda1g` feature) [[pac]](https://github.com/atsamd-rs/atsamd/tree/master/pac/atsamda1g)
* `atsamda1j` (via the `samda1j` feature) [[pac]](https://github.com/atsamd-rs/atsamd/tree/master/pac/atsamda1j)
* `atsamd11c` (via the `samd11c` feature) [[pac]](https://github.com/atsamd-rs/atsamd/tree/master/pac/atsamd11c)
* `atsamd21e` (via the `samd21e` feature) [[pac]](https://github.com/atsamd-rs/atsamd/tree/master/pac/atsamd21e)
* `atsamd21g` (via the `samd21g` feature) [[pac]](https://github.com/atsamd-rs/atsamd/tree/master/pac/atsamd21g)
Expand Down
6 changes: 3 additions & 3 deletions hal/src/dmac/channel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! requires setting a priority level, as well as enabling or disabling
//! interrupt requests (only for the specific channel being initialized).
#![cfg_attr(
not(any(feature = "samd11", feature = "samd21")),
not(any(feature = "samda1", feature = "samd11", feature = "samd21")),
doc = "# Burst Length and FIFO Threshold (SAMD51/SAME5x only)

The transfer burst length can be configured through the
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<Id: ChId, S: Status> Channel<Id, S> {
// Software reset the channel for good measure
self._reset_private();

#[cfg(any(feature = "samd11", feature = "samd21"))]
#[cfg(any(feature = "samda1", feature = "samd11", feature = "samd21"))]
// Setup priority level
self.regs.chctrlb.modify(|_, w| w.lvl().bits(lvl as u8));

Expand Down Expand Up @@ -253,7 +253,7 @@ impl<Id: ChId> Channel<Id, Ready> {
// SAFETY: This is actually safe because we are writing the correct enum value
// (imported from the PAC) into the register
unsafe {
#[cfg(any(feature = "samd11", feature = "samd21"))]
#[cfg(any(feature = "samda1", feature = "samd11", feature = "samd21"))]
self.regs.chctrlb.modify(|_, w| {
w.trigsrc().bits(trig_src as u8);
w.trigact().bits(trig_act as u8)
Expand Down
4 changes: 2 additions & 2 deletions hal/src/dmac/channel/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::pac::{
Peripherals, DMAC,
};

#[cfg(any(feature = "samd11", feature = "samd21"))]
#[cfg(any(feature = "samda1", feature = "samd11", feature = "samd21"))]
use pac::dmac as channel_regs;

#[cfg(feature = "min-samd51g")]
Expand Down Expand Up @@ -56,7 +56,7 @@ pub(super) trait Register<Id: ChId> {
/// the CHID register, then access the channel control registers.
/// If an interrupt were to change the CHID register and not reset it
/// to the expected value, we would be faced with undefined behaviour.
#[cfg(any(feature = "samd11", feature = "samd21"))]
#[cfg(any(feature = "samda1", feature = "samd11", feature = "samd21"))]
#[inline]
fn with_chid<F: FnOnce(&DMAC) -> R, R>(&mut self, fun: F) -> R {
// SAFETY: This method is ONLY safe if the individual channels are GUARANTEED
Expand Down
6 changes: 3 additions & 3 deletions hal/src/dmac/dma_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
use modular_bitfield::prelude::*;
use seq_macro::seq;

#[cfg(any(feature = "samd11", feature = "samd21"))]
#[cfg(any(feature = "samda1", feature = "samd11", feature = "samd21"))]
pub use crate::pac::dmac::chctrlb::{
LVL_A as PriorityLevel, TRIGACT_A as TriggerAction, TRIGSRC_A as TriggerSource,
};
Expand Down Expand Up @@ -134,7 +134,7 @@ impl DmaController {
#[inline]
pub fn init(mut dmac: DMAC, _pm: &mut PM) -> Self {
// ----- Initialize clocking ----- //
#[cfg(any(feature = "samd11", feature = "samd21"))]
#[cfg(any(feature = "samda1", feature = "samd11", feature = "samd21"))]
{
// Enable clocking
_pm.ahbmask.modify(|_, w| w.dmac_().set_bit());
Expand Down Expand Up @@ -230,7 +230,7 @@ impl DmaController {

Self::swreset(&mut self.dmac);

#[cfg(any(feature = "samd11", feature = "samd21"))]
#[cfg(any(feature = "samda1", feature = "samd11", feature = "samd21"))]
{
// Disable the DMAC clocking
_pm.apbbmask.modify(|_, w| w.dmac_().clear_bit());
Expand Down
4 changes: 2 additions & 2 deletions hal/src/dmac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ macro_rules! with_num_channels {
};
}

#[cfg(all(feature = "samd21", feature = "max-channels"))]
#[cfg(all(any(feature = "samda1", feature = "samd21"), feature = "max-channels"))]
#[macro_export]
macro_rules! with_num_channels {
($some_macro:ident) => {
Expand All @@ -308,7 +308,7 @@ macro_rules! with_num_channels {
};
}

#[cfg(all(feature = "samd21", not(feature = "max-channels")))]
#[cfg(all(any(feature = "samda1", feature = "samd21"), not(feature = "max-channels")))]
#[macro_export]
macro_rules! with_num_channels {
($some_macro:ident) => {
Expand Down
6 changes: 3 additions & 3 deletions hal/src/gpio/dynpin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub enum DynAlternate {
E,
F,
G,
#[cfg(any(feature = "samd21", feature = "min-samd51g"))]
#[cfg(any(feature = "samda1", feature = "samd21", feature = "min-samd51g"))]
H,
#[cfg(feature = "min-samd51g")]
I,
Expand Down Expand Up @@ -184,7 +184,7 @@ macro_rules! dyn_alternate {
}

dyn_alternate!(B, C, D, E, F, G);
#[cfg(any(feature = "samd21", feature = "min-samd51g"))]
#[cfg(any(feature = "samda1", feature = "samd21", feature = "min-samd51g"))]
dyn_alternate!(H);
#[cfg(feature = "min-samd51g")]
dyn_alternate!(I, J, K, L, M, N);
Expand All @@ -197,7 +197,7 @@ dyn_alternate!(I, J, K, L, M, N);
#[derive(PartialEq, Clone, Copy)]
pub enum DynGroup {
A,
#[cfg(any(feature = "samd21", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "samd21", feature = "min-samd51g"))]
B,
#[cfg(feature = "min-samd51n")]
C,
Expand Down
58 changes: 29 additions & 29 deletions hal/src/gpio/pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ macro_rules! alternate {

alternate!(B, C, D, E, F, G);

#[cfg(any(feature = "samd21", feature = "min-samd51g"))]
#[cfg(any(feature = "samda1", feature = "samd21", feature = "min-samd51g"))]
alternate!(H);

#[cfg(feature = "min-samd51g")]
Expand Down Expand Up @@ -749,7 +749,7 @@ impl_core_convert_from!(
AlternateE,
AlternateF,
AlternateG,
#[cfg(any(feature = "samd21", feature = "min-samd51g"))]
#[cfg(any(feature = "samda1", feature = "samd21", feature = "min-samd51g"))]
AlternateH,
#[cfg(feature = "min-samd51g")]
AlternateI,
Expand Down Expand Up @@ -1084,9 +1084,9 @@ declare_pins!(
(PA10, 10),
#[cfg(not(feature = "samd11"))]
(PA11, 11),
#[cfg(any(feature = "min-samd21g", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "min-samd21g", feature = "min-samd51g"))]
(PA12, 12),
#[cfg(any(feature = "min-samd21g", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "min-samd21g", feature = "min-samd51g"))]
(PA13, 13),
(PA14, 14),
(PA15, 15),
Expand All @@ -1098,9 +1098,9 @@ declare_pins!(
(PA18, 18),
#[cfg(not(feature = "samd11"))]
(PA19, 19),
#[cfg(any(feature = "min-samd21g", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "min-samd21g", feature = "min-samd51g"))]
(PA20, 20),
#[cfg(any(feature = "min-samd21g", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "min-samd21g", feature = "min-samd51g"))]
(PA21, 21),
#[cfg(not(feature = "samd11c"))]
(PA22, 22),
Expand All @@ -1110,47 +1110,47 @@ declare_pins!(
(PA25, 25),
#[cfg(not(feature = "samd11"))]
(PA27, 27),
#[cfg(all(any(feature = "samd11", feature = "samd21"), not(feature = "samd21el")))]
#[cfg(all(any(feature = "samda1", feature = "samd11", feature = "samd21"), not(feature = "samd21el")))]
(PA28, 28),
(PA30, 30),
(PA31, 31),
}
B {
#[cfg(any(feature = "min-samd21j", feature = "samd21gl", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "samd21gl", feature = "min-samd51j"))]
(PB00, 00),
#[cfg(any(feature = "min-samd21j", feature = "samd21gl", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "samd21gl", feature = "min-samd51j"))]
(PB01, 01),
#[cfg(any(feature = "min-samd21g", feature = "samd21el", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "min-samd21g", feature = "samd21el", feature = "min-samd51g"))]
(PB02, 02),
#[cfg(any(feature = "min-samd21g", feature = "samd21el", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "min-samd21g", feature = "samd21el", feature = "min-samd51g"))]
(PB03, 03),
#[cfg(any(feature = "min-samd21j", feature = "samd21el", feature = "samd21gl", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "samd21el", feature = "samd21gl", feature = "min-samd51j"))]
(PB04, 04),
#[cfg(any(feature = "min-samd21j", feature = "samd21el", feature = "samd21gl", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "samd21el", feature = "samd21gl", feature = "min-samd51j"))]
(PB05, 05),
#[cfg(any(feature = "min-samd21j", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "min-samd51j"))]
(PB06, 06),
#[cfg(any(feature = "min-samd21j", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "min-samd51j"))]
(PB07, 07),
#[cfg(any(feature = "min-samd21g", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21g", feature = "min-samd51g"))]
(PB08, 08),
#[cfg(any(feature = "min-samd21g", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "min-samd21g", feature = "min-samd51g"))]
(PB09, 09),
#[cfg(any(feature = "min-samd21g", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "min-samd21g", feature = "min-samd51g"))]
(PB10, 10),
#[cfg(any(feature = "min-samd21g", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "min-samd21g", feature = "min-samd51g"))]
(PB11, 11),
#[cfg(any(feature = "min-samd21j", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "min-samd51j"))]
(PB12, 12),
#[cfg(any(feature = "min-samd21j", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "min-samd51j"))]
(PB13, 13),
#[cfg(any(feature = "min-samd21j", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "min-samd51j"))]
(PB14, 14),
#[cfg(any(feature = "min-samd21j", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "min-samd51j"))]
(PB15, 15),
#[cfg(any(feature = "min-samd21j", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "min-samd51j"))]
(PB16, 16),
#[cfg(any(feature = "min-samd21j", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "min-samd51j"))]
(PB17, 17),
#[cfg(feature = "min-samd51n")]
(PB18, 18),
Expand All @@ -1160,9 +1160,9 @@ declare_pins!(
(PB20, 20),
#[cfg(feature = "min-samd51n")]
(PB21, 21),
#[cfg(all(any(feature = "min-samd21g", feature = "min-samd51g"), not(feature = "samd21gl")))]
#[cfg(all(any(feature = "min-samda1g", feature = "min-samd21g", feature = "min-samd51g"), not(feature = "samd21gl")))]
(PB22, 22),
#[cfg(all(any(feature = "min-samd21g", feature = "min-samd51g"), not(feature = "samd21gl")))]
#[cfg(all(any(feature = "min-samda1g", feature = "min-samd21g", feature = "min-samd51g"), not(feature = "samd21gl")))]
(PB23, 23),
#[cfg(feature = "min-samd51n")]
(PB24, 24),
Expand All @@ -1176,9 +1176,9 @@ declare_pins!(
(PB28, 28),
#[cfg(feature = "min-samd51p")]
(PB29, 29),
#[cfg(any(feature = "min-samd21j", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "min-samd51j"))]
(PB30, 30),
#[cfg(any(feature = "min-samd21j", feature = "min-samd51j"))]
#[cfg(any(feature = "min-samda1j", feature = "min-samd21j", feature = "min-samd51j"))]
(PB31, 31),
}
C {
Expand Down
10 changes: 5 additions & 5 deletions hal/src/gpio/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::pac::port::{
PMUX0_ as PMUX, WRCONFIG,
};

#[cfg(feature = "min-samd51g")]
#[cfg(any(feature = "samda1", feature = "min-samd51g"))]
use crate::pac::port::group::{
CTRL, DIR, DIRCLR, DIRSET, DIRTGL, IN, OUT, OUTCLR, OUTSET, OUTTGL, PINCFG, PMUX, WRCONFIG,
};
Expand Down Expand Up @@ -122,7 +122,7 @@ impl From<DynPinMode> for ModeFields {
G => {
fields.pmux = 6;
}
#[cfg(any(feature = "samd21", feature = "min-samd51g"))]
#[cfg(any(feature = "samda1", feature = "samd21", feature = "min-samd51g"))]
H => {
fields.pmux = 7;
}
Expand Down Expand Up @@ -163,8 +163,8 @@ impl From<DynPinMode> for ModeFields {

/// Represent the [`PORT`] register block
///
/// The SAMx5x PACs have a GROUP type to represent each [`PORT`] group, but the
/// SAMD11 and SAMD21 PACs do not. Manually re-implement it here.
/// The SAMx5x and SAMDA1 PACs have a GROUP type to represent each [`PORT`] group,
/// but the SAMD11 and SAMD21 PACs do not. Manually re-implement it here.
#[repr(C)]
#[allow(clippy::upper_case_acronyms)]
pub(super) struct GROUP {
Expand Down Expand Up @@ -231,7 +231,7 @@ pub(super) unsafe trait RegisterInterface {
fn group(&self) -> &GROUP {
let offset = match self.id().group {
DynGroup::A => 0,
#[cfg(any(feature = "samd21", feature = "min-samd51g"))]
#[cfg(any(feature = "min-samda1g", feature = "samd21", feature = "min-samd51g"))]
DynGroup::B => 1,
#[cfg(feature = "min-samd51n")]
DynGroup::C => 2,
Expand Down
15 changes: 12 additions & 3 deletions hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ compile_error!(
specifying the `library` feature"
);

#[cfg(feature = "samda1e")]
pub use atsamda1e as pac;

#[cfg(feature = "samda1g")]
pub use atsamda1g as pac;

#[cfg(feature = "samda1j")]
pub use atsamda1j as pac;

#[cfg(feature = "samd11c")]
pub use atsamd11c as pac;

Expand Down Expand Up @@ -105,13 +114,13 @@ compile_error!("'usb' is enabled, but USB isn't supported on SAMD11");

#[cfg(all(
feature = "usb",
not(any(feature = "samd21", feature = "min-samd51g", feature = "library"))
not(any(feature = "samda1", feature = "samd21", feature = "min-samd51g", feature = "library"))
))]
compile_error!("The 'usb' feature is enabled, but not a chip with USB support");

#[cfg(any(feature = "samd11", feature = "samd21"))]
#[cfg(any(feature = "samda1", feature = "samd11", feature = "samd21"))]
pub mod thumbv6m;
#[cfg(any(feature = "samd11", feature = "samd21"))]
#[cfg(any(feature = "samda1", feature = "samd11", feature = "samd21"))]
pub use crate::thumbv6m::*;

#[cfg(feature = "min-samd51g")]
Expand Down
Loading