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! { // TEMP TEMP, + + // Radio + RADIO, } impl_timer!(TIMER0, TIMER0, TIMER0); @@ -140,6 +143,8 @@ impl_pin!(P0_29, 0, 29); impl_pin!(P0_30, 0, 30); impl_pin!(P0_31, 0, 31); +impl_radio!(RADIO, RADIO, RADIO); + embassy_hal_internal::interrupt_mod!( POWER_CLOCK, 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! { // QDEC QDEC, + + // Radio + RADIO, } impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); @@ -209,6 +212,8 @@ impl_ppi_channel!(PPI_CH31, 31 => static); impl_saadc_input!(P0_04, ANALOG_INPUT2); impl_saadc_input!(P0_05, ANALOG_INPUT3); +impl_radio!(RADIO, RADIO, RADIO); + embassy_hal_internal::interrupt_mod!( POWER_CLOCK, 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! { // PDM PDM, + + // Radio + RADIO, } impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); @@ -235,6 +238,8 @@ impl_saadc_input!(P0_29, ANALOG_INPUT5); impl_saadc_input!(P0_30, ANALOG_INPUT6); impl_saadc_input!(P0_31, ANALOG_INPUT7); +impl_radio!(RADIO, RADIO, RADIO); + embassy_hal_internal::interrupt_mod!( POWER_CLOCK, 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! { // PDM PDM, + + // Radio + RADIO, } impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); @@ -237,6 +240,8 @@ impl_saadc_input!(P0_29, ANALOG_INPUT5); impl_saadc_input!(P0_30, ANALOG_INPUT6); impl_saadc_input!(P0_31, ANALOG_INPUT7); +impl_radio!(RADIO, RADIO, RADIO); + embassy_hal_internal::interrupt_mod!( POWER_CLOCK, 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! { // QDEC QDEC, + + // Radio + RADIO, } impl_usb!(USBD, USBD, USBD); @@ -224,6 +227,8 @@ impl_ppi_channel!(PPI_CH29, 29 => static); impl_ppi_channel!(PPI_CH30, 30 => static); impl_ppi_channel!(PPI_CH31, 31 => static); +impl_radio!(RADIO, RADIO, RADIO); + embassy_hal_internal::interrupt_mod!( POWER_CLOCK, 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! { // PDM PDM, + + // Radio + RADIO, } impl_uarte!(UARTE0, UARTE0, UARTE0_UART0); @@ -264,6 +267,8 @@ impl_saadc_input!(P0_31, ANALOG_INPUT7); impl_i2s!(I2S, I2S, I2S); +impl_radio!(RADIO, RADIO, RADIO); + embassy_hal_internal::interrupt_mod!( POWER_CLOCK, 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! { P1_13, P1_14, P1_15, + + // Radio + RADIO, } impl_uarte!(SERIAL0, UARTE0, SERIAL0); @@ -345,6 +348,8 @@ impl_ppi_channel!(PPI_CH29, 29 => configurable); impl_ppi_channel!(PPI_CH30, 30 => configurable); impl_ppi_channel!(PPI_CH31, 31 => configurable); +impl_radio!(RADIO, RADIO, RADIO); + embassy_hal_internal::interrupt_mod!( CLOCK_POWER, 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; pub mod gpiote; // TODO: tested on other chips -#[cfg(any(feature = "nrf52833", feature = "nrf52840"))] +#[cfg(not(any(feature = "nrf51", feature = "_nrf9160")))] pub mod radio; #[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; use embassy_hal_internal::drop::OnDrop; use embassy_hal_internal::{into_ref, PeripheralRef}; pub use pac::radio::mode::MODE_A as Mode; +#[cfg(not(feature = "nrf51"))] use pac::radio::pcnf0::PLEN_A as PreambleLength; use crate::interrupt::typelevel::Interrupt; @@ -84,6 +85,7 @@ impl<'d, T: Instance> Radio<'d, T> { // Ch map between 2400 MHZ .. 2500 MHz // All modes use this range + #[cfg(not(feature = "nrf51"))] r.frequency.write(|w| w.map().default()); // Configure shortcuts to simplify and speed up sending and receiving packets. @@ -121,10 +123,18 @@ impl<'d, T: Instance> Radio<'d, T> { let r = T::regs(); r.mode.write(|w| w.mode().variant(mode)); + #[cfg(not(feature = "nrf51"))] r.pcnf0.write(|w| { w.plen().variant(match mode { Mode::BLE_1MBIT => PreambleLength::_8BIT, Mode::BLE_2MBIT => PreambleLength::_16BIT, + #[cfg(any( + feature = "nrf52811", + feature = "nrf52820", + feature = "nrf52833", + feature = "nrf52840", + feature = "_nrf5340-net" + ))] Mode::BLE_LR125KBIT | Mode::BLE_LR500KBIT => PreambleLength::LONG_RANGE, _ => unimplemented!(), }) @@ -307,7 +317,11 @@ impl<'d, T: Instance> Radio<'d, T> { self.trigger_and_wait_end(move || { // Initialize the transmission // trace!("txen"); + + #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] r.tasks_txen.write(|w| w.tasks_txen().set_bit()); + #[cfg(any(feature = "nrf51", feature = "nrf52832"))] + r.tasks_txen.write(|w| unsafe { w.bits(1) }); }) .await; @@ -324,7 +338,10 @@ impl<'d, T: Instance> Radio<'d, T> { self.trigger_and_wait_end(move || { // Initialize the transmission // trace!("rxen"); + #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] r.tasks_rxen.write(|w| w.tasks_rxen().set_bit()); + #[cfg(any(feature = "nrf51", feature = "nrf52832"))] + r.tasks_rxen.write(|w| unsafe { w.bits(1) }); }) .await; @@ -346,10 +363,16 @@ impl<'d, T: Instance> Radio<'d, T> { r.intenclr.write(|w| w.end().clear()); r.events_end.reset(); + #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] r.tasks_stop.write(|w| w.tasks_stop().set_bit()); + #[cfg(any(feature = "nrf51", feature = "nrf52832"))] + r.tasks_stop.write(|w| unsafe { w.bits(1) }); // The docs don't explicitly mention any event to acknowledge the stop task + #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] while r.events_end.read().events_end().bit_is_clear() {} + #[cfg(any(feature = "nrf51", feature = "nrf52832"))] + while r.events_end.read().bits() == 0 {} trace!("radio drop: stopped"); }); @@ -370,7 +393,11 @@ impl<'d, T: Instance> Radio<'d, T> { // On poll check if interrupt happen poll_fn(|cx| { s.event_waker.register(cx.waker()); - if r.events_end.read().events_end().bit_is_set() { + #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] + let end_event = r.events_end.read().events_end().bit_is_set(); + #[cfg(any(feature = "nrf51", feature = "nrf52832"))] + let end_event = r.events_end.read().bits() == 1; + if end_event { // trace!("radio:end"); return core::task::Poll::Ready(()); } @@ -394,10 +421,16 @@ impl<'d, T: Instance> Radio<'d, T> { if self.state() != RadioState::DISABLED { trace!("radio:disable"); // Trigger the disable task + #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] r.tasks_disable.write(|w| w.tasks_disable().set_bit()); + #[cfg(any(feature = "nrf51", feature = "nrf52832"))] + r.tasks_disable.write(|w| unsafe { w.bits(1) }); // Wait until the radio is disabled + #[cfg(not(any(feature = "nrf51", feature = "nrf52832")))] while r.events_disabled.read().events_disabled().bit_is_clear() {} + #[cfg(any(feature = "nrf51", feature = "nrf52832"))] + while r.events_disabled.read().bits() == 0 {} compiler_fence(Ordering::SeqCst); 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> { self.needs_enable = true; let tx_power: TxPower = match power { + #[cfg(not(feature = "_nrf5340-net"))] 8 => TxPower::POS8D_BM, + #[cfg(not(feature = "_nrf5340-net"))] 7 => TxPower::POS7D_BM, + #[cfg(not(feature = "_nrf5340-net"))] 6 => TxPower::POS6D_BM, + #[cfg(not(feature = "_nrf5340-net"))] 5 => TxPower::POS5D_BM, + #[cfg(not(feature = "_nrf5340-net"))] 4 => TxPower::POS4D_BM, + #[cfg(not(feature = "_nrf5340-net"))] 3 => TxPower::POS3D_BM, + #[cfg(not(feature = "_nrf5340-net"))] 2 => TxPower::POS2D_BM, 0 => TxPower::_0D_BM, + #[cfg(feature = "_nrf5340-net")] + -1 => TxPower::NEG1D_BM, + #[cfg(feature = "_nrf5340-net")] + -2 => TxPower::NEG2D_BM, + #[cfg(feature = "_nrf5340-net")] + -3 => TxPower::NEG3D_BM, -4 => TxPower::NEG4D_BM, + #[cfg(feature = "_nrf5340-net")] + -5 => TxPower::NEG5D_BM, + #[cfg(feature = "_nrf5340-net")] + -6 => TxPower::NEG6D_BM, + #[cfg(feature = "_nrf5340-net")] + -7 => TxPower::NEG7D_BM, -8 => TxPower::NEG8D_BM, -12 => TxPower::NEG12D_BM, -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 @@ /// Bluetooth Low Energy Radio driver. pub mod ble; -#[cfg(any(feature = "nrf52840", feature = "nrf52833", feature = "_nrf5340-net"))] +#[cfg(any( + feature = "nrf52820", + feature = "nrf52833", + feature = "nrf52840", + feature = "_nrf5340-net" +))] /// IEEE 802.15.4 pub mod ieee802154;