Skip to content

Commit

Permalink
Adding atsam4s4b and atsam4s8b
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
haata authored and john-terrell committed Mar 28, 2021
1 parent f9934b7 commit a137ecf
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
mcu: [atsam4e16e, atsam4sd32c]
mcu: [atsam4e16e, atsam4s4b, atsam4s8b, atsam4sd32c]

steps:
- uses: actions/checkout@v1
Expand Down
21 changes: 20 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
31 changes: 25 additions & 6 deletions src/clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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() });
Expand All @@ -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() });
}
Expand Down
23 changes: 17 additions & 6 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<Enabled>)>,
piob: PhantomData<(PIOB, ParallelIOControllerBClock<Enabled>)>,
#[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))]
pioc: PhantomData<(PIOC, ParallelIOControllerCClock<Enabled>)>,
#[cfg(feature = "atsam4e")]
piod: PhantomData<(PIOD, ParallelIOControllerDClock<Enabled>)>,
Expand All @@ -44,14 +48,18 @@ impl Ports {
pub fn new(
_pioa: (PIOA, ParallelIOControllerAClock<Enabled>),
_piob: (PIOB, ParallelIOControllerBClock<Enabled>),
_pioc: (PIOC, ParallelIOControllerCClock<Enabled>),
#[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))] _pioc: (
PIOC,
ParallelIOControllerCClock<Enabled>,
),
#[cfg(feature = "atsam4e")] _piod: (PIOD, ParallelIOControllerDClock<Enabled>),
#[cfg(feature = "atsam4e")] _pioe: (PIOE, ParallelIOControllerEClock<Enabled>),
) -> Self {
// The above arguments are consumed here...never to be seen again.
Ports {
pioa: PhantomData,
piob: PhantomData,
#[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))]
pioc: PhantomData,
#[cfg(feature = "atsam4e")]
piod: PhantomData,
Expand Down Expand Up @@ -120,6 +128,7 @@ macro_rules! pins {
)+
$(
/// Pin $pin_identC
#[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))]
pub $pin_identC: $PinTypeC<Input<Floating>>,
)+
$(
Expand Down Expand Up @@ -147,6 +156,7 @@ macro_rules! pins {
$pin_identB: $PinTypeB { _mode: PhantomData },
)+
$(
#[cfg(any(feature = "atsam4s_c", feature = "atsam4e"))]
$pin_identC: $PinTypeC { _mode: PhantomData },
)+
$(
Expand All @@ -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);
)+
$(
Expand Down
21 changes: 19 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
1 change: 1 addition & 0 deletions src/static_memory_controller.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::upper_case_acronyms)]
#![cfg(any(feature = "atsam4_c", feature = "atsam4e"))]

use {
crate::clock::{Enabled, StaticMemoryControllerClock},
Expand Down

0 comments on commit a137ecf

Please sign in to comment.