@@ -1431,7 +1431,7 @@ impl DmaRxStreamBufView {
14311431
14321432/// DMA Streaming Transmit Buffer.
14331433///
1434- /// This is symmetric implementation to [DmaTxStreamBuf ], used for continuously
1434+ /// This is symmetric implementation to [DmaRxStreamBuf ], used for continuously
14351435/// streaming data to a peripheral's FIFO.
14361436///
14371437/// The list starts out like so `A(full) -> B(full) -> C(full) -> D(full) -> NULL`.
@@ -1448,7 +1448,7 @@ impl DmaRxStreamBufView {
14481448/// - `C(empty) -> D(full) -> A(full) -> B(full) -> NULL`
14491449/// - `D(full) -> A(full) -> B(full) -> C(full) -> NULL`
14501450///
1451- /// If all the descriptors fill up , the [DmaTxInterrupt::TotalEof] interrupt will fire and DMA
1451+ /// If all the descriptors run out , the [DmaTxInterrupt::TotalEof] interrupt will fire and DMA
14521452/// will stop writing, at which point it is up to you to resume/restart the transfer.
14531453pub struct DmaTxStreamBuf {
14541454 descriptors : & ' static mut [ DmaDescriptor ] ,
@@ -1506,15 +1506,26 @@ impl DmaTxStreamBuf {
15061506 ( self . descriptors , self . buffer )
15071507 }
15081508
1509- /// Fill the buffer with the given data before DMA transfer starts.
1509+ /// Push the buffer with the given data before DMA transfer starts.
15101510 ///
15111511 /// Otherwise the streaming buffer will transfer garbage data to
15121512 /// DMA so that CPU has enough time to fill the buffer after transfer starts.
1513- pub fn fill ( & mut self , data : & [ u8 ] ) -> usize {
1514- let n = self . buffer . len ( ) . min ( data. len ( ) ) ;
1515- self . buffer [ ..n] . copy_from_slice ( & data[ ..n] ) ;
1516- self . pre_filled = Some ( n) ;
1517- n
1513+ pub fn push ( & mut self , data : & [ u8 ] ) -> usize {
1514+ self . push_with ( |buf| {
1515+ let len = buf. len ( ) . min ( data. len ( ) ) ;
1516+ buf[ ..len] . copy_from_slice ( & data[ ..len] ) ;
1517+ len
1518+ } )
1519+ }
1520+
1521+ /// Push the buffer with the given data before DMA transfer starts.
1522+ ///
1523+ /// Returns the number of bytes filled.
1524+ pub fn push_with ( & mut self , f : impl FnOnce ( & mut [ u8 ] ) -> usize ) -> usize {
1525+ let start = self . pre_filled . unwrap_or ( 0 ) ;
1526+ let bytes_pushed = f ( & mut self . buffer [ start..] ) ;
1527+ self . pre_filled = Some ( start + bytes_pushed) ;
1528+ bytes_pushed
15181529 }
15191530}
15201531
@@ -1555,7 +1566,7 @@ unsafe impl DmaTxBuffer for DmaTxStreamBuf {
15551566 descriptor_idx : 0 ,
15561567 descriptor_offset : 0 ,
15571568 } ;
1558- view. update_state ( pre_filled) ;
1569+ view. advance ( pre_filled) ;
15591570 view
15601571 }
15611572
@@ -1591,12 +1602,12 @@ impl DmaTxStreamBufView {
15911602 let dma_end = ( dma_start + self . available_bytes ( ) ) . min ( self . buf . buffer . len ( ) ) ;
15921603 let bytes_pushed = f ( & mut self . buf . buffer [ dma_start..dma_end] ) ;
15931604
1594- self . update_state ( bytes_pushed) ;
1605+ self . advance ( bytes_pushed) ;
15951606 bytes_pushed
15961607 }
15971608
1598- /// Updates the view state on pushed with `bytes_pushed` many bytes.
1599- fn update_state ( & mut self , bytes_pushed : usize ) {
1609+ /// Advances the first `n` bytes from the available data
1610+ fn advance ( & mut self , bytes_pushed : usize ) {
16001611 let mut bytes_filled = 0 ;
16011612 for d in ( self . descriptor_idx ..self . buf . descriptors . len ( ) ) . chain ( core:: iter:: once ( 0 ) ) {
16021613 let desc = & mut self . buf . descriptors [ d] ;
0 commit comments