Skip to content

Commit

Permalink
USB: set rx transfer buffer to the max packet size reported by the en…
Browse files Browse the repository at this point in the history
…dpoint

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.
  • Loading branch information
arteme committed Nov 19, 2024
1 parent fc24213 commit de2a951
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion usb/src/dev_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion usb/src/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: UsbContext>(
Expand Down Expand Up @@ -38,6 +39,7 @@ pub fn find_endpoint<T: UsbContext>(
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,
});
}
}
Expand Down

0 comments on commit de2a951

Please sign in to comment.