From a137ecf88a08308b9b9b022456b6c51dafd3657c Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Tue, 23 Mar 2021 01:33:20 -0700 Subject: [PATCH] Adding atsam4s4b and atsam4s8b - Adds atsam4s_a (48-pin), atsam4s_b (64-pin), atsam4s_c (100-pin) features - Adds atsam4sd (dual bank flash) feature - Resolving new clippy errors (upper_case_acronyms) --- .github/workflows/rust.yml | 2 +- Cargo.toml | 21 ++++++++++++++++++++- src/clock.rs | 31 +++++++++++++++++++++++++------ src/gpio.rs | 23 +++++++++++++++++------ src/lib.rs | 21 +++++++++++++++++++-- src/static_memory_controller.rs | 1 + 6 files changed, 83 insertions(+), 16 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index b233d3e..d22fb94 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - mcu: [atsam4e16e, atsam4sd32c] + mcu: [atsam4e16e, atsam4s4b, atsam4s8b, atsam4sd32c] steps: - uses: actions/checkout@v1 diff --git a/Cargo.toml b/Cargo.toml index d854bad..ba3ae9f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,14 @@ version = "0.1.0" version = "0.1.2" optional = true +[dependencies.atsam4s4b-pac] +version = "0.1.1" +optional = true + +[dependencies.atsam4s8b-pac] +version = "0.1.1" +optional = true + [dependencies.atsam4sd32c-pac] version = "0.1.1" optional = true @@ -56,7 +64,18 @@ version = "0.4.1" default = ["atsam4e16e"] unstable = [] disable_watchdog_timer = [] + +# atsam4e atsam4e = [] atsam4e16e = ["atsam4e", "atsam4e16e-pac", "atsam4e16e-pac/rt"] + +# atsam4s atsam4s = [] -atsam4sd32c = ["atsam4s", "atsam4sd32c-pac", "atsam4sd32c-pac/rt"] +atsam4s_a = [] # 48-pin +atsam4s_b = [] # 64-pin +atsam4s_c = [] # 100-pin +atsam4sd = [] # Dual bank flash + +atsam4s4b = ["atsam4s", "atsam4s_b", "atsam4s4b-pac", "atsam4s4b-pac/rt"] +atsam4s8b = ["atsam4s", "atsam4s_b", "atsam4s8b-pac", "atsam4s8b-pac/rt"] +atsam4sd32c = ["atsam4s", "atsam4sd", "atsam4s_c", "atsam4sd32c-pac", "atsam4sd32c-pac/rt"] diff --git a/src/clock.rs b/src/clock.rs index b646fc0..b5b27ec 100644 --- a/src/clock.rs +++ b/src/clock.rs @@ -4,7 +4,10 @@ use crate::pac::{pmc, EFC, PMC}; #[cfg(feature = "atsam4s")] -use crate::pac::{pmc, EFC0, EFC1, PMC}; +use crate::pac::{pmc, EFC0, PMC}; + +#[cfg(feature = "atsam4sd")] +use crate::pac::EFC1; use crate::time::Hertz; use crate::BorrowUnchecked; @@ -26,10 +29,19 @@ pub fn init(pmc: &mut PMC, efc: &mut EFC) { // called by pre_init() #[cfg(feature = "atsam4s")] -pub fn init(pmc: &mut PMC, efc0: &mut EFC0, efc1: &mut EFC1) { - set_flash_wait_states_to_maximum(efc0, efc1); +pub fn init(pmc: &mut PMC, efc0: &mut EFC0, #[cfg(feature = "atsam4sd")] efc1: &mut EFC1) { + set_flash_wait_states_to_maximum( + efc0, + #[cfg(feature = "atsam4sd")] + efc1, + ); let master_clock_frequency = setup_main_clock(pmc); - set_flash_wait_states_to_match_frequence(efc0, efc1, master_clock_frequency); + set_flash_wait_states_to_match_frequence( + efc0, + #[cfg(feature = "atsam4sd")] + efc1, + master_clock_frequency, + ); } pub fn get_master_clock_frequency() -> Hertz { @@ -120,7 +132,13 @@ fn set_flash_wait_states_to_maximum(efc: &mut EFC) { .modify(|_, w| unsafe { w.fws().bits(5).cloe().set_bit() }); } -#[cfg(feature = "atsam4s")] +#[cfg(all(feature = "atsam4s", not(feature = "atsam4sd")))] +fn set_flash_wait_states_to_maximum(efc0: &mut EFC0) { + efc0.fmr + .modify(|_, w| unsafe { w.fws().bits(5).cloe().set_bit() }); +} + +#[cfg(feature = "atsam4sd")] fn set_flash_wait_states_to_maximum(efc0: &mut EFC0, efc1: &mut EFC1) { efc0.fmr .modify(|_, w| unsafe { w.fws().bits(5).cloe().set_bit() }); @@ -139,13 +157,14 @@ fn set_flash_wait_states_to_match_frequence(efc: &mut EFC, clock_frequency: Hert #[cfg(feature = "atsam4s")] fn set_flash_wait_states_to_match_frequence( efc0: &mut EFC0, - efc1: &mut EFC1, + #[cfg(feature = "atsam4sd")] efc1: &mut EFC1, clock_frequency: Hertz, ) { let wait_state_count = get_flash_wait_states_for_clock_frequency(clock_frequency); efc0.fmr .modify(|_, w| unsafe { w.fws().bits(wait_state_count).cloe().set_bit() }); + #[cfg(feature = "atsam4sd")] efc1.fmr .modify(|_, w| unsafe { w.fws().bits(wait_state_count).cloe().set_bit() }); } diff --git a/src/gpio.rs b/src/gpio.rs index 8fa9b93..4d6ee23 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -15,10 +15,14 @@ use { #[cfg(feature = "atsam4s")] use { - crate::clock::{ - Enabled, ParallelIOControllerAClock, ParallelIOControllerBClock, ParallelIOControllerCClock, - }, - crate::pac::{pioa, piob, pioc, PIOA, PIOB, PIOC}, + crate::clock::{Enabled, ParallelIOControllerAClock, ParallelIOControllerBClock}, + crate::pac::{pioa, piob, PIOA, PIOB}, +}; + +#[cfg(feature = "atsam4s_c")] +use { + crate::clock::ParallelIOControllerCClock, + crate::pac::{pioc, PIOC}, }; /// The GpioExt trait allows splitting the PORT hardware into @@ -29,10 +33,10 @@ pub trait GpioExt { /// Consume and split the device into its constitent parts fn split(self) -> Self::Parts; } - pub struct Ports { pioa: PhantomData<(PIOA, ParallelIOControllerAClock)>, piob: PhantomData<(PIOB, ParallelIOControllerBClock)>, + #[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))] pioc: PhantomData<(PIOC, ParallelIOControllerCClock)>, #[cfg(feature = "atsam4e")] piod: PhantomData<(PIOD, ParallelIOControllerDClock)>, @@ -44,7 +48,10 @@ impl Ports { pub fn new( _pioa: (PIOA, ParallelIOControllerAClock), _piob: (PIOB, ParallelIOControllerBClock), - _pioc: (PIOC, ParallelIOControllerCClock), + #[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))] _pioc: ( + PIOC, + ParallelIOControllerCClock, + ), #[cfg(feature = "atsam4e")] _piod: (PIOD, ParallelIOControllerDClock), #[cfg(feature = "atsam4e")] _pioe: (PIOE, ParallelIOControllerEClock), ) -> Self { @@ -52,6 +59,7 @@ impl Ports { Ports { pioa: PhantomData, piob: PhantomData, + #[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))] pioc: PhantomData, #[cfg(feature = "atsam4e")] piod: PhantomData, @@ -120,6 +128,7 @@ macro_rules! pins { )+ $( /// Pin $pin_identC + #[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))] pub $pin_identC: $PinTypeC>, )+ $( @@ -147,6 +156,7 @@ macro_rules! pins { $pin_identB: $PinTypeB { _mode: PhantomData }, )+ $( + #[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))] $pin_identC: $PinTypeC { _mode: PhantomData }, )+ $( @@ -168,6 +178,7 @@ macro_rules! pins { pin!($PinTypeB, $pin_identB, $pin_noB, PIOB, piob); )+ $( + #[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))] pin!($PinTypeC, $pin_identC, $pin_noC, PIOC, pioc); )+ $( diff --git a/src/lib.rs b/src/lib.rs index 63dc7bf..57bb6f6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,9 @@ //#![deny(missing_docs)] //#![deny(warnings)] #![no_std] +// Needed to quiet names such as NCS1 and UART0Clock (which now throw linting errors) +// These errors seem to have been removed in nightly, so I suspect they may not stay. +#![allow(clippy::upper_case_acronyms)] #[macro_use] extern crate lazy_static; @@ -33,6 +36,12 @@ extern crate smoltcp; #[cfg(feature = "atsam4e16e")] pub use atsam4e16e_pac as pac; +#[cfg(feature = "atsam4s4b")] +pub use atsam4s4b_pac as pac; + +#[cfg(feature = "atsam4s8b")] +pub use atsam4s8b_pac as pac; + #[cfg(feature = "atsam4sd32c")] pub use atsam4sd32c_pac as pac; @@ -66,7 +75,12 @@ unsafe fn pre_init() { clock::init(pmc, efc); }); - #[cfg(feature = "atsam4s")] + #[cfg(all(not(feature = "atsam4sd"), feature = "atsam4s"))] + pac::EFC0::borrow_unchecked(|efc0| { + clock::init(pmc, efc0); + }); + + #[cfg(feature = "atsam4sd")] pac::EFC0::borrow_unchecked(|efc0| { pac::EFC1::borrow_unchecked(|efc1| { clock::init(pmc, efc0, efc1); @@ -97,4 +111,7 @@ macro_rules! borrow_unchecked { borrow_unchecked!(WDT, PMC, EFC); #[cfg(feature = "atsam4s")] -borrow_unchecked!(WDT, PMC, EFC0, EFC1); +borrow_unchecked!(WDT, PMC, EFC0); + +#[cfg(feature = "atsam4sd")] +borrow_unchecked!(EFC1); diff --git a/src/static_memory_controller.rs b/src/static_memory_controller.rs index e087e38..afb9bc2 100644 --- a/src/static_memory_controller.rs +++ b/src/static_memory_controller.rs @@ -1,4 +1,5 @@ #![allow(clippy::upper_case_acronyms)] +#![cfg(any(feature = "atsam4_c", feature = "atsam4e"))] use { crate::clock::{Enabled, StaticMemoryControllerClock},