diff options
| author | Erik Bånvik <[email protected]> | 2024-03-05 11:39:15 +0100 |
|---|---|---|
| committer | Erik Bånvik <[email protected]> | 2024-03-05 11:39:15 +0100 |
| commit | bc258b322b3828b5e52cba3e51c7de4ec014268e (patch) | |
| tree | 6fbd663b526df7b4bf220fcec82c34787e9a68f3 /embassy-nrf/src/radio | |
| parent | 84935fbfab6a053113c135110ec4a1f4373ccfb3 (diff) | |
Support nearly all nRF5 RADIOs
Diffstat (limited to 'embassy-nrf/src/radio')
| -rw-r--r-- | embassy-nrf/src/radio/ble.rs | 35 | ||||
| -rw-r--r-- | embassy-nrf/src/radio/ieee802154.rs | 19 | ||||
| -rw-r--r-- | embassy-nrf/src/radio/mod.rs | 7 |
3 files changed, 59 insertions, 2 deletions
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; | |||
| 7 | use embassy_hal_internal::drop::OnDrop; | 7 | use embassy_hal_internal::drop::OnDrop; |
| 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; | 8 | use embassy_hal_internal::{into_ref, PeripheralRef}; |
| 9 | pub use pac::radio::mode::MODE_A as Mode; | 9 | pub use pac::radio::mode::MODE_A as Mode; |
| 10 | #[cfg(not(feature = "nrf51"))] | ||
| 10 | use pac::radio::pcnf0::PLEN_A as PreambleLength; | 11 | use pac::radio::pcnf0::PLEN_A as PreambleLength; |
| 11 | 12 | ||
| 12 | use crate::interrupt::typelevel::Interrupt; | 13 | use 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. |
| 9 | pub mod ble; | 9 | pub 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 |
| 12 | pub mod ieee802154; | 17 | pub mod ieee802154; |
| 13 | 18 | ||
