From 8ca0f947159b9d6586715cce124cde44cba94536 Mon Sep 17 00:00:00 2001 From: Kirill Mikhailov <62840029+playfulFence@users.noreply.github.com> Date: Mon, 28 Jul 2025 13:40:56 +0200 Subject: [PATCH] Get rid of `EspRadio` prefix in `esp-radio` structs (#3869) * get rid of `EspRadio` prefix in esp-radio structs * changelog entry + migration guide entry * reword entries * fmt run * Fix migration guide entry * edit the changelog entry to still reflect `esp-wifi` changes --- esp-radio/CHANGELOG.md | 3 +- esp-radio/MIGRATING-0.15.0.md | 7 ++++ esp-radio/src/ble/controller/mod.rs | 4 +- esp-radio/src/config.rs | 2 +- esp-radio/src/lib.rs | 10 ++--- esp-radio/src/wifi/mod.rs | 42 +++++++++---------- examples/src/bin/wifi_embassy_access_point.rs | 4 +- .../bin/wifi_embassy_access_point_with_sta.rs | 4 +- examples/src/bin/wifi_embassy_bench.rs | 4 +- examples/src/bin/wifi_embassy_ble.rs | 4 +- examples/src/bin/wifi_embassy_dhcp.rs | 4 +- examples/src/bin/wifi_embassy_esp_now.rs | 4 +- .../src/bin/wifi_embassy_esp_now_duplex.rs | 4 +- 13 files changed, 51 insertions(+), 45 deletions(-) diff --git a/esp-radio/CHANGELOG.md b/esp-radio/CHANGELOG.md index 6d77ae537..e78c35851 100644 --- a/esp-radio/CHANGELOG.md +++ b/esp-radio/CHANGELOG.md @@ -16,7 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `esp_wifi::init` no longer needs an `RNG` driver. (#3829) - The `builtin-scheduler` feature has been removed. Your project will have to specify a task scheduler. (#3855) -- Rename `esp-wifi` to `esp-radio`. (#3858) +- `esp-wifi` has been renamed to `esp-radio`. (#3858) +- Removed `EspWifi` prefix from structs in the package codebase. (#3869) ### Fixed diff --git a/esp-radio/MIGRATING-0.15.0.md b/esp-radio/MIGRATING-0.15.0.md index 5eed18263..1f8587ff9 100644 --- a/esp-radio/MIGRATING-0.15.0.md +++ b/esp-radio/MIGRATING-0.15.0.md @@ -23,3 +23,10 @@ Furthermore, `esp_wifi::init` no longer requires `RNG` or a timer. - esp-wifi = "0.15.0" + esp-radio = "{{currentVersion}}" ``` + +## `EspWifi` prefix has been removed + +```diff +- use esp_wifi::EspWifiController; ++ use esp_radio::Controller; +``` diff --git a/esp-radio/src/ble/controller/mod.rs b/esp-radio/src/ble/controller/mod.rs index c7e47e5c9..f94033473 100644 --- a/esp-radio/src/ble/controller/mod.rs +++ b/esp-radio/src/ble/controller/mod.rs @@ -1,7 +1,7 @@ use embedded_io::{Error, ErrorType, Read, Write}; use super::{read_hci, read_next, send_hci}; -use crate::EspRadioController; +use crate::Controller; /// A blocking HCI connector pub struct BleConnector<'d> { @@ -16,7 +16,7 @@ impl Drop for BleConnector<'_> { impl<'d> BleConnector<'d> { pub fn new( - _init: &'d EspRadioController<'d>, + _init: &'d Controller<'d>, device: crate::hal::peripherals::BT<'d>, ) -> BleConnector<'d> { crate::ble::ble_init(); diff --git a/esp-radio/src/config.rs b/esp-radio/src/config.rs index f0bd1c148..937280dc2 100644 --- a/esp-radio/src/config.rs +++ b/esp-radio/src/config.rs @@ -2,7 +2,7 @@ #[cfg_attr(feature = "defmt", derive(defmt::Format))] /// Tunable parameters for the WiFi driver #[allow(unused)] // currently there are no ble tunables -pub(crate) struct EspRadioConfig { +pub(crate) struct Config { pub(crate) rx_queue_size: usize, pub(crate) tx_queue_size: usize, pub(crate) static_rx_buf_num: usize, diff --git a/esp-radio/src/lib.rs b/esp-radio/src/lib.rs index 4b43c7797..73a547c96 100644 --- a/esp-radio/src/lib.rs +++ b/esp-radio/src/lib.rs @@ -170,7 +170,7 @@ const _: () = { }; }; -pub(crate) const CONFIG: config::EspRadioConfig = config::EspRadioConfig { +pub(crate) const CONFIG: config::Config = config::Config { rx_queue_size: esp_config_int!(usize, "ESP_RADIO_CONFIG_RX_QUEUE_SIZE"), tx_queue_size: esp_config_int!(usize, "ESP_RADIO_CONFIG_TX_QUEUE_SIZE"), static_rx_buf_num: esp_config_int!(usize, "ESP_RADIO_CONFIG_STATIC_RX_BUF_NUM"), @@ -197,11 +197,11 @@ pub(crate) const CONFIG: config::EspRadioConfig = config::EspRadioConfig { #[derive(Debug, PartialEq, PartialOrd)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] -pub struct EspRadioController<'d> { +pub struct Controller<'d> { _inner: PhantomData<&'d ()>, } -impl Drop for EspRadioController<'_> { +impl Drop for Controller<'_> { fn drop(&mut self) { // Disable coexistence #[cfg(coex)] @@ -220,7 +220,7 @@ impl Drop for EspRadioController<'_> { /// Initialize for using WiFi and or BLE. /// /// Make sure to **not** call this function while interrupts are disabled. -pub fn init<'d>() -> Result, InitializationError> { +pub fn init<'d>() -> Result, InitializationError> { if crate::is_interrupts_disabled() { return Err(InitializationError::InterruptsDisabled); } @@ -257,7 +257,7 @@ pub fn init<'d>() -> Result, InitializationError> { error => return Err(InitializationError::General(error)), } - Ok(EspRadioController { + Ok(Controller { _inner: PhantomData, }) } diff --git a/esp-radio/src/wifi/mod.rs b/esp-radio/src/wifi/mod.rs index 7d375fb5c..10b000b45 100644 --- a/esp-radio/src/wifi/mod.rs +++ b/esp-radio/src/wifi/mod.rs @@ -62,12 +62,12 @@ use smoltcp::phy::{Device, DeviceCapabilities, RxToken, TxToken}; pub use state::*; use crate::{ - EspRadioController, + Controller, common_adapter::*, config::PowerSaveMode, esp_wifi_result, hal::ram, - wifi::private::EspRadioPacketBuffer, + wifi::private::PacketBuffer, }; const MTU: usize = crate::CONFIG.mtu; @@ -1148,11 +1148,9 @@ impl CsiConfig { const RX_QUEUE_SIZE: usize = crate::CONFIG.rx_queue_size; const TX_QUEUE_SIZE: usize = crate::CONFIG.tx_queue_size; -pub(crate) static DATA_QUEUE_RX_AP: Locked> = - Locked::new(VecDeque::new()); +pub(crate) static DATA_QUEUE_RX_AP: Locked> = Locked::new(VecDeque::new()); -pub(crate) static DATA_QUEUE_RX_STA: Locked> = - Locked::new(VecDeque::new()); +pub(crate) static DATA_QUEUE_RX_STA: Locked> = Locked::new(VecDeque::new()); /// Common errors. #[derive(Debug, Clone, Copy)] @@ -1452,10 +1450,10 @@ unsafe extern "C" fn recv_cb_sta( len: u16, eb: *mut c_types::c_void, ) -> esp_err_t { - let packet = EspRadioPacketBuffer { buffer, len, eb }; + let packet = PacketBuffer { buffer, len, eb }; // We must handle the result outside of the lock because - // EspRadioPacketBuffer::drop must not be called in a critical section. - // Dropping an EspRadioPacketBuffer will call `esp_wifi_internal_free_rx_buffer` + // PacketBuffer::drop must not be called in a critical section. + // Dropping an PacketBuffer will call `esp_wifi_internal_free_rx_buffer` // which will try to lock an internal mutex. If the mutex is already taken, // the function will try to trigger a context switch, which will fail if we // are in an interrupt-free context. @@ -1483,10 +1481,10 @@ unsafe extern "C" fn recv_cb_ap( len: u16, eb: *mut c_types::c_void, ) -> esp_err_t { - let packet = EspRadioPacketBuffer { buffer, len, eb }; + let packet = PacketBuffer { buffer, len, eb }; // We must handle the result outside of the critical section because - // EspRadioPacketBuffer::drop must not be called in a critical section. - // Dropping an EspRadioPacketBuffer will call `esp_wifi_internal_free_rx_buffer` + // PacketBuffer::drop must not be called in a critical section. + // Dropping an PacketBuffer will call `esp_wifi_internal_free_rx_buffer` // which will try to lock an internal mutex. If the mutex is already taken, // the function will try to trigger a context switch, which will fail if we // are in an interrupt-free context. @@ -1708,27 +1706,27 @@ mod private { #[cfg_attr(feature = "defmt", derive(defmt::Format))] /// Take care not to drop this while in a critical section. /// - /// Dropping an EspRadioPacketBuffer will call + /// Dropping an PacketBuffer will call /// `esp_wifi_internal_free_rx_buffer` which will try to lock an /// internal mutex. If the mutex is already taken, the function will try /// to trigger a context switch, which will fail if we are in a critical /// section. - pub struct EspRadioPacketBuffer { + pub struct PacketBuffer { pub(crate) buffer: *mut c_types::c_void, pub(crate) len: u16, pub(crate) eb: *mut c_types::c_void, } - unsafe impl Send for EspRadioPacketBuffer {} + unsafe impl Send for PacketBuffer {} - impl Drop for EspRadioPacketBuffer { + impl Drop for PacketBuffer { fn drop(&mut self) { - trace!("Dropping EspRadioPacketBuffer, freeing memory"); + trace!("Dropping PacketBuffer, freeing memory"); unsafe { esp_wifi_internal_free_rx_buffer(self.eb) }; } } - impl EspRadioPacketBuffer { + impl PacketBuffer { pub fn as_slice_mut(&mut self) -> &mut [u8] { unsafe { core::slice::from_raw_parts_mut(self.buffer as *mut u8, self.len as usize) } } @@ -1758,7 +1756,7 @@ impl WifiDeviceMode { } } - fn data_queue_rx(&self) -> &'static Locked> { + fn data_queue_rx(&self) -> &'static Locked> { match self { WifiDeviceMode::Sta => &DATA_QUEUE_RX_STA, WifiDeviceMode::Ap => &DATA_QUEUE_RX_AP, @@ -2213,8 +2211,8 @@ impl WifiRxToken { }); // We handle the received data outside of the lock because - // EspRadioPacketBuffer::drop must not be called in a critical section. - // Dropping an EspRadioPacketBuffer will call `esp_wifi_internal_free_rx_buffer` + // PacketBuffer::drop must not be called in a critical section. + // Dropping an PacketBuffer will call `esp_wifi_internal_free_rx_buffer` // which will try to lock an internal mutex. If the mutex is already // taken, the function will try to trigger a context switch, which will // fail if we are in an interrupt-free context. @@ -2652,7 +2650,7 @@ pub struct Interfaces<'d> { /// Make sure to **not** call this function while interrupts are disabled, or IEEE 802.15.4 is /// currently in use. pub fn new<'d>( - _inited: &'d EspRadioController<'d>, + _inited: &'d Controller<'d>, _device: crate::hal::peripherals::WIFI<'d>, ) -> Result<(WifiController<'d>, Interfaces<'d>), WifiError> { if crate::is_interrupts_disabled() { diff --git a/examples/src/bin/wifi_embassy_access_point.rs b/examples/src/bin/wifi_embassy_access_point.rs index 4aa9bb4c4..edb1b9f10 100644 --- a/examples/src/bin/wifi_embassy_access_point.rs +++ b/examples/src/bin/wifi_embassy_access_point.rs @@ -34,7 +34,7 @@ use esp_backtrace as _; use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_radio::{ - EspRadioController, + Controller, wifi::{ AccessPointConfiguration, Configuration, @@ -70,7 +70,7 @@ async fn main(spawner: Spawner) -> ! { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_radio_preempt_baremetal::init(timg0.timer0); - let esp_wifi_ctrl = &*mk_static!(EspRadioController<'static>, esp_radio::init().unwrap()); + let esp_wifi_ctrl = &*mk_static!(Controller<'static>, esp_radio::init().unwrap()); let (controller, interfaces) = esp_radio::wifi::new(&esp_wifi_ctrl, peripherals.WIFI).unwrap(); diff --git a/examples/src/bin/wifi_embassy_access_point_with_sta.rs b/examples/src/bin/wifi_embassy_access_point_with_sta.rs index 745f98a94..f42aadf71 100644 --- a/examples/src/bin/wifi_embassy_access_point_with_sta.rs +++ b/examples/src/bin/wifi_embassy_access_point_with_sta.rs @@ -40,7 +40,7 @@ use esp_backtrace as _; use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup}; use esp_println::{print, println}; use esp_radio::{ - EspRadioController, + Controller, wifi::{ AccessPointConfiguration, ClientConfiguration, @@ -78,7 +78,7 @@ async fn main(spawner: Spawner) -> ! { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_radio_preempt_baremetal::init(timg0.timer0); - let esp_wifi_ctrl = &*mk_static!(EspRadioController<'static>, esp_radio::init().unwrap()); + let esp_wifi_ctrl = &*mk_static!(Controller<'static>, esp_radio::init().unwrap()); let (mut controller, interfaces) = esp_radio::wifi::new(&esp_wifi_ctrl, peripherals.WIFI).unwrap(); diff --git a/examples/src/bin/wifi_embassy_bench.rs b/examples/src/bin/wifi_embassy_bench.rs index adf3f7b0b..6720bf5e0 100644 --- a/examples/src/bin/wifi_embassy_bench.rs +++ b/examples/src/bin/wifi_embassy_bench.rs @@ -31,7 +31,7 @@ use esp_backtrace as _; use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_radio::{ - EspRadioController, + Controller, wifi::{ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiState}, }; @@ -78,7 +78,7 @@ async fn main(spawner: Spawner) -> ! { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_radio_preempt_baremetal::init(timg0.timer0); - let esp_wifi_ctrl = &*mk_static!(EspRadioController<'static>, esp_radio::init().unwrap()); + let esp_wifi_ctrl = &*mk_static!(Controller<'static>, esp_radio::init().unwrap()); let (mut controller, interfaces) = esp_radio::wifi::new(&esp_wifi_ctrl, peripherals.WIFI).unwrap(); diff --git a/examples/src/bin/wifi_embassy_ble.rs b/examples/src/bin/wifi_embassy_ble.rs index 07e3220fa..17cbb8db8 100644 --- a/examples/src/bin/wifi_embassy_ble.rs +++ b/examples/src/bin/wifi_embassy_ble.rs @@ -37,7 +37,7 @@ use esp_hal::{ timer::timg::TimerGroup, }; use esp_println::println; -use esp_radio::{EspRadioController, ble::controller::BleConnector}; +use esp_radio::{Controller, ble::controller::BleConnector}; esp_bootloader_esp_idf::esp_app_desc!(); @@ -62,7 +62,7 @@ async fn main(_spawner: Spawner) -> ! { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_radio_preempt_baremetal::init(timg0.timer0); - let esp_wifi_ctrl = &*mk_static!(EspRadioController<'static>, esp_radio::init().unwrap()); + let esp_wifi_ctrl = &*mk_static!(Controller<'static>, esp_radio::init().unwrap()); let config = InputConfig::default().with_pull(Pull::Down); cfg_if::cfg_if! { diff --git a/examples/src/bin/wifi_embassy_dhcp.rs b/examples/src/bin/wifi_embassy_dhcp.rs index e9f6e51de..280856281 100644 --- a/examples/src/bin/wifi_embassy_dhcp.rs +++ b/examples/src/bin/wifi_embassy_dhcp.rs @@ -24,7 +24,7 @@ use esp_backtrace as _; use esp_hal::{clock::CpuClock, rng::Rng, timer::timg::TimerGroup}; use esp_println::println; use esp_radio::{ - EspRadioController, + Controller, wifi::{ClientConfiguration, Configuration, WifiController, WifiDevice, WifiEvent, WifiState}, }; @@ -54,7 +54,7 @@ async fn main(spawner: Spawner) -> ! { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_radio_preempt_baremetal::init(timg0.timer0); - let esp_wifi_ctrl = &*mk_static!(EspRadioController<'static>, esp_radio::init().unwrap()); + let esp_wifi_ctrl = &*mk_static!(Controller<'static>, esp_radio::init().unwrap()); let (controller, interfaces) = esp_radio::wifi::new(&esp_wifi_ctrl, peripherals.WIFI).unwrap(); diff --git a/examples/src/bin/wifi_embassy_esp_now.rs b/examples/src/bin/wifi_embassy_esp_now.rs index 752488a7b..443d150ba 100644 --- a/examples/src/bin/wifi_embassy_esp_now.rs +++ b/examples/src/bin/wifi_embassy_esp_now.rs @@ -18,7 +18,7 @@ use esp_backtrace as _; use esp_hal::{clock::CpuClock, timer::timg::TimerGroup}; use esp_println::println; use esp_radio::{ - EspRadioController, + Controller, esp_now::{BROADCAST_ADDRESS, PeerInfo}, }; @@ -45,7 +45,7 @@ async fn main(_spawner: Spawner) -> ! { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_radio_preempt_baremetal::init(timg0.timer0); - let esp_wifi_ctrl = &*mk_static!(EspRadioController<'static>, esp_radio::init().unwrap()); + let esp_wifi_ctrl = &*mk_static!(Controller<'static>, esp_radio::init().unwrap()); let wifi = peripherals.WIFI; let (mut controller, interfaces) = esp_radio::wifi::new(&esp_wifi_ctrl, wifi).unwrap(); diff --git a/examples/src/bin/wifi_embassy_esp_now_duplex.rs b/examples/src/bin/wifi_embassy_esp_now_duplex.rs index 396a6110a..ced263455 100644 --- a/examples/src/bin/wifi_embassy_esp_now_duplex.rs +++ b/examples/src/bin/wifi_embassy_esp_now_duplex.rs @@ -19,7 +19,7 @@ use esp_backtrace as _; use esp_hal::{clock::CpuClock, timer::timg::TimerGroup}; use esp_println::println; use esp_radio::{ - EspRadioController, + Controller, esp_now::{BROADCAST_ADDRESS, EspNowManager, EspNowReceiver, EspNowSender, PeerInfo}, }; @@ -46,7 +46,7 @@ async fn main(spawner: Spawner) -> ! { let timg0 = TimerGroup::new(peripherals.TIMG0); esp_radio_preempt_baremetal::init(timg0.timer0); - let esp_wifi_ctrl = &*mk_static!(EspRadioController<'static>, esp_radio::init().unwrap()); + let esp_wifi_ctrl = &*mk_static!(Controller<'static>, esp_radio::init().unwrap()); let wifi = peripherals.WIFI; let (mut controller, interfaces) = esp_radio::wifi::new(&esp_wifi_ctrl, wifi).unwrap();