aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
authorAlex Moon <[email protected]>2024-04-16 12:14:22 -0400
committerAlex Moon <[email protected]>2024-04-16 12:14:22 -0400
commit34668bae5c646d03e744efddc86052dbebe0ec40 (patch)
treeb9ae0414d8cc3e9de17442cd07cba16ec4988fa2 /embassy-nrf
parentbd13b5c0604787a52322308353bec9996f9a199d (diff)
Add `wait_disabled` method to `embassy_nrf::usb::Endpoint`
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/src/usb/mod.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/embassy-nrf/src/usb/mod.rs b/embassy-nrf/src/usb/mod.rs
index 09cf87e97..8cbb1a350 100644
--- a/embassy-nrf/src/usb/mod.rs
+++ b/embassy-nrf/src/usb/mod.rs
@@ -471,12 +471,19 @@ impl<'d, T: Instance, Dir: EndpointDir> driver::Endpoint for Endpoint<'d, T, Dir
471 } 471 }
472 472
473 async fn wait_enabled(&mut self) { 473 async fn wait_enabled(&mut self) {
474 self.wait_enabled_state(true).await
475 }
476}
477
478#[allow(private_bounds)]
479impl<'d, T: Instance, Dir: EndpointDir> Endpoint<'d, T, Dir> {
480 async fn wait_enabled_state(&mut self, state: bool) {
474 let i = self.info.addr.index(); 481 let i = self.info.addr.index();
475 assert!(i != 0); 482 assert!(i != 0);
476 483
477 poll_fn(move |cx| { 484 poll_fn(move |cx| {
478 Dir::waker(i).register(cx.waker()); 485 Dir::waker(i).register(cx.waker());
479 if Dir::is_enabled(T::regs(), i) { 486 if Dir::is_enabled(T::regs(), i) == state {
480 Poll::Ready(()) 487 Poll::Ready(())
481 } else { 488 } else {
482 Poll::Pending 489 Poll::Pending
@@ -484,6 +491,11 @@ impl<'d, T: Instance, Dir: EndpointDir> driver::Endpoint for Endpoint<'d, T, Dir
484 }) 491 })
485 .await 492 .await
486 } 493 }
494
495 /// Wait for the endpoint to be disabled
496 pub async fn wait_disabled(&mut self) {
497 self.wait_enabled_state(false).await
498 }
487} 499}
488 500
489impl<'d, T: Instance, Dir> Endpoint<'d, T, Dir> { 501impl<'d, T: Instance, Dir> Endpoint<'d, T, Dir> {