otg: Use chunks_exact for more efficient rx copy

This commit is contained in:
Matt Johnston 2025-08-11 15:19:51 +08:00 committed by Dario Nieuwenhuis
parent bc448985d5
commit cac3964252
2 changed files with 10 additions and 2 deletions

View File

@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## 0.3.1 - 2025-08-26
- Improve receive performance, more efficient copy from FIFO
## 0.3.0 - 2025-07-22
- Bump `embassy-usb-driver` to v0.2.0

View File

@ -76,10 +76,16 @@ pub unsafe fn on_interrupt<const MAX_EP_COUNT: usize>(r: Otg, state: &State<MAX_
let buf =
unsafe { core::slice::from_raw_parts_mut(*state.ep_states[ep_num].out_buffer.get(), len) };
for chunk in buf.chunks_mut(4) {
let mut chunks = buf.chunks_exact_mut(4);
for chunk in &mut chunks {
// RX FIFO is shared so always read from fifo(0)
let data = r.fifo(0).read().0;
chunk.copy_from_slice(&data.to_ne_bytes()[0..chunk.len()]);
chunk.copy_from_slice(&data.to_ne_bytes());
}
let rem = chunks.into_remainder();
if !rem.is_empty() {
let data = r.fifo(0).read().0;
rem.copy_from_slice(&data.to_ne_bytes()[0..rem.len()]);
}
state.ep_states[ep_num].out_size.store(len as u16, Ordering::Release);