aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2020-10-31 23:03:09 +0100
committerDario Nieuwenhuis <[email protected]>2020-10-31 23:03:09 +0100
commit0643095695949c2ce42312c353cb5e9510ca4618 (patch)
treef8d0d6f55a16d60881c75d73c5a3171f2afee867
parent2684bf605ac7c7937cb8db7bc9142b3d34c77b17 (diff)
Fix build with all nrf chip models
-rw-r--r--embassy-nrf/Cargo.toml17
-rw-r--r--embassy-nrf/src/gpiote.rs4
-rw-r--r--embassy-nrf/src/interrupt.rs2
-rw-r--r--embassy-nrf/src/lib.rs12
-rw-r--r--embassy-nrf/src/qspi.rs7
-rw-r--r--embassy-nrf/src/rtc.rs4
-rw-r--r--embassy-nrf/src/uarte.rs23
7 files changed, 50 insertions, 19 deletions
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml
index 62df81f42..0019cbfb9 100644
--- a/embassy-nrf/Cargo.toml
+++ b/embassy-nrf/Cargo.toml
@@ -12,11 +12,11 @@ defmt-info = []
12defmt-warn = [] 12defmt-warn = []
13defmt-error = [] 13defmt-error = []
14 14
1552810 = ["nrf52810-pac"] 1552810 = ["nrf52810-pac", "nrf52810-hal"]
1652811 = ["nrf52811-pac"] 1652811 = ["nrf52811-pac"] #, "nrf52811-hal"]
1752832 = ["nrf52832-pac"] 1752832 = ["nrf52832-pac", "nrf52832-hal"]
1852833 = ["nrf52833-pac"] 1852833 = ["nrf52833-pac", "nrf52833-hal"]
1952840 = ["nrf52840-pac"] 1952840 = ["nrf52840-pac", "nrf52840-hal"]
20 20
21 21
22[dependencies] 22[dependencies]
@@ -24,7 +24,6 @@ embassy = { version = "0.1.0", path = "../embassy" }
24cortex-m-rt = "0.6.12" 24cortex-m-rt = "0.6.12"
25cortex-m = { version = "0.6.3" } 25cortex-m = { version = "0.6.3" }
26embedded-hal = { version = "0.2.4" } 26embedded-hal = { version = "0.2.4" }
27nrf52840-hal = { version = "0.11.0" }
28bare-metal = { version = "0.2.0", features = ["const-fn"] } 27bare-metal = { version = "0.2.0", features = ["const-fn"] }
29defmt = "0.1.0" 28defmt = "0.1.0"
30 29
@@ -33,3 +32,9 @@ nrf52811-pac = { version = "0.9.0", optional = true }
33nrf52832-pac = { version = "0.9.0", optional = true } 32nrf52832-pac = { version = "0.9.0", optional = true }
34nrf52833-pac = { version = "0.9.0", optional = true } 33nrf52833-pac = { version = "0.9.0", optional = true }
35nrf52840-pac = { version = "0.9.0", optional = true } 34nrf52840-pac = { version = "0.9.0", optional = true }
35
36nrf52810-hal = { version = "0.11.0", optional = true }
37#nrf52811-hal = { version = "0.11.0", optional = true } # doesn't exist yet
38nrf52832-hal = { version = "0.11.0", optional = true }
39nrf52833-hal = { version = "0.11.0", optional = true }
40nrf52840-hal = { version = "0.11.0", optional = true }
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index ef25109ee..0b9a33b3a 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -2,8 +2,8 @@ use core::cell::Cell;
2use core::ptr; 2use core::ptr;
3use defmt::trace; 3use defmt::trace;
4use embassy::util::Signal; 4use embassy::util::Signal;
5use nrf52840_hal::gpio::{Input, Level, Output, Pin, Port};
6 5
6use crate::hal::gpio::{Input, Level, Output, Pin, Port};
7use crate::interrupt; 7use crate::interrupt;
8use crate::pac::generic::Reg; 8use crate::pac::generic::Reg;
9use crate::pac::gpiote::_TASKS_OUT; 9use crate::pac::gpiote::_TASKS_OUT;
@@ -100,6 +100,7 @@ impl Gpiote {
100 EventPolarity::None => w.mode().event().polarity().none(), 100 EventPolarity::None => w.mode().event().polarity().none(),
101 EventPolarity::Toggle => w.mode().event().polarity().toggle(), 101 EventPolarity::Toggle => w.mode().event().polarity().toggle(),
102 }; 102 };
103 #[cfg(any(feature = "52833", feature = "52840"))]
103 w.port().bit(match pin.port() { 104 w.port().bit(match pin.port() {
104 Port::Port0 => false, 105 Port::Port0 => false,
105 Port::Port1 => true, 106 Port::Port1 => true,
@@ -140,6 +141,7 @@ impl Gpiote {
140 TaskOutPolarity::Clear => w.polarity().hi_to_lo(), 141 TaskOutPolarity::Clear => w.polarity().hi_to_lo(),
141 TaskOutPolarity::Toggle => w.polarity().toggle(), 142 TaskOutPolarity::Toggle => w.polarity().toggle(),
142 }; 143 };
144 #[cfg(any(feature = "52833", feature = "52840"))]
143 w.port().bit(match pin.port() { 145 w.port().bit(match pin.port() {
144 Port::Port0 => false, 146 Port::Port0 => false,
145 Port::Port1 => true, 147 Port::Port1 => true,
diff --git a/embassy-nrf/src/interrupt.rs b/embassy-nrf/src/interrupt.rs
index 30979b8ca..581adff74 100644
--- a/embassy-nrf/src/interrupt.rs
+++ b/embassy-nrf/src/interrupt.rs
@@ -3,7 +3,7 @@
3//! This module implements an API for managing interrupts compatible with 3//! This module implements an API for managing interrupts compatible with
4//! nrf_softdevice::interrupt. Intended for switching between the two at compile-time. 4//! nrf_softdevice::interrupt. Intended for switching between the two at compile-time.
5 5
6use core::sync::atomic::{compiler_fence, AtomicBool, Ordering}; 6use core::sync::atomic::{compiler_fence, Ordering};
7 7
8use crate::pac::{NVIC, NVIC_PRIO_BITS}; 8use crate::pac::{NVIC, NVIC_PRIO_BITS};
9 9
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index 578d76635..8efd6c568 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -37,8 +37,20 @@ pub use nrf52833_pac as pac;
37#[cfg(feature = "52840")] 37#[cfg(feature = "52840")]
38pub use nrf52840_pac as pac; 38pub use nrf52840_pac as pac;
39 39
40#[cfg(feature = "52810")]
41pub use nrf52810_hal as hal;
42#[cfg(feature = "52811")]
43pub use nrf52811_hal as hal;
44#[cfg(feature = "52832")]
45pub use nrf52832_hal as hal;
46#[cfg(feature = "52833")]
47pub use nrf52833_hal as hal;
48#[cfg(feature = "52840")]
49pub use nrf52840_hal as hal;
50
40pub mod gpiote; 51pub mod gpiote;
41pub mod interrupt; 52pub mod interrupt;
53#[cfg(feature = "52840")]
42pub mod qspi; 54pub mod qspi;
43pub mod rtc; 55pub mod rtc;
44pub mod uarte; 56pub mod uarte;
diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs
index d2caddee0..367a1d2d3 100644
--- a/embassy-nrf/src/qspi.rs
+++ b/embassy-nrf/src/qspi.rs
@@ -1,6 +1,7 @@
1use crate::pac::{Interrupt, QSPI};
2use core::future::Future; 1use core::future::Future;
3use nrf52840_hal::gpio::{Output, Pin as GpioPin, Port as GpioPort, PushPull}; 2
3use crate::hal::gpio::{Output, Pin as GpioPin, Port as GpioPort, PushPull};
4use crate::pac::{Interrupt, QSPI};
4 5
5pub use crate::pac::qspi::ifconfig0::ADDRMODE_A as AddressMode; 6pub use crate::pac::qspi::ifconfig0::ADDRMODE_A as AddressMode;
6pub use crate::pac::qspi::ifconfig0::PPSIZE_A as WritePageSize; 7pub use crate::pac::qspi::ifconfig0::PPSIZE_A as WritePageSize;
@@ -314,7 +315,7 @@ static SIGNAL: Signal<()> = Signal::new();
314 315
315#[interrupt] 316#[interrupt]
316unsafe fn QSPI() { 317unsafe fn QSPI() {
317 let p = unsafe { crate::pac::Peripherals::steal().QSPI }; 318 let p = crate::pac::Peripherals::steal().QSPI;
318 if p.events_ready.read().events_ready().bit_is_set() { 319 if p.events_ready.read().events_ready().bit_is_set() {
319 p.events_ready.reset(); 320 p.events_ready.reset();
320 SIGNAL.signal(()); 321 SIGNAL.signal(());
diff --git a/embassy-nrf/src/rtc.rs b/embassy-nrf/src/rtc.rs
index 29c06b860..66e2f552d 100644
--- a/embassy-nrf/src/rtc.rs
+++ b/embassy-nrf/src/rtc.rs
@@ -96,8 +96,8 @@ impl<T: Instance> RTC<T> {
96 w 96 w
97 }); 97 });
98 98
99 self.rtc.tasks_clear.write(|w| w.tasks_clear().set_bit()); 99 self.rtc.tasks_clear.write(|w| unsafe { w.bits(1) });
100 self.rtc.tasks_start.write(|w| w.tasks_start().set_bit()); 100 self.rtc.tasks_start.write(|w| unsafe { w.bits(1) });
101 101
102 // Wait for clear 102 // Wait for clear
103 while self.rtc.counter.read().bits() != 0 {} 103 while self.rtc.counter.read().bits() != 0 {}
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index b904f006a..575405b57 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -13,11 +13,14 @@ use core::ptr;
13use core::sync::atomic::{compiler_fence, Ordering}; 13use core::sync::atomic::{compiler_fence, Ordering};
14use core::task::{Context, Poll}; 14use core::task::{Context, Poll};
15 15
16use embedded_hal::digital::v2::OutputPin;
17
18use crate::hal::gpio::{Floating, Input, Output, Pin as GpioPin, Port as GpioPort, PushPull};
16use crate::interrupt; 19use crate::interrupt;
17use crate::interrupt::CriticalSection; 20use crate::interrupt::CriticalSection;
18use crate::pac::{uarte0, Interrupt, UARTE0, UARTE1}; 21#[cfg(any(feature = "52833", feature = "52840", feature = "9160"))]
19use embedded_hal::digital::v2::OutputPin; 22use crate::pac::UARTE1;
20use nrf52840_hal::gpio::{Floating, Input, Output, Pin as GpioPin, Port as GpioPort, PushPull}; 23use crate::pac::{uarte0, Interrupt, UARTE0};
21 24
22// Re-export SVD variants to allow user to directly set values 25// Re-export SVD variants to allow user to directly set values
23pub use uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; 26pub use uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
@@ -152,6 +155,7 @@ pub struct UarteState<T> {
152 _pin: PhantomPinned, 155 _pin: PhantomPinned,
153} 156}
154 157
158#[cfg(any(feature = "52833", feature = "52840"))]
155fn port_bit(port: GpioPort) -> bool { 159fn port_bit(port: GpioPort) -> bool {
156 match port { 160 match port {
157 GpioPort::Port0 => false, 161 GpioPort::Port0 => false,
@@ -164,12 +168,14 @@ impl<T: Instance> Uarte<T> {
164 // Select pins 168 // Select pins
165 uarte.psel.rxd.write(|w| { 169 uarte.psel.rxd.write(|w| {
166 let w = unsafe { w.pin().bits(pins.rxd.pin()) }; 170 let w = unsafe { w.pin().bits(pins.rxd.pin()) };
171 #[cfg(any(feature = "52833", feature = "52840"))]
167 let w = w.port().bit(port_bit(pins.rxd.port())); 172 let w = w.port().bit(port_bit(pins.rxd.port()));
168 w.connect().connected() 173 w.connect().connected()
169 }); 174 });
170 pins.txd.set_high().unwrap(); 175 pins.txd.set_high().unwrap();
171 uarte.psel.txd.write(|w| { 176 uarte.psel.txd.write(|w| {
172 let w = unsafe { w.pin().bits(pins.txd.pin()) }; 177 let w = unsafe { w.pin().bits(pins.txd.pin()) };
178 #[cfg(any(feature = "52833", feature = "52840"))]
173 let w = w.port().bit(port_bit(pins.txd.port())); 179 let w = w.port().bit(port_bit(pins.txd.port()));
174 w.connect().connected() 180 w.connect().connected()
175 }); 181 });
@@ -178,6 +184,7 @@ impl<T: Instance> Uarte<T> {
178 uarte.psel.cts.write(|w| { 184 uarte.psel.cts.write(|w| {
179 if let Some(ref pin) = pins.cts { 185 if let Some(ref pin) = pins.cts {
180 let w = unsafe { w.pin().bits(pin.pin()) }; 186 let w = unsafe { w.pin().bits(pin.pin()) };
187 #[cfg(any(feature = "52833", feature = "52840"))]
181 let w = w.port().bit(port_bit(pin.port())); 188 let w = w.port().bit(port_bit(pin.port()));
182 w.connect().connected() 189 w.connect().connected()
183 } else { 190 } else {
@@ -188,6 +195,7 @@ impl<T: Instance> Uarte<T> {
188 uarte.psel.rts.write(|w| { 195 uarte.psel.rts.write(|w| {
189 if let Some(ref pin) = pins.rts { 196 if let Some(ref pin) = pins.rts {
190 let w = unsafe { w.pin().bits(pin.pin()) }; 197 let w = unsafe { w.pin().bits(pin.pin()) };
198 #[cfg(any(feature = "52833", feature = "52840"))]
191 let w = w.port().bit(port_bit(pin.port())); 199 let w = w.port().bit(port_bit(pin.port()));
192 w.connect().connected() 200 w.connect().connected()
193 } else { 201 } else {
@@ -493,11 +501,11 @@ pub struct Pins {
493} 501}
494 502
495mod private { 503mod private {
496 use nrf52840_pac::{UARTE0, UARTE1};
497 pub trait Sealed {} 504 pub trait Sealed {}
498 505
499 impl Sealed for UARTE0 {} 506 impl Sealed for crate::pac::UARTE0 {}
500 impl Sealed for UARTE1 {} 507 #[cfg(any(feature = "52833", feature = "52840", feature = "9160"))]
508 impl Sealed for crate::pac::UARTE1 {}
501} 509}
502 510
503pub trait Instance: Deref<Target = uarte0::RegisterBlock> + Sized + private::Sealed { 511pub trait Instance: Deref<Target = uarte0::RegisterBlock> + Sized + private::Sealed {
@@ -515,12 +523,14 @@ unsafe fn UARTE0_UART0() {
515 interrupt::free(|cs| UARTE0::get_state(cs).as_mut().unwrap().on_interrupt()); 523 interrupt::free(|cs| UARTE0::get_state(cs).as_mut().unwrap().on_interrupt());
516} 524}
517 525
526#[cfg(any(feature = "52833", feature = "52840", feature = "9160"))]
518#[interrupt] 527#[interrupt]
519unsafe fn UARTE1() { 528unsafe fn UARTE1() {
520 interrupt::free(|cs| UARTE1::get_state(cs).as_mut().unwrap().on_interrupt()); 529 interrupt::free(|cs| UARTE1::get_state(cs).as_mut().unwrap().on_interrupt());
521} 530}
522 531
523static mut UARTE0_STATE: *mut UarteState<UARTE0> = ptr::null_mut(); 532static mut UARTE0_STATE: *mut UarteState<UARTE0> = ptr::null_mut();
533#[cfg(any(feature = "52833", feature = "52840", feature = "9160"))]
524static mut UARTE1_STATE: *mut UarteState<UARTE1> = ptr::null_mut(); 534static mut UARTE1_STATE: *mut UarteState<UARTE1> = ptr::null_mut();
525 535
526impl Instance for UARTE0 { 536impl Instance for UARTE0 {
@@ -536,6 +546,7 @@ impl Instance for UARTE0 {
536 } 546 }
537} 547}
538 548
549#[cfg(any(feature = "52833", feature = "52840", feature = "9160"))]
539impl Instance for UARTE1 { 550impl Instance for UARTE1 {
540 fn interrupt() -> Interrupt { 551 fn interrupt() -> Interrupt {
541 Interrupt::UARTE1 552 Interrupt::UARTE1