Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- NVS: Implemented `RawHandle` for `EspNvs<NvsDefault>`
- NVS: Added `EspNvs::erase_all` to remove all data stored in an nvs namespace
- NVS: Added `EspNvs::keys` to iterate over all stored keys
- esp32p4: This chip has no radio, so wifi has been disabled for this
- esp32p4: This chip has no radio, but can use wifi via esp_wifi_remote. Support for esp_wifi_remote has been added.
- HTTP: added `keep_alive_*` option into configuration

## [0.51.0] - 2025-01-15
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ pub mod thread;
pub mod timer;
pub mod tls;
#[cfg(all(
not(any(esp32h2, esp32p4)),
not(esp32h2),
feature = "alloc",
esp_idf_comp_esp_wifi_enabled,
any(esp_idf_comp_esp_wifi_enabled, esp_idf_comp_esp_wifi_remote_enabled),
esp_idf_comp_esp_event_enabled,
))]
pub mod wifi;
Expand Down
21 changes: 19 additions & 2 deletions src/netif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,26 @@ impl NetifStack {
fn default_mac(&self) -> Result<Option<[u8; 6]>, EspError> {
if let Some(mac_type) = self.default_mac_raw_type() {
let mut mac = [0; 6];
esp!(unsafe { esp_read_mac(mac.as_mut_ptr() as *mut _, mac_type) })?;

Ok(Some(mac))
// On SoCs without native WiFi hardware (e.g., ESP32-P4 using
// esp_wifi_remote), the eFuse has no WiFi MAC address.
// esp_read_mac will fail for WiFi MAC types. Return None and let
// esp_wifi_start() set the real MAC from the companion chip later.
#[cfg(not(esp_idf_soc_wifi_supported))]
{
let err = unsafe { esp_read_mac(mac.as_mut_ptr() as *mut _, mac_type) };
if err == ESP_OK {
return Ok(Some(mac));
} else {
return Ok(None);
}
}

#[cfg(esp_idf_soc_wifi_supported)]
{
esp!(unsafe { esp_read_mac(mac.as_mut_ptr() as *mut _, mac_type) })?;
Ok(Some(mac))
}
} else {
Ok(None)
}
Expand Down
43 changes: 32 additions & 11 deletions src/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2373,18 +2373,39 @@ impl EspEventDeserializer for WifiEvent<'_> {
),
)))]
wifi_event_t_WIFI_EVENT_HOME_CHANNEL_CHANGE => {
let payload = unsafe {
(data.payload.unwrap() as *const _ as *const wifi_event_home_channel_change_t)
.as_ref()
#[cfg(esp_idf_soc_wifi_supported)]
{
let payload = unsafe {
(data.payload.unwrap() as *const _
as *const wifi_event_home_channel_change_t)
.as_ref()
}
.unwrap();

WifiEvent::HomeChannelChange(HomeChannelChange {
old_chan: payload.old_chan,
old_snd: payload.old_snd.try_into().ok(),
new_chan: payload.new_chan,
new_snd: payload.new_snd.try_into().ok(),
})
}

// On SoCs without native WiFi (using esp_wifi_remote), this
// event may fire without a payload.
#[cfg(not(esp_idf_soc_wifi_supported))]
{
let payload = data
.payload
.map(|p| p as *const _ as *const wifi_event_home_channel_change_t)
.and_then(|p| unsafe { p.as_ref() });

WifiEvent::HomeChannelChange(HomeChannelChange {
old_chan: payload.map_or(0, |p| p.old_chan),
old_snd: payload.and_then(|p| p.old_snd.try_into().ok()),
new_chan: payload.map_or(0, |p| p.new_chan),
new_snd: payload.and_then(|p| p.new_snd.try_into().ok()),
})
}
.unwrap();

WifiEvent::HomeChannelChange(HomeChannelChange {
old_chan: payload.old_chan,
old_snd: payload.old_snd.try_into().ok(),
new_chan: payload.new_chan,
new_snd: payload.new_snd.try_into().ok(),
})
}
_ => panic!("unknown event ID: {event_id}"),
}
Expand Down