Skip to content

Commit c6cdbd4

Browse files
committed
refactor: simplify tx streaming logic
1 parent 4b311b6 commit c6cdbd4

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

esp-hal/src/dma/buffers.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ impl DmaTxStreamBufView {
16071607
}
16081608

16091609
/// Advances the first `n` bytes from the available data
1610-
fn advance(&mut self, bytes_pushed: usize) {
1610+
pub fn advance(&mut self, bytes_pushed: usize) {
16111611
let mut bytes_filled = 0;
16121612
for d in (self.descriptor_idx..self.buf.descriptors.len()).chain(core::iter::once(0)) {
16131613
let desc = &mut self.buf.descriptors[d];
@@ -1638,20 +1638,19 @@ impl DmaTxStreamBufView {
16381638
/// Pushes a buffer into the stream buffer.
16391639
/// Returns the number of bytes pushed.
16401640
pub fn push(&mut self, data: &[u8]) -> usize {
1641-
let mut remaining = data.len();
1642-
let mut offset = 0;
1641+
let total_len = data.len();
1642+
let mut remaining = data;
16431643

1644-
while self.available_bytes() >= remaining && remaining > 0 {
1644+
while self.available_bytes() >= remaining.len() && remaining.len() > 0 {
16451645
let written = self.push_with(|buffer| {
1646-
let len = usize::min(buffer.len(), data.len() - offset);
1647-
buffer[..len].copy_from_slice(&data[offset..][..len]);
1646+
let len = usize::min(buffer.len(), remaining.len());
1647+
buffer[..len].copy_from_slice(&remaining[..len]);
16481648
len
16491649
});
1650-
offset += written;
1651-
remaining -= written;
1650+
remaining = &remaining[written..];
16521651
}
16531652

1654-
offset
1653+
total_len - remaining.len()
16551654
}
16561655
}
16571656

0 commit comments

Comments
 (0)