pub fn init_master(
        mut stream: STREAM,
        peripheral: PERIPHERAL,
        mut memory: BUF,
        mut second_buf: Option<BUF>,
        config: mdma::MdmaConfig,
    ) -> Self {
        stream.disable();

        // 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 { memory.write_buffer() };

        let (
            source_address,
            destination_address,
            source_len,
            destination_len,
            is_ahb,
        ) = match DIR::direction() {
            DmaDirection::MemoryToMemory => {
                // must have 2nd buffer
                if let Some(ref mut sb) = second_buf {
                    // 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 (sb_ptr, sb_len) = unsafe { sb.write_buffer() };
                    let is_ahb = (
                        mdma::is_ahb_port(sb_ptr as usize),
                        mdma::is_ahb_port(buf_ptr as usize),
                    );

                    // second buffer is the source in mem2mem mode
                    (
                        sb_ptr as usize,  // source address
                        buf_ptr as usize, // destination address
                        Some(sb_len),
                        Some(buf_len),
                        is_ahb,
                    )
                } else {
                    panic!("must have second buffer");
                }
            }
            DmaDirection::MemoryToPeripheral => {
                let is_ahb = mdma::is_ahb_port(buf_ptr as usize);

                (
                    buf_ptr as usize,     // source address
                    peripheral.address(), // destination address
                    Some(buf_len),
                    None,
                    (is_ahb, false),
                )
            }
            DmaDirection::PeripheralToMemory => {
                let is_ahb = mdma::is_ahb_port(buf_ptr as usize);

                (
                    peripheral.address(), // source address
                    buf_ptr as usize,     // destination address
                    None,
                    Some(buf_len),
                    (false, is_ahb),
                )
            }
        };

        // Set the source/destination address
        //
        // # Safety
        // Must be a valid source/destination address
        unsafe {
            stream.set_source_address(source_address);
            stream.set_destination_address(destination_address);
        }

        // Set block length
        let block_number_of_bytes =
            Self::m_number_of_bytes(&config, source_len, destination_len);
        assert!(
            block_number_of_bytes <= 65536,
            "Hardware does not support more than 65536 bytes in a single transfer"
        );
        // Set transfer length (within the block). If block_number_of_bytes is
        // not a integer multiple of transfer_length, the last buffer will be
        // shorter
        let transfer_length =
            cmp::min(128, config.buffer_length.unwrap_or(128)) as usize;
        let transfer_length = cmp::min(transfer_length, block_number_of_bytes);
        // This is overridden if set in `config`

        //NOTE(unsafe) Configuration (Number of bytes, size, offset) configured
        // to be within both source and destination buffers
        unsafe {
            stream.set_transfer_length(transfer_length as u8);
            stream.set_block_bytes(block_number_of_bytes as u32);
        }

        let mut transfer = Self {
            stream,
            peripheral,
            _direction: PhantomData,
            buf: [Some(memory), None],
            inner: MasterTransfer {
                source_len: source_len.unwrap_or(0),
                destination_len: destination_len.unwrap_or(0),
                block_number_of_bytes: block_number_of_bytes as u32,
            },
        };
        transfer.apply_config_master(config, is_ahb, transfer_length);

        transfer
    }
/// Configures the MDMA source and destination and applies supplied
/// configuration. In a memory to memory transfer, the `second_buf` argument
/// is the source of the data
///
/// # Panics
///
/// * When a memory-memory transfer is specified but the `second_buf`
/// argument is `None`.
///
/// * When the length is greater than 65536 bytes.
///
/// * When `config` specifies a `source_increment` that is smaller than the
/// source size.
///
/// * When `config` specifies a `destination_increment` that is smaller than
/// the destination size.
///
/// * When `config` specifies a `transfer_length` that is not a multiple of
/// both the source and destination sizes.
///
/// * When `config` specifies a `packing_alignment` that extends the source,
/// but the source size is larger than the destination size.
///
/// * When `config` specifies a `packing_alignment` that truncates the
/// source, but the source size is smaller than the destination size.
Configures the MDMA source and destination and applies supplied
configuration. In a memory to memory transfer, the `second_buf` argument
is the source of the data
Configures the MDMA source and destination and applies supplied configuration . In a memory to memory transfer the ` second_buf ` argument is the source of the data
pub fn init_master(
        mut stream: STREAM,
        peripheral: PERIPHERAL,
        mut memory: BUF,
        mut second_buf: Option<BUF>,
        config: mdma::MdmaConfig,
    ) -> Self {
        stream.disable();
        // 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 { memory.write_buffer() };
        let (
            source_address,
            destination_address,
            source_len,
            destination_len,
            is_ahb,
        ) = match DIR::direction() {
            DmaDirection::MemoryToMemory => {
                // must have 2nd buffer
                if let Some(ref mut sb) = second_buf {
                    // 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 (sb_ptr, sb_len) = unsafe { sb.write_buffer() };
                    let is_ahb = (
                        mdma::is_ahb_port(sb_ptr as usize),
                        mdma::is_ahb_port(buf_ptr as usize),
                    );
                    // second buffer is the source in mem2mem mode
                    (
                        sb_ptr as usize,  // source address
                        buf_ptr as usize, // destination address
                        Some(sb_len),
                        Some(buf_len),
                        is_ahb,
                    )
                } else {
                    panic!("must have second buffer");
                }
            }
            DmaDirection::MemoryToPeripheral => {
                let is_ahb = mdma::is_ahb_port(buf_ptr as usize);
                (
                    buf_ptr as usize,     // source address
                    peripheral.address(), // destination address
                    Some(buf_len),
                    None,
                    (is_ahb, false),
                )
            }
            DmaDirection::PeripheralToMemory => {
                let is_ahb = mdma::is_ahb_port(buf_ptr as usize);
                (
                    peripheral.address(), // source address
                    buf_ptr as usize,     // destination address
                    None,
                    Some(buf_len),
                    (false, is_ahb),
                )
            }
        };
        // Set the source/destination address
        //
        // # Safety
        // Must be a valid source/destination address
        unsafe {
            stream.set_source_address(source_address);
            stream.set_destination_address(destination_address);
        }
        // Set block length
        let block_number_of_bytes =
            Self::m_number_of_bytes(&config, source_len, destination_len);
        assert!(
            block_number_of_bytes <= 65536,
            "Hardware does not support more than 65536 bytes in a single transfer"
        );
        // Set transfer length (within the block). If block_number_of_bytes is
        // not a integer multiple of transfer_length, the last buffer will be
        // shorter
        let transfer_length =
            cmp::min(128, config.buffer_length.unwrap_or(128)) as usize;
        let transfer_length = cmp::min(transfer_length, block_number_of_bytes);
        // This is overridden if set in `config`
        //NOTE(unsafe) Configuration (Number of bytes, size, offset) configured
        // to be within both source and destination buffers
        unsafe {
            stream.set_transfer_length(transfer_length as u8);
            stream.set_block_bytes(block_number_of_bytes as u32);
        }
        let mut transfer = Self {
            stream,
            peripheral,
            _direction: PhantomData,
            buf: [Some(memory), None],
            inner: MasterTransfer {
                source_len: source_len.unwrap_or(0),
                destination_len: destination_len.unwrap_or(0),
                block_number_of_bytes: block_number_of_bytes as u32,
            },
        };
        transfer.apply_config_master(config, is_ahb, transfer_length);
        transfer
    }
pub fn init_master ( mut stream : STREAM , peripheral : PERIPHERAL , mut memory : BUF , mut second_buf : Option < BUF > , config : mdma :: MdmaConfig , ) -> Self { stream . disable ( ) ; // 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 { memory . write_buffer ( ) } ; let ( source_address , destination_address , source_len , destination_len , is_ahb , ) = match DIR :: direction ( ) { DmaDirection :: MemoryToMemory => { // must have 2nd buffer if let Some ( ref mut sb ) = second_buf { // 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 ( sb_ptr , sb_len ) = unsafe { sb . write_buffer ( ) } ; let is_ahb = ( mdma :: is_ahb_port ( sb_ptr as usize ) , mdma :: is_ahb_port ( buf_ptr as usize ) , ) ; // second buffer is the source in mem2mem mode ( sb_ptr as usize , // source address buf_ptr as usize , // destination address Some ( sb_len ) , Some ( buf_len ) , is_ahb , ) } else { panic ! ( " " ) ; } } DmaDirection :: MemoryToPeripheral => { let is_ahb = mdma :: is_ahb_port ( buf_ptr as usize ) ; ( buf_ptr as usize , // source address peripheral . address ( ) , // destination address Some ( buf_len ) , None , ( is_ahb , false ) , ) } DmaDirection :: PeripheralToMemory => { let is_ahb = mdma :: is_ahb_port ( buf_ptr as usize ) ; ( peripheral . address ( ) , // source address buf_ptr as usize , // destination address None , Some ( buf_len ) , ( false , is_ahb ) , ) } } ; // Set the source/destination address // // # Safety // Must be a valid source/destination address unsafe { stream . set_source_address ( source_address ) ; stream . set_destination_address ( destination_address ) ; } // Set block length let block_number_of_bytes = Self :: m_number_of_bytes ( & config , source_len , destination_len ) ; assert ! ( block_number_of_bytes 65536 " " ) ; // Set transfer length (within the block). If block_number_of_bytes is // not a integer multiple of transfer_length, the last buffer will be // shorter let transfer_length = cmp :: min ( 128 , config . buffer_length . unwrap_or ( 128 ) ) as usize ; let transfer_length = cmp :: min ( transfer_length , block_number_of_bytes ) ; // This is overridden if set in `config` //NOTE(unsafe) Configuration (Number of bytes, size, offset) configured // to be within both source and destination buffers unsafe { stream . set_transfer_length ( transfer_length as u8 ) ; stream . set_block_bytes ( block_number_of_bytes as u32 ) ; } let mut transfer = Self { stream , peripheral , _direction : PhantomData , buf : [ Some ( memory ) , None ] , inner : MasterTransfer { source_len : source_len . unwrap_or ( 0 ) , destination_len : destination_len . unwrap_or ( 0 ) , block_number_of_bytes : block_number_of_bytes as u32 , } , } ; transfer . apply_config_master ( config , is_ahb , transfer_length ) ; transfer }
Configures the MDMA source and destination and applies supplied
configuration.
Configures the MDMA source and destination and applies supplied configuration .
stream
STREAM
peripheral
PERIPHERAL
memory
BUF
second_buf
Option<BUF>
config
mdma::MdmaConfig
stream
STREAM
peripheral
PERIPHERAL
memory
BUF
second_buf
Option<BUF>
config
mdma::MdmaConfig
panics
When a memory-memory transfer is specified but the `second_buf`
argument is `None`.

When the length is greater than 65536 bytes.

When `config` specifies a `source_increment` that is smaller than the
source size.

When `config` specifies a `destination_increment` that is smaller than
the destination size.

When `config` specifies a `transfer_length` that is not a multiple of
both the source and destination sizes.

When `config` specifies a `packing_alignment` that extends the source,
but the source size is larger than the destination size.

When `config` specifies a `packing_alignment` that truncates the
source, but the source size is smaller than the destination size.
When a memory - memory transfer is specified but the ` second_buf ` argument is ` None ` . When the length is greater than 65536 bytes . When ` config ` specifies a ` source_increment ` that is smaller than the source size . When ` config ` specifies a ` destination_increment ` that is smaller than the destination size . When ` config ` specifies a ` transfer_length ` that is not a multiple of both the source and destination sizes . When ` config ` specifies a ` packing_alignment ` that extends the source but the source size is larger than the destination size . When ` config ` specifies a ` packing_alignment ` that truncates the source but the source size is smaller than the destination size .