From 62a174fd06f2294aac4583b514146169bb2129da Mon Sep 17 00:00:00 2001 From: Jesse Braham Date: Fri, 20 Oct 2023 03:11:32 -0700 Subject: [PATCH] Replace the `radio` module with peripheral singleton structs (#852) * Replace the `radio` module with peripheral singleton structs * Update `CHANGELOG.md` --- CHANGELOG.md | 1 + esp-hal-common/devices/esp32/device.toml | 1 - esp-hal-common/devices/esp32c2/device.toml | 1 - esp-hal-common/devices/esp32c3/device.toml | 1 - esp-hal-common/devices/esp32c6/device.toml | 1 - esp-hal-common/devices/esp32h2/device.toml | 1 - esp-hal-common/devices/esp32s2/device.toml | 1 - esp-hal-common/devices/esp32s3/device.toml | 1 - esp-hal-common/src/lib.rs | 2 - esp-hal-common/src/prelude.rs | 2 - esp-hal-common/src/radio.rs | 127 ------------------ esp-hal-common/src/soc/esp32/peripherals.rs | 9 +- esp-hal-common/src/soc/esp32c2/peripherals.rs | 5 +- esp-hal-common/src/soc/esp32c3/peripherals.rs | 5 +- esp-hal-common/src/soc/esp32c6/peripherals.rs | 10 +- esp-hal-common/src/soc/esp32h2/peripherals.rs | 9 +- esp-hal-common/src/soc/esp32s2/peripherals.rs | 4 +- esp-hal-common/src/soc/esp32s3/peripherals.rs | 5 +- 18 files changed, 35 insertions(+), 151 deletions(-) delete mode 100644 esp-hal-common/src/radio.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index d1d916e9761..8f0e59d39a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - The `spi` and `spi_slave` modules have been refactored into the `spi`, `spi::master`, and `spi::slave` modules (#843) - The `WithDmaSpi2`/`WithDmaSpi3` structs are no longer generic around the inner peripheral type (#853) - The `SarAdcExt`/`SensExt` traits are now collectively named `AnalogExt` instead (#857) +- Replace the `radio` module with peripheral singleton structs (#852) ## [0.12.0] diff --git a/esp-hal-common/devices/esp32/device.toml b/esp-hal-common/devices/esp32/device.toml index 1836bd9ac9d..5119a8f660b 100644 --- a/esp-hal-common/devices/esp32/device.toml +++ b/esp-hal-common/devices/esp32/device.toml @@ -54,7 +54,6 @@ symbols = [ "adc", "dac", "pdma", - "radio", "phy", "bt", "wifi", diff --git a/esp-hal-common/devices/esp32c2/device.toml b/esp-hal-common/devices/esp32c2/device.toml index e859184fbc1..a9db07055d2 100644 --- a/esp-hal-common/devices/esp32c2/device.toml +++ b/esp-hal-common/devices/esp32c2/device.toml @@ -36,7 +36,6 @@ symbols = [ "adc", "assist_debug_sp_monitor", "gdma", - "radio", "phy", "bt", "wifi", diff --git a/esp-hal-common/devices/esp32c3/device.toml b/esp-hal-common/devices/esp32c3/device.toml index 13b5cea10fe..422f5d8b396 100644 --- a/esp-hal-common/devices/esp32c3/device.toml +++ b/esp-hal-common/devices/esp32c3/device.toml @@ -48,7 +48,6 @@ symbols = [ "assist_debug_sp_monitor", "assist_debug_region_monitor", "gdma", - "radio", "phy", "bt", "wifi", diff --git a/esp-hal-common/devices/esp32c6/device.toml b/esp-hal-common/devices/esp32c6/device.toml index fc6bc7e3628..42dd1ef7e51 100644 --- a/esp-hal-common/devices/esp32c6/device.toml +++ b/esp-hal-common/devices/esp32c6/device.toml @@ -76,7 +76,6 @@ symbols = [ "gdma", "large_intr_status", "plic", - "radio", "phy", "bt", "wifi", diff --git a/esp-hal-common/devices/esp32h2/device.toml b/esp-hal-common/devices/esp32h2/device.toml index 3bc52035745..d31cc23e7cb 100644 --- a/esp-hal-common/devices/esp32h2/device.toml +++ b/esp-hal-common/devices/esp32h2/device.toml @@ -67,7 +67,6 @@ symbols = [ "assist_debug_region_monitor", "gdma", "plic", - "radio", "phy", "bt", "ieee802154", diff --git a/esp-hal-common/devices/esp32s2/device.toml b/esp-hal-common/devices/esp32s2/device.toml index e39ee43ac32..17e76599db5 100644 --- a/esp-hal-common/devices/esp32s2/device.toml +++ b/esp-hal-common/devices/esp32s2/device.toml @@ -52,7 +52,6 @@ symbols = [ "adc", "dac", "pdma", - "radio", "phy", "wifi", "psram", diff --git a/esp-hal-common/devices/esp32s3/device.toml b/esp-hal-common/devices/esp32s3/device.toml index 7e51bda191b..aa45c719f3c 100644 --- a/esp-hal-common/devices/esp32s3/device.toml +++ b/esp-hal-common/devices/esp32s3/device.toml @@ -63,7 +63,6 @@ symbols = [ "adc", "assist_debug_region_monitor", "gdma", - "radio", "phy", "bt", "wifi", diff --git a/esp-hal-common/src/lib.rs b/esp-hal-common/src/lib.rs index 3172477f2ea..2fd7da9b731 100644 --- a/esp-hal-common/src/lib.rs +++ b/esp-hal-common/src/lib.rs @@ -118,8 +118,6 @@ pub mod parl_io; pub mod pcnt; pub mod peripheral; pub mod prelude; -#[cfg(radio)] -pub mod radio; #[cfg(any(hmac, sha))] mod reg_access; pub mod reset; diff --git a/esp-hal-common/src/prelude.rs b/esp-hal-common/src/prelude.rs index b4ec500b3c3..16784394578 100644 --- a/esp-hal-common/src/prelude.rs +++ b/esp-hal-common/src/prelude.rs @@ -58,8 +58,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(spi3)] 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 deleted file mode 100644 index ece23d02749..00000000000 --- a/esp-hal-common/src/radio.rs +++ /dev/null @@ -1,127 +0,0 @@ -//! # 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; -} - -/// WiFi radio -pub struct Wifi { - _private: (), -} - -/// Bluetooth radio -pub struct Bluetooth { - _private: (), -} - -/// IEEE 802.15.4 Low rate wireless personal area radio -pub struct LowRate { - _private: (), -} - -impl Wifi { - pub const unsafe fn steal() -> Self { - Self { _private: () } - } -} - -impl crate::peripheral::Peripheral for Wifi { - type P = Self; - - unsafe fn clone_unchecked(&mut self) -> Self::P { - Self::steal() - } -} - -impl crate::peripheral::sealed::Sealed for Wifi {} - -impl Bluetooth { - pub const unsafe fn steal() -> Self { - Self { _private: () } - } -} - -impl crate::peripheral::Peripheral for Bluetooth { - type P = Self; - - unsafe fn clone_unchecked(&mut self) -> Self::P { - Self::steal() - } -} - -impl crate::peripheral::sealed::Sealed for Bluetooth {} - -impl LowRate { - pub const unsafe fn steal() -> Self { - Self { _private: () } - } -} - -impl crate::peripheral::Peripheral for LowRate { - type P = Self; - - unsafe fn clone_unchecked(&mut self) -> Self::P { - Self::steal() - } -} - -impl crate::peripheral::sealed::Sealed for LowRate {} - -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 { - 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 { - 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 { - unsafe { - (Wifi::steal(), Bluetooth::steal()) - } - } - } - } else if #[cfg(wifi)] { - impl RadioExt for crate::peripherals::RADIO { - type Components = Wifi; - - fn split(self) -> Self::Components { - unsafe { - Wifi::steal() - } - } - } - } -} diff --git a/esp-hal-common/src/soc/esp32/peripherals.rs b/esp-hal-common/src/soc/esp32/peripherals.rs index f7f857006e5..5f334ce5afa 100644 --- a/esp-hal-common/src/soc/esp32/peripherals.rs +++ b/esp-hal-common/src/soc/esp32/peripherals.rs @@ -32,8 +32,6 @@ crate::peripherals! { AES <= AES, APB_CTRL <= APB_CTRL, BB <= BB, - // SYSTEM is derived from DPORT - SYSTEM <= DPORT, EFUSE <= EFUSE, FLASH_ENCRYPTION <= FLASH_ENCRYPTION, FRC_TIMER <= FRC_TIMER, @@ -65,6 +63,8 @@ crate::peripherals! { SPI1 <= SPI1, SPI2 <= SPI2, SPI3 <= SPI3, + // SYSTEM is derived from DPORT: + SYSTEM <= DPORT, TIMG0 <= TIMG0, TIMG1 <= TIMG1, TWAI0 <= TWAI0, @@ -73,6 +73,9 @@ crate::peripherals! { UART2 <= UART2, UHCI0 <= UHCI0, UHCI1 <= UHCI1, - RADIO <= virtual, + + // Virtual peripherals: + BT <= virtual, PSRAM <= virtual, + WIFI <= virtual, } diff --git a/esp-hal-common/src/soc/esp32c2/peripherals.rs b/esp-hal-common/src/soc/esp32c2/peripherals.rs index 116b17d9990..72da6e943a0 100644 --- a/esp-hal-common/src/soc/esp32c2/peripherals.rs +++ b/esp-hal-common/src/soc/esp32c2/peripherals.rs @@ -53,5 +53,8 @@ crate::peripherals! { UART0 <= UART0, UART1 <= UART1, XTS_AES <= XTS_AES, - RADIO <= virtual + + // Virtual peripherals: + BT <= virtual, + WIFI <= virtual, } diff --git a/esp-hal-common/src/soc/esp32c3/peripherals.rs b/esp-hal-common/src/soc/esp32c3/peripherals.rs index f68379b1914..88649eb18a9 100644 --- a/esp-hal-common/src/soc/esp32c3/peripherals.rs +++ b/esp-hal-common/src/soc/esp32c3/peripherals.rs @@ -64,5 +64,8 @@ crate::peripherals! { UHCI1 <= UHCI1, USB_DEVICE <= USB_DEVICE, XTS_AES <= XTS_AES, - RADIO <= virtual + + // Virtual peripherals: + BT <= virtual, + WIFI <= virtual, } diff --git a/esp-hal-common/src/soc/esp32c6/peripherals.rs b/esp-hal-common/src/soc/esp32c6/peripherals.rs index b51aea9c55c..898b72446f2 100644 --- a/esp-hal-common/src/soc/esp32c6/peripherals.rs +++ b/esp-hal-common/src/soc/esp32c6/peripherals.rs @@ -69,8 +69,6 @@ crate::peripherals! { PARL_IO <= PARL_IO, PAU <= PAU, PCNT <= PCNT, - // SYSTEM is derived from PCR - SYSTEM <= PCR, PMU <= PMU, RMT <= RMT, RNG <= RNG, @@ -81,6 +79,8 @@ crate::peripherals! { SPI0 <= SPI0, SPI1 <= SPI1, SPI2 <= SPI2, + // SYSTEM is derived from PCR + SYSTEM <= PCR, SYSTIMER <= SYSTIMER, TEE <= TEE, TIMG0 <= TIMG0, @@ -92,6 +92,10 @@ crate::peripherals! { UART1 <= UART1, UHCI0 <= UHCI0, USB_DEVICE <= USB_DEVICE, - RADIO <= virtual, + + // Virtual peripherals: + BT <= virtual, + IEEE802154 <= virtual, LP_CORE <= virtual, + WIFI <= virtual, } diff --git a/esp-hal-common/src/soc/esp32h2/peripherals.rs b/esp-hal-common/src/soc/esp32h2/peripherals.rs index e8efe4a7803..714958914f5 100644 --- a/esp-hal-common/src/soc/esp32h2/peripherals.rs +++ b/esp-hal-common/src/soc/esp32h2/peripherals.rs @@ -62,8 +62,6 @@ crate::peripherals! { PARL_IO <= PARL_IO, PAU <= PAU, PCNT <= PCNT, - // SYSTEM is derived from PCR - SYSTEM <= PCR, PMU <= PMU, RMT <= RMT, RNG <= RNG, @@ -73,6 +71,8 @@ crate::peripherals! { SPI0 <= SPI0, SPI1 <= SPI1, SPI2 <= SPI2, + // SYSTEM is derived from PCR: + SYSTEM <= PCR, SYSTIMER <= SYSTIMER, TEE <= TEE, TIMG0 <= TIMG0, @@ -83,5 +83,8 @@ crate::peripherals! { UART1 <= UART1, UHCI0 <= UHCI0, USB_DEVICE <= USB_DEVICE, - RADIO <= virtual, + + // Virtual peripherals: + BT <= virtual, + IEEE802154 <= virtual, } diff --git a/esp-hal-common/src/soc/esp32s2/peripherals.rs b/esp-hal-common/src/soc/esp32s2/peripherals.rs index e93d9e149b8..76443d034c0 100644 --- a/esp-hal-common/src/soc/esp32s2/peripherals.rs +++ b/esp-hal-common/src/soc/esp32s2/peripherals.rs @@ -71,7 +71,9 @@ crate::peripherals! { USB0 <= USB0, USB_WRAP <= USB_WRAP, XTS_AES <= XTS_AES, - RADIO <= virtual, + + // Virtual peripherals: PSRAM <= virtual, ULP_RISCV_CORE <= virtual, + WIFI <= virtual, } diff --git a/esp-hal-common/src/soc/esp32s3/peripherals.rs b/esp-hal-common/src/soc/esp32s3/peripherals.rs index 924a28ed2ad..846bef689b0 100644 --- a/esp-hal-common/src/soc/esp32s3/peripherals.rs +++ b/esp-hal-common/src/soc/esp32s3/peripherals.rs @@ -81,7 +81,10 @@ crate::peripherals! { USB_WRAP <= USB_WRAP, WCL <= WCL, XTS_AES <= XTS_AES, - RADIO <= virtual, + + // Virtual peripherals: + BT <= virtual, PSRAM <= virtual, ULP_RISCV_CORE <= virtual, + WIFI <= virtual, }