pub fn next_transfer<F>(
        &mut self,
        new_buf: BUF,
        f: F,
    ) -> Result<(), DMAError>
    where
        F: FnOnce(&mut PERIPHERAL),
    {
        let mut buf = new_buf;

        // Disable stream (waits for CTCIF=1), clear transfer complete flag
        self.stream.disable();
        self.stream.clear_transfer_complete_flag();

        // NOTE(unsafe) We now own this buffer and we won't call any &mut
        // methods on it until the end of the DMA transfer
        let (buf_ptr, buf_len) = unsafe { buf.write_buffer() };

        // Check buf_len is at least the length required for this transfer
        let check_source = DIR::direction() == DmaDirection::MemoryToPeripheral;
        let check_destination = !check_source;

        if check_source && buf_len < self.inner.source_len {
            return Err(DMAError::SmallBuffer);
        }
        if check_destination && buf_len < self.inner.destination_len {
            return Err(DMAError::SmallBuffer);
        }

        // Configure next transfer
        unsafe {
            self.stream
                .set_block_bytes(self.inner.block_number_of_bytes);
        }

        match DIR::direction() {
            DmaDirection::MemoryToPeripheral => unsafe {
                self.stream.set_source_address(buf_ptr as usize);
            },
            DmaDirection::PeripheralToMemory => unsafe {
                self.stream.set_destination_address(buf_ptr as usize);
            },
            DmaDirection::MemoryToMemory => panic!(),
        }

        f(&mut self.peripheral);

        // Preserve the instruction and bus ordering of preceding buffer access
        // to the subsequent access by the DMA peripheral due to enabling it.
        fence(Ordering::SeqCst);

        unsafe {
            self.stream.enable();
        }

        // NOTE(unsafe): previous buf was previously a valid value
        Ok(())
    }
/// Changes the buffer and restarts a transfer
///
/// The length of the transfer remains fixed. This method returns
/// Err([SmallBuffer](DMAError::SmallBuffer)) if the new buffer is shorter
/// than the original.
///
/// This method will clear the transfer complete flag. This method can be
/// called before the end of an ongoing transfer. In that case, the ongoing
/// transfer will be canceled and a new one will be started.
///
/// The closure will be executed immediately before restarting the stream.
///
/// TODO: This method always panics for Memory-Memory transfers
Changes the buffer and restarts a transfer
The length of the transfer remains fixed. This method returns
Err([SmallBuffer](DMAError::SmallBuffer)) if the new buffer is shorter
than the original.

This method will clear the transfer complete flag. This method can be
called before the end of an ongoing transfer. In that case, the ongoing
transfer will be canceled and a new one will be started.

The closure will be executed immediately before restarting the stream.

This method always panics for Memory-Memory transfers
Changes the buffer and restarts a transfer The length of the transfer remains fixed . This method returns Err ( [ SmallBuffer ] ( DMAError :: SmallBuffer )) if the new buffer is shorter than the original . This method will clear the transfer complete flag . This method can be called before the end of an ongoing transfer . In that case the ongoing transfer will be canceled and a new one will be started . The closure will be executed immediately before restarting the stream . This method always panics for Memory - Memory transfers
pub fn next_transfer<F>(
        &mut self,
        new_buf: BUF,
        f: F,
    ) -> Result<(), DMAError>
    where
        F: FnOnce(&mut PERIPHERAL),
    {
        let mut buf = new_buf;
        // Disable stream (waits for CTCIF=1), clear transfer complete flag
        self.stream.disable();
        self.stream.clear_transfer_complete_flag();
        // NOTE(unsafe) We now own this buffer and we won't call any &mut
        // methods on it until the end of the DMA transfer
        let (buf_ptr, buf_len) = unsafe { buf.write_buffer() };
        // Check buf_len is at least the length required for this transfer
        let check_source = DIR::direction() == DmaDirection::MemoryToPeripheral;
        let check_destination = !check_source;
        if check_source && buf_len < self.inner.source_len {
            return Err(DMAError::SmallBuffer);
        }
        if check_destination && buf_len < self.inner.destination_len {
            return Err(DMAError::SmallBuffer);
        }
        // Configure next transfer
        unsafe {
            self.stream
                .set_block_bytes(self.inner.block_number_of_bytes);
        }
        match DIR::direction() {
            DmaDirection::MemoryToPeripheral => unsafe {
                self.stream.set_source_address(buf_ptr as usize);
            },
            DmaDirection::PeripheralToMemory => unsafe {
                self.stream.set_destination_address(buf_ptr as usize);
            },
            DmaDirection::MemoryToMemory => panic!(),
        }
        f(&mut self.peripheral);
        // Preserve the instruction and bus ordering of preceding buffer access
        // to the subsequent access by the DMA peripheral due to enabling it.
        fence(Ordering::SeqCst);
        unsafe {
            self.stream.enable();
        }
        // NOTE(unsafe): previous buf was previously a valid value
        Ok(())
    }
pub fn next_transfer < F > ( & mut self , new_buf : BUF , f : F , ) -> Result < ( ) , DMAError > where F : FnOnce ( & mut PERIPHERAL ) , { let mut buf = new_buf ; // Disable stream (waits for CTCIF=1), clear transfer complete flag self . stream . disable ( ) ; self . stream . clear_transfer_complete_flag ( ) ; // NOTE(unsafe) We now own this buffer and we won't call any &mut // methods on it until the end of the DMA transfer let ( buf_ptr , buf_len ) = unsafe { buf . write_buffer ( ) } ; // Check buf_len is at least the length required for this transfer let check_source = DIR :: direction ( ) == DmaDirection :: MemoryToPeripheral ; let check_destination = ! check_source ; if check_source && buf_len < self . inner . source_len { return Err ( DMAError :: SmallBuffer ) ; } if check_destination && buf_len < self . inner . destination_len { return Err ( DMAError :: SmallBuffer ) ; } // Configure next transfer unsafe { self . stream . set_block_bytes ( self . inner . block_number_of_bytes ) ; } match DIR :: direction ( ) { DmaDirection :: MemoryToPeripheral => unsafe { self . stream . set_source_address ( buf_ptr as usize ) ; } , DmaDirection :: PeripheralToMemory => unsafe { self . stream . set_destination_address ( buf_ptr as usize ) ; } , DmaDirection :: MemoryToMemory => panic ! ( ) , } f ( & mut self . peripheral ) ; // Preserve the instruction and bus ordering of preceding buffer access // to the subsequent access by the DMA peripheral due to enabling it. fence ( Ordering :: SeqCst ) ; unsafe { self . stream . enable ( ) ; } // NOTE(unsafe): previous buf was previously a valid value Ok ( ( ) ) }
Changes the buffer and restarts a transfer
The length of the transfer remains fixed.
Changes the buffer and restarts a transfer The length of the transfer remains fixed .
&mut self
new_buf
BUF
f
F
&mut self
new_buf
BUF
f
F