aboutsummaryrefslogtreecommitdiff
path: root/embassy-nrf/src
diff options
context:
space:
mode:
authoralexmoon <[email protected]>2022-04-02 11:58:01 -0400
committerDario Nieuwenhuis <[email protected]>2022-04-06 05:38:11 +0200
commit99f95a33c30b08359fcd72123fea01f4de0903ec (patch)
tree95297df73349718b02f55e759f07c6edfd0d9390 /embassy-nrf/src
parentc8ad82057d25e6b9414c7065a750761e510d84d9 (diff)
Simplify hid output report handling
Diffstat (limited to 'embassy-nrf/src')
-rw-r--r--embassy-nrf/src/usb.rs20
1 files changed, 5 insertions, 15 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs
index df0efa511..124316a29 100644
--- a/embassy-nrf/src/usb.rs
+++ b/embassy-nrf/src/usb.rs
@@ -443,27 +443,12 @@ unsafe fn write_dma<T: Instance>(i: usize, buf: &[u8]) {
443 443
444impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { 444impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
445 type ReadFuture<'a> = impl Future<Output = Result<usize, ReadError>> + 'a where Self: 'a; 445 type ReadFuture<'a> = impl Future<Output = Result<usize, ReadError>> + 'a where Self: 'a;
446 type DataReadyFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
447 446
448 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> { 447 fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
449 async move { 448 async move {
450 let i = self.info.addr.index(); 449 let i = self.info.addr.index();
451 assert!(i != 0); 450 assert!(i != 0);
452 451
453 self.wait_data_ready().await;
454
455 // Mark as not ready
456 READY_ENDPOINTS.fetch_and(!(1 << (i + 16)), Ordering::AcqRel);
457
458 unsafe { read_dma::<T>(i, buf) }
459 }
460 }
461
462 fn wait_data_ready<'a>(&'a mut self) -> Self::DataReadyFuture<'a> {
463 async move {
464 let i = self.info.addr.index();
465 assert!(i != 0);
466
467 // Wait until ready 452 // Wait until ready
468 poll_fn(|cx| { 453 poll_fn(|cx| {
469 EP_OUT_WAKERS[i - 1].register(cx.waker()); 454 EP_OUT_WAKERS[i - 1].register(cx.waker());
@@ -475,6 +460,11 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
475 } 460 }
476 }) 461 })
477 .await; 462 .await;
463
464 // Mark as not ready
465 READY_ENDPOINTS.fetch_and(!(1 << (i + 16)), Ordering::AcqRel);
466
467 unsafe { read_dma::<T>(i, buf) }
478 } 468 }
479 } 469 }
480} 470}