aboutsummaryrefslogtreecommitdiff
path: root/embassy-usb-driver/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'embassy-usb-driver/src/lib.rs')
-rw-r--r--embassy-usb-driver/src/lib.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/embassy-usb-driver/src/lib.rs b/embassy-usb-driver/src/lib.rs
index 99616f1ec..3ad96c61d 100644
--- a/embassy-usb-driver/src/lib.rs
+++ b/embassy-usb-driver/src/lib.rs
@@ -236,6 +236,22 @@ pub trait EndpointOut: Endpoint {
236 /// 236 ///
237 /// This should also clear any NAK flags and prepare the endpoint to receive the next packet. 237 /// This should also clear any NAK flags and prepare the endpoint to receive the next packet.
238 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, EndpointError>; 238 async fn read(&mut self, buf: &mut [u8]) -> Result<usize, EndpointError>;
239
240 /// Read until the buffer is full or we receive a short packet from the USB host returning the
241 /// actual length of the entire data block.
242 ///
243 /// This should also clear any NAK flags and prepare the endpoint to receive the next packet or
244 /// data block.
245 async fn read_transfer(&mut self, buf: &mut [u8]) -> Result<usize, EndpointError> {
246 let mut n = 0;
247 loop {
248 let i = self.read(&mut buf[n..]).await?;
249 n += i;
250 if i < self.info().max_packet_size as usize {
251 return Ok(n);
252 }
253 }
254 }
239} 255}
240 256
241/// USB control pipe trait. 257/// USB control pipe trait.
@@ -349,6 +365,20 @@ pub trait ControlPipe {
349pub trait EndpointIn: Endpoint { 365pub trait EndpointIn: Endpoint {
350 /// Write a single packet of data to the endpoint. 366 /// Write a single packet of data to the endpoint.
351 async fn write(&mut self, buf: &[u8]) -> Result<(), EndpointError>; 367 async fn write(&mut self, buf: &[u8]) -> Result<(), EndpointError>;
368
369 /// Write all the data from buf to the endpoint one wMaxPacketSize chunk at a time.
370 ///
371 /// If the buffer size is evenly divisible by wMaxPacketSize, this will also ensure the
372 /// terminating zero-length-packet is transmitted.
373 async fn write_transfer(&mut self, buf: &[u8], needs_zlp: bool) -> Result<(), EndpointError> {
374 for chunk in buf.chunks(self.info().max_packet_size as usize) {
375 self.write(chunk).await?;
376 }
377 if needs_zlp && buf.len() % self.info().max_packet_size as usize == 0 {
378 self.write(&[]).await?;
379 }
380 Ok(())
381 }
352} 382}
353 383
354#[derive(Copy, Clone, Eq, PartialEq, Debug)] 384#[derive(Copy, Clone, Eq, PartialEq, Debug)]