/// This function can send/receive a list messages
/// In each message, the length of send-msg should be equal with rec-msg's
/// if those is different, the smaller will be used
This function can send/receive a list messages
In each message, the length of send-msg should be equal with rec-msg's
if those is different, the smaller will be used
This function can send / receive a list messages In each message the length of send - msg should be equal with rec - msg ' s if those is different the smaller will be used
pub fn transfer(&self, msg: SpiMsg) -> Result<(), RTTError> {
        let mut inner_msg_vec = Vec::new();
        let mut length_temp = 4096;
        let mut msg_ptr = Some(Box::new(msg));
        while let Some(msg_for_trans) = msg_ptr {
            let inner_msg = Box::new(InnerSpiMsg {
                send_buf: match msg_for_trans.send.as_ref() {
                    Some(msg) => {
                        length_temp = msg.len();
                        msg.as_ptr() as *const CVoid
                    }
                    None => 0 as *const CVoid,
                },
                rec_buf: match msg_for_trans.rec.as_ref() {
                    Some(msg) => {
                        length_temp = min(length_temp, msg.len());
                        msg.as_ptr() as *mut CVoid
                    }
                    None => 0 as *mut CVoid,
                },
                length: length_temp,
                next: 0 as _,
                flag: 0,
            });
            inner_msg_vec.push(inner_msg);
            msg_ptr = msg_for_trans.next
        }
        // link msg
        for i in 1..inner_msg_vec.len() {
            inner_msg_vec[i - 1].as_mut().next =
                inner_msg_vec[i].as_ref() as *const _ as *mut InnerSpiMsg;
        }
        // cs_take: 1bits
        // cs_release: 1bits
        // begin: 01 take:1 release:0
        // end: 10 take:0 release:1
        inner_msg_vec[0].as_mut().flag = 1;
        let end = inner_msg_vec.len() - 1;
        inner_msg_vec[end].as_mut().flag |= 3;
        unsafe {
            if 0 != rt_spi_transfer_message(
                self.handle.raw(),
                inner_msg_vec[0].as_mut() as *mut _ as *mut _,
            ) {
                Err(RTTError::DeviceTransFailed)
            } else {
                Ok(())
            }
        }
    }
pub fn transfer ( & self , msg : SpiMsg ) -> Result < ( ) , RTTError > { let mut inner_msg_vec = Vec :: new ( ) ; let mut length_temp = 4096 ; let mut msg_ptr = Some ( Box :: new ( msg ) ) ; while let Some ( msg_for_trans ) = msg_ptr { let inner_msg = Box :: new ( InnerSpiMsg { send_buf : match msg_for_trans . send . as_ref ( ) { Some ( msg ) => { length_temp = msg . len ( ) ; msg . as_ptr ( ) as * const CVoid } None => 0 as * const CVoid , } , rec_buf : match msg_for_trans . rec . as_ref ( ) { Some ( msg ) => { length_temp = min ( length_temp , msg . len ( ) ) ; msg . as_ptr ( ) as * mut CVoid } None => 0 as * mut CVoid , } , length : length_temp , next : 0 as _ , flag : 0 , } ) ; inner_msg_vec . push ( inner_msg ) ; msg_ptr = msg_for_trans . next } // link msg for i in 1 .. inner_msg_vec . len ( ) { inner_msg_vec [ i - 1 ] . as_mut ( ) . next = inner_msg_vec [ i ] . as_ref ( ) as * const _ as * mut InnerSpiMsg ; } // cs_take: 1bits // cs_release: 1bits // begin: 01 take:1 release:0 // end: 10 take:0 release:1 inner_msg_vec [ 0 ] . as_mut ( ) . flag = 1 ; let end = inner_msg_vec . len ( ) - 1 ; inner_msg_vec [ end ] . as_mut ( ) . flag |= 3 ; unsafe { if 0 != rt_spi_transfer_message ( self . handle . raw ( ) , inner_msg_vec [ 0 ] . as_mut ( ) as * mut _ as * mut _ , ) { Err ( RTTError :: DeviceTransFailed ) } else { Ok ( ( ) ) } } }
This function can send/receive a list messages
In each message, the length of send-msg should be equal with rec-msg's
if those is different, the smaller will be used
This function can send / receive a list messages In each message the length of send - msg should be equal with rec - msg ' s if those is different the smaller will be used
&self
msg
SpiMsg