summaryrefslogtreecommitdiff
path: root/embassy-nrf
diff options
context:
space:
mode:
authoralexmoon <alex.r.moon@gmail.com>2022-04-01 15:48:37 -0400
committerDario Nieuwenhuis <dirbaio@dirbaio.net>2022-04-06 05:38:11 +0200
commitc8ad82057d25e6b9414c7065a750761e510d84d9 (patch)
tree7149db9cff6d6da49ec3d683e3794988c08d72ff /embassy-nrf
parentc309531874052bc96ef9ce39dd8698c120cee824 (diff)
downloadembassy-c8ad82057d25e6b9414c7065a750761e510d84d9.zip
Reduce memory overhead and simplify logic for merging endpoint and control request output reports.
Diffstat (limited to 'embassy-nrf')
-rw-r--r--embassy-nrf/src/usb.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/embassy-nrf/src/usb.rs b/embassy-nrf/src/usb.rs
index 124316a2..df0efa51 100644
--- a/embassy-nrf/src/usb.rs
+++ b/embassy-nrf/src/usb.rs
@@ -443,12 +443,27 @@ unsafe fn write_dma<T: Instance>(i: usize, buf: &[u8]) {
impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
type ReadFuture<'a> = impl Future<Output = Result<usize, ReadError>> + 'a where Self: 'a;
+ type DataReadyFuture<'a> = impl Future<Output = ()> + 'a where Self: 'a;
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
async move {
let i = self.info.addr.index();
assert!(i != 0);
+ self.wait_data_ready().await;
+
+ // Mark as not ready
+ READY_ENDPOINTS.fetch_and(!(1 << (i + 16)), Ordering::AcqRel);
+
+ unsafe { read_dma::<T>(i, buf) }
+ }
+ }
+
+ fn wait_data_ready<'a>(&'a mut self) -> Self::DataReadyFuture<'a> {
+ async move {
+ let i = self.info.addr.index();
+ assert!(i != 0);
+
// Wait until ready
poll_fn(|cx| {
EP_OUT_WAKERS[i - 1].register(cx.waker());
@@ -460,11 +475,6 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> {
}
})
.await;
-
- // Mark as not ready
- READY_ENDPOINTS.fetch_and(!(1 << (i + 16)), Ordering::AcqRel);
-
- unsafe { read_dma::<T>(i, buf) }
}
}
}