Skip to content

Commit

Permalink
Converted adc and serial_number variants to cargo features
Browse files Browse the repository at this point in the history
  • Loading branch information
TethysSvensson committed Jan 14, 2024
1 parent ceca9d4 commit 456fa93
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 74 deletions.
18 changes: 12 additions & 6 deletions hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,12 @@ thumbv6 = ["device"]
thumbv7 = ["device"]

# Map each series of chips to its instruction set
samd11 = ["thumbv6"]
samd21 = ["thumbv6"]
samd51 = ["thumbv7"]
same51 = ["thumbv7"]
same53 = ["thumbv7"]
same54 = ["thumbv7"]
samd11 = ["thumbv6", "has-adc-variant1", "has-serial-numbers-variant1a"]
samd21 = ["thumbv6", "has-adc-variant1", "has-serial-numbers-variant1a"]
samd51 = ["thumbv7", "has-adc-variant2", "has-serial-numbers-variant1b"]
same51 = ["thumbv7", "has-adc-variant2", "has-serial-numbers-variant1b"]
same53 = ["thumbv7", "has-adc-variant2", "has-serial-numbers-variant1b"]
same54 = ["thumbv7", "has-adc-variant2", "has-serial-numbers-variant1b"]

#-------------------------------------------------------------------------------
# Pins
Expand Down Expand Up @@ -316,6 +316,12 @@ has-tcc2 = []
has-tcc3 = []
has-usb = []

has-adc-variant1 = []
has-adc-variant2 = []

has-serial-numbers-variant1a = []
has-serial-numbers-variant1b = []

# Map each variant to its collection of peripherals
periph-d11c = ["has-sercom0", "has-sercom1", "has-tc1", "has-tc2", "has-tcc0"]
periph-d11d = ["periph-d11c", "has-sercom2"]
Expand Down
5 changes: 5 additions & 0 deletions hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ pub mod thumbv7em;
#[doc(inline)]
pub use crate::thumbv7em::*;

#[doc(hidden)]
pub mod peripherals;
#[doc(inline)]
pub use crate::peripherals::*;

#[macro_use]
mod bsp_peripherals_macro;
pub use bsp_peripherals_macro::*;
File renamed without changes.
File renamed without changes.
10 changes: 10 additions & 0 deletions hal/src/peripherals/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#[cfg(all(feature = "unproven", feature = "has-adc-variant1"))]
#[path = "adc/variant1.rs"]
pub mod adc;

#[cfg(all(feature = "unproven", feature = "has-adc-variant2"))]
#[path = "adc/variant2.rs"]
pub mod adc;

mod serial_number;
pub use serial_number::*;
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
//! Serial number
// See 9.6 Memories --> Serial Number, page 24 for samd11
// See 10.3.3 Memories --> Serial Number, page 45 for samd21
use core::ptr;

const SN_1: u32 = 0x0080A00C;
const SN_2: u32 = 0x0080A040;
const SN_3: u32 = 0x0080A044;
const SN_4: u32 = 0x0080A048;
#[cfg(feature = "has-serial-numbers-variant1a")]
mod constants {
// See 9.6 Memories --> Serial Number, page 24 for samd11
// See 10.3.3 Memories --> Serial Number, page 45 for samd21
pub(super) const SN_1: u32 = 0x0080A00C;
pub(super) const SN_2: u32 = 0x0080A040;
pub(super) const SN_3: u32 = 0x0080A044;
pub(super) const SN_4: u32 = 0x0080A048;
}

#[cfg(feature = "has-serial-numbers-variant1b")]
mod constants {
// See 9.6 Memories --> Serial Number, page 60
pub(super) const SN_1: u32 = 0x008061FC;
pub(super) const SN_2: u32 = 0x00806010;
pub(super) const SN_3: u32 = 0x00806014;
pub(super) const SN_4: u32 = 0x00806018;
}

/// Returns the serial number of the chip as 4 32-bit integers. The serial
/// number is only guaranteed to be unique if all 128 bits are used.
pub fn split_serial_number() -> (u32, u32, u32, u32) {
unsafe {
(
ptr::read(SN_1 as *const u32),
ptr::read(SN_2 as *const u32),
ptr::read(SN_3 as *const u32),
ptr::read(SN_4 as *const u32),
ptr::read(constants::SN_1 as *const u32),
ptr::read(constants::SN_2 as *const u32),
ptr::read(constants::SN_3 as *const u32),
ptr::read(constants::SN_4 as *const u32),
)
}
}
Expand Down
21 changes: 15 additions & 6 deletions hal/src/thumbv6m/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,10 @@ pub mod eic;
mod reset_cause;
pub use reset_cause::*;

mod serial_number;
pub use serial_number::*;

pub mod calibration;
pub mod clock;
pub mod timer;

#[cfg(feature = "unproven")]
pub mod adc;

#[cfg(feature = "unproven")]
pub mod pwm;

Expand All @@ -21,3 +15,18 @@ pub mod watchdog;

#[cfg(all(feature = "usb", feature = "has-usb"))]
pub mod usb;

hal_feature!(
i2c,
variant1 => "i2c/variant1.rs",
variant2 => "i2c/variant2.rs",
);

hal_feature!(
serial_numbers,
variant1 => "serial_numbers.rs",
);

#[cfg(any(feature = "l22g", ...))]
#[path = "serial_numbers.rs"]
mod serial_numbers;
6 changes: 0 additions & 6 deletions hal/src/thumbv7em/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ pub mod usb;
mod reset_cause;
pub use reset_cause::*;

mod serial_number;
pub use serial_number::*;

#[cfg(feature = "unproven")]
pub mod adc;

#[cfg(feature = "unproven")]
pub mod pwm;

Expand Down
46 changes: 0 additions & 46 deletions hal/src/thumbv7em/serial_number.rs

This file was deleted.

0 comments on commit 456fa93

Please sign in to comment.