From 7afa19a82b9b9575cae73eedee16c4e991396784 Mon Sep 17 00:00:00 2001 From: 9names <60134748+9names@users.noreply.github.com> Date: Sat, 11 Sep 2021 18:31:45 +1000 Subject: [PATCH] Usb fixes (#104) * Remove check for ep0 buffer.len == 64 * Simplify EP buffer check --- rp2040-hal/src/usb.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/rp2040-hal/src/usb.rs b/rp2040-hal/src/usb.rs index 7e26e31..05be781 100644 --- a/rp2040-hal/src/usb.rs +++ b/rp2040-hal/src/usb.rs @@ -133,7 +133,7 @@ impl Inner { let is_ep0 = ep_addr.index() == 0; let is_ctrl_ep = ep_type == EndpointType::Control; - if !(is_ep0 ^ !is_ctrl_ep) || (is_ep0 && (max_packet_size != 64)) { + if !(is_ep0 ^ !is_ctrl_ep) { return Err(UsbError::Unsupported); } @@ -149,10 +149,12 @@ impl Inner { return Err(UsbError::InvalidEndpoint); } - // validate buffer size - if let (EndpointType::Isochronous, true) = (ep_type, max_packet_size > 1023) { - return Err(UsbError::Unsupported); - } else if max_packet_size > 64 { + // Validate buffer size. From datasheet (4.1.2.5): + // Data Buffers are typically 64 bytes long as this is the max normal packet size for most FS packets. + // For Isochronous endpoints a maximum buffer size of 1023 bytes is supported. + // For other packet types the maximum size is 64 bytes per buffer. + if (ep_type != EndpointType::Isochronous && max_packet_size > 64) || max_packet_size > 1023 + { return Err(UsbError::Unsupported); }