From cef8612c4dde272db61722d3b71a1059b6bf2b97 Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Thu, 31 Oct 2024 12:19:59 +0100 Subject: [PATCH] feat: Cfg CSI stuff when CSI is disabled instead of panicing --- esp-wifi/src/esp_now/mod.rs | 5 +---- esp-wifi/src/wifi/mod.rs | 28 +++++++++++++++++----------- examples/src/bin/wifi_csi.rs | 4 +--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/esp-wifi/src/esp_now/mod.rs b/esp-wifi/src/esp_now/mod.rs index 7c923515fad..49c8e257823 100644 --- a/esp-wifi/src/esp_now/mod.rs +++ b/esp-wifi/src/esp_now/mod.rs @@ -362,15 +362,12 @@ impl EspNowManager<'_> { } /// Set CSI configuration and register the receiving callback. + #[cfg(csi_enable)] pub fn set_csi( &mut self, mut csi: CsiConfig, cb: fn(crate::binary::include::wifi_csi_info_t), ) -> Result<(), WifiError> { - if !crate::CONFIG.csi_enable { - panic!("CSI is not enabled in the configuration"); - } - csi.apply_config()?; csi.set_receive_cb(cb)?; csi.set_csi(true)?; diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index 4377ba40b6f..c0f9b1da9d4 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -90,8 +90,10 @@ use crate::binary::{ esp_err_t, esp_interface_t_ESP_IF_WIFI_AP, esp_interface_t_ESP_IF_WIFI_STA, + esp_supplicant_deinit, esp_supplicant_init, esp_wifi_connect, + esp_wifi_deinit_internal, esp_wifi_disconnect, esp_wifi_get_mode, esp_wifi_init_internal, @@ -118,6 +120,8 @@ use crate::binary::{ wifi_config_t, wifi_country_policy_t_WIFI_COUNTRY_POLICY_MANUAL, wifi_country_t, + wifi_csi_acquire_config_t, + wifi_csi_config_t, wifi_init_config_t, wifi_interface_t, wifi_interface_t_WIFI_IF_AP, @@ -342,9 +346,11 @@ impl Default for ClientConfiguration { } #[allow(clippy::type_complexity)] +#[cfg(csi_enable)] static CSI_CB: Mutex>> = Mutex::new(RefCell::new(None)); +#[cfg(csi_enable)] unsafe extern "C" fn promiscuous_csi_rx_cb( _ctx: *mut crate::wifi::c_types::c_void, data: *mut crate::binary::include::wifi_csi_info_t, @@ -360,7 +366,7 @@ unsafe extern "C" fn promiscuous_csi_rx_cb( #[derive(Clone, PartialEq, Eq)] // https://github.com/esp-rs/esp-wifi-sys/blob/main/esp-wifi-sys/headers/local/esp_wifi_types_native.h#L94 /// Channel state information(CSI) configuration -#[cfg(not(esp32c6))] +#[cfg(all(not(esp32c6), csi_enable))] pub struct CsiConfig { /// Enable to receive legacy long training field(lltf) data. pub lltf_en: bool, @@ -387,7 +393,7 @@ pub struct CsiConfig { } #[derive(Clone, PartialEq, Eq)] -#[cfg(esp32c6)] +#[cfg(all(esp32c6, csi_enable))] // See https://github.com/esp-rs/esp-wifi-sys/blob/2a466d96fe8119d49852fc794aea0216b106ba7b/esp-wifi-sys/src/include/esp32c6.rs#L5702-L5705 pub struct CsiConfig { /// Enable to acquire CSI. @@ -418,6 +424,7 @@ pub struct CsiConfig { pub reserved: u32, } +#[cfg(csi_enable)] impl Default for CsiConfig { #[cfg(not(esp32c6))] fn default() -> Self { @@ -453,11 +460,12 @@ impl Default for CsiConfig { } } -impl From for crate::include::wifi_csi_config_t { +#[cfg(csi_enable)] +impl From for wifi_csi_config_t { fn from(config: CsiConfig) -> Self { #[cfg(not(esp32c6))] { - crate::include::wifi_csi_config_t { + wifi_csi_config_t { lltf_en: config.lltf_en, htltf_en: config.htltf_en, stbc_htltf2_en: config.stbc_htltf2_en, @@ -470,9 +478,9 @@ impl From for crate::include::wifi_csi_config_t { } #[cfg(esp32c6)] { - crate::include::wifi_csi_acquire_config_t { + wifi_csi_acquire_config_t { _bitfield_align_1: [0; 0], - _bitfield_1: crate::include::wifi_csi_acquire_config_t::new_bitfield_1( + _bitfield_1: wifi_csi_acquire_config_t::new_bitfield_1( config.enable, config.acquire_csi_legacy, config.acquire_csi_ht20, @@ -491,11 +499,12 @@ impl From for crate::include::wifi_csi_config_t { } } +#[cfg(csi_enable)] impl CsiConfig { /// Set CSI data configuration pub(crate) fn apply_config(&self) -> Result<(), WifiError> { // let conf = self.clone().into(); - let conf: crate::include::wifi_csi_config_t = self.clone().into(); + let conf: wifi_csi_config_t = self.clone().into(); unsafe { esp_wifi_result!(esp_wifi_set_csi_config(&conf))?; @@ -2755,15 +2764,12 @@ impl<'d> WifiController<'d> { } /// Set CSI configuration and register the receiving callback. + #[cfg(csi_enable)] pub fn set_csi( &mut self, mut csi: CsiConfig, cb: fn(crate::binary::include::wifi_csi_info_t), ) -> Result<(), WifiError> { - if !crate::CONFIG.csi_enable { - panic!("CSI is not enabled in the configuration"); - } - csi.apply_config()?; csi.set_receive_cb(cb)?; csi.set_csi(true)?; diff --git a/examples/src/bin/wifi_csi.rs b/examples/src/bin/wifi_csi.rs index fb6cc9edac1..a1b41a36341 100644 --- a/examples/src/bin/wifi_csi.rs +++ b/examples/src/bin/wifi_csi.rs @@ -33,7 +33,7 @@ use esp_wifi::{ WifiStaDevice, }, wifi_interface::WifiStack, - EspWifiInitFor, + // EspWifiInitFor, }; use smoltcp::iface::SocketStorage; @@ -52,9 +52,7 @@ fn main() -> ! { esp_alloc::heap_allocator!(72 * 1024); let timg0 = TimerGroup::new(peripherals.TIMG0); - let init = init( - EspWifiInitFor::Wifi, timg0.timer0, Rng::new(peripherals.RNG), peripherals.RADIO_CLK,