@@ -1806,11 +1806,10 @@ pub mod asynch {
18061806 Async ,
18071807 dma:: {
18081808 DmaEligible ,
1809- ReadBuffer ,
1809+ DmaTxBuffer ,
18101810 RxCircularState ,
1811- TxCircularState ,
18121811 WriteBuffer ,
1813- asynch:: { DmaRxDoneChFuture , DmaRxFuture , DmaTxDoneChFuture , DmaTxFuture } ,
1812+ asynch:: { DmaRxDoneChFuture , DmaRxFuture , DmaTxDoneChFuture } ,
18141813 } ,
18151814 } ;
18161815
@@ -1901,17 +1900,43 @@ pub mod asynch {
19011900 Ok ( self . state . push ( & data[ ..to_send] ) ?)
19021901 }
19031902
1904- /// Push bytes into the DMA buffer via the given closure.
1905- /// The closure *must* return the actual number of bytes written.
1906- /// The closure *might* get called with a slice which is smaller than
1907- /// the total available buffer. Only useful for circular DMA
1908- /// transfers
1909- pub async fn push_with (
1910- & mut self ,
1911- f : impl FnOnce ( & mut [ u8 ] ) -> usize ,
1912- ) -> Result < usize , Error > {
1913- let _avail = self . available ( ) . await ;
1914- Ok ( self . state . push_with ( f) ?)
1903+ /// Checks if the DMA transfer is done.
1904+ pub fn is_done ( & self ) -> bool {
1905+ self . i2s_tx . tx_channel . is_done ( )
1906+ }
1907+
1908+ /// Stops and restarts the DMA transfer.
1909+ pub fn restart ( self ) -> Result < Self , Error > {
1910+ let ( i2s, buf) = self . stop ( ) ;
1911+ i2s. write ( buf)
1912+ }
1913+
1914+ /// Checks if the DMA transfer has an error.
1915+ pub fn has_error ( & self ) -> bool {
1916+ self . i2s_tx . tx_channel . has_error ( )
1917+ }
1918+
1919+ /// Waits for any DMA process to be made.
1920+ pub async fn process ( & mut self ) -> Result < ( ) , Error > {
1921+ DmaTxDoneChFuture :: new ( & mut self . i2s_tx . tx_channel ) . await ?;
1922+ Ok ( ( ) )
1923+ }
1924+
1925+ fn release ( mut self ) -> ( I2sTx < ' d , Async > , BUFFER :: View ) {
1926+ // SAFETY: Since forget is called on self, we know that self.i2s_tx and
1927+ // self.buffer_view won't be touched again.
1928+ let result = unsafe {
1929+ (
1930+ ManuallyDrop :: take ( & mut self . i2s_tx ) ,
1931+ ManuallyDrop :: take ( & mut self . buffer_view ) ,
1932+ )
1933+ } ;
1934+ core:: mem:: forget ( self ) ;
1935+ result
1936+ }
1937+
1938+ fn stop_peripheral ( & mut self ) {
1939+ self . i2s_tx . i2s . tx_stop ( ) ;
19151940 }
19161941 }
19171942
0 commit comments