mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-21 22:32:29 +00:00
Merge pull request #2827 from alexmoon/wait-disabled
Add `wait_disabled` method to `embassy_nrf::usb::Endpoint`
This commit is contained in:
commit
1b36bef4b8
@ -471,12 +471,19 @@ impl<'d, T: Instance, Dir: EndpointDir> driver::Endpoint for Endpoint<'d, T, Dir
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn wait_enabled(&mut self) {
|
async fn wait_enabled(&mut self) {
|
||||||
|
self.wait_enabled_state(true).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[allow(private_bounds)]
|
||||||
|
impl<'d, T: Instance, Dir: EndpointDir> Endpoint<'d, T, Dir> {
|
||||||
|
async fn wait_enabled_state(&mut self, state: bool) {
|
||||||
let i = self.info.addr.index();
|
let i = self.info.addr.index();
|
||||||
assert!(i != 0);
|
assert!(i != 0);
|
||||||
|
|
||||||
poll_fn(move |cx| {
|
poll_fn(move |cx| {
|
||||||
Dir::waker(i).register(cx.waker());
|
Dir::waker(i).register(cx.waker());
|
||||||
if Dir::is_enabled(T::regs(), i) {
|
if Dir::is_enabled(T::regs(), i) == state {
|
||||||
Poll::Ready(())
|
Poll::Ready(())
|
||||||
} else {
|
} else {
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
@ -484,6 +491,11 @@ impl<'d, T: Instance, Dir: EndpointDir> driver::Endpoint for Endpoint<'d, T, Dir
|
|||||||
})
|
})
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Wait for the endpoint to be disabled
|
||||||
|
pub async fn wait_disabled(&mut self) {
|
||||||
|
self.wait_enabled_state(false).await
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'d, T: Instance, Dir> Endpoint<'d, T, Dir> {
|
impl<'d, T: Instance, Dir> Endpoint<'d, T, Dir> {
|
||||||
|
Loading…
Reference in New Issue
Block a user