mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 14:44:42 +00:00
Misc esp wifi (#3364)
* Allow `Configuration::None` * esp-wifi: set country early * CHANGELOG.md * Set power-save-mode to None initially
This commit is contained in:
parent
ba944a2931
commit
1c74bc2adf
@ -19,7 +19,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Update bt-hci version to fix serialization/deserialization of byte slices
|
- Update bt-hci version to fix serialization/deserialization of byte slices (#3340)
|
||||||
|
|
||||||
|
- Allow `Configuration::None`, set country early, changed default power-save-mode to None (#3364)
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ use esp_wifi_sys::include::{
|
|||||||
esp_eap_fast_config,
|
esp_eap_fast_config,
|
||||||
esp_wifi_sta_enterprise_enable,
|
esp_wifi_sta_enterprise_enable,
|
||||||
wifi_pkt_rx_ctrl_t,
|
wifi_pkt_rx_ctrl_t,
|
||||||
|
wifi_ps_type_t_WIFI_PS_NONE,
|
||||||
wifi_scan_channel_bitmap_t,
|
wifi_scan_channel_bitmap_t,
|
||||||
WIFI_PROTOCOL_11AX,
|
WIFI_PROTOCOL_11AX,
|
||||||
WIFI_PROTOCOL_11B,
|
WIFI_PROTOCOL_11B,
|
||||||
@ -1501,23 +1502,6 @@ pub(crate) fn wifi_start() -> Result<(), WifiError> {
|
|||||||
crate::CONFIG.beacon_timeout
|
crate::CONFIG.beacon_timeout
|
||||||
))?;
|
))?;
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut cntry_code = [0u8; 3];
|
|
||||||
cntry_code[..crate::CONFIG.country_code.len()]
|
|
||||||
.copy_from_slice(crate::CONFIG.country_code.as_bytes());
|
|
||||||
cntry_code[2] = crate::CONFIG.country_code_operating_class;
|
|
||||||
|
|
||||||
#[allow(clippy::useless_transmute)]
|
|
||||||
let country = wifi_country_t {
|
|
||||||
// FIXME once we bumped the MSRV accordingly (see https://github.com/esp-rs/esp-hal/pull/3027#discussion_r1944718266)
|
|
||||||
#[allow(clippy::useless_transmute)]
|
|
||||||
cc: core::mem::transmute::<[u8; 3], [core::ffi::c_char; 3]>(cntry_code),
|
|
||||||
schan: 1,
|
|
||||||
nchan: 13,
|
|
||||||
max_tx_power: 20,
|
|
||||||
policy: wifi_country_policy_t_WIFI_COUNTRY_POLICY_MANUAL,
|
|
||||||
};
|
|
||||||
esp_wifi_result!(esp_wifi_set_country(&country))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -2613,6 +2597,29 @@ pub fn new<'d>(
|
|||||||
) -> Result<(WifiController<'d>, Interfaces<'d>), WifiError> {
|
) -> Result<(WifiController<'d>, Interfaces<'d>), WifiError> {
|
||||||
if !inited.wifi() {
|
if !inited.wifi() {
|
||||||
crate::wifi::wifi_init()?;
|
crate::wifi::wifi_init()?;
|
||||||
|
|
||||||
|
let mut cntry_code = [0u8; 3];
|
||||||
|
cntry_code[..crate::CONFIG.country_code.len()]
|
||||||
|
.copy_from_slice(crate::CONFIG.country_code.as_bytes());
|
||||||
|
cntry_code[2] = crate::CONFIG.country_code_operating_class;
|
||||||
|
|
||||||
|
#[allow(clippy::useless_transmute)]
|
||||||
|
unsafe {
|
||||||
|
let country = wifi_country_t {
|
||||||
|
// FIXME once we bumped the MSRV accordingly (see https://github.com/esp-rs/esp-hal/pull/3027#discussion_r1944718266)
|
||||||
|
#[allow(clippy::useless_transmute)]
|
||||||
|
cc: core::mem::transmute::<[u8; 3], [core::ffi::c_char; 3]>(cntry_code),
|
||||||
|
schan: 1,
|
||||||
|
nchan: 13,
|
||||||
|
max_tx_power: 20,
|
||||||
|
policy: wifi_country_policy_t_WIFI_COUNTRY_POLICY_MANUAL,
|
||||||
|
};
|
||||||
|
esp_wifi_result!(esp_wifi_set_country(&country))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
esp_wifi_result!(unsafe {
|
||||||
|
esp_wifi_sys::include::esp_wifi_set_ps(wifi_ps_type_t_WIFI_PS_NONE)
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
Ok((
|
Ok((
|
||||||
WifiController {
|
WifiController {
|
||||||
@ -2805,15 +2812,16 @@ impl WifiController<'_> {
|
|||||||
///
|
///
|
||||||
/// This will set the mode accordingly.
|
/// This will set the mode accordingly.
|
||||||
/// You need to use Wifi::connect() for connecting to an AP.
|
/// You need to use Wifi::connect() for connecting to an AP.
|
||||||
|
///
|
||||||
|
/// Passing [Configuration::None] will disable both, AP and STA mode.
|
||||||
|
///
|
||||||
|
/// If you don't intent to use WiFi anymore at all consider tearing down
|
||||||
|
/// WiFi completely.
|
||||||
pub fn set_configuration(&mut self, conf: &Configuration) -> Result<(), WifiError> {
|
pub fn set_configuration(&mut self, conf: &Configuration) -> Result<(), WifiError> {
|
||||||
conf.validate()?;
|
conf.validate()?;
|
||||||
|
|
||||||
let mode = match conf {
|
let mode = match conf {
|
||||||
Configuration::None => {
|
Configuration::None => wifi_mode_t_WIFI_MODE_NULL,
|
||||||
return Err(WifiError::InternalError(
|
|
||||||
InternalWifiError::EspErrInvalidArg,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Configuration::Client(_) => wifi_mode_t_WIFI_MODE_STA,
|
Configuration::Client(_) => wifi_mode_t_WIFI_MODE_STA,
|
||||||
Configuration::AccessPoint(_) => wifi_mode_t_WIFI_MODE_AP,
|
Configuration::AccessPoint(_) => wifi_mode_t_WIFI_MODE_AP,
|
||||||
Configuration::Mixed(_, _) => wifi_mode_t_WIFI_MODE_APSTA,
|
Configuration::Mixed(_, _) => wifi_mode_t_WIFI_MODE_APSTA,
|
||||||
@ -2823,25 +2831,20 @@ impl WifiController<'_> {
|
|||||||
esp_wifi_result!(unsafe { esp_wifi_set_mode(mode) })?;
|
esp_wifi_result!(unsafe { esp_wifi_set_mode(mode) })?;
|
||||||
|
|
||||||
match conf {
|
match conf {
|
||||||
Configuration::None => {
|
Configuration::None => Ok::<(), WifiError>(()),
|
||||||
return Err(WifiError::InternalError(
|
Configuration::Client(config) => apply_sta_config(config),
|
||||||
InternalWifiError::EspErrInvalidArg,
|
Configuration::AccessPoint(config) => apply_ap_config(config),
|
||||||
));
|
|
||||||
}
|
|
||||||
Configuration::Client(config) => {
|
|
||||||
apply_sta_config(config)?;
|
|
||||||
}
|
|
||||||
Configuration::AccessPoint(config) => {
|
|
||||||
apply_ap_config(config)?;
|
|
||||||
}
|
|
||||||
Configuration::Mixed(sta_config, ap_config) => {
|
Configuration::Mixed(sta_config, ap_config) => {
|
||||||
apply_ap_config(ap_config)?;
|
apply_ap_config(ap_config).and_then(|()| apply_sta_config(sta_config))
|
||||||
apply_sta_config(sta_config)?;
|
|
||||||
}
|
}
|
||||||
Configuration::EapClient(config) => {
|
Configuration::EapClient(config) => apply_sta_eap_config(config),
|
||||||
apply_sta_eap_config(config)?;
|
|
||||||
}
|
}
|
||||||
};
|
.inspect_err(|_| {
|
||||||
|
// we/the driver might have applied a partial configuration
|
||||||
|
// so we better disable AP/STA just in case the caller ignores the error we
|
||||||
|
// return here - they will run into futher errors this way
|
||||||
|
unsafe { esp_wifi_set_mode(wifi_mode_t_WIFI_MODE_NULL) };
|
||||||
|
})?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user