aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--embassy-nrf/Cargo.toml2
-rw-r--r--embassy-nrf/src/buffered_uarte.rs5
-rw-r--r--embassy-nrf/src/chips/nrf9160.rs209
-rw-r--r--embassy-nrf/src/gpio.rs7
-rw-r--r--embassy-nrf/src/gpiote.rs65
-rw-r--r--embassy-nrf/src/lib.rs20
-rw-r--r--embassy-nrf/src/ppi.rs151
-rw-r--r--embassy-nrf/src/pwm.rs10
-rw-r--r--embassy-nrf/src/saadc.rs7
-rw-r--r--embassy-nrf/src/spim.rs11
-rw-r--r--embassy-nrf/src/time_driver.rs10
-rw-r--r--embassy-nrf/src/timer.rs11
-rw-r--r--embassy-nrf/src/twim.rs9
-rw-r--r--embassy-nrf/src/uarte.rs11
-rw-r--r--embassy-nrf/src/wdt.rs15
-rw-r--r--rust-toolchain.toml2
16 files changed, 458 insertions, 87 deletions
diff --git a/embassy-nrf/Cargo.toml b/embassy-nrf/Cargo.toml
index d472069e7..7c5f8d32b 100644
--- a/embassy-nrf/Cargo.toml
+++ b/embassy-nrf/Cargo.toml
@@ -25,6 +25,7 @@ nrf52820 = ["nrf52820-pac"]
25nrf52832 = ["nrf52832-pac"] 25nrf52832 = ["nrf52832-pac"]
26nrf52833 = ["nrf52833-pac"] 26nrf52833 = ["nrf52833-pac"]
27nrf52840 = ["nrf52840-pac"] 27nrf52840 = ["nrf52840-pac"]
28nrf9160 = ["nrf9160-pac"]
28 29
29# Features starting with `_` are for internal use only. They're not intended 30# Features starting with `_` are for internal use only. They're not intended
30# to be enabled by other crates, and are not covered by semver guarantees. 31# to be enabled by other crates, and are not covered by semver guarantees.
@@ -55,3 +56,4 @@ nrf52820-pac = { version = "0.10.1", optional = true, features = [ "rt" ] }
55nrf52832-pac = { version = "0.10.1", optional = true, features = [ "rt" ] } 56nrf52832-pac = { version = "0.10.1", optional = true, features = [ "rt" ] }
56nrf52833-pac = { version = "0.10.1", optional = true, features = [ "rt" ] } 57nrf52833-pac = { version = "0.10.1", optional = true, features = [ "rt" ] }
57nrf52840-pac = { version = "0.10.1", optional = true, features = [ "rt" ] } 58nrf52840-pac = { version = "0.10.1", optional = true, features = [ "rt" ] }
59nrf9160-pac = { version = "0.10.1", optional = true, features = [ "rt" ] }
diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs
index cd08875cd..31acb80d6 100644
--- a/embassy-nrf/src/buffered_uarte.rs
+++ b/embassy-nrf/src/buffered_uarte.rs
@@ -14,14 +14,13 @@ use embassy_hal_common::{low_power_wait_until, unborrow};
14 14
15use crate::gpio::sealed::Pin as _; 15use crate::gpio::sealed::Pin as _;
16use crate::gpio::{OptionalPin as GpioOptionalPin, Pin as GpioPin}; 16use crate::gpio::{OptionalPin as GpioOptionalPin, Pin as GpioPin};
17use crate::pac;
18use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task}; 17use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
19use crate::timer::Instance as TimerInstance; 18use crate::timer::Instance as TimerInstance;
20use crate::timer::{Frequency, Timer}; 19use crate::timer::{Frequency, Timer};
21use crate::uarte::{Config, Instance as UarteInstance}; 20use crate::uarte::{Config, Instance as UarteInstance, uarte0};
22 21
23// Re-export SVD variants to allow user to directly set values 22// Re-export SVD variants to allow user to directly set values
24pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; 23pub use uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
25 24
26#[derive(Copy, Clone, Debug, PartialEq)] 25#[derive(Copy, Clone, Debug, PartialEq)]
27enum RxState { 26enum RxState {
diff --git a/embassy-nrf/src/chips/nrf9160.rs b/embassy-nrf/src/chips/nrf9160.rs
new file mode 100644
index 000000000..0730c1258
--- /dev/null
+++ b/embassy-nrf/src/chips/nrf9160.rs
@@ -0,0 +1,209 @@
1pub use nrf9160_pac as pac;
2
3/// The maximum buffer size that the EasyDMA can send/recv in one operation.
4pub const EASY_DMA_SIZE: usize = (1 << 12) - 1;
5pub const FORCE_COPY_BUFFER_SIZE: usize = 1024;
6
7embassy_hal_common::peripherals! {
8 // RTC
9 RTC0,
10 RTC1,
11
12 // WDT
13 WDT,
14
15 // UARTE
16 UARTE0,
17 UARTE1,
18 UARTE2,
19 UARTE3,
20
21 // TWI
22 TWI0,
23 TWI1,
24 TWI2,
25 TWI3,
26
27 // SPI
28 SPI0,
29 SPI1,
30 SPI2,
31 SPI3,
32
33 // SAADC
34 SAADC,
35
36 // PWM
37 PWM0,
38 PWM1,
39 PWM2,
40 PWM3,
41
42 // TIMER
43 TIMER0,
44 TIMER1,
45 TIMER2,
46
47 // GPIOTE
48 GPIOTE_CH0,
49 GPIOTE_CH1,
50 GPIOTE_CH2,
51 GPIOTE_CH3,
52 GPIOTE_CH4,
53 GPIOTE_CH5,
54 GPIOTE_CH6,
55 GPIOTE_CH7,
56
57 // PPI
58 PPI_CH0,
59 PPI_CH1,
60 PPI_CH2,
61 PPI_CH3,
62 PPI_CH4,
63 PPI_CH5,
64 PPI_CH6,
65 PPI_CH7,
66 PPI_CH8,
67 PPI_CH9,
68 PPI_CH10,
69 PPI_CH11,
70 PPI_CH12,
71 PPI_CH13,
72 PPI_CH14,
73 PPI_CH15,
74
75 PPI_GROUP0,
76 PPI_GROUP1,
77 PPI_GROUP2,
78 PPI_GROUP3,
79 PPI_GROUP4,
80 PPI_GROUP5,
81
82 // GPIO port 0
83 P0_00,
84 P0_01,
85 P0_02,
86 P0_03,
87 P0_04,
88 P0_05,
89 P0_06,
90 P0_07,
91 P0_08,
92 P0_09,
93 P0_10,
94 P0_11,
95 P0_12,
96 P0_13,
97 P0_14,
98 P0_15,
99 P0_16,
100 P0_17,
101 P0_18,
102 P0_19,
103 P0_20,
104 P0_21,
105 P0_22,
106 P0_23,
107 P0_24,
108 P0_25,
109 P0_26,
110 P0_27,
111 P0_28,
112 P0_29,
113 P0_30,
114 P0_31,
115}
116
117impl_uarte!(UARTE0, UARTE0_NS, UARTE0_SPIM0_SPIS0_TWIM0_TWIS0);
118impl_uarte!(UARTE1, UARTE1_NS, UARTE1_SPIM1_SPIS1_TWIM1_TWIS1);
119impl_uarte!(UARTE2, UARTE2_NS, UARTE2_SPIM2_SPIS2_TWIM2_TWIS2);
120impl_uarte!(UARTE3, UARTE3_NS, UARTE3_SPIM3_SPIS3_TWIM3_TWIS3);
121
122impl_spim!(SPI0, SPIM0_NS, UARTE0_SPIM0_SPIS0_TWIM0_TWIS0);
123impl_spim!(SPI1, SPIM1_NS, UARTE1_SPIM1_SPIS1_TWIM1_TWIS1);
124impl_spim!(SPI2, SPIM2_NS, UARTE2_SPIM2_SPIS2_TWIM2_TWIS2);
125impl_spim!(SPI3, SPIM3_NS, UARTE3_SPIM3_SPIS3_TWIM3_TWIS3);
126
127impl_twim!(TWI0, TWIM0_NS, UARTE0_SPIM0_SPIS0_TWIM0_TWIS0);
128impl_twim!(TWI1, TWIM1_NS, UARTE1_SPIM1_SPIS1_TWIM1_TWIS1);
129impl_twim!(TWI2, TWIM2_NS, UARTE2_SPIM2_SPIS2_TWIM2_TWIS2);
130impl_twim!(TWI3, TWIM3_NS, UARTE3_SPIM3_SPIS3_TWIM3_TWIS3);
131
132impl_pwm!(PWM0, PWM0_NS, PWM0);
133impl_pwm!(PWM1, PWM1_NS, PWM1);
134impl_pwm!(PWM2, PWM2_NS, PWM2);
135impl_pwm!(PWM3, PWM3_NS, PWM3);
136
137impl_timer!(TIMER0, TIMER0_NS, TIMER0);
138impl_timer!(TIMER1, TIMER1_NS, TIMER1);
139impl_timer!(TIMER2, TIMER2_NS, TIMER2);
140
141impl_pin!(P0_00, 0, 0);
142impl_pin!(P0_01, 0, 1);
143impl_pin!(P0_02, 0, 2);
144impl_pin!(P0_03, 0, 3);
145impl_pin!(P0_04, 0, 4);
146impl_pin!(P0_05, 0, 5);
147impl_pin!(P0_06, 0, 6);
148impl_pin!(P0_07, 0, 7);
149impl_pin!(P0_08, 0, 8);
150impl_pin!(P0_09, 0, 9);
151impl_pin!(P0_10, 0, 10);
152impl_pin!(P0_11, 0, 11);
153impl_pin!(P0_12, 0, 12);
154impl_pin!(P0_13, 0, 13);
155impl_pin!(P0_14, 0, 14);
156impl_pin!(P0_15, 0, 15);
157impl_pin!(P0_16, 0, 16);
158impl_pin!(P0_17, 0, 17);
159impl_pin!(P0_18, 0, 18);
160impl_pin!(P0_19, 0, 19);
161impl_pin!(P0_20, 0, 20);
162impl_pin!(P0_21, 0, 21);
163impl_pin!(P0_22, 0, 22);
164impl_pin!(P0_23, 0, 23);
165impl_pin!(P0_24, 0, 24);
166impl_pin!(P0_25, 0, 25);
167impl_pin!(P0_26, 0, 26);
168impl_pin!(P0_27, 0, 27);
169impl_pin!(P0_28, 0, 28);
170impl_pin!(P0_29, 0, 29);
171impl_pin!(P0_30, 0, 30);
172impl_pin!(P0_31, 0, 31);
173
174pub mod irqs {
175 use crate::pac::Interrupt as InterruptEnum;
176 use embassy_macros::interrupt_declare as declare;
177
178 declare!(SPU);
179 declare!(CLOCK_POWER);
180 declare!(UARTE0_SPIM0_SPIS0_TWIM0_TWIS0);
181 declare!(UARTE1_SPIM1_SPIS1_TWIM1_TWIS1);
182 declare!(UARTE2_SPIM2_SPIS2_TWIM2_TWIS2);
183 declare!(UARTE3_SPIM3_SPIS3_TWIM3_TWIS3);
184 declare!(GPIOTE0);
185 declare!(SAADC);
186 declare!(TIMER0);
187 declare!(TIMER1);
188 declare!(TIMER2);
189 declare!(RTC0);
190 declare!(RTC1);
191 declare!(WDT);
192 declare!(EGU0);
193 declare!(EGU1);
194 declare!(EGU2);
195 declare!(EGU3);
196 declare!(EGU4);
197 declare!(EGU5);
198 declare!(PWM0);
199 declare!(PWM1);
200 declare!(PWM2);
201 declare!(PDM);
202 declare!(PWM3);
203 declare!(I2S);
204 declare!(IPC);
205 declare!(FPU);
206 declare!(GPIOTE1);
207 declare!(KMU);
208 declare!(CRYPTOCELL);
209}
diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs
index e30df7e7e..4cb1d36b9 100644
--- a/embassy-nrf/src/gpio.rs
+++ b/embassy-nrf/src/gpio.rs
@@ -10,7 +10,11 @@ use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin};
10use gpio::pin_cnf::DRIVE_A; 10use gpio::pin_cnf::DRIVE_A;
11 11
12use crate::pac; 12use crate::pac;
13
14#[cfg(not(feature = "nrf9160"))]
13use crate::pac::p0 as gpio; 15use crate::pac::p0 as gpio;
16#[cfg(feature = "nrf9160")]
17use crate::pac::p0_ns as gpio;
14 18
15use self::sealed::Pin as _; 19use self::sealed::Pin as _;
16 20
@@ -299,7 +303,10 @@ pub(crate) mod sealed {
299 fn block(&self) -> &gpio::RegisterBlock { 303 fn block(&self) -> &gpio::RegisterBlock {
300 unsafe { 304 unsafe {
301 match self.pin_port() / 32 { 305 match self.pin_port() / 32 {
306 #[cfg(not(feature = "nrf9160"))]
302 0 => &*pac::P0::ptr(), 307 0 => &*pac::P0::ptr(),
308 #[cfg(feature = "nrf9160")]
309 0 => &*pac::P0_NS::ptr(),
303 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 310 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
304 1 => &*pac::P1::ptr(), 311 1 => &*pac::P1::ptr(),
305 _ => unreachable_unchecked(), 312 _ => unreachable_unchecked(),
diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs
index 001ee7fb8..fe181a3c6 100644
--- a/embassy-nrf/src/gpiote.rs
+++ b/embassy-nrf/src/gpiote.rs
@@ -22,6 +22,18 @@ pub const PIN_COUNT: usize = 48;
22#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))] 22#[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
23pub const PIN_COUNT: usize = 32; 23pub const PIN_COUNT: usize = 32;
24 24
25#[cfg(not(feature = "nrf9160"))]
26pub(crate) use pac::P0;
27#[cfg(feature = "nrf9160")]
28pub(crate) use pac::P0_NS as P0;
29#[cfg(not(feature = "nrf9160"))]
30pub(crate) use pac::P1;
31
32#[cfg(not(feature = "nrf9160"))]
33pub(crate) use pac::GPIOTE;
34#[cfg(feature = "nrf9160")]
35pub(crate) use pac::GPIOTE1_NS as GPIOTE;
36
25const NEW_AW: AtomicWaker = AtomicWaker::new(); 37const NEW_AW: AtomicWaker = AtomicWaker::new();
26static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT]; 38static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT];
27static PORT_WAKERS: [AtomicWaker; PIN_COUNT] = [NEW_AW; PIN_COUNT]; 39static PORT_WAKERS: [AtomicWaker; PIN_COUNT] = [NEW_AW; PIN_COUNT];
@@ -42,9 +54,9 @@ pub enum OutputChannelPolarity {
42 54
43pub(crate) fn init(irq_prio: crate::interrupt::Priority) { 55pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
44 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 56 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
45 let ports = unsafe { &[&*pac::P0::ptr(), &*pac::P1::ptr()] }; 57 let ports = unsafe { &[&*P0::ptr(), &*P1::ptr()] };
46 #[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))] 58 #[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
47 let ports = unsafe { &[&*pac::P0::ptr()] }; 59 let ports = unsafe { &[&*P0::ptr()] };
48 60
49 for &p in ports { 61 for &p in ports {
50 // Enable latched detection 62 // Enable latched detection
@@ -55,19 +67,34 @@ pub(crate) fn init(irq_prio: crate::interrupt::Priority) {
55 67
56 // Enable interrupts 68 // Enable interrupts
57 69
70 #[cfg(not(feature = "nrf9160"))]
58 let irq = unsafe { interrupt::GPIOTE::steal() }; 71 let irq = unsafe { interrupt::GPIOTE::steal() };
72 #[cfg(feature = "nrf9160")]
73 let irq = unsafe { interrupt::GPIOTE1::steal() };
74
59 irq.unpend(); 75 irq.unpend();
60 irq.set_priority(irq_prio); 76 irq.set_priority(irq_prio);
61 irq.enable(); 77 irq.enable();
62 78
63 let g = unsafe { &*pac::GPIOTE::ptr() }; 79 let g = unsafe { &*GPIOTE::ptr() };
64 g.events_port.write(|w| w); 80 g.events_port.write(|w| w);
65 g.intenset.write(|w| w.port().set()); 81 g.intenset.write(|w| w.port().set());
66} 82}
67 83
84#[cfg(not(feature = "nrf9160"))]
68#[interrupt] 85#[interrupt]
69unsafe fn GPIOTE() { 86fn GPIOTE() {
70 let g = &*pac::GPIOTE::ptr(); 87 unsafe { handle_gpiote_interrupt() };
88}
89
90#[cfg(feature = "nrf9160")]
91#[interrupt]
92fn GPIOTE1() {
93 unsafe { handle_gpiote_interrupt() };
94}
95
96unsafe fn handle_gpiote_interrupt() {
97 let g = &*GPIOTE::ptr();
71 98
72 for i in 0..CHANNEL_COUNT { 99 for i in 0..CHANNEL_COUNT {
73 if g.events_in[i].read().bits() != 0 { 100 if g.events_in[i].read().bits() != 0 {
@@ -80,9 +107,9 @@ unsafe fn GPIOTE() {
80 g.events_port.write(|w| w); 107 g.events_port.write(|w| w);
81 108
82 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 109 #[cfg(any(feature = "nrf52833", feature = "nrf52840"))]
83 let ports = &[&*pac::P0::ptr(), &*pac::P1::ptr()]; 110 let ports = &[&*P0::ptr(), &*P1::ptr()];
84 #[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))] 111 #[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))]
85 let ports = &[&*pac::P0::ptr()]; 112 let ports = &[&*P0::ptr()];
86 113
87 for (port, &p) in ports.iter().enumerate() { 114 for (port, &p) in ports.iter().enumerate() {
88 let bits = p.latch.read().bits(); 115 let bits = p.latch.read().bits();
@@ -119,7 +146,7 @@ pub struct InputChannel<'d, C: Channel, T: GpioPin> {
119 146
120impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> { 147impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> {
121 fn drop(&mut self) { 148 fn drop(&mut self) {
122 let g = unsafe { &*pac::GPIOTE::ptr() }; 149 let g = unsafe { &*GPIOTE::ptr() };
123 let num = self.ch.number(); 150 let num = self.ch.number();
124 g.config[num].write(|w| w.mode().disabled()); 151 g.config[num].write(|w| w.mode().disabled());
125 g.intenclr.write(|w| unsafe { w.bits(1 << num) }); 152 g.intenclr.write(|w| unsafe { w.bits(1 << num) });
@@ -128,7 +155,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for InputChannel<'d, C, T> {
128 155
129impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> { 156impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
130 pub fn new(ch: C, pin: Input<'d, T>, polarity: InputChannelPolarity) -> Self { 157 pub fn new(ch: C, pin: Input<'d, T>, polarity: InputChannelPolarity) -> Self {
131 let g = unsafe { &*pac::GPIOTE::ptr() }; 158 let g = unsafe { &*GPIOTE::ptr() };
132 let num = ch.number(); 159 let num = ch.number();
133 160
134 g.config[num].write(|w| { 161 g.config[num].write(|w| {
@@ -152,7 +179,7 @@ impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
152 } 179 }
153 180
154 pub async fn wait(&self) { 181 pub async fn wait(&self) {
155 let g = unsafe { &*pac::GPIOTE::ptr() }; 182 let g = unsafe { &*GPIOTE::ptr() };
156 let num = self.ch.number(); 183 let num = self.ch.number();
157 184
158 // Enable interrupt 185 // Enable interrupt
@@ -173,7 +200,7 @@ impl<'d, C: Channel, T: GpioPin> InputChannel<'d, C, T> {
173 200
174 /// Returns the IN event, for use with PPI. 201 /// Returns the IN event, for use with PPI.
175 pub fn event_in(&self) -> Event { 202 pub fn event_in(&self) -> Event {
176 let g = unsafe { &*pac::GPIOTE::ptr() }; 203 let g = unsafe { &*GPIOTE::ptr() };
177 Event::from_reg(&g.events_in[self.ch.number()]) 204 Event::from_reg(&g.events_in[self.ch.number()])
178 } 205 }
179} 206}
@@ -198,7 +225,7 @@ pub struct OutputChannel<'d, C: Channel, T: GpioPin> {
198 225
199impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> { 226impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
200 fn drop(&mut self) { 227 fn drop(&mut self) {
201 let g = unsafe { &*pac::GPIOTE::ptr() }; 228 let g = unsafe { &*GPIOTE::ptr() };
202 let num = self.ch.number(); 229 let num = self.ch.number();
203 g.config[num].write(|w| w.mode().disabled()); 230 g.config[num].write(|w| w.mode().disabled());
204 g.intenclr.write(|w| unsafe { w.bits(1 << num) }); 231 g.intenclr.write(|w| unsafe { w.bits(1 << num) });
@@ -207,7 +234,7 @@ impl<'d, C: Channel, T: GpioPin> Drop for OutputChannel<'d, C, T> {
207 234
208impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> { 235impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
209 pub fn new(ch: C, pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self { 236 pub fn new(ch: C, pin: Output<'d, T>, polarity: OutputChannelPolarity) -> Self {
210 let g = unsafe { &*pac::GPIOTE::ptr() }; 237 let g = unsafe { &*GPIOTE::ptr() };
211 let num = ch.number(); 238 let num = ch.number();
212 239
213 g.config[num].write(|w| { 240 g.config[num].write(|w| {
@@ -234,41 +261,41 @@ impl<'d, C: Channel, T: GpioPin> OutputChannel<'d, C, T> {
234 261
235 /// Triggers `task out` (as configured with task_out_polarity, defaults to Toggle). 262 /// Triggers `task out` (as configured with task_out_polarity, defaults to Toggle).
236 pub fn out(&self) { 263 pub fn out(&self) {
237 let g = unsafe { &*pac::GPIOTE::ptr() }; 264 let g = unsafe { &*GPIOTE::ptr() };
238 g.tasks_out[self.ch.number()].write(|w| unsafe { w.bits(1) }); 265 g.tasks_out[self.ch.number()].write(|w| unsafe { w.bits(1) });
239 } 266 }
240 267
241 /// Triggers `task set` (set associated pin high). 268 /// Triggers `task set` (set associated pin high).
242 #[cfg(not(feature = "51"))] 269 #[cfg(not(feature = "51"))]
243 pub fn set(&self) { 270 pub fn set(&self) {
244 let g = unsafe { &*pac::GPIOTE::ptr() }; 271 let g = unsafe { &*GPIOTE::ptr() };
245 g.tasks_set[self.ch.number()].write(|w| unsafe { w.bits(1) }); 272 g.tasks_set[self.ch.number()].write(|w| unsafe { w.bits(1) });
246 } 273 }
247 274
248 /// Triggers `task clear` (set associated pin low). 275 /// Triggers `task clear` (set associated pin low).
249 #[cfg(not(feature = "51"))] 276 #[cfg(not(feature = "51"))]
250 pub fn clear(&self) { 277 pub fn clear(&self) {
251 let g = unsafe { &*pac::GPIOTE::ptr() }; 278 let g = unsafe { &*GPIOTE::ptr() };
252 g.tasks_clr[self.ch.number()].write(|w| unsafe { w.bits(1) }); 279 g.tasks_clr[self.ch.number()].write(|w| unsafe { w.bits(1) });
253 } 280 }
254 281
255 /// Returns the OUT task, for use with PPI. 282 /// Returns the OUT task, for use with PPI.
256 pub fn task_out(&self) -> Task { 283 pub fn task_out(&self) -> Task {
257 let g = unsafe { &*pac::GPIOTE::ptr() }; 284 let g = unsafe { &*GPIOTE::ptr() };
258 Task::from_reg(&g.tasks_out[self.ch.number()]) 285 Task::from_reg(&g.tasks_out[self.ch.number()])
259 } 286 }
260 287
261 /// Returns the CLR task, for use with PPI. 288 /// Returns the CLR task, for use with PPI.
262 #[cfg(not(feature = "51"))] 289 #[cfg(not(feature = "51"))]
263 pub fn task_clr(&self) -> Task { 290 pub fn task_clr(&self) -> Task {
264 let g = unsafe { &*pac::GPIOTE::ptr() }; 291 let g = unsafe { &*GPIOTE::ptr() };
265 Task::from_reg(&g.tasks_clr[self.ch.number()]) 292 Task::from_reg(&g.tasks_clr[self.ch.number()])
266 } 293 }
267 294
268 /// Returns the SET task, for use with PPI. 295 /// Returns the SET task, for use with PPI.
269 #[cfg(not(feature = "51"))] 296 #[cfg(not(feature = "51"))]
270 pub fn task_set(&self) -> Task { 297 pub fn task_set(&self) -> Task {
271 let g = unsafe { &*pac::GPIOTE::ptr() }; 298 let g = unsafe { &*GPIOTE::ptr() };
272 Task::from_reg(&g.tasks_set[self.ch.number()]) 299 Task::from_reg(&g.tasks_set[self.ch.number()])
273 } 300 }
274} 301}
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index 9a0e9c3a1..5924a42bb 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -34,6 +34,7 @@ pub mod ppi;
34pub mod pwm; 34pub mod pwm;
35#[cfg(feature = "nrf52840")] 35#[cfg(feature = "nrf52840")]
36pub mod qspi; 36pub mod qspi;
37#[cfg(not(feature = "nrf9160"))]
37pub mod rng; 38pub mod rng;
38#[cfg(not(feature = "nrf52820"))] 39#[cfg(not(feature = "nrf52820"))]
39pub mod saadc; 40pub mod saadc;
@@ -65,6 +66,9 @@ mod chip;
65#[cfg(feature = "nrf52840")] 66#[cfg(feature = "nrf52840")]
66#[path = "chips/nrf52840.rs"] 67#[path = "chips/nrf52840.rs"]
67mod chip; 68mod chip;
69#[cfg(feature = "nrf9160")]
70#[path = "chips/nrf9160.rs"]
71mod chip;
68 72
69pub use chip::EASY_DMA_SIZE; 73pub use chip::EASY_DMA_SIZE;
70 74
@@ -75,6 +79,11 @@ pub(crate) use chip::pac;
75 79
76pub use chip::{peripherals, Peripherals}; 80pub use chip::{peripherals, Peripherals};
77 81
82#[cfg(feature = "nrf9160")]
83use crate::pac::CLOCK_NS as CLOCK;
84#[cfg(not(feature = "nrf9160"))]
85use crate::pac::CLOCK;
86
78pub mod interrupt { 87pub mod interrupt {
79 pub use crate::chip::irqs::*; 88 pub use crate::chip::irqs::*;
80 pub use cortex_m::interrupt::{CriticalSection, Mutex}; 89 pub use cortex_m::interrupt::{CriticalSection, Mutex};
@@ -91,9 +100,12 @@ pub mod config {
91 100
92 pub enum LfclkSource { 101 pub enum LfclkSource {
93 InternalRC, 102 InternalRC,
103 #[cfg(not(feature = "nrf9160"))]
94 Synthesized, 104 Synthesized,
95 ExternalXtal, 105 ExternalXtal,
106 #[cfg(not(feature = "nrf9160"))]
96 ExternalLowSwing, 107 ExternalLowSwing,
108 #[cfg(not(feature = "nrf9160"))]
97 ExternalFullSwing, 109 ExternalFullSwing,
98 } 110 }
99 111
@@ -129,7 +141,7 @@ pub fn init(config: config::Config) -> Peripherals {
129 // before doing anything important. 141 // before doing anything important.
130 let peripherals = Peripherals::take(); 142 let peripherals = Peripherals::take();
131 143
132 let r = unsafe { &*pac::CLOCK::ptr() }; 144 let r = unsafe { &*CLOCK::ptr() };
133 145
134 // Start HFCLK. 146 // Start HFCLK.
135 match config.hfclk_source { 147 match config.hfclk_source {
@@ -143,6 +155,7 @@ pub fn init(config: config::Config) -> Peripherals {
143 } 155 }
144 156
145 // Configure LFCLK. 157 // Configure LFCLK.
158 #[cfg(not(feature = "nrf9160"))]
146 match config.lfclk_source { 159 match config.lfclk_source {
147 config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().rc()), 160 config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().rc()),
148 config::LfclkSource::Synthesized => r.lfclksrc.write(|w| w.src().synth()), 161 config::LfclkSource::Synthesized => r.lfclksrc.write(|w| w.src().synth()),
@@ -162,6 +175,11 @@ pub fn init(config: config::Config) -> Peripherals {
162 w 175 w
163 }), 176 }),
164 } 177 }
178 #[cfg(feature = "nrf9160")]
179 match config.lfclk_source {
180 config::LfclkSource::InternalRC => r.lfclksrc.write(|w| w.src().lfrc()),
181 config::LfclkSource::ExternalXtal => r.lfclksrc.write(|w| w.src().lfxo()),
182 }
165 183
166 // Start LFCLK. 184 // Start LFCLK.
167 // Datasheet says this could take 100us from synth source 185 // Datasheet says this could take 100us from synth source
diff --git a/embassy-nrf/src/ppi.rs b/embassy-nrf/src/ppi.rs
index 61028c03a..1d1f88915 100644
--- a/embassy-nrf/src/ppi.rs
+++ b/embassy-nrf/src/ppi.rs
@@ -16,6 +16,11 @@ use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
16 16
17use crate::{pac, peripherals}; 17use crate::{pac, peripherals};
18 18
19#[cfg(not(feature = "nrf9160"))]
20pub(crate) use pac::PPI;
21#[cfg(feature = "nrf9160")]
22pub(crate) use pac::DPPIC_NS as PPI;
23
19// ====================== 24// ======================
20// driver 25// driver
21 26
@@ -27,45 +32,60 @@ pub struct Ppi<'d, C: Channel> {
27impl<'d, C: Channel> Ppi<'d, C> { 32impl<'d, C: Channel> Ppi<'d, C> {
28 pub fn new(ch: impl Unborrow<Target = C> + 'd) -> Self { 33 pub fn new(ch: impl Unborrow<Target = C> + 'd) -> Self {
29 unborrow!(ch); 34 unborrow!(ch);
35
36 #[allow(unused_mut)]
30 let mut this = Self { 37 let mut this = Self {
31 ch, 38 ch,
32 phantom: PhantomData, 39 phantom: PhantomData,
33 }; 40 };
34 #[cfg(not(feature = "51"))] 41 #[cfg(not(any(feature = "51", feature = "nrf9160")))]
35 this.clear_fork_task(); 42 this.clear_fork_task();
36 this 43 this
37 } 44 }
38 45
39 /// Enables the channel. 46 /// Enables the channel.
40 pub fn enable(&mut self) { 47 pub fn enable(&mut self) {
41 let r = unsafe { &*pac::PPI::ptr() }; 48 let r = unsafe { &*PPI::ptr() };
42 r.chenset 49 r.chenset
43 .write(|w| unsafe { w.bits(1 << self.ch.number()) }); 50 .write(|w| unsafe { w.bits(1 << self.ch.number()) });
44 } 51 }
45 52
46 /// Disables the channel. 53 /// Disables the channel.
47 pub fn disable(&mut self) { 54 pub fn disable(&mut self) {
48 let r = unsafe { &*pac::PPI::ptr() }; 55 let r = unsafe { &*PPI::ptr() };
49 r.chenclr 56 r.chenclr
50 .write(|w| unsafe { w.bits(1 << self.ch.number()) }); 57 .write(|w| unsafe { w.bits(1 << self.ch.number()) });
51 } 58 }
52 59
53 #[cfg(not(feature = "51"))] 60 #[cfg(not(any(feature = "51", feature = "nrf9160")))]
54 /// Sets the fork task that must be triggered when the configured event occurs. The user must 61 /// Sets the fork task that must be triggered when the configured event occurs. The user must
55 /// provide a reference to the task. 62 /// provide a reference to the task.
56 pub fn set_fork_task(&mut self, task: Task) { 63 pub fn set_fork_task(&mut self, task: Task) {
57 let r = unsafe { &*pac::PPI::ptr() }; 64 let r = unsafe { &*PPI::ptr() };
58 r.fork[self.ch.number()] 65 r.fork[self.ch.number()]
59 .tep 66 .tep
60 .write(|w| unsafe { w.bits(task.0.as_ptr() as u32) }) 67 .write(|w| unsafe { w.bits(task.0.as_ptr() as u32) })
61 } 68 }
62 69
63 #[cfg(not(feature = "51"))] 70 #[cfg(not(any(feature = "51", feature = "nrf9160")))]
64 /// Clear the fork task endpoint. Previously set task will no longer be triggered. 71 /// Clear the fork task endpoint. Previously set task will no longer be triggered.
65 pub fn clear_fork_task(&mut self) { 72 pub fn clear_fork_task(&mut self) {
66 let r = unsafe { &*pac::PPI::ptr() }; 73 let r = unsafe { &*PPI::ptr() };
67 r.fork[self.ch.number()].tep.write(|w| unsafe { w.bits(0) }) 74 r.fork[self.ch.number()].tep.write(|w| unsafe { w.bits(0) })
68 } 75 }
76
77 #[cfg(feature = "nrf9160")]
78 /// Sets the fork task that must be triggered when the configured event occurs. The user must
79 /// provide a reference to the task.
80 pub fn set_fork_task(&mut self, _task: Task) {
81 todo!("Tasks not yet implemented for nrf9160");
82 }
83
84 #[cfg(feature = "nrf9160")]
85 /// Clear the fork task endpoint. Previously set task will no longer be triggered.
86 pub fn clear_fork_task(&mut self) {
87 todo!("Tasks not yet implemented for nrf9160");
88 }
69} 89}
70 90
71impl<'d, C: Channel> Drop for Ppi<'d, C> { 91impl<'d, C: Channel> Drop for Ppi<'d, C> {
@@ -74,10 +94,11 @@ impl<'d, C: Channel> Drop for Ppi<'d, C> {
74 } 94 }
75} 95}
76 96
97#[cfg(not(feature = "nrf9160"))]
77impl<'d, C: ConfigurableChannel> Ppi<'d, C> { 98impl<'d, C: ConfigurableChannel> Ppi<'d, C> {
78 /// Sets the task to be triggered when the configured event occurs. 99 /// Sets the task to be triggered when the configured event occurs.
79 pub fn set_task(&mut self, task: Task) { 100 pub fn set_task(&mut self, task: Task) {
80 let r = unsafe { &*pac::PPI::ptr() }; 101 let r = unsafe { &*PPI::ptr() };
81 r.ch[self.ch.number()] 102 r.ch[self.ch.number()]
82 .tep 103 .tep
83 .write(|w| unsafe { w.bits(task.0.as_ptr() as u32) }) 104 .write(|w| unsafe { w.bits(task.0.as_ptr() as u32) })
@@ -85,13 +106,26 @@ impl<'d, C: ConfigurableChannel> Ppi<'d, C> {
85 106
86 /// Sets the event that will trigger the chosen task(s). 107 /// Sets the event that will trigger the chosen task(s).
87 pub fn set_event(&mut self, event: Event) { 108 pub fn set_event(&mut self, event: Event) {
88 let r = unsafe { &*pac::PPI::ptr() }; 109 let r = unsafe { &*PPI::ptr() };
89 r.ch[self.ch.number()] 110 r.ch[self.ch.number()]
90 .eep 111 .eep
91 .write(|w| unsafe { w.bits(event.0.as_ptr() as u32) }) 112 .write(|w| unsafe { w.bits(event.0.as_ptr() as u32) })
92 } 113 }
93} 114}
94 115
116#[cfg(feature = "nrf9160")]
117impl<'d, C: ConfigurableChannel> Ppi<'d, C> {
118 /// Sets the task to be triggered when the configured event occurs.
119 pub fn set_task(&mut self, _task: Task) {
120 todo!("Tasks not yet implemented for nrf9160")
121 }
122
123 /// Sets the event that will trigger the chosen task(s).
124 pub fn set_event(&mut self, _event: Event) {
125 todo!("Events not yet implemented for nrf9160")
126 }
127}
128
95// ====================== 129// ======================
96// traits 130// traits
97 131
@@ -183,42 +217,69 @@ macro_rules! impl_channel {
183 }; 217 };
184} 218}
185 219
186impl_channel!(PPI_CH0, 0, configurable); 220pub use channel_impl::*;
187impl_channel!(PPI_CH1, 1, configurable); 221#[cfg(not(feature = "nrf9160"))]
188impl_channel!(PPI_CH2, 2, configurable); 222mod channel_impl {
189impl_channel!(PPI_CH3, 3, configurable); 223 use super::*;
190impl_channel!(PPI_CH4, 4, configurable); 224
191impl_channel!(PPI_CH5, 5, configurable); 225 impl_channel!(PPI_CH0, 0, configurable);
192impl_channel!(PPI_CH6, 6, configurable); 226 impl_channel!(PPI_CH1, 1, configurable);
193impl_channel!(PPI_CH7, 7, configurable); 227 impl_channel!(PPI_CH2, 2, configurable);
194impl_channel!(PPI_CH8, 8, configurable); 228 impl_channel!(PPI_CH3, 3, configurable);
195impl_channel!(PPI_CH9, 9, configurable); 229 impl_channel!(PPI_CH4, 4, configurable);
196impl_channel!(PPI_CH10, 10, configurable); 230 impl_channel!(PPI_CH5, 5, configurable);
197impl_channel!(PPI_CH11, 11, configurable); 231 impl_channel!(PPI_CH6, 6, configurable);
198impl_channel!(PPI_CH12, 12, configurable); 232 impl_channel!(PPI_CH7, 7, configurable);
199impl_channel!(PPI_CH13, 13, configurable); 233 impl_channel!(PPI_CH8, 8, configurable);
200impl_channel!(PPI_CH14, 14, configurable); 234 impl_channel!(PPI_CH9, 9, configurable);
201impl_channel!(PPI_CH15, 15, configurable); 235 impl_channel!(PPI_CH10, 10, configurable);
202#[cfg(not(feature = "51"))] 236 impl_channel!(PPI_CH11, 11, configurable);
203impl_channel!(PPI_CH16, 16, configurable); 237 impl_channel!(PPI_CH12, 12, configurable);
204#[cfg(not(feature = "51"))] 238 impl_channel!(PPI_CH13, 13, configurable);
205impl_channel!(PPI_CH17, 17, configurable); 239 impl_channel!(PPI_CH14, 14, configurable);
206#[cfg(not(feature = "51"))] 240 impl_channel!(PPI_CH15, 15, configurable);
207impl_channel!(PPI_CH18, 18, configurable); 241 #[cfg(not(feature = "51",))]
208#[cfg(not(feature = "51"))] 242 impl_channel!(PPI_CH16, 16, configurable);
209impl_channel!(PPI_CH19, 19, configurable); 243 #[cfg(not(feature = "51"))]
210impl_channel!(PPI_CH20, 20); 244 impl_channel!(PPI_CH17, 17, configurable);
211impl_channel!(PPI_CH21, 21); 245 #[cfg(not(feature = "51"))]
212impl_channel!(PPI_CH22, 22); 246 impl_channel!(PPI_CH18, 18, configurable);
213impl_channel!(PPI_CH23, 23); 247 #[cfg(not(feature = "51"))]
214impl_channel!(PPI_CH24, 24); 248 impl_channel!(PPI_CH19, 19, configurable);
215impl_channel!(PPI_CH25, 25); 249 impl_channel!(PPI_CH20, 20);
216impl_channel!(PPI_CH26, 26); 250 impl_channel!(PPI_CH21, 21);
217impl_channel!(PPI_CH27, 27); 251 impl_channel!(PPI_CH22, 22);
218impl_channel!(PPI_CH28, 28); 252 impl_channel!(PPI_CH23, 23);
219impl_channel!(PPI_CH29, 29); 253 impl_channel!(PPI_CH24, 24);
220impl_channel!(PPI_CH30, 30); 254 impl_channel!(PPI_CH25, 25);
221impl_channel!(PPI_CH31, 31); 255 impl_channel!(PPI_CH26, 26);
256 impl_channel!(PPI_CH27, 27);
257 impl_channel!(PPI_CH28, 28);
258 impl_channel!(PPI_CH29, 29);
259 impl_channel!(PPI_CH30, 30);
260 impl_channel!(PPI_CH31, 31);
261}
262#[cfg(feature = "nrf9160")] // TODO: Implement configurability for nrf9160 and then remove these channel_impl modules
263mod channel_impl {
264 use super::*;
265
266 impl_channel!(PPI_CH0, 0, configurable);
267 impl_channel!(PPI_CH1, 1, configurable);
268 impl_channel!(PPI_CH2, 2, configurable);
269 impl_channel!(PPI_CH3, 3, configurable);
270 impl_channel!(PPI_CH4, 4, configurable);
271 impl_channel!(PPI_CH5, 5, configurable);
272 impl_channel!(PPI_CH6, 6, configurable);
273 impl_channel!(PPI_CH7, 7, configurable);
274 impl_channel!(PPI_CH8, 8, configurable);
275 impl_channel!(PPI_CH9, 9, configurable);
276 impl_channel!(PPI_CH10, 10, configurable);
277 impl_channel!(PPI_CH11, 11, configurable);
278 impl_channel!(PPI_CH12, 12, configurable);
279 impl_channel!(PPI_CH13, 13, configurable);
280 impl_channel!(PPI_CH14, 14, configurable);
281 impl_channel!(PPI_CH15, 15, configurable);
282}
222 283
223// ====================== 284// ======================
224// groups 285// groups
diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs
index 5e996e882..057a13594 100644
--- a/embassy-nrf/src/pwm.rs
+++ b/embassy-nrf/src/pwm.rs
@@ -11,6 +11,12 @@ use crate::gpio::OptionalPin as GpioOptionalPin;
11use crate::interrupt::Interrupt; 11use crate::interrupt::Interrupt;
12use crate::pac; 12use crate::pac;
13 13
14#[cfg(not(feature = "nrf9160"))]
15pub(crate) use pac::pwm0;
16#[cfg(feature = "nrf9160")]
17pub(crate) use pac::pwm0_ns as pwm0;
18
19
14#[derive(Debug, Eq, PartialEq, Clone, Copy)] 20#[derive(Debug, Eq, PartialEq, Clone, Copy)]
15pub enum Prescaler { 21pub enum Prescaler {
16 Div1, 22 Div1,
@@ -203,7 +209,7 @@ pub(crate) mod sealed {
203 } 209 }
204 210
205 pub trait Instance { 211 pub trait Instance {
206 fn regs() -> &'static pac::pwm0::RegisterBlock; 212 fn regs() -> &'static pwm0::RegisterBlock;
207 fn state() -> &'static State; 213 fn state() -> &'static State;
208 } 214 }
209} 215}
@@ -215,7 +221,7 @@ pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static {
215macro_rules! impl_pwm { 221macro_rules! impl_pwm {
216 ($type:ident, $pac_type:ident, $irq:ident) => { 222 ($type:ident, $pac_type:ident, $irq:ident) => {
217 impl crate::pwm::sealed::Instance for peripherals::$type { 223 impl crate::pwm::sealed::Instance for peripherals::$type {
218 fn regs() -> &'static pac::pwm0::RegisterBlock { 224 fn regs() -> &'static crate::pwm::pwm0::RegisterBlock {
219 unsafe { &*pac::$pac_type::ptr() } 225 unsafe { &*pac::$pac_type::ptr() }
220 } 226 }
221 fn state() -> &'static crate::pwm::sealed::State { 227 fn state() -> &'static crate::pwm::sealed::State {
diff --git a/embassy-nrf/src/saadc.rs b/embassy-nrf/src/saadc.rs
index b6e8f4e44..49a71e497 100644
--- a/embassy-nrf/src/saadc.rs
+++ b/embassy-nrf/src/saadc.rs
@@ -10,7 +10,10 @@ use futures::future::poll_fn;
10use crate::interrupt; 10use crate::interrupt;
11use crate::{pac, peripherals}; 11use crate::{pac, peripherals};
12 12
13#[cfg(not(feature = "nrf9160"))]
13use pac::{saadc, SAADC}; 14use pac::{saadc, SAADC};
15#[cfg(feature = "nrf9160")]
16use pac::{saadc_ns as saadc, SAADC_NS as SAADC};
14 17
15pub use saadc::{ 18pub use saadc::{
16 ch::{ 19 ch::{
@@ -200,7 +203,7 @@ macro_rules! positive_pin_mappings {
200 203
201// TODO the variant names are unchecked 204// TODO the variant names are unchecked
202// the pins are copied from nrf hal 205// the pins are copied from nrf hal
203#[cfg(feature = "9160")] 206#[cfg(feature = "nrf9160")]
204positive_pin_mappings! { 207positive_pin_mappings! {
205 ANALOGINPUT0 => P0_13, 208 ANALOGINPUT0 => P0_13,
206 ANALOGINPUT1 => P0_14, 209 ANALOGINPUT1 => P0_14,
@@ -212,7 +215,7 @@ positive_pin_mappings! {
212 ANALOGINPUT7 => P0_20, 215 ANALOGINPUT7 => P0_20,
213} 216}
214 217
215#[cfg(not(feature = "9160"))] 218#[cfg(not(feature = "nrf9160"))]
216positive_pin_mappings! { 219positive_pin_mappings! {
217 ANALOGINPUT0 => P0_02, 220 ANALOGINPUT0 => P0_02,
218 ANALOGINPUT1 => P0_03, 221 ANALOGINPUT1 => P0_03,
diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs
index e88fb460c..f40da54e5 100644
--- a/embassy-nrf/src/spim.rs
+++ b/embassy-nrf/src/spim.rs
@@ -17,8 +17,13 @@ use crate::gpio::{OptionalPin, Pin as GpioPin};
17use crate::interrupt::Interrupt; 17use crate::interrupt::Interrupt;
18use crate::{pac, util::slice_in_ram_or}; 18use crate::{pac, util::slice_in_ram_or};
19 19
20#[cfg(not(feature = "nrf9160"))]
21pub(crate) use pac::spim0;
22#[cfg(feature = "nrf9160")]
23pub(crate) use pac::spim0_ns as spim0;
24
20pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; 25pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
21pub use pac::spim0::frequency::FREQUENCY_A as Frequency; 26pub use spim0::frequency::FREQUENCY_A as Frequency;
22 27
23#[derive(Debug, Clone, Copy, PartialEq, Eq)] 28#[derive(Debug, Clone, Copy, PartialEq, Eq)]
24#[cfg_attr(feature = "defmt", derive(defmt::Format))] 29#[cfg_attr(feature = "defmt", derive(defmt::Format))]
@@ -376,7 +381,7 @@ pub(crate) mod sealed {
376 } 381 }
377 382
378 pub trait Instance { 383 pub trait Instance {
379 fn regs() -> &'static pac::spim0::RegisterBlock; 384 fn regs() -> &'static spim0::RegisterBlock;
380 fn state() -> &'static State; 385 fn state() -> &'static State;
381 } 386 }
382} 387}
@@ -388,7 +393,7 @@ pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static {
388macro_rules! impl_spim { 393macro_rules! impl_spim {
389 ($type:ident, $pac_type:ident, $irq:ident) => { 394 ($type:ident, $pac_type:ident, $irq:ident) => {
390 impl crate::spim::sealed::Instance for peripherals::$type { 395 impl crate::spim::sealed::Instance for peripherals::$type {
391 fn regs() -> &'static pac::spim0::RegisterBlock { 396 fn regs() -> &'static crate::spim::spim0::RegisterBlock {
392 unsafe { &*pac::$pac_type::ptr() } 397 unsafe { &*pac::$pac_type::ptr() }
393 } 398 }
394 fn state() -> &'static crate::spim::sealed::State { 399 fn state() -> &'static crate::spim::sealed::State {
diff --git a/embassy-nrf/src/time_driver.rs b/embassy-nrf/src/time_driver.rs
index 19356c2d2..366f270c0 100644
--- a/embassy-nrf/src/time_driver.rs
+++ b/embassy-nrf/src/time_driver.rs
@@ -9,8 +9,16 @@ use embassy::time::driver::{AlarmHandle, Driver};
9use crate::interrupt; 9use crate::interrupt;
10use crate::pac; 10use crate::pac;
11 11
12fn rtc() -> &'static pac::rtc0::RegisterBlock { 12#[cfg(not(feature = "nrf9160"))]
13pub(crate) use pac::rtc0;
14#[cfg(feature = "nrf9160")]
15pub(crate) use pac::rtc0_ns as rtc0;
16
17fn rtc() -> &'static rtc0::RegisterBlock {
18 #[cfg(not(feature = "nrf9160"))]
13 unsafe { &*pac::RTC1::ptr() } 19 unsafe { &*pac::RTC1::ptr() }
20 #[cfg(feature = "nrf9160")]
21 unsafe { &*pac::RTC1_NS::ptr() }
14} 22}
15 23
16// RTC timekeeping works with something we call "periods", which are time intervals 24// RTC timekeeping works with something we call "periods", which are time intervals
diff --git a/embassy-nrf/src/timer.rs b/embassy-nrf/src/timer.rs
index 5690ff0d8..066609ec6 100644
--- a/embassy-nrf/src/timer.rs
+++ b/embassy-nrf/src/timer.rs
@@ -15,6 +15,11 @@ use crate::pac;
15use crate::ppi::Event; 15use crate::ppi::Event;
16use crate::ppi::Task; 16use crate::ppi::Task;
17 17
18#[cfg(not(feature = "nrf9160"))]
19pub(crate) use pac::timer0;
20#[cfg(feature = "nrf9160")]
21pub(crate) use pac::timer0_ns as timer0;
22
18pub(crate) mod sealed { 23pub(crate) mod sealed {
19 24
20 use super::*; 25 use super::*;
@@ -22,7 +27,7 @@ pub(crate) mod sealed {
22 pub trait Instance { 27 pub trait Instance {
23 /// The number of CC registers this instance has. 28 /// The number of CC registers this instance has.
24 const CCS: usize; 29 const CCS: usize;
25 fn regs() -> &'static pac::timer0::RegisterBlock; 30 fn regs() -> &'static timer0::RegisterBlock;
26 /// Storage for the waker for CC register `n`. 31 /// Storage for the waker for CC register `n`.
27 fn waker(n: usize) -> &'static AtomicWaker; 32 fn waker(n: usize) -> &'static AtomicWaker;
28 } 33 }
@@ -40,8 +45,8 @@ macro_rules! impl_timer {
40 ($type:ident, $pac_type:ident, $irq:ident, $ccs:literal) => { 45 ($type:ident, $pac_type:ident, $irq:ident, $ccs:literal) => {
41 impl crate::timer::sealed::Instance for peripherals::$type { 46 impl crate::timer::sealed::Instance for peripherals::$type {
42 const CCS: usize = $ccs; 47 const CCS: usize = $ccs;
43 fn regs() -> &'static pac::timer0::RegisterBlock { 48 fn regs() -> &'static crate::timer::timer0::RegisterBlock {
44 unsafe { &*(pac::$pac_type::ptr() as *const pac::timer0::RegisterBlock) } 49 unsafe { &*(pac::$pac_type::ptr() as *const crate::timer::timer0::RegisterBlock) }
45 } 50 }
46 fn waker(n: usize) -> &'static ::embassy::waitqueue::AtomicWaker { 51 fn waker(n: usize) -> &'static ::embassy::waitqueue::AtomicWaker {
47 use ::embassy::waitqueue::AtomicWaker; 52 use ::embassy::waitqueue::AtomicWaker;
diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs
index 8173f66b0..8dcfb4143 100644
--- a/embassy-nrf/src/twim.rs
+++ b/embassy-nrf/src/twim.rs
@@ -24,6 +24,11 @@ use crate::gpio::Pin as GpioPin;
24use crate::pac; 24use crate::pac;
25use crate::util::{slice_in_ram, slice_in_ram_or}; 25use crate::util::{slice_in_ram, slice_in_ram_or};
26 26
27#[cfg(not(feature = "nrf9160"))]
28pub(crate) use pac::twim0;
29#[cfg(feature = "nrf9160")]
30pub(crate) use pac::twim0_ns as twim0;
31
27pub enum Frequency { 32pub enum Frequency {
28 #[doc = "26738688: 100 kbps"] 33 #[doc = "26738688: 100 kbps"]
29 K100 = 26738688, 34 K100 = 26738688,
@@ -721,7 +726,7 @@ pub(crate) mod sealed {
721 } 726 }
722 727
723 pub trait Instance { 728 pub trait Instance {
724 fn regs() -> &'static pac::twim0::RegisterBlock; 729 fn regs() -> &'static twim0::RegisterBlock;
725 fn state() -> &'static State; 730 fn state() -> &'static State;
726 } 731 }
727} 732}
@@ -733,7 +738,7 @@ pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static {
733macro_rules! impl_twim { 738macro_rules! impl_twim {
734 ($type:ident, $pac_type:ident, $irq:ident) => { 739 ($type:ident, $pac_type:ident, $irq:ident) => {
735 impl crate::twim::sealed::Instance for peripherals::$type { 740 impl crate::twim::sealed::Instance for peripherals::$type {
736 fn regs() -> &'static pac::twim0::RegisterBlock { 741 fn regs() -> &'static crate::twim::twim0::RegisterBlock {
737 unsafe { &*pac::$pac_type::ptr() } 742 unsafe { &*pac::$pac_type::ptr() }
738 } 743 }
739 fn state() -> &'static crate::twim::sealed::State { 744 fn state() -> &'static crate::twim::sealed::State {
diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs
index 320426060..286e324b0 100644
--- a/embassy-nrf/src/uarte.rs
+++ b/embassy-nrf/src/uarte.rs
@@ -22,8 +22,13 @@ use crate::ppi::{AnyConfigurableChannel, ConfigurableChannel, Event, Ppi, Task};
22use crate::timer::Instance as TimerInstance; 22use crate::timer::Instance as TimerInstance;
23use crate::timer::{Frequency, Timer}; 23use crate::timer::{Frequency, Timer};
24 24
25#[cfg(not(feature = "nrf9160"))]
26pub(crate) use pac::uarte0;
27#[cfg(feature = "nrf9160")]
28pub(crate) use pac::uarte0_ns as uarte0;
29
25// Re-export SVD variants to allow user to directly set values. 30// Re-export SVD variants to allow user to directly set values.
26pub use pac::uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity}; 31pub use uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
27 32
28#[non_exhaustive] 33#[non_exhaustive]
29pub struct Config { 34pub struct Config {
@@ -458,7 +463,7 @@ pub(crate) mod sealed {
458 } 463 }
459 464
460 pub trait Instance { 465 pub trait Instance {
461 fn regs() -> &'static pac::uarte0::RegisterBlock; 466 fn regs() -> &'static uarte0::RegisterBlock;
462 fn state() -> &'static State; 467 fn state() -> &'static State;
463 } 468 }
464} 469}
@@ -470,7 +475,7 @@ pub trait Instance: Unborrow<Target = Self> + sealed::Instance + 'static + Send
470macro_rules! impl_uarte { 475macro_rules! impl_uarte {
471 ($type:ident, $pac_type:ident, $irq:ident) => { 476 ($type:ident, $pac_type:ident, $irq:ident) => {
472 impl crate::uarte::sealed::Instance for peripherals::$type { 477 impl crate::uarte::sealed::Instance for peripherals::$type {
473 fn regs() -> &'static pac::uarte0::RegisterBlock { 478 fn regs() -> &'static crate::uarte::uarte0::RegisterBlock {
474 unsafe { &*pac::$pac_type::ptr() } 479 unsafe { &*pac::$pac_type::ptr() }
475 } 480 }
476 fn state() -> &'static crate::uarte::sealed::State { 481 fn state() -> &'static crate::uarte::sealed::State {
diff --git a/embassy-nrf/src/wdt.rs b/embassy-nrf/src/wdt.rs
index cd62d0d60..98ddd71af 100644
--- a/embassy-nrf/src/wdt.rs
+++ b/embassy-nrf/src/wdt.rs
@@ -3,7 +3,13 @@
3//! This HAL implements a basic watchdog timer with 1..=8 handles. 3//! This HAL implements a basic watchdog timer with 1..=8 handles.
4//! Once the watchdog has been started, it cannot be stopped. 4//! Once the watchdog has been started, it cannot be stopped.
5 5
6use crate::pac::WDT; 6use crate::pac;
7
8#[cfg(not(feature = "nrf9160"))]
9pub(crate) use pac::WDT;
10#[cfg(feature = "nrf9160")]
11pub(crate) use pac::WDT_NS as WDT;
12
7use crate::peripherals; 13use crate::peripherals;
8 14
9const MIN_TICKS: u32 = 15; 15const MIN_TICKS: u32 = 15;
@@ -58,7 +64,12 @@ impl Watchdog {
58 let crv = config.timeout_ticks.max(MIN_TICKS); 64 let crv = config.timeout_ticks.max(MIN_TICKS);
59 let rren = (1u32 << N) - 1; 65 let rren = (1u32 << N) - 1;
60 66
61 if r.runstatus.read().runstatus().bit() { 67 #[cfg(not(feature = "nrf9160"))]
68 let runstatus = r.runstatus.read().runstatus().bit();
69 #[cfg(feature = "nrf9160")]
70 let runstatus = r.runstatus.read().runstatuswdt().bit();
71
72 if runstatus {
62 let curr_config = r.config.read(); 73 let curr_config = r.config.read();
63 if curr_config.halt().bit() != config.run_during_debug_halt 74 if curr_config.halt().bit() != config.run_during_debug_halt
64 || curr_config.sleep().bit() != config.run_during_sleep 75 || curr_config.sleep().bit() != config.run_during_sleep
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
index 8f3473433..00901f820 100644
--- a/rust-toolchain.toml
+++ b/rust-toolchain.toml
@@ -3,4 +3,4 @@
3[toolchain] 3[toolchain]
4channel = "nightly-2021-08-18" 4channel = "nightly-2021-08-18"
5components = [ "rust-src", "rustfmt" ] 5components = [ "rust-src", "rustfmt" ]
6targets = [ "thumbv7em-none-eabi", "thumbv7m-none-eabi", "thumbv6m-none-eabi", "thumbv7em-none-eabihf", "wasm32-unknown-unknown" ] 6targets = [ "thumbv7em-none-eabi", "thumbv7m-none-eabi", "thumbv6m-none-eabi", "thumbv7em-none-eabihf", "thumbv8m.main-none-eabihf", "wasm32-unknown-unknown" ]