Skip to content
Open
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
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ pub mod tls;
esp_idf_comp_esp_event_enabled,
))]
pub mod wifi;
#[cfg(all(
feature = "alloc",
esp_idf_comp_wpa_supplicant_enabled,
any(esp_idf_esp_wifi_dpp_support, esp_idf_wpa_dpp_support)
))]
pub mod wifi_dpp;
pub mod ws;

mod private;
39 changes: 39 additions & 0 deletions src/private/waitable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ where
}
}

pub fn wait_while_and_get_mut<Q>(
&self,
condition: impl Fn(&T) -> bool,
getter: impl Fn(&mut T) -> Q,
) -> Q {
let mut state = self.state.lock();

loop {
if !condition(&state) {
return getter(&mut state);
}

state = self.cvar.wait(state);
}
}

pub fn wait_timeout_while_and_get<Q>(
&self,
dur: Duration,
Expand All @@ -80,4 +96,27 @@ where
}
}
}

pub fn wait_timeout_while_and_get_mut<Q>(
&self,
dur: Duration,
condition: impl Fn(&T) -> bool,
getter: impl Fn(&mut T) -> Q,
) -> (bool, Q) {
let mut state = self.state.lock();

loop {
if !condition(&state) {
return (false, getter(&mut state));
}

let (new_state, timeout) = self.cvar.wait_timeout(state, dur);

state = new_state;

if timeout {
return (true, getter(&mut state));
}
}
}
}
23 changes: 23 additions & 0 deletions src/wifi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ use crate::private::cstr::*;
use crate::private::mutex;
use crate::private::waitable::*;

#[cfg(all(
feature = "alloc",
esp_idf_comp_wpa_supplicant_enabled,
any(esp_idf_esp_wifi_dpp_support, esp_idf_wpa_dpp_support)
))]
use crate::wifi_dpp::{EspWifiDpp, QrCode};

pub mod config {
use core::time::Duration;

Expand Down Expand Up @@ -1122,6 +1129,22 @@ impl<'d> EspWifi<'d> {

Ok(())
}

/// Generate a QR code that can be used with a Wi-Fi Easy Connect compatible
/// configurator (e.g. a smart phone) to provision the MCU.
#[cfg(all(
feature = "alloc",
esp_idf_comp_wpa_supplicant_enabled,
any(esp_idf_esp_wifi_dpp_support, esp_idf_wpa_dpp_support)
))]
pub fn dpp_generate_qrcode(
&mut self,
channels: &[u8],
key: Option<&[u8; 32]>,
associated_data: Option<&[u8]>,
) -> Result<EspWifiDpp<'_, 'd, QrCode>, EspError> {
EspWifiDpp::generate_qrcode(self, channels, key, associated_data)
}
}

#[cfg(esp_idf_comp_esp_netif_enabled)]
Expand Down
Loading