mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 16:23:10 +00:00
esp-hosted: wait for esp firmware init.
This commit is contained in:
parent
082f1ab494
commit
764b43e82c
@ -29,6 +29,9 @@ impl<'a> Control<'a> {
|
||||
}
|
||||
|
||||
pub async fn init(&mut self) {
|
||||
debug!("wait for init event...");
|
||||
self.shared.init_wait().await;
|
||||
|
||||
debug!("set wifi mode");
|
||||
self.set_wifi_mode(WifiMode::Sta as _).await;
|
||||
let mac_addr = self.get_mac_addr().await;
|
||||
|
@ -23,6 +23,7 @@ pub struct Shared(RefCell<SharedInner>);
|
||||
|
||||
struct SharedInner {
|
||||
ioctl: IoctlState,
|
||||
is_init: bool,
|
||||
control_waker: WakerRegistration,
|
||||
runner_waker: WakerRegistration,
|
||||
}
|
||||
@ -31,6 +32,7 @@ impl Shared {
|
||||
pub fn new() -> Self {
|
||||
Self(RefCell::new(SharedInner {
|
||||
ioctl: IoctlState::Done { resp_len: 0 },
|
||||
is_init: false,
|
||||
control_waker: WakerRegistration::new(),
|
||||
runner_waker: WakerRegistration::new(),
|
||||
}))
|
||||
@ -97,4 +99,25 @@ impl Shared {
|
||||
warn!("IOCTL Response but no pending Ioctl");
|
||||
}
|
||||
}
|
||||
|
||||
// // // // // // // // // // // // // // // // // // // //
|
||||
|
||||
pub fn init_done(&self) {
|
||||
let mut this = self.0.borrow_mut();
|
||||
this.is_init = true;
|
||||
this.control_waker.wake();
|
||||
}
|
||||
|
||||
pub async fn init_wait(&self) {
|
||||
poll_fn(|cx| {
|
||||
let mut this = self.0.borrow_mut();
|
||||
if this.is_init {
|
||||
Poll::Ready(())
|
||||
} else {
|
||||
this.control_waker.register(cx.waker());
|
||||
Poll::Pending
|
||||
}
|
||||
})
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ use ioctl::Shared;
|
||||
use proto::CtrlMsg;
|
||||
|
||||
use crate::ioctl::PendingIoctl;
|
||||
use crate::proto::CtrlMsgPayload;
|
||||
|
||||
mod proto;
|
||||
|
||||
@ -308,6 +309,16 @@ where
|
||||
};
|
||||
|
||||
debug!("event: {:?}", &event);
|
||||
|
||||
let Some(payload) = &event.payload else {
|
||||
warn!("event without payload?");
|
||||
return
|
||||
};
|
||||
|
||||
match payload {
|
||||
CtrlMsgPayload::EventEspInit(_) => self.shared.init_done(),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,9 +69,6 @@ async fn main(spawner: Spawner) {
|
||||
|
||||
unwrap!(spawner.spawn(wifi_task(runner)));
|
||||
|
||||
// TODO: wait for ESP_INIT event instead of hardcoding delay.
|
||||
Timer::after(Duration::from_secs(3)).await;
|
||||
|
||||
control.init().await;
|
||||
control.join(env!("WIFI_NETWORK"), env!("WIFI_PASSWORD")).await;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user