Skip to content

Commit

Permalink
Updating docs, updating next_transfer_with
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-summers committed Dec 15, 2020
1 parent e70a787 commit 8483294
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/dma/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,11 @@ where

/// Changes the buffer and restarts or continues a double buffer
/// transfer. This must be called immediately after a transfer complete
/// event. Returns the old buffer together with its `CurrentBuffer`. If an
/// error occurs, this method will return the new buffer with the error.
/// event. Returns (old_buffer, `CurrentBuffer`, remaining), where
/// `old_buffer` is the old buffer, `CurrentBuffer` indicates which buffer
/// the data represents, and `remaining` indicates the number of remaining
/// data in the transfer. If an error occurs, this method will return the
/// new buffer with the error.
///
/// This method will clear the transfer complete flag on entry, it will also
/// clear it again if an overrun occurs during its execution. Moreover, if
Expand Down Expand Up @@ -656,6 +659,10 @@ where
/// error will be returned if this method is called before the end of a
/// transfer while double buffering and the closure won't be executed.
///
/// The closure accepts the current buffer, the `CurrentBuffer` indicating
/// which buffer is provided, and a `remaining` parameter indicating the
/// number of transfers not completed in the DMA transfer.
///
/// # Panics
///
/// This method will panic when double buffering and one or both of the
Expand All @@ -677,7 +684,7 @@ where
f: F,
) -> Result<T, DMAError<()>>
where
F: FnOnce(BUF, CurrentBuffer) -> (BUF, T),
F: FnOnce(BUF, CurrentBuffer, usize) -> (BUF, T),
{
if self.double_buf.is_some()
&& DIR::direction() != DmaDirection::MemoryToMemory
Expand All @@ -694,7 +701,7 @@ where
} else {
self.double_buf.take().unwrap()
};
let r = f(db, !current_buffer);
let r = f(db, !current_buffer, 0);
let mut new_buf = r.0;
let (new_buf_ptr, new_buf_len) = new_buf.write_buffer();

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

let remaining_data = STREAM::get_number_of_transfers();

// Can never fail, we never let the Transfer without a buffer
let old_buf = self.buf.take().unwrap();
let r = f(old_buf, CurrentBuffer::FirstBuffer);
let r = f(old_buf, CurrentBuffer::FirstBuffer, remaining_data as usize);
let mut new_buf = r.0;

let (buf_ptr, buf_len) = new_buf.write_buffer();
Expand Down

0 comments on commit 8483294

Please sign in to comment.