From 55966072222521b4f986d734ff9ccd558b3ae655 Mon Sep 17 00:00:00 2001 From: Codetector Date: Sun, 3 Nov 2024 11:43:52 -0800 Subject: [PATCH] cleanup(usb): EndpointBufferAllocator asserts Small cleanup in EndpointBufferAllocator to ensure we don't request max_packet_size > 64 --- src/usb/mod.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/usb/mod.rs b/src/usb/mod.rs index 4a1887c..4a880f1 100644 --- a/src/usb/mod.rs +++ b/src/usb/mod.rs @@ -22,6 +22,9 @@ impl<'d, const NR_EP: usize> EndpointBufferAllocator<'d, NR_EP> { let ep_buf_idx = self.ep_next; self.ep_next += 1; + // TODO: Fix this, and allow variable buffer sizes + assert!(max_packet_size as usize <= ENDPOINT_DATA_BUFFER_SIZE); + Ok(EndpointData { max_packet_size, buffer: unsafe { core::mem::transmute(&self.ep_buffer[ep_buf_idx] as *const EndpointDataBuffer) }, @@ -41,11 +44,11 @@ impl<'d> EndpointData<'d> { } // todo generic -const EP_MAX_PACKET_SIZE: usize = 64; +const ENDPOINT_DATA_BUFFER_SIZE: usize = 64; #[repr(C, align(4))] pub struct EndpointDataBuffer { - data: [u8; EP_MAX_PACKET_SIZE as usize], + data: [u8; ENDPOINT_DATA_BUFFER_SIZE as usize], } impl Default for EndpointDataBuffer {