diff options
| author | Erik Bånvik <[email protected]> | 2024-03-05 15:01:05 +0100 |
|---|---|---|
| committer | Erik Bånvik <[email protected]> | 2024-03-05 15:01:05 +0100 |
| commit | bb73d6b3fe81f26cb527d45bd700d2aef9b07090 (patch) | |
| tree | 502275cdc4c7ea8281e79c10f0b5fc7b5e1aa67b /embassy-nrf/src/radio | |
| parent | 5b5d54c0c75e8a7fbe5370af4932c9845f4ce123 (diff) | |
Fixed suggestions, added nRF51 to BLE
Diffstat (limited to 'embassy-nrf/src/radio')
| -rw-r--r-- | embassy-nrf/src/radio/ble.rs | 36 | ||||
| -rw-r--r-- | embassy-nrf/src/radio/ieee802154.rs | 10 | ||||
| -rw-r--r-- | embassy-nrf/src/radio/mod.rs | 20 |
3 files changed, 10 insertions, 56 deletions
diff --git a/embassy-nrf/src/radio/ble.rs b/embassy-nrf/src/radio/ble.rs index a306971b0..93003fb19 100644 --- a/embassy-nrf/src/radio/ble.rs +++ b/embassy-nrf/src/radio/ble.rs | |||
| @@ -11,8 +11,8 @@ pub use pac::radio::mode::MODE_A as Mode; | |||
| 11 | use pac::radio::pcnf0::PLEN_A as PreambleLength; | 11 | use pac::radio::pcnf0::PLEN_A as PreambleLength; |
| 12 | 12 | ||
| 13 | use crate::interrupt::typelevel::Interrupt; | 13 | use crate::interrupt::typelevel::Interrupt; |
| 14 | pub use crate::radio::Error; | ||
| 15 | use crate::radio::*; | 14 | use crate::radio::*; |
| 15 | pub use crate::radio::{Error, TxPower}; | ||
| 16 | use crate::util::slice_in_ram_or; | 16 | use crate::util::slice_in_ram_or; |
| 17 | 17 | ||
| 18 | /// Radio driver. | 18 | /// Radio driver. |
| @@ -103,15 +103,7 @@ impl<'d, T: Instance> Radio<'d, T> { | |||
| 103 | } | 103 | } |
| 104 | 104 | ||
| 105 | fn state(&self) -> RadioState { | 105 | fn state(&self) -> RadioState { |
| 106 | match T::regs().state.read().state().variant() { | 106 | super::state(T::regs()) |
| 107 | Some(s) => s, | ||
| 108 | None => unreachable!(), | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | #[allow(dead_code)] | ||
| 113 | fn trace_state(&self) { | ||
| 114 | super::trace_state(T::regs()) | ||
| 115 | } | 107 | } |
| 116 | 108 | ||
| 117 | /// Set the radio mode | 109 | /// Set the radio mode |
| @@ -318,9 +310,6 @@ impl<'d, T: Instance> Radio<'d, T> { | |||
| 318 | // Initialize the transmission | 310 | // Initialize the transmission |
| 319 | // trace!("txen"); | 311 | // trace!("txen"); |
| 320 | 312 | ||
| 321 | #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] | ||
| 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) }); | 313 | r.tasks_txen.write(|w| unsafe { w.bits(1) }); |
| 325 | }) | 314 | }) |
| 326 | .await; | 315 | .await; |
| @@ -338,9 +327,6 @@ impl<'d, T: Instance> Radio<'d, T> { | |||
| 338 | self.trigger_and_wait_end(move || { | 327 | self.trigger_and_wait_end(move || { |
| 339 | // Initialize the transmission | 328 | // Initialize the transmission |
| 340 | // trace!("rxen"); | 329 | // trace!("rxen"); |
| 341 | #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] | ||
| 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) }); | 330 | r.tasks_rxen.write(|w| unsafe { w.bits(1) }); |
| 345 | }) | 331 | }) |
| 346 | .await; | 332 | .await; |
| @@ -363,15 +349,9 @@ impl<'d, T: Instance> Radio<'d, T> { | |||
| 363 | r.intenclr.write(|w| w.end().clear()); | 349 | r.intenclr.write(|w| w.end().clear()); |
| 364 | r.events_end.reset(); | 350 | r.events_end.reset(); |
| 365 | 351 | ||
| 366 | #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] | ||
| 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) }); | 352 | r.tasks_stop.write(|w| unsafe { w.bits(1) }); |
| 370 | 353 | ||
| 371 | // The docs don't explicitly mention any event to acknowledge the stop task | 354 | // The docs don't explicitly mention any event to acknowledge the stop task |
| 372 | #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] | ||
| 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 {} | 355 | while r.events_end.read().bits() == 0 {} |
| 376 | 356 | ||
| 377 | trace!("radio drop: stopped"); | 357 | trace!("radio drop: stopped"); |
| @@ -393,11 +373,7 @@ impl<'d, T: Instance> Radio<'d, T> { | |||
| 393 | // On poll check if interrupt happen | 373 | // On poll check if interrupt happen |
| 394 | poll_fn(|cx| { | 374 | poll_fn(|cx| { |
| 395 | s.event_waker.register(cx.waker()); | 375 | s.event_waker.register(cx.waker()); |
| 396 | #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] | 376 | if r.events_end.read().bits() == 1 { |
| 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 { | ||
| 401 | // trace!("radio:end"); | 377 | // trace!("radio:end"); |
| 402 | return core::task::Poll::Ready(()); | 378 | return core::task::Poll::Ready(()); |
| 403 | } | 379 | } |
| @@ -421,15 +397,9 @@ impl<'d, T: Instance> Radio<'d, T> { | |||
| 421 | if self.state() != RadioState::DISABLED { | 397 | if self.state() != RadioState::DISABLED { |
| 422 | trace!("radio:disable"); | 398 | trace!("radio:disable"); |
| 423 | // Trigger the disable task | 399 | // Trigger the disable task |
| 424 | #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] | ||
| 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) }); | 400 | r.tasks_disable.write(|w| unsafe { w.bits(1) }); |
| 428 | 401 | ||
| 429 | // Wait until the radio is disabled | 402 | // Wait until the radio is disabled |
| 430 | #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] | ||
| 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 {} | 403 | while r.events_disabled.read().bits() == 0 {} |
| 434 | 404 | ||
| 435 | compiler_fence(Ordering::SeqCst); | 405 | compiler_fence(Ordering::SeqCst); |
diff --git a/embassy-nrf/src/radio/ieee802154.rs b/embassy-nrf/src/radio/ieee802154.rs index 7bec4cb8c..298f8a574 100644 --- a/embassy-nrf/src/radio/ieee802154.rs +++ b/embassy-nrf/src/radio/ieee802154.rs | |||
| @@ -162,19 +162,19 @@ 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 | #[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))] |
| 166 | 8 => TxPower::POS8D_BM, | 166 | 8 => TxPower::POS8D_BM, |
| 167 | #[cfg(not(feature = "_nrf5340-net"))] | 167 | #[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))] |
| 168 | 7 => TxPower::POS7D_BM, | 168 | 7 => TxPower::POS7D_BM, |
| 169 | #[cfg(not(feature = "_nrf5340-net"))] | 169 | #[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))] |
| 170 | 6 => TxPower::POS6D_BM, | 170 | 6 => TxPower::POS6D_BM, |
| 171 | #[cfg(not(feature = "_nrf5340-net"))] | 171 | #[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))] |
| 172 | 5 => TxPower::POS5D_BM, | 172 | 5 => TxPower::POS5D_BM, |
| 173 | #[cfg(not(feature = "_nrf5340-net"))] | 173 | #[cfg(not(feature = "_nrf5340-net"))] |
| 174 | 4 => TxPower::POS4D_BM, | 174 | 4 => TxPower::POS4D_BM, |
| 175 | #[cfg(not(feature = "_nrf5340-net"))] | 175 | #[cfg(not(feature = "_nrf5340-net"))] |
| 176 | 3 => TxPower::POS3D_BM, | 176 | 3 => TxPower::POS3D_BM, |
| 177 | #[cfg(not(feature = "_nrf5340-net"))] | 177 | #[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))] |
| 178 | 2 => TxPower::POS2D_BM, | 178 | 2 => TxPower::POS2D_BM, |
| 179 | 0 => TxPower::_0D_BM, | 179 | 0 => TxPower::_0D_BM, |
| 180 | #[cfg(feature = "_nrf5340-net")] | 180 | #[cfg(feature = "_nrf5340-net")] |
diff --git a/embassy-nrf/src/radio/mod.rs b/embassy-nrf/src/radio/mod.rs index 5a2982d89..4c0cc3280 100644 --- a/embassy-nrf/src/radio/mod.rs +++ b/embassy-nrf/src/radio/mod.rs | |||
| @@ -6,9 +6,9 @@ | |||
| 6 | #![macro_use] | 6 | #![macro_use] |
| 7 | 7 | ||
| 8 | /// Bluetooth Low Energy Radio driver. | 8 | /// Bluetooth Low Energy Radio driver. |
| 9 | #[cfg(not(feature = "nrf51"))] | ||
| 10 | pub mod ble; | 9 | pub mod ble; |
| 11 | #[cfg(any( | 10 | #[cfg(any( |
| 11 | feature = "nrf52811", | ||
| 12 | feature = "nrf52820", | 12 | feature = "nrf52820", |
| 13 | feature = "nrf52833", | 13 | feature = "nrf52833", |
| 14 | feature = "nrf52840", | 14 | feature = "nrf52840", |
| @@ -20,8 +20,7 @@ pub mod ieee802154; | |||
| 20 | use core::marker::PhantomData; | 20 | use core::marker::PhantomData; |
| 21 | 21 | ||
| 22 | use pac::radio::state::STATE_A as RadioState; | 22 | use pac::radio::state::STATE_A as RadioState; |
| 23 | #[cfg(not(feature = "nrf51"))] | 23 | pub use pac::radio::txpower::TXPOWER_A as TxPower; |
| 24 | use pac::radio::txpower::TXPOWER_A as TxPower; | ||
| 25 | 24 | ||
| 26 | use crate::{interrupt, pac, Peripheral}; | 25 | use crate::{interrupt, pac, Peripheral}; |
| 27 | 26 | ||
| @@ -109,18 +108,3 @@ pub(crate) fn state(radio: &pac::radio::RegisterBlock) -> RadioState { | |||
| 109 | None => unreachable!(), | 108 | None => unreachable!(), |
| 110 | } | 109 | } |
| 111 | } | 110 | } |
| 112 | |||
| 113 | #[allow(dead_code)] | ||
| 114 | pub(crate) fn trace_state(radio: &pac::radio::RegisterBlock) { | ||
| 115 | match state(radio) { | ||
| 116 | RadioState::DISABLED => trace!("radio:state:DISABLED"), | ||
| 117 | RadioState::RX_RU => trace!("radio:state:RX_RU"), | ||
| 118 | RadioState::RX_IDLE => trace!("radio:state:RX_IDLE"), | ||
| 119 | RadioState::RX => trace!("radio:state:RX"), | ||
| 120 | RadioState::RX_DISABLE => trace!("radio:state:RX_DISABLE"), | ||
| 121 | RadioState::TX_RU => trace!("radio:state:TX_RU"), | ||
| 122 | RadioState::TX_IDLE => trace!("radio:state:TX_IDLE"), | ||
| 123 | RadioState::TX => trace!("radio:state:TX"), | ||
| 124 | RadioState::TX_DISABLE => trace!("radio:state:TX_DISABLE"), | ||
| 125 | } | ||
| 126 | } | ||
