Skip to content

Commit

Permalink
modem powersaving
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Nov 1, 2024
1 parent 060aa7e commit 9c2ab81
Show file tree
Hide file tree
Showing 18 changed files with 46 additions and 44 deletions.
13 changes: 10 additions & 3 deletions esp-config/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}\"")
}
_ => {}
}
Expand Down
38 changes: 16 additions & 22 deletions esp-wifi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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"]

Expand All @@ -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"))'] }
2 changes: 2 additions & 0 deletions esp-wifi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ fn main() -> Result<(), Box<dyn Error>> {
("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
);
Expand Down
4 changes: 2 additions & 2 deletions esp-wifi/src/compat/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions esp-wifi/src/esp_now/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)})?;
Expand Down
4 changes: 2 additions & 2 deletions esp-wifi/src/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_80211_tx.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_access_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_access_point_with_sta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_coex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_dhcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_embassy_access_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_embassy_access_point_with_sta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_embassy_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_sniffer.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/src/bin/wifi_static_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9c2ab81

Please sign in to comment.