aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
authorErik Bånvik <[email protected]>2024-03-05 11:39:15 +0100
committerErik Bånvik <[email protected]>2024-03-05 11:39:15 +0100
commitbc258b322b3828b5e52cba3e51c7de4ec014268e (patch)
tree6fbd663b526df7b4bf220fcec82c34787e9a68f3 /embassy-nrf
parent84935fbfab6a053113c135110ec4a1f4373ccfb3 (diff)
Support nearly all nRF5 RADIOs
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/src/chips/nrf51.rs5
-rw-r--r--embassy-nrf/src/chips/nrf52805.rs5
-rw-r--r--embassy-nrf/src/chips/nrf52810.rs5
-rw-r--r--embassy-nrf/src/chips/nrf52811.rs5
-rw-r--r--embassy-nrf/src/chips/nrf52820.rs5
-rw-r--r--embassy-nrf/src/chips/nrf52832.rs5
-rw-r--r--embassy-nrf/src/chips/nrf5340_net.rs5
-rw-r--r--embassy-nrf/src/lib.rs2
-rw-r--r--embassy-nrf/src/radio/ble.rs35
-rw-r--r--embassy-nrf/src/radio/ieee802154.rs19
-rw-r--r--embassy-nrf/src/radio/mod.rs7
11 files changed, 95 insertions, 3 deletions
diff --git a/embassy-nrf/src/chips/nrf51.rs b/embassy-nrf/src/chips/nrf51.rs
index 016352fb8..cc1cbc8a0 100644
--- a/embassy-nrf/src/chips/nrf51.rs
+++ b/embassy-nrf/src/chips/nrf51.rs
@@ -99,6 +99,9 @@ embassy_hal_internal::peripherals! {
99 99
100 // TEMP 100 // TEMP
101 TEMP, 101 TEMP,
102
103 // Radio
104 RADIO,
102} 105}
103 106
104impl_timer!(TIMER0, TIMER0, TIMER0); 107impl_timer!(TIMER0, TIMER0, TIMER0);
@@ -140,6 +143,8 @@ impl_pin!(P0_29, 0, 29);
140impl_pin!(P0_30, 0, 30); 143impl_pin!(P0_30, 0, 30);
141impl_pin!(P0_31, 0, 31); 144impl_pin!(P0_31, 0, 31);
142 145
146impl_radio!(RADIO, RADIO, RADIO);
147
143embassy_hal_internal::interrupt_mod!( 148embassy_hal_internal::interrupt_mod!(
144 POWER_CLOCK, 149 POWER_CLOCK,
145 RADIO, 150 RADIO,
diff --git a/embassy-nrf/src/chips/nrf52805.rs b/embassy-nrf/src/chips/nrf52805.rs
index 624d6613d..14c3f9b1a 100644
--- a/embassy-nrf/src/chips/nrf52805.rs
+++ b/embassy-nrf/src/chips/nrf52805.rs
@@ -129,6 +129,9 @@ embassy_hal_internal::peripherals! {
129 129
130 // QDEC 130 // QDEC
131 QDEC, 131 QDEC,
132
133 // Radio
134 RADIO,
132} 135}
133 136
134impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); 137impl_uarte!(UARTE0, UARTE0, UARTE0_UART0);
@@ -209,6 +212,8 @@ impl_ppi_channel!(PPI_CH31, 31 => static);
209impl_saadc_input!(P0_04, ANALOG_INPUT2); 212impl_saadc_input!(P0_04, ANALOG_INPUT2);
210impl_saadc_input!(P0_05, ANALOG_INPUT3); 213impl_saadc_input!(P0_05, ANALOG_INPUT3);
211 214
215impl_radio!(RADIO, RADIO, RADIO);
216
212embassy_hal_internal::interrupt_mod!( 217embassy_hal_internal::interrupt_mod!(
213 POWER_CLOCK, 218 POWER_CLOCK,
214 RADIO, 219 RADIO,
diff --git a/embassy-nrf/src/chips/nrf52810.rs b/embassy-nrf/src/chips/nrf52810.rs
index 002feab3b..c607586db 100644
--- a/embassy-nrf/src/chips/nrf52810.rs
+++ b/embassy-nrf/src/chips/nrf52810.rs
@@ -135,6 +135,9 @@ embassy_hal_internal::peripherals! {
135 135
136 // PDM 136 // PDM
137 PDM, 137 PDM,
138
139 // Radio
140 RADIO,
138} 141}
139 142
140impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); 143impl_uarte!(UARTE0, UARTE0, UARTE0_UART0);
@@ -235,6 +238,8 @@ impl_saadc_input!(P0_29, ANALOG_INPUT5);
235impl_saadc_input!(P0_30, ANALOG_INPUT6); 238impl_saadc_input!(P0_30, ANALOG_INPUT6);
236impl_saadc_input!(P0_31, ANALOG_INPUT7); 239impl_saadc_input!(P0_31, ANALOG_INPUT7);
237 240
241impl_radio!(RADIO, RADIO, RADIO);
242
238embassy_hal_internal::interrupt_mod!( 243embassy_hal_internal::interrupt_mod!(
239 POWER_CLOCK, 244 POWER_CLOCK,
240 RADIO, 245 RADIO,
diff --git a/embassy-nrf/src/chips/nrf52811.rs b/embassy-nrf/src/chips/nrf52811.rs
index 5952907f8..5f70365b4 100644
--- a/embassy-nrf/src/chips/nrf52811.rs
+++ b/embassy-nrf/src/chips/nrf52811.rs
@@ -135,6 +135,9 @@ embassy_hal_internal::peripherals! {
135 135
136 // PDM 136 // PDM
137 PDM, 137 PDM,
138
139 // Radio
140 RADIO,
138} 141}
139 142
140impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); 143impl_uarte!(UARTE0, UARTE0, UARTE0_UART0);
@@ -237,6 +240,8 @@ impl_saadc_input!(P0_29, ANALOG_INPUT5);
237impl_saadc_input!(P0_30, ANALOG_INPUT6); 240impl_saadc_input!(P0_30, ANALOG_INPUT6);
238impl_saadc_input!(P0_31, ANALOG_INPUT7); 241impl_saadc_input!(P0_31, ANALOG_INPUT7);
239 242
243impl_radio!(RADIO, RADIO, RADIO);
244
240embassy_hal_internal::interrupt_mod!( 245embassy_hal_internal::interrupt_mod!(
241 POWER_CLOCK, 246 POWER_CLOCK,
242 RADIO, 247 RADIO,
diff --git a/embassy-nrf/src/chips/nrf52820.rs b/embassy-nrf/src/chips/nrf52820.rs
index c2f792cb9..82d097407 100644
--- a/embassy-nrf/src/chips/nrf52820.rs
+++ b/embassy-nrf/src/chips/nrf52820.rs
@@ -130,6 +130,9 @@ embassy_hal_internal::peripherals! {
130 130
131 // QDEC 131 // QDEC
132 QDEC, 132 QDEC,
133
134 // Radio
135 RADIO,
133} 136}
134 137
135impl_usb!(USBD, USBD, USBD); 138impl_usb!(USBD, USBD, USBD);
@@ -224,6 +227,8 @@ impl_ppi_channel!(PPI_CH29, 29 => static);
224impl_ppi_channel!(PPI_CH30, 30 => static); 227impl_ppi_channel!(PPI_CH30, 30 => static);
225impl_ppi_channel!(PPI_CH31, 31 => static); 228impl_ppi_channel!(PPI_CH31, 31 => static);
226 229
230impl_radio!(RADIO, RADIO, RADIO);
231
227embassy_hal_internal::interrupt_mod!( 232embassy_hal_internal::interrupt_mod!(
228 POWER_CLOCK, 233 POWER_CLOCK,
229 RADIO, 234 RADIO,
diff --git a/embassy-nrf/src/chips/nrf52832.rs b/embassy-nrf/src/chips/nrf52832.rs
index 65d52364d..67b32fe5f 100644
--- a/embassy-nrf/src/chips/nrf52832.rs
+++ b/embassy-nrf/src/chips/nrf52832.rs
@@ -150,6 +150,9 @@ embassy_hal_internal::peripherals! {
150 150
151 // PDM 151 // PDM
152 PDM, 152 PDM,
153
154 // Radio
155 RADIO,
153} 156}
154 157
155impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); 158impl_uarte!(UARTE0, UARTE0, UARTE0_UART0);
@@ -264,6 +267,8 @@ impl_saadc_input!(P0_31, ANALOG_INPUT7);
264 267
265impl_i2s!(I2S, I2S, I2S); 268impl_i2s!(I2S, I2S, I2S);
266 269
270impl_radio!(RADIO, RADIO, RADIO);
271
267embassy_hal_internal::interrupt_mod!( 272embassy_hal_internal::interrupt_mod!(
268 POWER_CLOCK, 273 POWER_CLOCK,
269 RADIO, 274 RADIO,
diff --git a/embassy-nrf/src/chips/nrf5340_net.rs b/embassy-nrf/src/chips/nrf5340_net.rs
index a7cf82872..65e8f9653 100644
--- a/embassy-nrf/src/chips/nrf5340_net.rs
+++ b/embassy-nrf/src/chips/nrf5340_net.rs
@@ -248,6 +248,9 @@ embassy_hal_internal::peripherals! {
248 P1_13, 248 P1_13,
249 P1_14, 249 P1_14,
250 P1_15, 250 P1_15,
251
252 // Radio
253 RADIO,
251} 254}
252 255
253impl_uarte!(SERIAL0, UARTE0, SERIAL0); 256impl_uarte!(SERIAL0, UARTE0, SERIAL0);
@@ -345,6 +348,8 @@ impl_ppi_channel!(PPI_CH29, 29 => configurable);
345impl_ppi_channel!(PPI_CH30, 30 => configurable); 348impl_ppi_channel!(PPI_CH30, 30 => configurable);
346impl_ppi_channel!(PPI_CH31, 31 => configurable); 349impl_ppi_channel!(PPI_CH31, 31 => configurable);
347 350
351impl_radio!(RADIO, RADIO, RADIO);
352
348embassy_hal_internal::interrupt_mod!( 353embassy_hal_internal::interrupt_mod!(
349 CLOCK_POWER, 354 CLOCK_POWER,
350 RADIO, 355 RADIO,
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs
index 132bffa8b..06a25a36d 100644
--- a/embassy-nrf/src/lib.rs
+++ b/embassy-nrf/src/lib.rs
@@ -47,7 +47,7 @@ pub mod gpio;
47pub mod gpiote; 47pub mod gpiote;
48 48
49// TODO: tested on other chips 49// TODO: tested on other chips
50#[cfg(any(feature = "nrf52833", feature = "nrf52840"))] 50#[cfg(not(any(feature = "nrf51", feature = "_nrf9160")))]
51pub mod radio; 51pub mod radio;
52 52
53#[cfg(any(feature = "nrf52832", feature = "nrf52833", feature = "nrf52840"))] 53#[cfg(any(feature = "nrf52832", feature = "nrf52833", feature = "nrf52840"))]
diff --git a/embassy-nrf/src/radio/ble.rs b/embassy-nrf/src/radio/ble.rs
index 846ac98af..a306971b0 100644
--- a/embassy-nrf/src/radio/ble.rs
+++ b/embassy-nrf/src/radio/ble.rs
@@ -7,6 +7,7 @@ use core::task::Poll;
7use embassy_hal_internal::drop::OnDrop; 7use embassy_hal_internal::drop::OnDrop;
8use embassy_hal_internal::{into_ref, PeripheralRef}; 8use embassy_hal_internal::{into_ref, PeripheralRef};
9pub use pac::radio::mode::MODE_A as Mode; 9pub use pac::radio::mode::MODE_A as Mode;
10#[cfg(not(feature = "nrf51"))]
10use pac::radio::pcnf0::PLEN_A as PreambleLength; 11use pac::radio::pcnf0::PLEN_A as PreambleLength;
11 12
12use crate::interrupt::typelevel::Interrupt; 13use crate::interrupt::typelevel::Interrupt;
@@ -84,6 +85,7 @@ impl<'d, T: Instance> Radio<'d, T> {
84 85
85 // Ch map between 2400 MHZ .. 2500 MHz 86 // Ch map between 2400 MHZ .. 2500 MHz
86 // All modes use this range 87 // All modes use this range
88 #[cfg(not(feature = "nrf51"))]
87 r.frequency.write(|w| w.map().default()); 89 r.frequency.write(|w| w.map().default());
88 90
89 // Configure shortcuts to simplify and speed up sending and receiving packets. 91 // Configure shortcuts to simplify and speed up sending and receiving packets.
@@ -121,10 +123,18 @@ impl<'d, T: Instance> Radio<'d, T> {
121 let r = T::regs(); 123 let r = T::regs();
122 r.mode.write(|w| w.mode().variant(mode)); 124 r.mode.write(|w| w.mode().variant(mode));
123 125
126 #[cfg(not(feature = "nrf51"))]
124 r.pcnf0.write(|w| { 127 r.pcnf0.write(|w| {
125 w.plen().variant(match mode { 128 w.plen().variant(match mode {
126 Mode::BLE_1MBIT => PreambleLength::_8BIT, 129 Mode::BLE_1MBIT => PreambleLength::_8BIT,
127 Mode::BLE_2MBIT => PreambleLength::_16BIT, 130 Mode::BLE_2MBIT => PreambleLength::_16BIT,
131 #[cfg(any(
132 feature = "nrf52811",
133 feature = "nrf52820",
134 feature = "nrf52833",
135 feature = "nrf52840",
136 feature = "_nrf5340-net"
137 ))]
128 Mode::BLE_LR125KBIT | Mode::BLE_LR500KBIT => PreambleLength::LONG_RANGE, 138 Mode::BLE_LR125KBIT | Mode::BLE_LR500KBIT => PreambleLength::LONG_RANGE,
129 _ => unimplemented!(), 139 _ => unimplemented!(),
130 }) 140 })
@@ -307,7 +317,11 @@ impl<'d, T: Instance> Radio<'d, T> {
307 self.trigger_and_wait_end(move || { 317 self.trigger_and_wait_end(move || {
308 // Initialize the transmission 318 // Initialize the transmission
309 // trace!("txen"); 319 // trace!("txen");
320
321 #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
310 r.tasks_txen.write(|w| w.tasks_txen().set_bit()); 322 r.tasks_txen.write(|w| w.tasks_txen().set_bit());
323 #[cfg(any(feature = "nrf51", feature = "nrf52832"))]
324 r.tasks_txen.write(|w| unsafe { w.bits(1) });
311 }) 325 })
312 .await; 326 .await;
313 327
@@ -324,7 +338,10 @@ impl<'d, T: Instance> Radio<'d, T> {
324 self.trigger_and_wait_end(move || { 338 self.trigger_and_wait_end(move || {
325 // Initialize the transmission 339 // Initialize the transmission
326 // trace!("rxen"); 340 // trace!("rxen");
341 #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
327 r.tasks_rxen.write(|w| w.tasks_rxen().set_bit()); 342 r.tasks_rxen.write(|w| w.tasks_rxen().set_bit());
343 #[cfg(any(feature = "nrf51", feature = "nrf52832"))]
344 r.tasks_rxen.write(|w| unsafe { w.bits(1) });
328 }) 345 })
329 .await; 346 .await;
330 347
@@ -346,10 +363,16 @@ impl<'d, T: Instance> Radio<'d, T> {
346 r.intenclr.write(|w| w.end().clear()); 363 r.intenclr.write(|w| w.end().clear());
347 r.events_end.reset(); 364 r.events_end.reset();
348 365
366 #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
349 r.tasks_stop.write(|w| w.tasks_stop().set_bit()); 367 r.tasks_stop.write(|w| w.tasks_stop().set_bit());
368 #[cfg(any(feature = "nrf51", feature = "nrf52832"))]
369 r.tasks_stop.write(|w| unsafe { w.bits(1) });
350 370
351 // The docs don't explicitly mention any event to acknowledge the stop task 371 // The docs don't explicitly mention any event to acknowledge the stop task
372 #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
352 while r.events_end.read().events_end().bit_is_clear() {} 373 while r.events_end.read().events_end().bit_is_clear() {}
374 #[cfg(any(feature = "nrf51", feature = "nrf52832"))]
375 while r.events_end.read().bits() == 0 {}
353 376
354 trace!("radio drop: stopped"); 377 trace!("radio drop: stopped");
355 }); 378 });
@@ -370,7 +393,11 @@ impl<'d, T: Instance> Radio<'d, T> {
370 // On poll check if interrupt happen 393 // On poll check if interrupt happen
371 poll_fn(|cx| { 394 poll_fn(|cx| {
372 s.event_waker.register(cx.waker()); 395 s.event_waker.register(cx.waker());
373 if r.events_end.read().events_end().bit_is_set() { 396 #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
397 let end_event = r.events_end.read().events_end().bit_is_set();
398 #[cfg(any(feature = "nrf51", feature = "nrf52832"))]
399 let end_event = r.events_end.read().bits() == 1;
400 if end_event {
374 // trace!("radio:end"); 401 // trace!("radio:end");
375 return core::task::Poll::Ready(()); 402 return core::task::Poll::Ready(());
376 } 403 }
@@ -394,10 +421,16 @@ impl<'d, T: Instance> Radio<'d, T> {
394 if self.state() != RadioState::DISABLED { 421 if self.state() != RadioState::DISABLED {
395 trace!("radio:disable"); 422 trace!("radio:disable");
396 // Trigger the disable task 423 // Trigger the disable task
424 #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
397 r.tasks_disable.write(|w| w.tasks_disable().set_bit()); 425 r.tasks_disable.write(|w| w.tasks_disable().set_bit());
426 #[cfg(any(feature = "nrf51", feature = "nrf52832"))]
427 r.tasks_disable.write(|w| unsafe { w.bits(1) });
398 428
399 // Wait until the radio is disabled 429 // Wait until the radio is disabled
430 #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
400 while r.events_disabled.read().events_disabled().bit_is_clear() {} 431 while r.events_disabled.read().events_disabled().bit_is_clear() {}
432 #[cfg(any(feature = "nrf51", feature = "nrf52832"))]
433 while r.events_disabled.read().bits() == 0 {}
401 434
402 compiler_fence(Ordering::SeqCst); 435 compiler_fence(Ordering::SeqCst);
403 436
diff --git a/embassy-nrf/src/radio/ieee802154.rs b/embassy-nrf/src/radio/ieee802154.rs
index 2de53b392..7bec4cb8c 100644
--- a/embassy-nrf/src/radio/ieee802154.rs
+++ b/embassy-nrf/src/radio/ieee802154.rs
@@ -162,15 +162,34 @@ impl<'d, T: Instance> Radio<'d, T> {
162 self.needs_enable = true; 162 self.needs_enable = true;
163 163
164 let tx_power: TxPower = match power { 164 let tx_power: TxPower = match power {
165 #[cfg(not(feature = "_nrf5340-net"))]
165 8 => TxPower::POS8D_BM, 166 8 => TxPower::POS8D_BM,
167 #[cfg(not(feature = "_nrf5340-net"))]
166 7 => TxPower::POS7D_BM, 168 7 => TxPower::POS7D_BM,
169 #[cfg(not(feature = "_nrf5340-net"))]
167 6 => TxPower::POS6D_BM, 170 6 => TxPower::POS6D_BM,
171 #[cfg(not(feature = "_nrf5340-net"))]
168 5 => TxPower::POS5D_BM, 172 5 => TxPower::POS5D_BM,
173 #[cfg(not(feature = "_nrf5340-net"))]
169 4 => TxPower::POS4D_BM, 174 4 => TxPower::POS4D_BM,
175 #[cfg(not(feature = "_nrf5340-net"))]
170 3 => TxPower::POS3D_BM, 176 3 => TxPower::POS3D_BM,
177 #[cfg(not(feature = "_nrf5340-net"))]
171 2 => TxPower::POS2D_BM, 178 2 => TxPower::POS2D_BM,
172 0 => TxPower::_0D_BM, 179 0 => TxPower::_0D_BM,
180 #[cfg(feature = "_nrf5340-net")]
181 -1 => TxPower::NEG1D_BM,
182 #[cfg(feature = "_nrf5340-net")]
183 -2 => TxPower::NEG2D_BM,
184 #[cfg(feature = "_nrf5340-net")]
185 -3 => TxPower::NEG3D_BM,
173 -4 => TxPower::NEG4D_BM, 186 -4 => TxPower::NEG4D_BM,
187 #[cfg(feature = "_nrf5340-net")]
188 -5 => TxPower::NEG5D_BM,
189 #[cfg(feature = "_nrf5340-net")]
190 -6 => TxPower::NEG6D_BM,
191 #[cfg(feature = "_nrf5340-net")]
192 -7 => TxPower::NEG7D_BM,
174 -8 => TxPower::NEG8D_BM, 193 -8 => TxPower::NEG8D_BM,
175 -12 => TxPower::NEG12D_BM, 194 -12 => TxPower::NEG12D_BM,
176 -16 => TxPower::NEG16D_BM, 195 -16 => TxPower::NEG16D_BM,
diff --git a/embassy-nrf/src/radio/mod.rs b/embassy-nrf/src/radio/mod.rs
index 487e52d79..adb8e1206 100644
--- a/embassy-nrf/src/radio/mod.rs
+++ b/embassy-nrf/src/radio/mod.rs
@@ -7,7 +7,12 @@
7 7
8/// Bluetooth Low Energy Radio driver. 8/// Bluetooth Low Energy Radio driver.
9pub mod ble; 9pub mod ble;
10#[cfg(any(feature = "nrf52840", feature = "nrf52833", feature = "_nrf5340-net"))] 10#[cfg(any(
11 feature = "nrf52820",
12 feature = "nrf52833",
13 feature = "nrf52840",
14 feature = "_nrf5340-net"
15))]
11/// IEEE 802.15.4 16/// IEEE 802.15.4
12pub mod ieee802154; 17pub mod ieee802154;
13 18