@@ -467,8 +467,11 @@ where
467
467
468
468
/// Changes the buffer and restarts or continues a double buffer
469
469
/// 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.
472
475
///
473
476
/// This method will clear the transfer complete flag on entry, it will also
474
477
/// clear it again if an overrun occurs during its execution. Moreover, if
@@ -656,6 +659,10 @@ where
656
659
/// error will be returned if this method is called before the end of a
657
660
/// transfer while double buffering and the closure won't be executed.
658
661
///
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
+ ///
659
666
/// # Panics
660
667
///
661
668
/// This method will panic when double buffering and one or both of the
@@ -677,7 +684,7 @@ where
677
684
f : F ,
678
685
) -> Result < T , DMAError < ( ) > >
679
686
where
680
- F : FnOnce ( BUF , CurrentBuffer ) -> ( BUF , T ) ,
687
+ F : FnOnce ( BUF , CurrentBuffer , usize ) -> ( BUF , T ) ,
681
688
{
682
689
if self . double_buf . is_some ( )
683
690
&& DIR :: direction ( ) != DmaDirection :: MemoryToMemory
@@ -694,7 +701,7 @@ where
694
701
} else {
695
702
self . double_buf . take ( ) . unwrap ( )
696
703
} ;
697
- let r = f ( db, !current_buffer) ;
704
+ let r = f ( db, !current_buffer, 0 ) ;
698
705
let mut new_buf = r. 0 ;
699
706
let ( new_buf_ptr, new_buf_len) = new_buf. write_buffer ( ) ;
700
707
@@ -754,9 +761,11 @@ where
754
761
// "No re-ordering of reads and writes across this point is allowed"
755
762
compiler_fence ( Ordering :: SeqCst ) ;
756
763
764
+ let remaining_data = STREAM :: get_number_of_transfers ( ) ;
765
+
757
766
// Can never fail, we never let the Transfer without a buffer
758
767
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 ) ;
760
769
let mut new_buf = r. 0 ;
761
770
762
771
let ( buf_ptr, buf_len) = new_buf. write_buffer ( ) ;
0 commit comments