From de2a951e3d0684e398756985bcced063ec2aa2d1 Mon Sep 17 00:00:00 2001 From: Artem Egorkine Date: Wed, 20 Nov 2024 01:25:35 +0200 Subject: [PATCH] USB: set rx transfer buffer to the max packet size reported by the endpoint Trying to limit data loss by limiting the size of the rx buffer for sumbitted transfers to the max packet size reported by the rx endpoint. --- usb/src/dev_handler.rs | 2 +- usb/src/endpoint.rs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/usb/src/dev_handler.rs b/usb/src/dev_handler.rs index 21fc050..f3057ba 100644 --- a/usb/src/dev_handler.rs +++ b/usb/src/dev_handler.rs @@ -140,7 +140,7 @@ impl DeviceInner { let closed = Arc::new(AtomicBool::new(false)); let (mut framer, out_framer) = Self::init_framers(&handle, &read_ep); - let mut read_transfer = Transfer::new_bulk(&handle, read_ep.address, 1024); + let mut read_transfer = Transfer::new_bulk(&handle, read_ep.address, read_ep.max_packet_size); read_transfer.set_timeout(READ_DURATION); read_transfer.set_callback(move |buf| { let Some(buf) = buf else { diff --git a/usb/src/endpoint.rs b/usb/src/endpoint.rs index 4217bff..22cd902 100644 --- a/usb/src/endpoint.rs +++ b/usb/src/endpoint.rs @@ -9,7 +9,8 @@ pub struct Endpoint { pub iface: u8, pub setting: u8, pub address: u8, - pub transfer_type: TransferType + pub transfer_type: TransferType, + pub max_packet_size: usize, } pub fn find_endpoint( @@ -38,6 +39,7 @@ pub fn find_endpoint( setting: interface_desc.setting_number(), address: endpoint_desc.address(), transfer_type: endpoint_desc.transfer_type(), + max_packet_size: endpoint_desc.max_packet_size() as usize, }); } }