Skip to content

Commit

Permalink
Add wifi_set_mode for Wifi Protocol Support (esp-rs#156)
Browse files Browse the repository at this point in the history
* Add set_mode

* Revert unnecessary changes

* Review changes

* Removed unecessary change

* Review changes, merge conflict fix
  • Loading branch information
Nereuxofficial authored and bjoernQ committed May 23, 2024
1 parent 38bce5d commit dbf2867
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 0 additions & 2 deletions esp-wifi/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ fn main() -> Result<(), String> {
.to_string();
println!("cargo:warning={}", message);
}

()
}
Err(_err) => (),
}
Expand Down
22 changes: 21 additions & 1 deletion esp-wifi/src/wifi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::common_adapter::*;

use crate::esp_wifi_result;
use critical_section::Mutex;
use embedded_svc::wifi::{AccessPointInfo, AuthMethod, SecondaryChannel};
use embedded_svc::wifi::{AccessPointInfo, AuthMethod, Protocol, SecondaryChannel};
use enumset::EnumSet;
use enumset::EnumSetType;
use esp_hal_common::peripheral::Peripheral;
Expand All @@ -29,6 +29,7 @@ use esp_wifi_sys::include::wifi_interface_t_WIFI_IF_AP;
use esp_wifi_sys::include::wifi_mode_t_WIFI_MODE_AP;
use esp_wifi_sys::include::wifi_mode_t_WIFI_MODE_APSTA;
use esp_wifi_sys::include::wifi_mode_t_WIFI_MODE_NULL;
use esp_wifi_sys::include::esp_wifi_set_protocol;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;

Expand Down Expand Up @@ -752,6 +753,25 @@ impl<'d> WifiController<'d> {
Self { _device, config }
}

/// Set the wifi mode.
/// This will set the wifi protocol to the desired protocol, the default for this is:
/// `WIFI_PROTOCOL_11B|WIFI_PROTOCOL_11G|WIFI_PROTOCOL_11N`
/// # Arguments:
/// * `protocol` - The desired protocol
/// # Example:
/// ```
/// use embedded_svc::wifi::Protocol;
/// use esp_wifi::wifi::WifiController;
/// let mut wifi = WifiController::new();
/// wifi.set_mode(Protocol::P802D11BGNLR);
/// ```
pub fn set_mode(&mut self, protocol: Protocol) -> Result<(), WifiError> {
let mut mode = wifi_mode_t_WIFI_MODE_NULL;
esp_wifi_result!(unsafe { esp_wifi_get_mode(&mut mode) })?;
esp_wifi_result!(unsafe { esp_wifi_set_protocol(mode, protocol as u8) })?;
Ok(())
}

fn is_sta_enabled(&self) -> Result<bool, WifiError> {
let mut mode: esp_wifi_sys::include::wifi_mode_t = 0;
esp_wifi_result!(unsafe { esp_wifi_sys::include::esp_wifi_get_mode(&mut mode) })?;
Expand Down

0 comments on commit dbf2867

Please sign in to comment.