diff options
| -rw-r--r-- | embassy-nrf/src/lib.rs | 3 | ||||
| -rw-r--r-- | embassy-nrf/src/radio/ble.rs | 22 |
2 files changed, 7 insertions, 18 deletions
diff --git a/embassy-nrf/src/lib.rs b/embassy-nrf/src/lib.rs index 5dba6f975..04a6293a4 100644 --- a/embassy-nrf/src/lib.rs +++ b/embassy-nrf/src/lib.rs | |||
| @@ -46,7 +46,8 @@ pub mod gpio; | |||
| 46 | #[cfg(feature = "gpiote")] | 46 | #[cfg(feature = "gpiote")] |
| 47 | pub mod gpiote; | 47 | pub mod gpiote; |
| 48 | 48 | ||
| 49 | #[cfg(any(feature = "nrf52840"))] // needs to be tested on other chips | 49 | // TODO: tested on other chips |
| 50 | #[cfg(any(feature = "nrf52840"))] | ||
| 50 | pub mod radio; | 51 | pub mod radio; |
| 51 | 52 | ||
| 52 | #[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 ba9ac5f2e..81ef96b65 100644 --- a/embassy-nrf/src/radio/ble.rs +++ b/embassy-nrf/src/radio/ble.rs | |||
| @@ -1,15 +1,4 @@ | |||
| 1 | //! Radio driver implementation focused on Bluetooth Low-Energy transmission. | 1 | //! Radio driver implementation focused on Bluetooth Low-Energy transmission. |
| 2 | //! | ||
| 3 | //! The radio can calculate the CRC, perform data whitening, | ||
| 4 | //! automatically send the right preamble. | ||
| 5 | //! Most of the configuration is done automatically when you choose the mode and this driver. | ||
| 6 | //! | ||
| 7 | //! Some configuration can just be done when de device is disabled, | ||
| 8 | //! and the configuration varies depending if is a transmitter or a receiver. | ||
| 9 | //! Because of that we have a state machine to keep track of the state of the radio. | ||
| 10 | //! The Radio is the disable radio which configure the common parameters between | ||
| 11 | //! the bluetooth protocols, like the package format, the CRC and the whitening. | ||
| 12 | //! The TxRadio radio enable and configured as a transmitter with the specific parameters. | ||
| 13 | 2 | ||
| 14 | use core::future::poll_fn; | 3 | use core::future::poll_fn; |
| 15 | use core::sync::atomic::{compiler_fence, Ordering}; | 4 | use core::sync::atomic::{compiler_fence, Ordering}; |
| @@ -241,7 +230,7 @@ impl<'d, T: Instance> Radio<'d, T> { | |||
| 241 | .write(|w| unsafe { w.ap0().bits((access_address >> 24) as u8) }); | 230 | .write(|w| unsafe { w.ap0().bits((access_address >> 24) as u8) }); |
| 242 | 231 | ||
| 243 | // The base address is truncated from the least significant byte (because the BALEN is less than 4) | 232 | // The base address is truncated from the least significant byte (because the BALEN is less than 4) |
| 244 | // So we need to shift the address to the right | 233 | // So it shifts the address to the right |
| 245 | r.base0.write(|w| unsafe { w.bits(access_address << 8) }); | 234 | r.base0.write(|w| unsafe { w.bits(access_address << 8) }); |
| 246 | 235 | ||
| 247 | // Don't match tx address | 236 | // Don't match tx address |
| @@ -317,13 +306,12 @@ impl<'d, T: Instance> Radio<'d, T> { | |||
| 317 | /// Also if the buffer is smaller than the packet length, the radio will | 306 | /// Also if the buffer is smaller than the packet length, the radio will |
| 318 | /// read/write memory out of the buffer bounds. | 307 | /// read/write memory out of the buffer bounds. |
| 319 | fn set_buffer(&mut self, buffer: &[u8]) -> Result<(), Error> { | 308 | fn set_buffer(&mut self, buffer: &[u8]) -> Result<(), Error> { |
| 320 | // Because we are serializing the buffer, we should always have the buffer in RAM | ||
| 321 | slice_in_ram_or(buffer, Error::BufferNotInRAM)?; | 309 | slice_in_ram_or(buffer, Error::BufferNotInRAM)?; |
| 322 | 310 | ||
| 323 | let r = T::regs(); | 311 | let r = T::regs(); |
| 324 | 312 | ||
| 325 | // Here we are considering that the length of the packet is | 313 | // Here it consider that the length of the packet is |
| 326 | // correctly set in the buffer, otherwise we will sending | 314 | // correctly set in the buffer, otherwise it will send |
| 327 | // unowned regions of memory | 315 | // unowned regions of memory |
| 328 | let ptr = buffer.as_ptr(); | 316 | let ptr = buffer.as_ptr(); |
| 329 | 317 | ||
| @@ -374,7 +362,7 @@ impl<'d, T: Instance> Radio<'d, T> { | |||
| 374 | let s = T::state(); | 362 | let s = T::state(); |
| 375 | 363 | ||
| 376 | // If the Future is dropped before the end of the transmission | 364 | // If the Future is dropped before the end of the transmission |
| 377 | // we need to disable the interrupt and stop the transmission | 365 | // it disable the interrupt and stop the transmission |
| 378 | // to keep the state consistent | 366 | // to keep the state consistent |
| 379 | let drop = OnDrop::new(|| { | 367 | let drop = OnDrop::new(|| { |
| 380 | trace!("radio drop: stopping"); | 368 | trace!("radio drop: stopping"); |
| @@ -417,7 +405,7 @@ impl<'d, T: Instance> Radio<'d, T> { | |||
| 417 | compiler_fence(Ordering::SeqCst); | 405 | compiler_fence(Ordering::SeqCst); |
| 418 | r.events_disabled.reset(); // ACK | 406 | r.events_disabled.reset(); // ACK |
| 419 | 407 | ||
| 420 | // Everthing ends fine, so we can disable the drop | 408 | // Everthing ends fine, so it disable the drop |
| 421 | drop.defuse(); | 409 | drop.defuse(); |
| 422 | } | 410 | } |
| 423 | 411 | ||
