From ce86e09ea367c91aef02544ebb4d6bd816427fcf Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Fri, 1 Nov 2024 14:49:30 +0000 Subject: [PATCH 01/10] remove async features --- esp-wifi/Cargo.toml | 24 +++------ esp-wifi/src/ble/btdm.rs | 1 - esp-wifi/src/ble/controller/mod.rs | 2 +- esp-wifi/src/ble/mod.rs | 1 - esp-wifi/src/ble/npl.rs | 2 - esp-wifi/src/esp_now/mod.rs | 4 -- esp-wifi/src/wifi/mod.rs | 86 ++++++++++++------------------ esp-wifi/src/wifi/os_adapter.rs | 2 - esp-wifi/src/wifi/state.rs | 2 - 9 files changed, 42 insertions(+), 82 deletions(-) diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index 4ac482a6a88..61e0351724c 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -25,7 +25,7 @@ smoltcp = { version = "0.11.0", default-features = false, features = [ critical-section = "1.1.3" enumset = { version = "1.1.5", default-features = false, optional = true } embedded-io = { version = "0.6.1", default-features = false } -embedded-io-async = { version = "0.6.1", optional = true } +embedded-io-async = { version = "0.6.1" } fugit = "0.3.7" heapless = { version = "0.8.0", default-features = false, features = [ "portable-atomic", @@ -33,8 +33,8 @@ heapless = { version = "0.8.0", default-features = false, features = [ num-derive = { version = "0.4.2" } num-traits = { version = "0.2.19", default-features = false } esp-wifi-sys = { version = "0.6.0", git = "https://github.com/esp-rs/esp-wifi-sys.git", rev = "a3e2ed64e9095f120bbcebe6287ddf62760774db"} -embassy-sync = { version = "0.6.0", optional = true } -embassy-net-driver = { version = "0.2.0", optional = true } +embassy-sync = { version = "0.6.0" } +embassy-net-driver = { version = "0.2.0" } libm = "0.2.8" cfg-if = "1.0.0" portable-atomic = { version = "1.9.0", default-features = false } @@ -101,16 +101,6 @@ esp32s3 = [ "xtensa-lx-rt/float-save-restore", ] -## Enable Async support -async = [ - "dep:embassy-sync", - "dep:embedded-io-async", - "dep:bt-hci", -] - -## Enable `embassy-net` support -embassy-net = ["dep:embassy-net-driver", "async"] - ## Enable WiFi-BLE coexistence support coex = [] @@ -118,7 +108,7 @@ coex = [] sys-logs = ["esp-wifi-sys/sys-logs"] ## Dumps packet info at log level info -dump-packets = [] +dump-packets = [] # config ## Provide implementations of smoltcp traits smoltcp = ["dep:smoltcp"] @@ -133,13 +123,13 @@ wifi = ["dep:enumset"] ble = ["esp-hal/bluetooth"] ## See USB-SERIAL-JTAG below -phy-enable-usb = [] +phy-enable-usb = [] # config ## Enable minimum modem sleep. Only affects STA mode -ps-min-modem = [] +ps-min-modem = [] # config ## Enable maximum modem sleep. Only affects STA mode -ps-max-modem = [] +ps-max-modem = [] # config ## Enable esp-now support esp-now = ["wifi"] diff --git a/esp-wifi/src/ble/btdm.rs b/esp-wifi/src/ble/btdm.rs index c6ca321db35..6d444c2d464 100644 --- a/esp-wifi/src/ble/btdm.rs +++ b/esp-wifi/src/ble/btdm.rs @@ -79,7 +79,6 @@ extern "C" fn notify_host_recv(data: *mut u8, len: u16) -> i32 { super::dump_packet_info(data); - #[cfg(feature = "async")] crate::ble::controller::asynch::hci_read_data_available(); 0 diff --git a/esp-wifi/src/ble/controller/mod.rs b/esp-wifi/src/ble/controller/mod.rs index bd2b58c92f9..31a51646767 100644 --- a/esp-wifi/src/ble/controller/mod.rs +++ b/esp-wifi/src/ble/controller/mod.rs @@ -83,7 +83,7 @@ impl Write for BleConnector<'_> { } /// Async Interface -#[cfg(feature = "async")] + pub(crate) mod asynch { use core::task::Poll; diff --git a/esp-wifi/src/ble/mod.rs b/esp-wifi/src/ble/mod.rs index 7246ffbcb8b..aa313b0ed27 100644 --- a/esp-wifi/src/ble/mod.rs +++ b/esp-wifi/src/ble/mod.rs @@ -117,7 +117,6 @@ impl defmt::Format for ReceivedPacket { } } -#[cfg(feature = "async")] pub fn have_hci_read_data() -> bool { critical_section::with(|cs| { let queue = BT_RECEIVE_QUEUE.borrow_ref_mut(cs); diff --git a/esp-wifi/src/ble/npl.rs b/esp-wifi/src/ble/npl.rs index 3d8696966b5..f08516f95da 100644 --- a/esp-wifi/src/ble/npl.rs +++ b/esp-wifi/src/ble/npl.rs @@ -1298,7 +1298,6 @@ unsafe extern "C" fn ble_hs_hci_rx_evt(cmd: *const u8, arg: *const c_void) -> i3 r_ble_hci_trans_buf_free(cmd); - #[cfg(feature = "async")] crate::ble::controller::asynch::hci_read_data_available(); 0 @@ -1327,7 +1326,6 @@ unsafe extern "C" fn ble_hs_rx_data(om: *const OsMbuf, arg: *const c_void) -> i3 r_os_mbuf_free_chain(om as *mut _); - #[cfg(feature = "async")] crate::ble::controller::asynch::hci_read_data_available(); 0 diff --git a/esp-wifi/src/esp_now/mod.rs b/esp-wifi/src/esp_now/mod.rs index febd478bf30..d7bf5f42bd5 100644 --- a/esp-wifi/src/esp_now/mod.rs +++ b/esp-wifi/src/esp_now/mod.rs @@ -824,7 +824,6 @@ unsafe extern "C" fn send_cb(_mac_addr: *const u8, status: esp_now_send_status_t ESP_NOW_SEND_CB_INVOKED.store(true, Ordering::Release); - #[cfg(feature = "async")] asynch::ESP_NOW_TX_WAKER.wake(); }) } @@ -871,15 +870,12 @@ unsafe extern "C" fn rcv_cb( queue.push_back(ReceivedData { data, info }); - #[cfg(feature = "async")] asynch::ESP_NOW_RX_WAKER.wake(); }); } -#[cfg(feature = "async")] pub use asynch::SendFuture; -#[cfg(feature = "async")] mod asynch { use core::task::{Context, Poll}; diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index 33df1bcefee..4d681933ecb 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -1623,7 +1623,6 @@ unsafe extern "C" fn recv_cb_sta( false } }) { - #[cfg(feature = "embassy-net")] embassy::STA_RECEIVE_WAKER.wake(); include::ESP_OK as esp_err_t } else { @@ -1653,7 +1652,6 @@ unsafe extern "C" fn recv_cb_ap( false } }) { - #[cfg(feature = "embassy-net")] embassy::AP_RECEIVE_WAKER.wake(); include::ESP_OK as esp_err_t } else { @@ -1683,7 +1681,6 @@ unsafe extern "C" fn esp_wifi_tx_done_cb( decrement_inflight_counter(); - #[cfg(feature = "embassy-net")] embassy::TRANSMIT_WAKER.wake(); } @@ -2041,18 +2038,14 @@ mod sealed { fn interface(self) -> wifi_interface_t; - #[cfg(feature = "embassy-net")] fn register_transmit_waker(self, cx: &mut core::task::Context) { embassy::TRANSMIT_WAKER.register(cx.waker()) } - #[cfg(feature = "embassy-net")] fn register_receive_waker(self, cx: &mut core::task::Context); - #[cfg(feature = "embassy-net")] fn register_link_state_waker(self, cx: &mut core::task::Context); - #[cfg(feature = "embassy-net")] fn link_state(self) -> embassy_net_driver::LinkState; } @@ -2075,17 +2068,14 @@ mod sealed { wifi_interface_t_WIFI_IF_STA } - #[cfg(feature = "embassy-net")] fn register_receive_waker(self, cx: &mut core::task::Context) { embassy::STA_RECEIVE_WAKER.register(cx.waker()); } - #[cfg(feature = "embassy-net")] fn register_link_state_waker(self, cx: &mut core::task::Context) { embassy::STA_LINK_STATE_WAKER.register(cx.waker()); } - #[cfg(feature = "embassy-net")] fn link_state(self) -> embassy_net_driver::LinkState { if matches!(get_sta_state(), WifiState::StaConnected) { embassy_net_driver::LinkState::Up @@ -2114,17 +2104,14 @@ mod sealed { wifi_interface_t_WIFI_IF_AP } - #[cfg(feature = "embassy-net")] fn register_receive_waker(self, cx: &mut core::task::Context) { embassy::AP_RECEIVE_WAKER.register(cx.waker()); } - #[cfg(feature = "embassy-net")] fn register_link_state_waker(self, cx: &mut core::task::Context) { embassy::AP_LINK_STATE_WAKER.register(cx.waker()); } - #[cfg(feature = "embassy-net")] fn link_state(self) -> embassy_net_driver::LinkState { if matches!(get_ap_state(), WifiState::ApStarted) { embassy_net_driver::LinkState::Up @@ -2684,6 +2671,33 @@ impl<'d> WifiController<'d> { Ok(scanned) } + + /// A blocking wifi network scan with default scanning options. + pub fn scan_n( + &mut self, + ) -> Result<(heapless::Vec, usize), WifiError> { + self.scan_with_config_sync(Default::default()) + } + + /// Starts the WiFi controller. + pub fn start(&mut self) -> Result<(), WifiError> { + crate::wifi::wifi_start() + } + + /// Stops the WiFi controller. + pub fn stop(&mut self) -> Result<(), WifiError> { + self.stop_impl() + } + + /// Connects the WiFi controller to a network. + pub fn connect(&mut self) -> Result<(), WifiError> { + self.connect_impl() + } + + /// Disconnects the WiFi controller from a network. + pub fn disconnect(&mut self) -> Result<(), WifiError> { + self.disconnect_impl() + } } // see https://docs.rs/smoltcp/0.7.1/smoltcp/phy/index.html @@ -3155,36 +3169,6 @@ impl WifiController<'_> { } } -#[cfg(not(feature = "async"))] -impl WifiController<'_> { - /// A blocking wifi network scan with default scanning options. - pub fn scan_n( - &mut self, - ) -> Result<(heapless::Vec, usize), WifiError> { - self.scan_with_config_sync(Default::default()) - } - - /// Starts the WiFi controller. - pub fn start(&mut self) -> Result<(), WifiError> { - crate::wifi::wifi_start() - } - - /// Stops the WiFi controller. - pub fn stop(&mut self) -> Result<(), WifiError> { - self.stop_impl() - } - - /// Connects the WiFi controller to a network. - pub fn connect(&mut self) -> Result<(), WifiError> { - self.connect_impl() - } - - /// Disconnects the WiFi controller from a network. - pub fn disconnect(&mut self) -> Result<(), WifiError> { - self.disconnect_impl() - } -} - fn dump_packet_info(_buffer: &[u8]) { #[cfg(feature = "dump-packets")] { @@ -3208,7 +3192,6 @@ macro_rules! esp_wifi_result { }}; } -#[cfg(feature = "embassy-net")] pub(crate) mod embassy { use embassy_net_driver::{Capabilities, Driver, HardwareAddress, RxToken, TxToken}; use embassy_sync::waitqueue::AtomicWaker; @@ -3289,7 +3272,6 @@ pub(crate) mod embassy { } } -#[cfg(feature = "async")] mod asynch { use core::task::Poll; @@ -3300,14 +3282,14 @@ mod asynch { // TODO assumes STA mode only impl WifiController<'_> { /// Async version of [`crate::wifi::WifiController`]'s `scan_n` method - pub async fn scan_n( + pub async fn scan_n_async( &mut self, ) -> Result<(heapless::Vec, usize), WifiError> { - self.scan_with_config(Default::default()).await + self.scan_with_config_async(Default::default()).await } /// An async wifi network scan with caller-provided scanning options. - pub async fn scan_with_config( + pub async fn scan_with_config_async( &mut self, config: ScanConfig<'_>, ) -> Result<(heapless::Vec, usize), WifiError> { @@ -3327,7 +3309,7 @@ mod asynch { } /// Async version of [`crate::wifi::WifiController`]'s `start` method - pub async fn start(&mut self) -> Result<(), WifiError> { + pub async fn start_async(&mut self) -> Result<(), WifiError> { let mode = WifiMode::try_from(&self.config)?; let mut events = enumset::enum_set! {}; @@ -3348,7 +3330,7 @@ mod asynch { } /// Async version of [`crate::wifi::WifiController`]'s `stop` method - pub async fn stop(&mut self) -> Result<(), WifiError> { + pub async fn stop_async(&mut self) -> Result<(), WifiError> { let mode = WifiMode::try_from(&self.config)?; let mut events = enumset::enum_set! {}; @@ -3372,7 +3354,7 @@ mod asynch { } /// Async version of [`crate::wifi::WifiController`]'s `connect` method - pub async fn connect(&mut self) -> Result<(), WifiError> { + pub async fn connect_async(&mut self) -> Result<(), WifiError> { Self::clear_events(WifiEvent::StaConnected | WifiEvent::StaDisconnected); let err = crate::wifi::WifiController::connect_impl(self).err(); @@ -3389,7 +3371,7 @@ mod asynch { /// Async version of [`crate::wifi::WifiController`]'s `Disconnect` /// method - pub async fn disconnect(&mut self) -> Result<(), WifiError> { + pub async fn disconnect_async(&mut self) -> Result<(), WifiError> { // If not connected, this will do nothing. // It will also wait forever for a `StaDisconnected` event that will never come. // Return early instead of hanging. diff --git a/esp-wifi/src/wifi/os_adapter.rs b/esp-wifi/src/wifi/os_adapter.rs index c059c8c1a5f..cd87ab6633d 100644 --- a/esp-wifi/src/wifi/os_adapter.rs +++ b/esp-wifi/src/wifi/os_adapter.rs @@ -870,10 +870,8 @@ pub unsafe extern "C" fn event_post( super::state::update_state(event); - #[cfg(feature = "async")] event.waker().wake(); - #[cfg(feature = "embassy-net")] match event { WifiEvent::StaConnected | WifiEvent::StaDisconnected => { crate::wifi::embassy::STA_LINK_STATE_WAKER.wake(); diff --git a/esp-wifi/src/wifi/state.rs b/esp-wifi/src/wifi/state.rs index 58d8d4441f9..e11f584f576 100644 --- a/esp-wifi/src/wifi/state.rs +++ b/esp-wifi/src/wifi/state.rs @@ -62,12 +62,10 @@ pub(crate) fn update_state(event: WifiEvent) { } } -#[cfg(feature = "async")] pub(crate) fn reset_ap_state() { AP_STATE.store(WifiState::Invalid, Ordering::Relaxed) } -#[cfg(feature = "async")] pub(crate) fn reset_sta_state() { STA_STATE.store(WifiState::Invalid, Ordering::Relaxed) } From 9ee092790627083384474da604ea67e2a36d7482 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Fri, 1 Nov 2024 15:07:43 +0000 Subject: [PATCH 02/10] phy-usb config --- esp-wifi/Cargo.toml | 8 -------- esp-wifi/build.rs | 2 ++ esp-wifi/src/ble/mod.rs | 2 +- esp-wifi/src/common_adapter/common_adapter_esp32c3.rs | 2 +- esp-wifi/src/common_adapter/common_adapter_esp32c6.rs | 2 +- esp-wifi/src/common_adapter/common_adapter_esp32h2.rs | 2 +- esp-wifi/src/common_adapter/common_adapter_esp32s3.rs | 2 +- esp-wifi/src/lib.rs | 9 +-------- esp-wifi/src/wifi/mod.rs | 2 +- examples/src/bin/wifi_80211_tx.rs | 2 +- examples/src/bin/wifi_access_point.rs | 2 +- examples/src/bin/wifi_access_point_with_sta.rs | 2 +- examples/src/bin/wifi_bench.rs | 2 +- examples/src/bin/wifi_coex.rs | 2 +- examples/src/bin/wifi_dhcp.rs | 2 +- examples/src/bin/wifi_embassy_access_point.rs | 2 +- examples/src/bin/wifi_embassy_access_point_with_sta.rs | 2 +- examples/src/bin/wifi_embassy_bench.rs | 2 +- examples/src/bin/wifi_embassy_dhcp.rs | 1 - examples/src/bin/wifi_sniffer.rs | 2 +- examples/src/bin/wifi_static_ip.rs | 2 +- extras/esp-wifishark/README.md | 4 ++-- xtask/src/main.rs | 2 +- 23 files changed, 23 insertions(+), 37 deletions(-) diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index 61e0351724c..bd30950059b 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -107,9 +107,6 @@ coex = [] ## Logs the WiFi logs from the driver at log level info (needs a nightly-compiler) sys-logs = ["esp-wifi-sys/sys-logs"] -## Dumps packet info at log level info -dump-packets = [] # config - ## Provide implementations of smoltcp traits smoltcp = ["dep:smoltcp"] @@ -122,9 +119,6 @@ wifi = ["dep:enumset"] ## Enable BLE support ble = ["esp-hal/bluetooth"] -## See USB-SERIAL-JTAG below -phy-enable-usb = [] # config - ## Enable minimum modem sleep. Only affects STA mode ps-min-modem = [] # config @@ -179,8 +173,6 @@ features = [ "wifi", "ble", "coex", - "async", - "embassy-net", "esp-hal/default", ] default-target = "riscv32imc-unknown-none-elf" diff --git a/esp-wifi/build.rs b/esp-wifi/build.rs index 5197c6ffb41..23be6c6ab3b 100644 --- a/esp-wifi/build.rs +++ b/esp-wifi/build.rs @@ -127,6 +127,8 @@ fn main() -> Result<(), Box> { ("ap_beacon_timeout", Value::UnsignedInteger(300), "For SoftAP, If the SoftAP doesn’t receive any data from the connected STA during inactive time, the SoftAP will force deauth the STA. Default is 300s"), ("failure_retry_cnt", Value::UnsignedInteger(1), "Number of connection retries station will do before moving to next AP. scan_method should be set as WIFI_ALL_CHANNEL_SCAN to use this config. Note: Enabling this may cause connection time to increase incase best AP doesn't behave properly. Defaults to 1"), ("scan_method", Value::UnsignedInteger(0), "0 = WIFI_FAST_SCAN, 1 = WIFI_ALL_CHANNEL_SCAN, defaults to 0"), + ("dump_packets", Value::Bool(false), "Dump packets via an info log statement"), + ("phy_enable_usb", Value::Bool(true), "Keeps USB running when using WiFi. This allows debugging and log messages via USB Serial JTAG. Turn off for best WiFi performance."), ], true ); diff --git a/esp-wifi/src/ble/mod.rs b/esp-wifi/src/ble/mod.rs index aa313b0ed27..22994478b53 100644 --- a/esp-wifi/src/ble/mod.rs +++ b/esp-wifi/src/ble/mod.rs @@ -159,7 +159,7 @@ pub fn read_hci(data: &mut [u8]) -> usize { } fn dump_packet_info(_buffer: &[u8]) { - #[cfg(feature = "dump-packets")] + #[cfg(dump_packets)] critical_section::with(|_cs| { info!("@HCIFRAME {:?}", _buffer); }); diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs index 8a4bf0ab044..eaa7903a1fe 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c3.rs @@ -76,7 +76,7 @@ pub(crate) unsafe fn phy_enable() { let init_data = &PHY_INIT_DATA_DEFAULT; - #[cfg(feature = "phy-enable-usb")] + #[cfg(phy_enable_usb)] { extern "C" { fn phy_bbpll_en_usb(param: bool); diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs b/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs index 74f3d76cecd..bd0e30cfe66 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32c6.rs @@ -41,7 +41,7 @@ pub(crate) unsafe fn phy_enable() { let init_data = &PHY_INIT_DATA_DEFAULT; - #[cfg(feature = "phy-enable-usb")] + #[cfg(phy_enable_usb)] { extern "C" { fn phy_bbpll_en_usb(param: bool); diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs b/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs index 1cb0b537589..0186c2759fa 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32h2.rs @@ -44,7 +44,7 @@ pub(crate) unsafe fn phy_enable() { // this would cause linker errors when the feature is activated - see https://github.com/esp-rs/esp-wifi/issues/457 - // #[cfg(feature = "phy-enable-usb")] + // #[cfg(phy_enable_usb)] // { // extern "C" { // pub fn phy_bbpll_en_usb(param: bool); diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs b/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs index 249370caa1f..f4213be87dd 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32s3.rs @@ -72,7 +72,7 @@ pub(crate) unsafe fn phy_enable() { let init_data = &PHY_INIT_DATA_DEFAULT; - #[cfg(feature = "phy-enable-usb")] + #[cfg(phy_enable_usb)] { extern "C" { fn phy_bbpll_en_usb(param: bool); diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index e96f3c41769..b672d91a3a0 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -48,19 +48,12 @@ //! Within this crate, `CCOMPARE0` CPU timer is used for timing, ensure that in //! your application you are not using this CPU timer. //! -//! ## USB-SERIAL-JTAG -//! -//! When using USB-SERIAL-JTAG (for example by selecting `jtag-serial` in [`esp-println`](https://crates.io/crates/esp-println)) you have to activate the feature `phy-enable-usb`. -//! -//! Don't use this feature if you are _not_ using USB-SERIAL-JTAG as it might -//! reduce WiFi performance. -//! //! # Features flags //! //! Note that not all features are available on every MCU. For example, `ble` //! (and thus, `coex`) is not available on ESP32-S2. //! -//! When using the `dump-packets` feature you can use the extcap in +//! When using the `dump_packets` config you can use the extcap in //! `extras/esp-wifishark` to analyze the frames in Wireshark. //! For more information see //! [extras/esp-wifishark/README.md](../extras/esp-wifishark/README.md) diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index 4d681933ecb..b477b8f6de1 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -3170,7 +3170,7 @@ impl WifiController<'_> { } fn dump_packet_info(_buffer: &[u8]) { - #[cfg(feature = "dump-packets")] + #[cfg(dump_packets)] { info!("@WIFIFRAME {:?}", _buffer); } diff --git a/examples/src/bin/wifi_80211_tx.rs b/examples/src/bin/wifi_80211_tx.rs index c073ce12789..69e2f75f93e 100644 --- a/examples/src/bin/wifi_80211_tx.rs +++ b/examples/src/bin/wifi_80211_tx.rs @@ -1,7 +1,7 @@ //! WiFi frame injection example //! //! Periodically transmits a beacon frame. -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils esp-wifi/sniffer //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_access_point.rs b/examples/src/bin/wifi_access_point.rs index a4e8032851f..2e9354c970e 100644 --- a/examples/src/bin/wifi_access_point.rs +++ b/examples/src/bin/wifi_access_point.rs @@ -6,7 +6,7 @@ //! Open http://192.168.2.1:8080/ in your browser //! //! On Android you might need to choose _Keep Accesspoint_ when it tells you the WiFi has no internet connection, Chrome might not want to load the URL - you can use a shell and try `curl` and `ping` -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_access_point_with_sta.rs b/examples/src/bin/wifi_access_point_with_sta.rs index 36e17512864..a8df7bf2b42 100644 --- a/examples/src/bin/wifi_access_point_with_sta.rs +++ b/examples/src/bin/wifi_access_point_with_sta.rs @@ -7,7 +7,7 @@ //! Open http://192.168.2.1:8080/ in your browser - the example will perform an HTTP get request to some "random" server //! //! On Android you might need to choose _Keep Accesspoint_ when it tells you the WiFi has no internet connection, Chrome might not want to load the URL - you can use a shell and try `curl` and `ping` -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_bench.rs b/examples/src/bin/wifi_bench.rs index 06a474b8f70..02aa7fc1ca9 100644 --- a/examples/src/bin/wifi_bench.rs +++ b/examples/src/bin/wifi_bench.rs @@ -6,7 +6,7 @@ //! cargo run --release //! ``` //! Ensure you have set the IP of your local machine in the `HOST_IP` env variable. E.g `HOST_IP="192.168.0.24"` and also set SSID and PASSWORD env variable before running this example. -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_coex.rs b/examples/src/bin/wifi_coex.rs index a8c779d117f..bfe9b374ed7 100644 --- a/examples/src/bin/wifi_coex.rs +++ b/examples/src/bin/wifi_coex.rs @@ -6,7 +6,7 @@ //! - does BLE advertising (you cannot connect to it - it's just not implemented in the example) //! //! Note: On ESP32-C2 and ESP32-C3 you need a wifi-heap size of 70000, on ESP32-C6 you need 80000 and a tx_queue_size of 10 -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils esp-wifi/ble esp-wifi/coex //% CHIPS: esp32 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_dhcp.rs b/examples/src/bin/wifi_dhcp.rs index 68f642c3d38..2682462f283 100644 --- a/examples/src/bin/wifi_dhcp.rs +++ b/examples/src/bin/wifi_dhcp.rs @@ -4,7 +4,7 @@ //! Set SSID and PASSWORD env variable before running this example. //! //! This gets an ip address via DHCP then performs an HTTP get request to some "random" server -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_embassy_access_point.rs b/examples/src/bin/wifi_embassy_access_point.rs index 748df8ccba5..789a16922fc 100644 --- a/examples/src/bin/wifi_embassy_access_point.rs +++ b/examples/src/bin/wifi_embassy_access_point.rs @@ -7,7 +7,7 @@ //! On Android you might need to choose _Keep Accesspoint_ when it tells you the WiFi has no internet connection, Chrome might not want to load the URL - you can use a shell and try `curl` and `ping` //! //! Because of the huge task-arena size configured this won't work on ESP32-S2 -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 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 82f74805509..016a4278354 100644 --- a/examples/src/bin/wifi_embassy_access_point_with_sta.rs +++ b/examples/src/bin/wifi_embassy_access_point_with_sta.rs @@ -10,7 +10,7 @@ //! On Android you might need to choose _Keep Accesspoint_ when it tells you the WiFi has no internet connection, Chrome might not want to load the URL - you can use a shell and try `curl` and `ping` //! //! Because of the huge task-arena size configured this won't work on ESP32-S2 -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_embassy_bench.rs b/examples/src/bin/wifi_embassy_bench.rs index 80334b862db..f93894e137b 100644 --- a/examples/src/bin/wifi_embassy_bench.rs +++ b/examples/src/bin/wifi_embassy_bench.rs @@ -8,7 +8,7 @@ //! Ensure you have set the IP of your local machine in the `HOST_IP` env variable. E.g `HOST_IP="192.168.0.24"` and also set SSID and PASSWORD env variable before running this example. //! //! Because of the huge task-arena size configured this won't work on ESP32-S2 and ESP32-C2 -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_embassy_dhcp.rs b/examples/src/bin/wifi_embassy_dhcp.rs index 5ee5bb322ba..31f276219d0 100644 --- a/examples/src/bin/wifi_embassy_dhcp.rs +++ b/examples/src/bin/wifi_embassy_dhcp.rs @@ -6,7 +6,6 @@ //! This gets an ip address via DHCP then performs an HTTP get request to some "random" server //! //! Because of the huge task-arena size configured this won't work on ESP32-S2 -//! When using USB-SERIAL-JTAG you have to activate the feature `phy-enable-usb` in the esp-wifi crate. //% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_sniffer.rs b/examples/src/bin/wifi_sniffer.rs index 4e56d6338ef..d65f42d0751 100644 --- a/examples/src/bin/wifi_sniffer.rs +++ b/examples/src/bin/wifi_sniffer.rs @@ -1,7 +1,7 @@ //! WiFi sniffer example //! //! Sniffs for beacon frames. -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils esp-wifi/sniffer //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_static_ip.rs b/examples/src/bin/wifi_static_ip.rs index e9a91fe1fac..25de248dc85 100644 --- a/examples/src/bin/wifi_static_ip.rs +++ b/examples/src/bin/wifi_static_ip.rs @@ -5,7 +5,7 @@ //! - might be necessary to configure your WiFi access point accordingly //! - uses the given static IP //! - responds with some HTML content when connecting to port 8080 -//! When using USB-SERIAL-JTAG you may have to activate the feature `phy-enable-usb` in the esp-wifi crate. +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/extras/esp-wifishark/README.md b/extras/esp-wifishark/README.md index 1a10a828f45..887a3e057c2 100644 --- a/extras/esp-wifishark/README.md +++ b/extras/esp-wifishark/README.md @@ -1,6 +1,6 @@ # esp-wifishark -This is an extcap to be used with esp-wifi and the `dump-packets` feature. +This is an extcap to be used with esp-wifi and the `dump_packets` config option. To use it build via `cargo build --release` and copy the resulting executable to the Wireshark's `extcap` folder. @@ -8,6 +8,6 @@ Then you should see two new capture interfaces in Wireshark - esp-wifi HCI capture (for Bluetooth HCI) - esp-wifi Ethernet capture (for WiFi traffic) -If you are running an application using esp-wifi's `dump-packets` feature and logging at INFO level active these capture interfaces can connect via serialport to give you insights on what is going on. +If you are running an application using esp-wifi's `dump_packets` config and logging at INFO level active these capture interfaces can connect via serialport to give you insights on what is going on. By default it tries to identify exactly one serialport. If that doesn't work for you, you can configure the serialport via the Wireshark UI. diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 4a43062fab2..bd008142a44 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -698,7 +698,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> { Package::EspWifi => { let mut features = - format!("--features={chip},async,ps-min-modem,defmt,dump-packets,sys-logs"); + format!("--features={chip},async,ps-min-modem,defmt,sys-logs"); if device.contains("wifi") { features.push_str(",wifi-default,esp-now,embassy-net,sniffer") From 1587dec04bb041e8864d51dbc32faee445af06b6 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Fri, 1 Nov 2024 15:36:46 +0000 Subject: [PATCH 03/10] modem powersaving --- esp-config/src/generate.rs | 13 +++++-- esp-wifi/Cargo.toml | 35 +++++++++---------- esp-wifi/build.rs | 2 ++ esp-wifi/src/esp_now/mod.rs | 4 +-- esp-wifi/src/wifi/mod.rs | 4 +-- examples/src/bin/wifi_80211_tx.rs | 2 +- examples/src/bin/wifi_access_point.rs | 2 +- .../src/bin/wifi_access_point_with_sta.rs | 2 +- examples/src/bin/wifi_bench.rs | 2 +- examples/src/bin/wifi_coex.rs | 2 +- examples/src/bin/wifi_dhcp.rs | 2 +- examples/src/bin/wifi_embassy_access_point.rs | 2 +- .../bin/wifi_embassy_access_point_with_sta.rs | 2 +- examples/src/bin/wifi_embassy_bench.rs | 2 +- examples/src/bin/wifi_sniffer.rs | 2 +- examples/src/bin/wifi_static_ip.rs | 2 +- xtask/src/main.rs | 3 +- 17 files changed, 44 insertions(+), 39 deletions(-) diff --git a/esp-config/src/generate.rs b/esp-config/src/generate.rs index 1afa1c92591..887b15e5dc8 100644 --- a/esp-config/src/generate.rs +++ b/esp-config/src/generate.rs @@ -149,10 +149,17 @@ fn emit_configuration( // emit cfgs and set envs for (name, value) in configs.into_iter() { let cfg_name = snake_case(name.trim_start_matches(prefix)); - println!("cargo:rustc-check-cfg=cfg({cfg_name})"); match value { - Value::Bool(true) => { - println!("cargo:rustc-cfg={cfg_name}") + Value::Bool(b) => { + println!("cargo:rustc-check-cfg=cfg({cfg_name})"); + if *b { + println!("cargo:rustc-cfg={cfg_name}") + } + } + Value::String(v) => { + // TODO we need to emit the other option else we'll get a lint warning... + println!("cargo:rustc-check-cfg=cfg({cfg_name}, values(\"{v}\"))"); + println!("cargo:rustc-cfg={cfg_name}=\"{v}\"") } _ => {} } diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index bd30950059b..52917cf8989 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -107,27 +107,30 @@ coex = [] ## Logs the WiFi logs from the driver at log level info (needs a nightly-compiler) sys-logs = ["esp-wifi-sys/sys-logs"] -## Provide implementations of smoltcp traits -smoltcp = ["dep:smoltcp"] +## Enable support for `defmt` +defmt = ["dep:defmt", "smoltcp?/defmt", "esp-hal/defmt", "bt-hci?/defmt", "esp-wifi-sys/defmt"] -## Provide utilities for smoltcp initialization. Adds smoltcp dependency -utils = ["smoltcp"] +## Enable support for the `log` crate +log = ["dep:log", "esp-hal/log", "esp-wifi-sys/log"] ## Enable WiFi support wifi = ["dep:enumset"] +## Enable sniffer mode support +sniffer = ["wifi"] + ## Enable BLE support ble = ["esp-hal/bluetooth"] -## Enable minimum modem sleep. Only affects STA mode -ps-min-modem = [] # config - -## Enable maximum modem sleep. Only affects STA mode -ps-max-modem = [] # config - ## Enable esp-now support esp-now = ["wifi"] +## Provide implementations of smoltcp traits +smoltcp = ["dep:smoltcp"] + +## Provide utilities for smoltcp initialization. Adds smoltcp dependency +utils = ["smoltcp"] + ## IPv6 support. Includes utils feature ipv6 = ["wifi", "utils", "smoltcp?/proto-ipv6"] @@ -155,15 +158,6 @@ dhcpv4 = ["wifi", "utils", "smoltcp?/proto-dhcpv4", "smoltcp?/socket-dhcpv4"] ## Convenience to enable "ipv4", "tcp", "udp", "icmp", "igmp", "dns", "dhcpv4" wifi-default = ["ipv4", "tcp", "udp", "icmp", "igmp", "dns", "dhcpv4"] -## Enable support for `defmt` -defmt = ["dep:defmt", "smoltcp?/defmt", "esp-hal/defmt", "bt-hci?/defmt", "esp-wifi-sys/defmt"] - -## Enable support for the `log` crate -log = ["dep:log", "esp-hal/log", "esp-wifi-sys/log"] - -## Enable sniffer mode support -sniffer = ["wifi"] - # Implement serde Serialize / Deserialize serde = ["dep:serde", "enumset?/serde", "heapless/serde"] @@ -176,3 +170,6 @@ features = [ "esp-hal/default", ] default-target = "riscv32imc-unknown-none-elf" + +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(modem_powersaving, values("max", "min", "none"))'] } \ No newline at end of file diff --git a/esp-wifi/build.rs b/esp-wifi/build.rs index 23be6c6ab3b..b0ad927e257 100644 --- a/esp-wifi/build.rs +++ b/esp-wifi/build.rs @@ -129,6 +129,8 @@ fn main() -> Result<(), Box> { ("scan_method", Value::UnsignedInteger(0), "0 = WIFI_FAST_SCAN, 1 = WIFI_ALL_CHANNEL_SCAN, defaults to 0"), ("dump_packets", Value::Bool(false), "Dump packets via an info log statement"), ("phy_enable_usb", Value::Bool(true), "Keeps USB running when using WiFi. This allows debugging and log messages via USB Serial JTAG. Turn off for best WiFi performance."), + ("modem_powersaving", Value::String("none".to_owned()), "Modem power saving. Possible values: \"max\", \"min\", \"none\". Defaults to \"none\" or \"min\" when coex is enabled."), + ("strchr_available", Value::Bool(false), "Enable to use a custom or third party strchr implementation"), ], true ); diff --git a/esp-wifi/src/esp_now/mod.rs b/esp-wifi/src/esp_now/mod.rs index d7bf5f42bd5..123f18f76b7 100644 --- a/esp-wifi/src/esp_now/mod.rs +++ b/esp-wifi/src/esp_now/mod.rs @@ -683,11 +683,11 @@ impl<'d> EspNow<'d> { esp_wifi_set_inactive_time(wifi_interface_t_WIFI_IF_STA, crate::CONFIG.beacon_timeout) })?; cfg_if::cfg_if! { - if #[cfg(feature = "ps-min-modem")] { + if #[cfg(modem_powersaving = "min")] { check_error!({esp_wifi_set_ps( crate::binary::include::wifi_ps_type_t_WIFI_PS_MIN_MODEM )})?; - } else if #[cfg(feature = "ps-max-modem")] { + } else if #[cfg(modem_powersaving = "max")] { check_error!({esp_wifi_set_ps( crate::binary::include::wifi_ps_type_t_WIFI_PS_MAX_MODEM )})?; diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index b477b8f6de1..37edfb8308a 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -1705,9 +1705,9 @@ pub(crate) fn wifi_start() -> Result<(), WifiError> { }; cfg_if::cfg_if! { - if #[cfg(feature = "ps-min-modem")] { + if #[cfg(modem_powersaving = "min")] { let ps_mode = include::wifi_ps_type_t_WIFI_PS_MIN_MODEM; - } else if #[cfg(feature = "ps-max-modem")] { + } else if #[cfg(modem_powersaving = "max")] { let ps_mode = include::wifi_ps_type_t_WIFI_PS_MAX_MODEM; } else if #[cfg(coex)] { let ps_mode = include::wifi_ps_type_t_WIFI_PS_MIN_MODEM; diff --git a/examples/src/bin/wifi_80211_tx.rs b/examples/src/bin/wifi_80211_tx.rs index 69e2f75f93e..3b33456fd09 100644 --- a/examples/src/bin/wifi_80211_tx.rs +++ b/examples/src/bin/wifi_80211_tx.rs @@ -1,7 +1,7 @@ //! WiFi frame injection example //! //! Periodically transmits a beacon frame. -//! +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils esp-wifi/sniffer //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_access_point.rs b/examples/src/bin/wifi_access_point.rs index 2e9354c970e..94c5b182105 100644 --- a/examples/src/bin/wifi_access_point.rs +++ b/examples/src/bin/wifi_access_point.rs @@ -6,7 +6,7 @@ //! Open http://192.168.2.1:8080/ in your browser //! //! On Android you might need to choose _Keep Accesspoint_ when it tells you the WiFi has no internet connection, Chrome might not want to load the URL - you can use a shell and try `curl` and `ping` -//! +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_access_point_with_sta.rs b/examples/src/bin/wifi_access_point_with_sta.rs index a8df7bf2b42..f9c3e0792e5 100644 --- a/examples/src/bin/wifi_access_point_with_sta.rs +++ b/examples/src/bin/wifi_access_point_with_sta.rs @@ -7,7 +7,7 @@ //! Open http://192.168.2.1:8080/ in your browser - the example will perform an HTTP get request to some "random" server //! //! On Android you might need to choose _Keep Accesspoint_ when it tells you the WiFi has no internet connection, Chrome might not want to load the URL - you can use a shell and try `curl` and `ping` -//! +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_bench.rs b/examples/src/bin/wifi_bench.rs index 02aa7fc1ca9..511773ee705 100644 --- a/examples/src/bin/wifi_bench.rs +++ b/examples/src/bin/wifi_bench.rs @@ -6,7 +6,7 @@ //! cargo run --release //! ``` //! Ensure you have set the IP of your local machine in the `HOST_IP` env variable. E.g `HOST_IP="192.168.0.24"` and also set SSID and PASSWORD env variable before running this example. -//! +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_coex.rs b/examples/src/bin/wifi_coex.rs index bfe9b374ed7..002ea35e8f3 100644 --- a/examples/src/bin/wifi_coex.rs +++ b/examples/src/bin/wifi_coex.rs @@ -6,7 +6,7 @@ //! - does BLE advertising (you cannot connect to it - it's just not implemented in the example) //! //! Note: On ESP32-C2 and ESP32-C3 you need a wifi-heap size of 70000, on ESP32-C6 you need 80000 and a tx_queue_size of 10 -//! +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils esp-wifi/ble esp-wifi/coex //% CHIPS: esp32 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_dhcp.rs b/examples/src/bin/wifi_dhcp.rs index 2682462f283..fd756e4478c 100644 --- a/examples/src/bin/wifi_dhcp.rs +++ b/examples/src/bin/wifi_dhcp.rs @@ -4,7 +4,7 @@ //! Set SSID and PASSWORD env variable before running this example. //! //! This gets an ip address via DHCP then performs an HTTP get request to some "random" server -//! +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_embassy_access_point.rs b/examples/src/bin/wifi_embassy_access_point.rs index 789a16922fc..cd5b0919960 100644 --- a/examples/src/bin/wifi_embassy_access_point.rs +++ b/examples/src/bin/wifi_embassy_access_point.rs @@ -7,7 +7,7 @@ //! On Android you might need to choose _Keep Accesspoint_ when it tells you the WiFi has no internet connection, Chrome might not want to load the URL - you can use a shell and try `curl` and `ping` //! //! Because of the huge task-arena size configured this won't work on ESP32-S2 -//! +//! //% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 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 016a4278354..41932e656ca 100644 --- a/examples/src/bin/wifi_embassy_access_point_with_sta.rs +++ b/examples/src/bin/wifi_embassy_access_point_with_sta.rs @@ -10,7 +10,7 @@ //! On Android you might need to choose _Keep Accesspoint_ when it tells you the WiFi has no internet connection, Chrome might not want to load the URL - you can use a shell and try `curl` and `ping` //! //! Because of the huge task-arena size configured this won't work on ESP32-S2 -//! +//! //% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_embassy_bench.rs b/examples/src/bin/wifi_embassy_bench.rs index f93894e137b..16a48d3306d 100644 --- a/examples/src/bin/wifi_embassy_bench.rs +++ b/examples/src/bin/wifi_embassy_bench.rs @@ -8,7 +8,7 @@ //! Ensure you have set the IP of your local machine in the `HOST_IP` env variable. E.g `HOST_IP="192.168.0.24"` and also set SSID and PASSWORD env variable before running this example. //! //! Because of the huge task-arena size configured this won't work on ESP32-S2 and ESP32-C2 -//! +//! //% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_sniffer.rs b/examples/src/bin/wifi_sniffer.rs index d65f42d0751..69256e326bc 100644 --- a/examples/src/bin/wifi_sniffer.rs +++ b/examples/src/bin/wifi_sniffer.rs @@ -1,7 +1,7 @@ //! WiFi sniffer example //! //! Sniffs for beacon frames. -//! +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils esp-wifi/sniffer //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/examples/src/bin/wifi_static_ip.rs b/examples/src/bin/wifi_static_ip.rs index 25de248dc85..af7f14d2674 100644 --- a/examples/src/bin/wifi_static_ip.rs +++ b/examples/src/bin/wifi_static_ip.rs @@ -5,7 +5,7 @@ //! - might be necessary to configure your WiFi access point accordingly //! - uses the given static IP //! - responds with some HTML content when connecting to port 8080 -//! +//! //% FEATURES: esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 diff --git a/xtask/src/main.rs b/xtask/src/main.rs index bd008142a44..877aed838d0 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -697,8 +697,7 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> { } Package::EspWifi => { - let mut features = - format!("--features={chip},async,ps-min-modem,defmt,sys-logs"); + let mut features = format!("--features={chip},async,defmt,sys-logs"); if device.contains("wifi") { features.push_str(",wifi-default,esp-now,embassy-net,sniffer") From 727ec80d4cbb16703a9f0721ddfa0c7bece5e296 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Fri, 1 Nov 2024 15:49:10 +0000 Subject: [PATCH 04/10] Fix examples --- esp-wifi/Cargo.toml | 14 +++++++------- examples/src/bin/wifi_embassy_access_point.rs | 4 ++-- .../src/bin/wifi_embassy_access_point_with_sta.rs | 6 +++--- examples/src/bin/wifi_embassy_bench.rs | 6 +++--- examples/src/bin/wifi_embassy_ble.rs | 2 +- examples/src/bin/wifi_embassy_dhcp.rs | 6 +++--- examples/src/bin/wifi_embassy_esp_now.rs | 2 +- examples/src/bin/wifi_embassy_esp_now_duplex.rs | 2 +- examples/src/bin/wifi_embassy_trouble.rs | 2 +- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index 52917cf8989..4fb1a26f416 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -33,8 +33,8 @@ heapless = { version = "0.8.0", default-features = false, features = [ num-derive = { version = "0.4.2" } num-traits = { version = "0.2.19", default-features = false } esp-wifi-sys = { version = "0.6.0", git = "https://github.com/esp-rs/esp-wifi-sys.git", rev = "a3e2ed64e9095f120bbcebe6287ddf62760774db"} -embassy-sync = { version = "0.6.0" } -embassy-net-driver = { version = "0.2.0" } +embassy-sync = { version = "0.6.0", optional = true } +embassy-net-driver = { version = "0.2.0", optional = true } libm = "0.2.8" cfg-if = "1.0.0" portable-atomic = { version = "1.9.0", default-features = false } @@ -114,16 +114,16 @@ defmt = ["dep:defmt", "smoltcp?/defmt", "esp-hal/defmt", "bt-hci?/defmt", "esp-w log = ["dep:log", "esp-hal/log", "esp-wifi-sys/log"] ## Enable WiFi support -wifi = ["dep:enumset"] +wifi = ["dep:enumset", "dep:embassy-net-driver", "dep:embassy-sync"] + +## Enable esp-now support +esp-now = ["wifi"] ## Enable sniffer mode support sniffer = ["wifi"] ## Enable BLE support -ble = ["esp-hal/bluetooth"] - -## Enable esp-now support -esp-now = ["wifi"] +ble = ["esp-hal/bluetooth", "dep:bt-hci", "dep:embassy-sync"] ## Provide implementations of smoltcp traits smoltcp = ["dep:smoltcp"] diff --git a/examples/src/bin/wifi_embassy_access_point.rs b/examples/src/bin/wifi_embassy_access_point.rs index cd5b0919960..ca86dc2d078 100644 --- a/examples/src/bin/wifi_embassy_access_point.rs +++ b/examples/src/bin/wifi_embassy_access_point.rs @@ -9,7 +9,7 @@ //! Because of the huge task-arena size configured this won't work on ESP32-S2 //! -//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils +//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 #![no_std] @@ -220,7 +220,7 @@ async fn connection(mut controller: WifiController<'static>) { }); controller.set_configuration(&client_config).unwrap(); println!("Starting wifi"); - controller.start().await.unwrap(); + controller.start_async().await.unwrap(); println!("Wifi started!"); } } 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 41932e656ca..6ce2d859052 100644 --- a/examples/src/bin/wifi_embassy_access_point_with_sta.rs +++ b/examples/src/bin/wifi_embassy_access_point_with_sta.rs @@ -12,7 +12,7 @@ //! Because of the huge task-arena size configured this won't work on ESP32-S2 //! -//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils +//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 #![no_std] @@ -315,7 +315,7 @@ async fn connection(mut controller: WifiController<'static>) { println!("Device capabilities: {:?}", controller.get_capabilities()); println!("Starting wifi"); - controller.start().await.unwrap(); + controller.start_async().await.unwrap(); println!("Wifi started!"); loop { @@ -323,7 +323,7 @@ async fn connection(mut controller: WifiController<'static>) { WifiState::ApStarted => { println!("About to connect..."); - match controller.connect().await { + match controller.connect_async().await { Ok(_) => { // wait until we're no longer connected controller.wait_for_event(WifiEvent::StaDisconnected).await; diff --git a/examples/src/bin/wifi_embassy_bench.rs b/examples/src/bin/wifi_embassy_bench.rs index 16a48d3306d..d33289a4218 100644 --- a/examples/src/bin/wifi_embassy_bench.rs +++ b/examples/src/bin/wifi_embassy_bench.rs @@ -10,7 +10,7 @@ //! Because of the huge task-arena size configured this won't work on ESP32-S2 and ESP32-C2 //! -//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils +//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c3 esp32c6 #![allow(static_mut_refs)] @@ -193,12 +193,12 @@ async fn connection(mut controller: WifiController<'static>) { }); controller.set_configuration(&client_config).unwrap(); println!("Starting wifi"); - controller.start().await.unwrap(); + controller.start_async().await.unwrap(); println!("Wifi started!"); } println!("About to connect..."); - match controller.connect().await { + match controller.connect_async().await { Ok(_) => println!("Wifi connected!"), Err(e) => { println!("Failed to connect to wifi: {e:?}"); diff --git a/examples/src/bin/wifi_embassy_ble.rs b/examples/src/bin/wifi_embassy_ble.rs index 3fb6d0dd181..5ba16b69863 100644 --- a/examples/src/bin/wifi_embassy_ble.rs +++ b/examples/src/bin/wifi_embassy_ble.rs @@ -4,7 +4,7 @@ //! - offers one service with three characteristics (one is read/write, one is write only, one is read/write/notify) //! - pressing the boot-button on a dev-board will send a notification if it is subscribed -//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/ble +//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/ble //% CHIPS: esp32 esp32s3 esp32c2 esp32c3 esp32c6 esp32h2 #![no_std] diff --git a/examples/src/bin/wifi_embassy_dhcp.rs b/examples/src/bin/wifi_embassy_dhcp.rs index 31f276219d0..67bea7f3ada 100644 --- a/examples/src/bin/wifi_embassy_dhcp.rs +++ b/examples/src/bin/wifi_embassy_dhcp.rs @@ -7,7 +7,7 @@ //! //! Because of the huge task-arena size configured this won't work on ESP32-S2 -//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils +//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 #![no_std] @@ -185,12 +185,12 @@ async fn connection(mut controller: WifiController<'static>) { }); controller.set_configuration(&client_config).unwrap(); println!("Starting wifi"); - controller.start().await.unwrap(); + controller.start_async().await.unwrap(); println!("Wifi started!"); } println!("About to connect..."); - match controller.connect().await { + match controller.connect_async().await { Ok(_) => println!("Wifi connected!"), Err(e) => { println!("Failed to connect to wifi: {e:?}"); diff --git a/examples/src/bin/wifi_embassy_esp_now.rs b/examples/src/bin/wifi_embassy_esp_now.rs index 3b7aecd43e8..3828ec9a9e8 100644 --- a/examples/src/bin/wifi_embassy_esp_now.rs +++ b/examples/src/bin/wifi_embassy_esp_now.rs @@ -4,7 +4,7 @@ //! //! Because of the huge task-arena size configured this won't work on ESP32-S2 -//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils esp-wifi/esp-now +//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils esp-wifi/esp-now //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 #![no_std] diff --git a/examples/src/bin/wifi_embassy_esp_now_duplex.rs b/examples/src/bin/wifi_embassy_esp_now_duplex.rs index 1eeec3a88a5..600aca964c9 100644 --- a/examples/src/bin/wifi_embassy_esp_now_duplex.rs +++ b/examples/src/bin/wifi_embassy_esp_now_duplex.rs @@ -4,7 +4,7 @@ //! //! Because of the huge task-arena size configured this won't work on ESP32-S2 -//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/embassy-net esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils esp-wifi/esp-now +//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/wifi-default esp-wifi/wifi esp-wifi/utils esp-wifi/esp-now //% CHIPS: esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 #![no_std] diff --git a/examples/src/bin/wifi_embassy_trouble.rs b/examples/src/bin/wifi_embassy_trouble.rs index 45253463ae6..a5f55a02750 100644 --- a/examples/src/bin/wifi_embassy_trouble.rs +++ b/examples/src/bin/wifi_embassy_trouble.rs @@ -5,7 +5,7 @@ //! - automatically notifies subscribers every second //! -//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/async esp-wifi/ble +//% FEATURES: embassy embassy-generic-timers esp-wifi esp-wifi/ble //% CHIPS: esp32 esp32s3 esp32c2 esp32c3 esp32c6 esp32h2 #![no_std] From 6af0c4afebc9d918e84f4a77151e9f029320584e Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Tue, 5 Nov 2024 16:07:15 +0000 Subject: [PATCH 05/10] make ps a runtime config --- esp-wifi/Cargo.toml | 5 +--- esp-wifi/build.rs | 2 -- esp-wifi/src/config.rs | 47 +++++++++++++++++++++++++++++++++++++ esp-wifi/src/esp_now/mod.rs | 28 +++++++--------------- esp-wifi/src/lib.rs | 33 +++----------------------- esp-wifi/src/wifi/mod.rs | 36 ++++++++++++++-------------- hil-test/Cargo.toml | 4 ---- 7 files changed, 79 insertions(+), 76 deletions(-) create mode 100644 esp-wifi/src/config.rs diff --git a/esp-wifi/Cargo.toml b/esp-wifi/Cargo.toml index 4fb1a26f416..65d1beb2443 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -169,7 +169,4 @@ features = [ "coex", "esp-hal/default", ] -default-target = "riscv32imc-unknown-none-elf" - -[lints.rust] -unexpected_cfgs = { level = "warn", check-cfg = ['cfg(modem_powersaving, values("max", "min", "none"))'] } \ No newline at end of file +default-target = "riscv32imc-unknown-none-elf" \ No newline at end of file diff --git a/esp-wifi/build.rs b/esp-wifi/build.rs index b0ad927e257..23be6c6ab3b 100644 --- a/esp-wifi/build.rs +++ b/esp-wifi/build.rs @@ -129,8 +129,6 @@ fn main() -> Result<(), Box> { ("scan_method", Value::UnsignedInteger(0), "0 = WIFI_FAST_SCAN, 1 = WIFI_ALL_CHANNEL_SCAN, defaults to 0"), ("dump_packets", Value::Bool(false), "Dump packets via an info log statement"), ("phy_enable_usb", Value::Bool(true), "Keeps USB running when using WiFi. This allows debugging and log messages via USB Serial JTAG. Turn off for best WiFi performance."), - ("modem_powersaving", Value::String("none".to_owned()), "Modem power saving. Possible values: \"max\", \"min\", \"none\". Defaults to \"none\" or \"min\" when coex is enabled."), - ("strchr_available", Value::Bool(false), "Enable to use a custom or third party strchr implementation"), ], true ); diff --git a/esp-wifi/src/config.rs b/esp-wifi/src/config.rs new file mode 100644 index 00000000000..31f4a0125fa --- /dev/null +++ b/esp-wifi/src/config.rs @@ -0,0 +1,47 @@ +use esp_wifi_sys::include; + +#[derive(Debug)] +#[cfg_attr(feature = "defmt", derive(defmt::Format))] +/// Tunable parameters for the WiFi driver +#[allow(unused)] // currently there are no ble tunables +pub(crate) struct EspWifiConfig { + pub(crate) rx_queue_size: usize, + pub(crate) tx_queue_size: usize, + pub(crate) static_rx_buf_num: usize, + pub(crate) dynamic_rx_buf_num: usize, + pub(crate) static_tx_buf_num: usize, + pub(crate) dynamic_tx_buf_num: usize, + pub(crate) ampdu_rx_enable: bool, + pub(crate) ampdu_tx_enable: bool, + pub(crate) amsdu_tx_enable: bool, + pub(crate) rx_ba_win: usize, + pub(crate) max_burst_size: usize, + pub(crate) country_code: &'static str, + pub(crate) country_code_operating_class: u8, + pub(crate) mtu: usize, + pub(crate) tick_rate_hz: u32, + pub(crate) listen_interval: u16, + pub(crate) beacon_timeout: u16, + pub(crate) ap_beacon_timeout: u16, + pub(crate) failure_retry_cnt: u8, + pub(crate) scan_method: u32, +} + +#[non_exhaustive] +#[derive(Default)] +pub enum PowerSaveMode { + None, + #[default] + Minimum, + Maximum, +} + +impl From for include::wifi_ps_type_t { + fn from(s: PowerSaveMode) -> Self { + match s { + PowerSaveMode::None => include::wifi_ps_type_t_WIFI_PS_NONE, + PowerSaveMode::Minimum => include::wifi_ps_type_t_WIFI_PS_MIN_MODEM, + PowerSaveMode::Maximum => include::wifi_ps_type_t_WIFI_PS_MAX_MODEM, + } + } +} diff --git a/esp-wifi/src/esp_now/mod.rs b/esp-wifi/src/esp_now/mod.rs index 123f18f76b7..adc9e1889a1 100644 --- a/esp-wifi/src/esp_now/mod.rs +++ b/esp-wifi/src/esp_now/mod.rs @@ -18,6 +18,7 @@ use portable_atomic::{AtomicBool, AtomicU8, Ordering}; use crate::{ binary::include::*, + config::PowerSaveMode, hal::peripheral::{Peripheral, PeripheralRef}, wifi::{Protocol, RxControlInfo, WifiError}, EspWifiController, @@ -335,6 +336,14 @@ impl EspNowManager<'_> { Ok(()) } + /// Configures modem power saving + /// + /// This is ignored, and set to `PowerSaveMode::Minimum` when `coex` is + /// enabled. + pub fn set_power_saving(&self, ps: PowerSaveMode) -> Result<(), WifiError> { + crate::wifi::apply_power_saving(ps) + } + /// Set primary WiFi channel. /// Should only be used when using ESP-NOW without AP or STA. pub fn set_channel(&self, channel: u8) -> Result<(), EspNowError> { @@ -682,25 +691,6 @@ impl<'d> EspNow<'d> { check_error!({ esp_wifi_set_inactive_time(wifi_interface_t_WIFI_IF_STA, crate::CONFIG.beacon_timeout) })?; - cfg_if::cfg_if! { - if #[cfg(modem_powersaving = "min")] { - check_error!({esp_wifi_set_ps( - crate::binary::include::wifi_ps_type_t_WIFI_PS_MIN_MODEM - )})?; - } else if #[cfg(modem_powersaving = "max")] { - check_error!({esp_wifi_set_ps( - crate::binary::include::wifi_ps_type_t_WIFI_PS_MAX_MODEM - )})?; - } else if #[cfg(coex)] { - check_error!({esp_wifi_set_ps( - crate::binary::include::wifi_ps_type_t_WIFI_PS_MIN_MODEM - )})?; - } else { - check_error!({esp_wifi_set_ps( - crate::binary::include::wifi_ps_type_t_WIFI_PS_NONE - )})?; - } - }; check_error!({ esp_now_init() })?; check_error!({ esp_now_register_recv_cb(Some(rcv_cb)) })?; check_error!({ esp_now_register_send_cb(Some(send_cb)) })?; diff --git a/esp-wifi/src/lib.rs b/esp-wifi/src/lib.rs index b672d91a3a0..3a7d1e195b5 100644 --- a/esp-wifi/src/lib.rs +++ b/esp-wifi/src/lib.rs @@ -127,6 +127,8 @@ pub mod ble; #[cfg(feature = "esp-now")] pub mod esp_now; +pub mod config; + pub(crate) mod common_adapter; #[doc(hidden)] @@ -162,34 +164,7 @@ const _: () = { }; }; -#[derive(Debug)] -#[cfg_attr(feature = "defmt", derive(defmt::Format))] -/// Tunable parameters for the WiFi driver -#[allow(unused)] // currently there are no ble tunables -struct Config { - rx_queue_size: usize, - tx_queue_size: usize, - static_rx_buf_num: usize, - dynamic_rx_buf_num: usize, - static_tx_buf_num: usize, - dynamic_tx_buf_num: usize, - ampdu_rx_enable: bool, - ampdu_tx_enable: bool, - amsdu_tx_enable: bool, - rx_ba_win: usize, - max_burst_size: usize, - country_code: &'static str, - country_code_operating_class: u8, - mtu: usize, - tick_rate_hz: u32, - listen_interval: u16, - beacon_timeout: u16, - ap_beacon_timeout: u16, - failure_retry_cnt: u8, - scan_method: u32, -} - -pub(crate) const CONFIG: Config = Config { +pub(crate) const CONFIG: config::EspWifiConfig = config::EspWifiConfig { rx_queue_size: esp_config_int!(usize, "ESP_WIFI_RX_QUEUE_SIZE"), tx_queue_size: esp_config_int!(usize, "ESP_WIFI_TX_QUEUE_SIZE"), static_rx_buf_num: esp_config_int!(usize, "ESP_WIFI_STATIC_RX_BUF_NUM"), @@ -364,11 +339,9 @@ impl private::Sealed for Trng<'_> {} /// ```rust, no_run #[doc = esp_hal::before_snippet!()] /// use esp_hal::{rng::Rng, timg::TimerGroup}; -/// use esp_wifi::EspWifiInitFor; /// /// let timg0 = TimerGroup::new(peripherals.TIMG0); /// let init = esp_wifi::init( -/// EspWifiInitFor::Wifi, /// timg0.timer0, /// Rng::new(peripherals.RNG), /// peripherals.RADIO_CLK, diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index 37edfb8308a..e43fd83682a 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -50,7 +50,6 @@ use esp_wifi_sys::include::{ wifi_promiscuous_pkt_type_t, }; use num_derive::FromPrimitive; -use num_traits::FromPrimitive; #[doc(hidden)] pub(crate) use os_adapter::*; #[cfg(feature = "sniffer")] @@ -64,6 +63,7 @@ pub use state::*; use crate::{ common_adapter::*, + config::PowerSaveMode, esp_wifi_result, hal::{ macros::ram, @@ -105,7 +105,6 @@ use crate::binary::{ esp_wifi_set_country, esp_wifi_set_mode, esp_wifi_set_protocol, - esp_wifi_set_ps, esp_wifi_set_tx_done_cb, esp_wifi_start, esp_wifi_stop, @@ -1704,20 +1703,6 @@ pub(crate) fn wifi_start() -> Result<(), WifiError> { ))?; }; - cfg_if::cfg_if! { - if #[cfg(modem_powersaving = "min")] { - let ps_mode = include::wifi_ps_type_t_WIFI_PS_MIN_MODEM; - } else if #[cfg(modem_powersaving = "max")] { - let ps_mode = include::wifi_ps_type_t_WIFI_PS_MAX_MODEM; - } else if #[cfg(coex)] { - let ps_mode = include::wifi_ps_type_t_WIFI_PS_MIN_MODEM; - } else { - let ps_mode = include::wifi_ps_type_t_WIFI_PS_NONE; - } - }; - - esp_wifi_result!(esp_wifi_set_ps(ps_mode))?; - let mut cntry_code = [0u8; 3]; cntry_code[..crate::CONFIG.country_code.len()] .copy_from_slice(crate::CONFIG.country_code.as_bytes()); @@ -2606,6 +2591,14 @@ impl<'d> WifiController<'d> { Ok(()) } + /// Configures modem power saving + /// + /// This is ignored, and set to `PowerSaveMode::Minimum` when `coex` is + /// enabled. + pub fn set_power_saving(&mut self, ps: PowerSaveMode) -> Result<(), WifiError> { + apply_power_saving(ps) + } + /// Checks if Wi-Fi is enabled as a station. pub fn is_sta_enabled(&self) -> Result { WifiMode::try_from(&self.config).map(|m| m.is_sta()) @@ -3180,8 +3173,9 @@ fn dump_packet_info(_buffer: &[u8]) { #[macro_export] macro_rules! esp_wifi_result { ($value:expr) => {{ + use num_traits::FromPrimitive; let result = $value; - if result != include::ESP_OK as i32 { + if result != esp_wifi_sys::include::ESP_OK as i32 { warn!("{} returned an error: {}", stringify!($value), result); Err(WifiError::InternalError(unwrap!(FromPrimitive::from_i32( result @@ -3272,6 +3266,14 @@ pub(crate) mod embassy { } } +pub(crate) fn apply_power_saving(mut ps: PowerSaveMode) -> Result<(), WifiError> { + if cfg!(coex) { + ps = PowerSaveMode::Minimum; + } + esp_wifi_result!(unsafe { esp_wifi_sys::include::esp_wifi_set_ps(ps.into()) })?; + Ok(()) +} + mod asynch { use core::task::Poll; diff --git a/hil-test/Cargo.toml b/hil-test/Cargo.toml index 980d53dce0e..112d87941bb 100644 --- a/hil-test/Cargo.toml +++ b/hil-test/Cargo.toml @@ -249,21 +249,18 @@ esp32c3 = [ "esp-hal/esp32c3", "esp-hal-embassy?/esp32c3", "esp-wifi?/esp32c3", - "esp-wifi?/phy-enable-usb", ] esp32c6 = [ "esp-backtrace/esp32c6", "esp-hal/esp32c6", "esp-hal-embassy?/esp32c6", "esp-wifi?/esp32c6", - "esp-wifi?/phy-enable-usb", ] esp32h2 = [ "esp-backtrace/esp32h2", "esp-hal/esp32h2", "esp-hal-embassy?/esp32h2", "esp-wifi?/esp32h2", - "esp-wifi?/phy-enable-usb", ] esp32s2 = [ "embedded-test/xtensa-semihosting", @@ -278,7 +275,6 @@ esp32s3 = [ "esp-hal/esp32s3", "esp-hal-embassy?/esp32s3", "esp-wifi?/esp32s3", - "esp-wifi?/phy-enable-usb", ] # Async & Embassy: embassy = [ From 62fc1c6cdad64ce2054fa1be1e3425e5ae694e82 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Tue, 5 Nov 2024 16:33:27 +0000 Subject: [PATCH 06/10] fix linting --- .github/workflows/ci.yml | 14 +++++++------- xtask/src/main.rs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79f6b994eb0..e8bef8ccac6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -137,10 +137,10 @@ jobs: - name: msrv RISCV (esp-wifi) run: | - cargo xtask build-package --features=esp32c2,wifi,ble,async --target=riscv32imc-unknown-none-elf esp-wifi - cargo xtask build-package --features=esp32c3,wifi,ble,async --target=riscv32imc-unknown-none-elf esp-wifi - cargo xtask build-package --features=esp32c6,wifi,ble,async --target=riscv32imac-unknown-none-elf esp-wifi - cargo xtask build-package --features=esp32h2,ble,async --target=riscv32imac-unknown-none-elf esp-wifi + cargo xtask build-package --features=esp32c2,wifi,ble --target=riscv32imc-unknown-none-elf esp-wifi + cargo xtask build-package --features=esp32c3,wifi,ble --target=riscv32imc-unknown-none-elf esp-wifi + cargo xtask build-package --features=esp32c6,wifi,ble --target=riscv32imac-unknown-none-elf esp-wifi + cargo xtask build-package --features=esp32h2,ble --target=riscv32imac-unknown-none-elf esp-wifi # Verify the MSRV for all Xtensa chips: - name: msrv Xtensa (esp-hal) @@ -151,9 +151,9 @@ jobs: - name: msrv Xtensa (esp-wifi) run: | - cargo xtask build-package --toolchain=esp --features=esp32,wifi,ble,async --target=xtensa-esp32-none-elf esp-wifi - cargo xtask build-package --toolchain=esp --features=esp32s2,wifi,async --target=xtensa-esp32s2-none-elf esp-wifi - cargo xtask build-package --toolchain=esp --features=esp32s3,wifi,ble,async --target=xtensa-esp32s3-none-elf esp-wifi + cargo xtask build-package --toolchain=esp --features=esp32,wifi,ble --target=xtensa-esp32-none-elf esp-wifi + cargo xtask build-package --toolchain=esp --features=esp32s2,wifi --target=xtensa-esp32s2-none-elf esp-wifi + cargo xtask build-package --toolchain=esp --features=esp32s3,wifi,ble --target=xtensa-esp32s3-none-elf esp-wifi - name: msrv (esp-lp-hal) run: | diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 877aed838d0..9a4488c6dab 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -697,10 +697,10 @@ fn lint_packages(workspace: &Path, args: LintPackagesArgs) -> Result<()> { } Package::EspWifi => { - let mut features = format!("--features={chip},async,defmt,sys-logs"); + let mut features = format!("--features={chip},defmt,sys-logs"); if device.contains("wifi") { - features.push_str(",wifi-default,esp-now,embassy-net,sniffer") + features.push_str(",wifi-default,esp-now,sniffer") } if device.contains("bt") { features.push_str(",ble") From a1b732c9a60f68abb3e9d9c0a8fda3e28cac52fb Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Wed, 6 Nov 2024 12:38:07 +0000 Subject: [PATCH 07/10] changelog and migration guide --- esp-wifi/CHANGELOG.md | 6 ++++++ esp-wifi/MIGRATING-0.10.md | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index fcf7d07bb3b..5174947a718 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -10,12 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Added `serde` support through the `serde` feature (#2346) +- Added `PowerSaveMode` and `set_power_saving` methods on `EspNowManager` & `WifiController` (#2446) ### Changed - `esp_wifi::init` no longer requires `EspWifiInitFor`, and now returns `EspWifiController`, see the migration guide for more details (#2301) - No need to add `rom_functions.x` manually anymore (#2374) - esp-now: Data is now private in `ReceivedData` - use `data()`(#2396) +- Changed the async APIs to have a `_async` postfix to avoid name collisions (#2446) ### Fixed @@ -25,6 +27,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - Feature `have-strchr` is removed (#2462) +- Features `async`, `embassy-net` have been removed (#2446) +- Features `phy-enable-usb` & `dump-packets` have been turned into configuration options `phy_enable_usb` & `dump_packets` (#2446) +- Features `ps-min-modem` & `ps-max-modem` have been removed in favour of a runtime config (#2446) + ## 0.10.1 - 2024-10-10 diff --git a/esp-wifi/MIGRATING-0.10.md b/esp-wifi/MIGRATING-0.10.md index 0bf1d4c5c73..d2763ba21fb 100644 --- a/esp-wifi/MIGRATING-0.10.md +++ b/esp-wifi/MIGRATING-0.10.md @@ -33,3 +33,12 @@ rustflags = [ Previously `data` and `len` were public - use the previously already existing `data()` function. Accessing `data` or `len` was never encouraged. + +## Async features have been removed and async functionality is always available + +The cost of this is that we need to rename the various `async` methods on `WifiController`. + +```diff +- controller.start().await.unwrap(); ++ controller.start_async().await.unwrap(); +``` From b0c85c81afda1ff7c0278b93008d9491ce458754 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Wed, 6 Nov 2024 12:39:08 +0000 Subject: [PATCH 08/10] revert esp-config changes --- esp-config/src/generate.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/esp-config/src/generate.rs b/esp-config/src/generate.rs index 887b15e5dc8..1afa1c92591 100644 --- a/esp-config/src/generate.rs +++ b/esp-config/src/generate.rs @@ -149,17 +149,10 @@ fn emit_configuration( // emit cfgs and set envs for (name, value) in configs.into_iter() { let cfg_name = snake_case(name.trim_start_matches(prefix)); + println!("cargo:rustc-check-cfg=cfg({cfg_name})"); match value { - Value::Bool(b) => { - println!("cargo:rustc-check-cfg=cfg({cfg_name})"); - if *b { - println!("cargo:rustc-cfg={cfg_name}") - } - } - Value::String(v) => { - // TODO we need to emit the other option else we'll get a lint warning... - println!("cargo:rustc-check-cfg=cfg({cfg_name}, values(\"{v}\"))"); - println!("cargo:rustc-cfg={cfg_name}=\"{v}\"") + Value::Bool(true) => { + println!("cargo:rustc-cfg={cfg_name}") } _ => {} } From b783b9d69b7e7eeb9b0bdf43ccaaf507572ccc53 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Wed, 6 Nov 2024 14:53:32 +0000 Subject: [PATCH 09/10] remove blanklines after doc comments --- esp-wifi/src/ble/controller/mod.rs | 1 - esp-wifi/src/ble/os_adapter_esp32.rs | 2 -- esp-wifi/src/common_adapter/common_adapter_esp32.rs | 1 - 3 files changed, 4 deletions(-) diff --git a/esp-wifi/src/ble/controller/mod.rs b/esp-wifi/src/ble/controller/mod.rs index 31a51646767..7667a187982 100644 --- a/esp-wifi/src/ble/controller/mod.rs +++ b/esp-wifi/src/ble/controller/mod.rs @@ -83,7 +83,6 @@ impl Write for BleConnector<'_> { } /// Async Interface - pub(crate) mod asynch { use core::task::Poll; diff --git a/esp-wifi/src/ble/os_adapter_esp32.rs b/esp-wifi/src/ble/os_adapter_esp32.rs index 39f55cadc2b..f49c2ac05ba 100644 --- a/esp-wifi/src/ble/os_adapter_esp32.rs +++ b/esp-wifi/src/ble/os_adapter_esp32.rs @@ -586,7 +586,6 @@ const BTDM_ASYNC_WAKEUP_REQ_COEX: i32 = 1; /// true if request lock is needed, false otherwise /// /// ************************************************************************* - #[cfg(coex)] fn async_wakeup_request(event: i32) -> bool { let mut do_wakeup_request = false; @@ -623,7 +622,6 @@ fn async_wakeup_request(event: i32) -> bool { /// true if request lock is needed, false otherwise /// /// ************************************************************************* - #[cfg(coex)] fn async_wakeup_request_end(event: i32) { let request_lock = match event { diff --git a/esp-wifi/src/common_adapter/common_adapter_esp32.rs b/esp-wifi/src/common_adapter/common_adapter_esp32.rs index 26a05931a95..268311fe81c 100644 --- a/esp-wifi/src/common_adapter/common_adapter_esp32.rs +++ b/esp-wifi/src/common_adapter/common_adapter_esp32.rs @@ -155,7 +155,6 @@ pub(crate) unsafe fn phy_disable_clock() { /// Register value /// /// ************************************************************************* - #[ram] #[no_mangle] unsafe extern "C" fn esp_dport_access_reg_read(reg: u32) -> u32 { From c23613a91036643e78e13f039f5dfe766e602745 Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Thu, 7 Nov 2024 11:38:32 +0000 Subject: [PATCH 10/10] cfg away ps API --- esp-wifi/CHANGELOG.md | 1 + esp-wifi/src/config.rs | 12 ++++++------ esp-wifi/src/esp_now/mod.rs | 7 +++---- esp-wifi/src/wifi/mod.rs | 13 +++++-------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/esp-wifi/CHANGELOG.md b/esp-wifi/CHANGELOG.md index 5174947a718..7351d11a835 100644 --- a/esp-wifi/CHANGELOG.md +++ b/esp-wifi/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - No need to add `rom_functions.x` manually anymore (#2374) - esp-now: Data is now private in `ReceivedData` - use `data()`(#2396) - Changed the async APIs to have a `_async` postfix to avoid name collisions (#2446) +- `phy_enable_usb` is enabled by default (#2446) ### Fixed diff --git a/esp-wifi/src/config.rs b/esp-wifi/src/config.rs index 31f4a0125fa..92f2a97e167 100644 --- a/esp-wifi/src/config.rs +++ b/esp-wifi/src/config.rs @@ -1,5 +1,3 @@ -use esp_wifi_sys::include; - #[derive(Debug)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] /// Tunable parameters for the WiFi driver @@ -27,6 +25,7 @@ pub(crate) struct EspWifiConfig { pub(crate) scan_method: u32, } +#[cfg(not(coex))] #[non_exhaustive] #[derive(Default)] pub enum PowerSaveMode { @@ -36,12 +35,13 @@ pub enum PowerSaveMode { Maximum, } -impl From for include::wifi_ps_type_t { +#[cfg(not(coex))] +impl From for esp_wifi_sys::include::wifi_ps_type_t { fn from(s: PowerSaveMode) -> Self { match s { - PowerSaveMode::None => include::wifi_ps_type_t_WIFI_PS_NONE, - PowerSaveMode::Minimum => include::wifi_ps_type_t_WIFI_PS_MIN_MODEM, - PowerSaveMode::Maximum => include::wifi_ps_type_t_WIFI_PS_MAX_MODEM, + PowerSaveMode::None => esp_wifi_sys::include::wifi_ps_type_t_WIFI_PS_NONE, + PowerSaveMode::Minimum => esp_wifi_sys::include::wifi_ps_type_t_WIFI_PS_MIN_MODEM, + PowerSaveMode::Maximum => esp_wifi_sys::include::wifi_ps_type_t_WIFI_PS_MAX_MODEM, } } } diff --git a/esp-wifi/src/esp_now/mod.rs b/esp-wifi/src/esp_now/mod.rs index adc9e1889a1..cc65c355577 100644 --- a/esp-wifi/src/esp_now/mod.rs +++ b/esp-wifi/src/esp_now/mod.rs @@ -16,9 +16,10 @@ use critical_section::Mutex; use enumset::EnumSet; use portable_atomic::{AtomicBool, AtomicU8, Ordering}; +#[cfg(not(coex))] +use crate::config::PowerSaveMode; use crate::{ binary::include::*, - config::PowerSaveMode, hal::peripheral::{Peripheral, PeripheralRef}, wifi::{Protocol, RxControlInfo, WifiError}, EspWifiController, @@ -336,10 +337,8 @@ impl EspNowManager<'_> { Ok(()) } + #[cfg(not(coex))] /// Configures modem power saving - /// - /// This is ignored, and set to `PowerSaveMode::Minimum` when `coex` is - /// enabled. pub fn set_power_saving(&self, ps: PowerSaveMode) -> Result<(), WifiError> { crate::wifi::apply_power_saving(ps) } diff --git a/esp-wifi/src/wifi/mod.rs b/esp-wifi/src/wifi/mod.rs index e43fd83682a..cfc22ef2ddb 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -61,9 +61,10 @@ use serde::{Deserialize, Serialize}; use smoltcp::phy::{Device, DeviceCapabilities, RxToken, TxToken}; pub use state::*; +#[cfg(not(coex))] +use crate::config::PowerSaveMode; use crate::{ common_adapter::*, - config::PowerSaveMode, esp_wifi_result, hal::{ macros::ram, @@ -2591,10 +2592,8 @@ impl<'d> WifiController<'d> { Ok(()) } + #[cfg(not(coex))] /// Configures modem power saving - /// - /// This is ignored, and set to `PowerSaveMode::Minimum` when `coex` is - /// enabled. pub fn set_power_saving(&mut self, ps: PowerSaveMode) -> Result<(), WifiError> { apply_power_saving(ps) } @@ -3266,10 +3265,8 @@ pub(crate) mod embassy { } } -pub(crate) fn apply_power_saving(mut ps: PowerSaveMode) -> Result<(), WifiError> { - if cfg!(coex) { - ps = PowerSaveMode::Minimum; - } +#[cfg(not(coex))] +pub(crate) fn apply_power_saving(ps: PowerSaveMode) -> Result<(), WifiError> { esp_wifi_result!(unsafe { esp_wifi_sys::include::esp_wifi_set_ps(ps.into()) })?; Ok(()) }