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 988bcc07788..1a918f62972 100644 --- a/esp-wifi/Cargo.toml +++ b/esp-wifi/Cargo.toml @@ -106,27 +106,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"] @@ -154,18 +157,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"] - -# Don't include `strchr` - not shown in docs -have-strchr = [] - # Implement serde Serialize / Deserialize serde = ["dep:serde", "enumset?/serde", "heapless/serde"] @@ -178,3 +169,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/compat/misc.rs b/esp-wifi/src/compat/misc.rs index 91035ffe268..409a3e4fa5b 100644 --- a/esp-wifi/src/compat/misc.rs +++ b/esp-wifi/src/compat/misc.rs @@ -46,12 +46,12 @@ unsafe extern "C" fn strcmp(str1: *const i8, str2: *const i8) -> i32 { } } -#[cfg(feature = "have-strchr")] +#[cfg(strchr_available)] extern "C" { fn strchr(str: *const i8, c: i32) -> *const i8; } -#[cfg(not(feature = "have-strchr"))] +#[cfg(not(strchr_available))] #[no_mangle] unsafe extern "C" fn strchr(str: *const i8, c: i32) -> *const i8 { trace!("strchr {:?} {}", str, c); diff --git a/esp-wifi/src/esp_now/mod.rs b/esp-wifi/src/esp_now/mod.rs index dfead4e3ea5..50bc140809d 100644 --- a/esp-wifi/src/esp_now/mod.rs +++ b/esp-wifi/src/esp_now/mod.rs @@ -658,11 +658,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 4d88729749b..e8e57d3d829 100644 --- a/esp-wifi/src/wifi/mod.rs +++ b/esp-wifi/src/wifi/mod.rs @@ -1694,9 +1694,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 a8f8d614d84..6a8a21ece39 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 2a952ebc53b..3e9115197d3 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 3b151f72eb3..b7efa320849 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 f946f6aebdd..5255b3442cd 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 6943be33ff3..674e3633a1d 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 7b78bee6209..aaaed5d526d 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 487c64ad5a1..388b965f969 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 a221272c62f..c8c36916209 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 cb068688aea..3c36229f46b 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 d4f8069449f..7ed3b672fc1 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 f2a3373b9d6..8288c367d5b 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")