fn write_read(&mut self, addr: u8, wbuf: &[u8], rbuf: &mut [u8]) -> Result<(), Self::Error> {
        //  We assume this is a Read I2C Register operation, with Register ID at wbuf[0]
        assert_eq!(wbuf.len(), 1);
        let reg_id = wbuf[0];

        //  Read I2C Registers, starting at Register ID
        let mut start = [reg_id ; 1];

        //  Compose I2C Transfer
        let msg = [
            //  First I2C Message: Send Register ID
            i2c_msg_s {
                frequency: self.frequency,  //  I2C Frequency
                addr:      addr as u16,     //  I2C Address
                buffer:    start.as_mut_ptr(),      //  Buffer to be sent
                length:    start.len() as ssize_t,  //  Number of bytes to send

                //  For BL602: Register ID must be passed as I2C Sub Address
                #[cfg(target_arch = "riscv32")]  //  If architecture is RISC-V 32-bit...
                flags:     crate::I2C_M_NOSTOP,  //  I2C Flags: Send I2C Sub Address
                
                //  Otherwise pass Register ID as I2C Data
                #[cfg(not(target_arch = "riscv32"))]  //  If architecture is not RISC-V 32-bit...
                flags:     0,  //  I2C Flags: None

                //  TODO: Check for BL602 specifically (by target_abi?), not just RISC-V 32-bit
            },
            //  Second I2C Message: Receive Register Values
            i2c_msg_s {
                frequency: self.frequency,  //  I2C Frequency
                addr:      addr as u16,     //  I2C Address
                buffer:    rbuf.as_mut_ptr(),      //  Buffer to be received
                length:    rbuf.len() as ssize_t,  //  Number of bytes to receive
                flags:     I2C_M_READ,  //  I2C Flags: Read I2C Data
            },
        ];

        //  Compose ioctl Argument
        let xfer = i2c_transfer_s {
            msgv: msg.as_ptr(),         //  Array of I2C messages for the transfer
            msgc: msg.len() as size_t,  //  Number of messages in the array
        };

        //  Execute I2C Transfer
        let ret = unsafe { 
            ioctl(
                self.fd,
                I2CIOC_TRANSFER,
                &xfer
            )
        };
        assert!(ret >= 0);   
        Ok(())
    }
/// Write `wbuf` to I2C Port and read `rbuf` from I2C Port.
/// We assume this is a Read I2C Register operation, with Register ID at `wbuf[0]`.
/// TODO: Handle other kinds of I2C operations
Write `wbuf` to I2C Port and read `rbuf` from I2C Port.
We assume this is a Read I2C Register operation, with Register ID at `wbuf[0]`.
TODO: Handle other kinds of I2C operations
Write ` wbuf ` to I2C Port and read ` rbuf ` from I2C Port . We assume this is a Read I2C Register operation with Register ID at ` wbuf [ 0 ] ` . TODO : Handle other kinds of I2C operations
fn write_read(&mut self, addr: u8, wbuf: &[u8], rbuf: &mut [u8]) -> Result<(), Self::Error> {
        //  We assume this is a Read I2C Register operation, with Register ID at wbuf[0]
        assert_eq!(wbuf.len(), 1);
        let reg_id = wbuf[0];
        //  Read I2C Registers, starting at Register ID
        let mut start = [reg_id ; 1];
        //  Compose I2C Transfer
        let msg = [
            //  First I2C Message: Send Register ID
            i2c_msg_s {
                frequency: self.frequency,  //  I2C Frequency
                addr:      addr as u16,     //  I2C Address
                buffer:    start.as_mut_ptr(),      //  Buffer to be sent
                length:    start.len() as ssize_t,  //  Number of bytes to send
                //  For BL602: Register ID must be passed as I2C Sub Address
                #[cfg(target_arch = "riscv32")]  //  If architecture is RISC-V 32-bit...
                flags:     crate::I2C_M_NOSTOP,  //  I2C Flags: Send I2C Sub Address
                //  Otherwise pass Register ID as I2C Data
                #[cfg(not(target_arch = "riscv32"))]  //  If architecture is not RISC-V 32-bit...
                flags:     0,  //  I2C Flags: None
                //  TODO: Check for BL602 specifically (by target_abi?), not just RISC-V 32-bit
            },
            //  Second I2C Message: Receive Register Values
            i2c_msg_s {
                frequency: self.frequency,  //  I2C Frequency
                addr:      addr as u16,     //  I2C Address
                buffer:    rbuf.as_mut_ptr(),      //  Buffer to be received
                length:    rbuf.len() as ssize_t,  //  Number of bytes to receive
                flags:     I2C_M_READ,  //  I2C Flags: Read I2C Data
            },
        ];
        //  Compose ioctl Argument
        let xfer = i2c_transfer_s {
            msgv: msg.as_ptr(),         //  Array of I2C messages for the transfer
            msgc: msg.len() as size_t,  //  Number of messages in the array
        };
        //  Execute I2C Transfer
        let ret = unsafe { 
            ioctl(
                self.fd,
                I2CIOC_TRANSFER,
                &xfer
            )
        };
        assert!(ret >= 0);   
        Ok(())
    }
fn write_read ( & mut self , addr : u8 , wbuf : & [ u8 ] , rbuf : & mut [ u8 ] ) -> Result < ( ) , Self :: Error > { //  We assume this is a Read I2C Register operation, with Register ID at wbuf[0] assert_eq ! ( wbuf len ( ) 1 ) ; let reg_id = wbuf [ 0 ] ; //  Read I2C Registers, starting at Register ID let mut start = [ reg_id ; 1 ] ; //  Compose I2C Transfer let msg = [ //  First I2C Message: Send Register ID i2c_msg_s { frequency : self . frequency , //  I2C Frequency addr : addr as u16 , //  I2C Address buffer : start . as_mut_ptr ( ) , //  Buffer to be sent length : start . len ( ) as ssize_t , //  Number of bytes to send //  For BL602: Register ID must be passed as I2C Sub Address # [ cfg ( target_arch " " ) ] //  If architecture is RISC-V 32-bit... flags : crate :: I2C_M_NOSTOP , //  I2C Flags: Send I2C Sub Address //  Otherwise pass Register ID as I2C Data # [ cfg ( not ( target_arch " " ) ) ] //  If architecture is not RISC-V 32-bit... flags : 0 , //  I2C Flags: None //  TODO: Check for BL602 specifically (by target_abi?), not just RISC-V 32-bit } , //  Second I2C Message: Receive Register Values i2c_msg_s { frequency : self . frequency , //  I2C Frequency addr : addr as u16 , //  I2C Address buffer : rbuf . as_mut_ptr ( ) , //  Buffer to be received length : rbuf . len ( ) as ssize_t , //  Number of bytes to receive flags : I2C_M_READ , //  I2C Flags: Read I2C Data } , ] ; //  Compose ioctl Argument let xfer = i2c_transfer_s { msgv : msg . as_ptr ( ) , //  Array of I2C messages for the transfer msgc : msg . len ( ) as size_t , //  Number of messages in the array } ; //  Execute I2C Transfer let ret = unsafe { ioctl ( self . fd , I2CIOC_TRANSFER , & xfer ) } ; assert ! ( ret 0 ) ; Ok ( ( ) ) }
Write `wbuf` to I2C Port and read `rbuf` from I2C Port.
Write ` wbuf ` to I2C Port and read ` rbuf ` from I2C Port .
&mut self
addr
u8
wbuf
&[u8]
rbuf
&mut [u8]
&mut self
addr
u8
wbuf
&[u8]
rbuf
&mut [u8]