diff --git a/esp-hal-common/src/prelude.rs b/esp-hal-common/src/prelude.rs index 6030b6c0632..78ce91ef50c 100644 --- a/esp-hal-common/src/prelude.rs +++ b/esp-hal-common/src/prelude.rs @@ -60,8 +60,6 @@ pub use crate::ledc::{ }, timer::{TimerHW as _esp_hal_ledc_timer_TimerHW, TimerIFace as _esp_hal_ledc_timer_TimerIFace}, }; -#[cfg(radio)] -pub use crate::radio::RadioExt as _esp_hal_RadioExt; #[cfg(any(esp32, esp32s2, esp32s3))] pub use crate::spi::master::dma::WithDmaSpi3 as _esp_hal_spi_dma_WithDmaSpi3; #[cfg(any(spi0, spi1, spi2, spi3))] diff --git a/esp-hal-common/src/radio.rs b/esp-hal-common/src/radio.rs index ece23d02749..4e5a5405a53 100644 --- a/esp-hal-common/src/radio.rs +++ b/esp-hal-common/src/radio.rs @@ -1,45 +1,26 @@ //! # Wireless communication peripheral implementations //! //! ## Overview -//! The radio module provides implementations for different wireless -//! communication peripherals, including WiFi, Bluetooth and -//! IEEE 802.15.4 Low Rate wireless personal area radio. //! -//! In addition to the structures defined in this module, the module also -//! defines the `RadioExt` trait, which provides a `split` method. This method -//! allows splitting the general `Radio` peripheral into its individual -//! components. -//! -//! Additionally, the module includes implementation blocks for each wireless -//! communication peripheral, providing necessary functions and traits for each -//! peripheral. -pub trait RadioExt { - type Components; - - fn split(self) -> Self::Components; -} +//! The radio module provides the individual peripheral structs for different +//! wireless communication peripherals, collectively represented by the virtual +//! `RADIO` peripheral. This includes Wi-Fi, Bluetooth, and IEEE 802.15.4 +//! low-rate radios, depending on the device. -/// WiFi radio +/// Wi-Fi radio +#[cfg(wifi)] pub struct Wifi { _private: (), } -/// Bluetooth radio -pub struct Bluetooth { - _private: (), -} - -/// IEEE 802.15.4 Low rate wireless personal area radio -pub struct LowRate { - _private: (), -} - +#[cfg(wifi)] impl Wifi { pub const unsafe fn steal() -> Self { Self { _private: () } } } +#[cfg(wifi)] impl crate::peripheral::Peripheral for Wifi { type P = Self; @@ -48,14 +29,23 @@ impl crate::peripheral::Peripheral for Wifi { } } +#[cfg(wifi)] impl crate::peripheral::sealed::Sealed for Wifi {} +/// Bluetooth radio +#[cfg(bt)] +pub struct Bluetooth { + _private: (), +} + +#[cfg(bt)] impl Bluetooth { pub const unsafe fn steal() -> Self { Self { _private: () } } } +#[cfg(bt)] impl crate::peripheral::Peripheral for Bluetooth { type P = Self; @@ -64,14 +54,23 @@ impl crate::peripheral::Peripheral for Bluetooth { } } +#[cfg(bt)] impl crate::peripheral::sealed::Sealed for Bluetooth {} +/// IEEE 802.15.4 low-rate radio +#[cfg(ieee802154)] +pub struct LowRate { + _private: (), +} + +#[cfg(ieee802154)] impl LowRate { pub const unsafe fn steal() -> Self { Self { _private: () } } } +#[cfg(ieee802154)] impl crate::peripheral::Peripheral for LowRate { type P = Self; @@ -80,44 +79,40 @@ impl crate::peripheral::Peripheral for LowRate { } } +#[cfg(ieee802154)] impl crate::peripheral::sealed::Sealed for LowRate {} +// Since each device has a different set of wireless radios available, we need +// per-device implementations of the `split` funciton on the `RADIO` peripheral +// singleton. cfg_if::cfg_if! { if #[cfg(all(bt, ieee802154, wifi))] { - impl RadioExt for crate::peripherals::RADIO { - type Components = (Wifi, Bluetooth, LowRate); - - fn split(self) -> Self::Components { + impl crate::peripherals::RADIO { + pub fn split(self) -> (Wifi, Bluetooth, LowRate) { unsafe { (Wifi::steal(), Bluetooth::steal(), LowRate::steal()) } } } } else if #[cfg(all(bt, ieee802154))] { - impl RadioExt for crate::peripherals::RADIO { - type Components = (Bluetooth, LowRate); - - fn split(self) -> Self::Components { + impl crate::peripherals::RADIO { + pub fn split(self) -> (Bluetooth, LowRate) { unsafe { (Bluetooth::steal(), LowRate::steal()) } } } } else if #[cfg(all(bt, wifi))] { - impl RadioExt for crate::peripherals::RADIO { - type Components = (Wifi, Bluetooth); - - fn split(self) -> Self::Components { + impl crate::peripherals::RADIO { + pub fn split(self) -> (Wifi, Bluetooth) { unsafe { (Wifi::steal(), Bluetooth::steal()) } } } } else if #[cfg(wifi)] { - impl RadioExt for crate::peripherals::RADIO { - type Components = Wifi; - - fn split(self) -> Self::Components { + impl crate::peripherals::RADIO { + pub fn split(self) -> Wifi { unsafe { Wifi::steal() }