Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"boards/actinius-icarus",
"nrf52810-hal",
"nrf52832-hal",
"nrf52833-hal",
"nrf52840-hal",
"nrf9160-hal",
"examples/rtfm-demo",
Expand Down
5 changes: 5 additions & 0 deletions nrf-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ version = "0.9.0"
optional = true
version = "0.9.0"

[dependencies.nrf52833-pac]
optional = true
version = "0.9.0"

[dependencies.nrf52840-pac]
optional = true
version = "0.9.0"
Expand All @@ -61,5 +65,6 @@ doc = []
51 = ["nrf51"]
52810 = ["nrf52810-pac"]
52832 = ["nrf52832-pac"]
52833 = ["nrf52833-pac"]
52840 = ["nrf52840-pac"]
9160 = ["nrf9160-pac"]
54 changes: 27 additions & 27 deletions nrf-hal-common/src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub enum Level {
/// Generic $PX pin
pub struct Pin<MODE> {
pub pin: u8,
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
pub port: bool,
_mode: PhantomData<MODE>,
}
Expand All @@ -59,7 +59,7 @@ use crate::target::P0_NS as P0;
#[cfg(not(any(feature = "9160", feature = "51")))]
use crate::target::P0;

#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
use crate::target::P1;

use crate::hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
Expand All @@ -70,11 +70,11 @@ impl<MODE> Pin<MODE> {
pub fn into_floating_input(self) -> Pin<Input<Floating>> {
unsafe {
&(*{
#[cfg(not(feature = "52840"))]
#[cfg(not(any(feature = "52833", feature = "52840")))]
{
P0::ptr()
}
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
{
if !self.port {
P0::ptr()
Expand All @@ -96,19 +96,19 @@ impl<MODE> Pin<MODE> {

Pin {
_mode: PhantomData,
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
port: self.port,
pin: self.pin,
}
}
pub fn into_pullup_input(self) -> Pin<Input<PullUp>> {
unsafe {
&(*{
#[cfg(not(feature = "52840"))]
#[cfg(not(any(feature = "52833", feature = "52840")))]
{
P0::ptr()
}
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
{
if !self.port {
P0::ptr()
Expand All @@ -130,19 +130,19 @@ impl<MODE> Pin<MODE> {

Pin {
_mode: PhantomData,
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
port: self.port,
pin: self.pin,
}
}
pub fn into_pulldown_input(self) -> Pin<Input<PullDown>> {
unsafe {
&(*{
#[cfg(not(feature = "52840"))]
#[cfg(not(any(feature = "52833", feature = "52840")))]
{
P0::ptr()
}
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
{
if !self.port {
P0::ptr()
Expand All @@ -164,7 +164,7 @@ impl<MODE> Pin<MODE> {

Pin {
_mode: PhantomData,
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
port: self.port,
pin: self.pin,
}
Expand All @@ -174,7 +174,7 @@ impl<MODE> Pin<MODE> {
pub fn into_push_pull_output(self, initial_output: Level) -> Pin<Output<PushPull>> {
let mut pin = Pin {
_mode: PhantomData,
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
port: self.port,
pin: self.pin,
};
Expand All @@ -186,11 +186,11 @@ impl<MODE> Pin<MODE> {

unsafe {
&(*{
#[cfg(not(feature = "52840"))]
#[cfg(not(any(feature = "52833", feature = "52840")))]
{
P0::ptr()
}
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
{
if !self.port {
P0::ptr()
Expand Down Expand Up @@ -224,7 +224,7 @@ impl<MODE> Pin<MODE> {
) -> Pin<Output<OpenDrain>> {
let mut pin = Pin {
_mode: PhantomData,
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
port: self.port,
pin: self.pin,
};
Expand All @@ -238,11 +238,11 @@ impl<MODE> Pin<MODE> {
// register for this pin.
let pin_cnf = unsafe {
&(*{
#[cfg(not(feature = "52840"))]
#[cfg(not(any(feature = "52833", feature = "52840")))]
{
P0::ptr()
}
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
{
if !self.port {
P0::ptr()
Expand Down Expand Up @@ -276,11 +276,11 @@ impl<MODE> InputPin for Pin<Input<MODE>> {
fn is_low(&self) -> Result<bool, Self::Error> {
Ok(unsafe {
((*{
#[cfg(not(feature = "52840"))]
#[cfg(not(any(feature = "52833", feature = "52840")))]
{
P0::ptr()
}
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
{
if !self.port {
P0::ptr()
Expand All @@ -307,11 +307,11 @@ impl<MODE> OutputPin for Pin<Output<MODE>> {
// TODO - I wish I could do something like `.pins$i()`...
unsafe {
(*{
#[cfg(not(feature = "52840"))]
#[cfg(not(any(feature = "52833", feature = "52840")))]
{
P0::ptr()
}
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
{
if !self.port {
P0::ptr()
Expand All @@ -332,11 +332,11 @@ impl<MODE> OutputPin for Pin<Output<MODE>> {
// TODO - I wish I could do something like `.pins$i()`...
unsafe {
(*{
#[cfg(not(feature = "52840"))]
#[cfg(not(any(feature = "52833", feature = "52840")))]
{
P0::ptr()
}
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
{
if !self.port {
P0::ptr()
Expand Down Expand Up @@ -364,11 +364,11 @@ impl<MODE> StatefulOutputPin for Pin<Output<MODE>> {
// TODO - I wish I could do something like `.pins$i()`...
Ok(unsafe {
((*{
#[cfg(not(feature = "52840"))]
#[cfg(not(any(feature = "52833", feature = "52840")))]
{
P0::ptr()
}
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
{
if !self.port {
P0::ptr()
Expand Down Expand Up @@ -592,7 +592,7 @@ macro_rules! gpio {
pub fn degrade(self) -> Pin<MODE> {
Pin {
_mode: PhantomData,
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
port: $port_value,
pin: $i
}
Expand Down Expand Up @@ -692,7 +692,7 @@ gpio!(P0, p0, p0, false, [

// The p1 types are present in the p0 module generated from the
// svd, but we want to export them in a p1 module from this crate.
#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
gpio!(P1, p0, p1, true, [
P1_00: (p1_00, 0, Input<Floating>),
P1_01: (p1_01, 1, Input<Floating>),
Expand Down
5 changes: 4 additions & 1 deletion nrf-hal-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ pub use nrf52810_pac as target;
#[cfg(feature = "52832")]
pub use nrf52832_pac as target;

#[cfg(feature = "52833")]
pub use nrf52833_pac as target;

#[cfg(feature = "52840")]
pub use nrf52840_pac as target;

Expand Down Expand Up @@ -64,7 +67,7 @@ pub mod target_constants {
pub const SRAM_UPPER: usize = 0x3000_0000;
pub const FORCE_COPY_BUFFER_SIZE: usize = 255;
}
#[cfg(any(feature = "52840", feature = "9160"))]
#[cfg(any(feature = "52840", feature = "52833", feature = "9160"))]
pub mod target_constants {
// NRF52840 and NRF9160 16 bits 1..0xFFFF
pub const EASY_DMA_SIZE: usize = 65535;
Expand Down
4 changes: 2 additions & 2 deletions nrf-hal-common/src/rtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::target::{rtc0_ns as rtc0, Interrupt, NVIC, RTC0_NS as RTC0, RTC1_NS a
#[cfg(not(feature = "9160"))]
use crate::target::{rtc0, Interrupt, NVIC, RTC0, RTC1};

#[cfg(any(feature = "52840", feature = "52832"))]
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
use crate::target::RTC2;

// Zero Size Type State structs
Expand Down Expand Up @@ -252,5 +252,5 @@ macro_rules! impl_instance {

impl_instance!(RTC0, RTC1,);

#[cfg(any(feature = "52840", feature = "52832"))]
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
impl_instance!(RTC2,);
16 changes: 8 additions & 8 deletions nrf-hal-common/src/spim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ pub use spim0::frequency::FREQUENCY_A as Frequency;

use core::iter::repeat_with;

#[cfg(any(feature = "52832", feature = "52840"))]
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
use crate::target::{SPIM1, SPIM2};

#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
use crate::target::SPIM3;

use crate::gpio::{Floating, Input, Output, Pin, PushPull};
Expand Down Expand Up @@ -97,15 +97,15 @@ where
// Select pins
spim.psel.sck.write(|w| {
let w = unsafe { w.pin().bits(pins.sck.pin) };
#[cfg(feature = "52840")]
#[cfg(any(feature = "52843", feature = "52840"))]
let w = w.port().bit(pins.sck.port);
w.connect().connected()
});

match pins.mosi {
Some(mosi) => spim.psel.mosi.write(|w| {
let w = unsafe { w.pin().bits(mosi.pin) };
#[cfg(feature = "52840")]
#[cfg(any(feature = "52843", feature = "52840"))]
let w = w.port().bit(mosi.port);
w.connect().connected()
}),
Expand All @@ -114,7 +114,7 @@ where
match pins.miso {
Some(miso) => spim.psel.miso.write(|w| {
let w = unsafe { w.pin().bits(miso.pin) };
#[cfg(feature = "52840")]
#[cfg(any(feature = "52843", feature = "52840"))]
let w = w.port().bit(miso.port);
w.connect().connected()
}),
Expand Down Expand Up @@ -407,11 +407,11 @@ pub trait Instance: Deref<Target = spim0::RegisterBlock> {}

impl Instance for SPIM0 {}

#[cfg(any(feature = "52832", feature = "52840"))]
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
impl Instance for SPIM1 {}

#[cfg(any(feature = "52832", feature = "52840"))]
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
impl Instance for SPIM2 {}

#[cfg(feature = "52840")]
#[cfg(any(feature = "52833", feature = "52840"))]
impl Instance for SPIM3 {}
4 changes: 2 additions & 2 deletions nrf-hal-common/src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use embedded_hal::{
use nb::{self, block};
use void::{unreachable, Void};

#[cfg(any(feature = "52832", feature = "52840"))]
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
use crate::target::{TIMER3, TIMER4};

use core::marker::PhantomData;
Expand Down Expand Up @@ -362,5 +362,5 @@ macro_rules! impl_instance {

impl_instance!(TIMER0, TIMER1, TIMER2,);

#[cfg(any(feature = "52832", feature = "52840"))]
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
impl_instance!(TIMER3, TIMER4,);
4 changes: 2 additions & 2 deletions nrf-hal-common/src/twim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::target::{twim0_ns as twim0, P0_NS as P0, TWIM0_NS as TWIM0};
#[cfg(not(feature = "9160"))]
use crate::target::{twim0, P0, TWIM0};

#[cfg(any(feature = "52832", feature = "52840"))]
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
use crate::target::TWIM1;

use crate::{
Expand Down Expand Up @@ -404,5 +404,5 @@ pub trait Instance: Deref<Target = twim0::RegisterBlock> {}

impl Instance for TWIM0 {}

#[cfg(any(feature = "52832", feature = "52840"))]
#[cfg(any(feature = "52832", feature = "52833", feature = "52840"))]
impl Instance for TWIM1 {}
Loading