Skip to content

Commit

Permalink
cfg away ps API
Browse files Browse the repository at this point in the history
  • Loading branch information
MabezDev committed Nov 7, 2024
1 parent b783b9d commit 9a3811e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions esp-wifi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions esp-wifi/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(crate) struct EspWifiConfig {
pub(crate) scan_method: u32,
}

#[cfg(not(coex))]
#[non_exhaustive]
#[derive(Default)]
pub enum PowerSaveMode {
Expand All @@ -36,6 +37,7 @@ pub enum PowerSaveMode {
Maximum,
}

#[cfg(not(coex))]
impl From<PowerSaveMode> for include::wifi_ps_type_t {
fn from(s: PowerSaveMode) -> Self {
match s {
Expand Down
7 changes: 3 additions & 4 deletions esp-wifi/src/esp_now/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ use critical_section::Mutex;
use enumset::EnumSet;
use portable_atomic::{AtomicBool, AtomicU8, Ordering};

#[cfg(coex)]
use crate::config::PowerSaveMode;
use crate::{
binary::include::*,
config::PowerSaveMode,
hal::peripheral::{Peripheral, PeripheralRef},
wifi::{Protocol, RxControlInfo, WifiError},
EspWifiController,
Expand Down Expand Up @@ -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)
}
Expand Down
13 changes: 5 additions & 8 deletions esp-wifi/src/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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(())
}
Expand Down

0 comments on commit 9a3811e

Please sign in to comment.