wip: add async-wifi support to S3-BOX

This commit is contained in:
Juraj Michálek 2025-07-14 08:11:42 +02:00 committed by Simon Hausmann
parent 2d27a17c37
commit 4e017f989d
2 changed files with 47 additions and 1 deletions

View file

@ -58,8 +58,38 @@ pub fn init() {
}))
.expect("backend already initialized");
}
macro_rules! mk_static {
($t:ty, $val:expr) => {{
static STATIC_CELL: static_cell::StaticCell<$t> = static_cell::StaticCell::new();
STATIC_CELL.init($val)
}};
}
use esp_wifi::wifi;
use esp_wifi::{
wifi::{ClientConfiguration, Configuration, WifiController, WifiEvent, WifiState},
EspWifiController,
};
use esp_hal::{rng::Rng, timer::timg::TimerGroup};
impl EspBackend {
pub fn wifi<'a>(&self, ssid: &'a str, password: &'a str) -> (wifi::WifiController<'a>, wifi::WifiDevice<'a>) {
// Initialize the Wi-Fi controller and device.
let peripherals = self.peripherals.borrow_mut().take().expect("Peripherals already taken");
let mut rng = Rng::new(peripherals.RNG);
let timer1 = TimerGroup::new(peripherals.TIMG0);
let wifi_init = &*mk_static!(
EspWifiController<'static>,
esp_wifi::init(timer1.timer0, rng.clone(), peripherals.RADIO_CLK).unwrap()
);
let (mut wifi_controller, interfaces) = esp_wifi::wifi::new(&wifi_init, peripherals.WIFI)
.expect("Failed to initialize WIFI controller");
let config = embassy_net::Config::dhcpv4(Default::default());
let wifi_device = interfaces.sta;
(wifi_controller, wifi_device)
}
impl slint::platform::Platform for EspBackend {
fn create_window_adapter(
&self,
) -> Result<Rc<dyn slint::platform::WindowAdapter>, slint::PlatformError> {