Skip to content

Commit 8483294

Browse files
committed
Updating docs, updating next_transfer_with
1 parent e70a787 commit 8483294

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/dma/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,11 @@ where
467467

468468
/// Changes the buffer and restarts or continues a double buffer
469469
/// transfer. This must be called immediately after a transfer complete
470-
/// event. Returns the old buffer together with its `CurrentBuffer`. If an
471-
/// error occurs, this method will return the new buffer with the error.
470+
/// event. Returns (old_buffer, `CurrentBuffer`, remaining), where
471+
/// `old_buffer` is the old buffer, `CurrentBuffer` indicates which buffer
472+
/// the data represents, and `remaining` indicates the number of remaining
473+
/// data in the transfer. If an error occurs, this method will return the
474+
/// new buffer with the error.
472475
///
473476
/// This method will clear the transfer complete flag on entry, it will also
474477
/// clear it again if an overrun occurs during its execution. Moreover, if
@@ -656,6 +659,10 @@ where
656659
/// error will be returned if this method is called before the end of a
657660
/// transfer while double buffering and the closure won't be executed.
658661
///
662+
/// The closure accepts the current buffer, the `CurrentBuffer` indicating
663+
/// which buffer is provided, and a `remaining` parameter indicating the
664+
/// number of transfers not completed in the DMA transfer.
665+
///
659666
/// # Panics
660667
///
661668
/// This method will panic when double buffering and one or both of the
@@ -677,7 +684,7 @@ where
677684
f: F,
678685
) -> Result<T, DMAError<()>>
679686
where
680-
F: FnOnce(BUF, CurrentBuffer) -> (BUF, T),
687+
F: FnOnce(BUF, CurrentBuffer, usize) -> (BUF, T),
681688
{
682689
if self.double_buf.is_some()
683690
&& DIR::direction() != DmaDirection::MemoryToMemory
@@ -694,7 +701,7 @@ where
694701
} else {
695702
self.double_buf.take().unwrap()
696703
};
697-
let r = f(db, !current_buffer);
704+
let r = f(db, !current_buffer, 0);
698705
let mut new_buf = r.0;
699706
let (new_buf_ptr, new_buf_len) = new_buf.write_buffer();
700707

@@ -754,9 +761,11 @@ where
754761
// "No re-ordering of reads and writes across this point is allowed"
755762
compiler_fence(Ordering::SeqCst);
756763

764+
let remaining_data = STREAM::get_number_of_transfers();
765+
757766
// Can never fail, we never let the Transfer without a buffer
758767
let old_buf = self.buf.take().unwrap();
759-
let r = f(old_buf, CurrentBuffer::FirstBuffer);
768+
let r = f(old_buf, CurrentBuffer::FirstBuffer, remaining_data as usize);
760769
let mut new_buf = r.0;
761770

762771
let (buf_ptr, buf_len) = new_buf.write_buffer();

0 commit comments

Comments
 (0)