fn write(&mut self, addr: u8, buf: &[u8]) -> Result<(), Self::Error> {
        //  Copy to local buffer because we need a mutable reference
        let mut buf2 = [0 ; 64];
        assert!(buf.len() <= buf2.len());
        buf2[..buf.len()].copy_from_slice(buf);

        //  Buffer for received I2C data
        let mut rbuf = [0 ; 1];

        //  Compose I2C Transfer
        let msg = [
            //  First I2C Message: Send Register ID and I2C Data as I2C Sub Address
            i2c_msg_s {
                frequency: self.frequency,  //  I2C Frequency
                addr:      addr as u16,     //  I2C Address
                buffer:    buf2.as_mut_ptr(),     //  Buffer to be sent
                length:    buf.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: Read I2C Data, because this forces BL602 to send the first message correctly
            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 to write I2C Registers
        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 to write I2C Registers
        let ret = unsafe { 
            ioctl(
                self.fd,          //  I2C Port
                I2CIOC_TRANSFER,  //  I2C Transfer
                &xfer             //  I2C Messages for the transfer
            )
        };
        assert!(ret >= 0);   
        Ok(())
    }
/// Write `buf` to I2C Port.
/// We assume this is a Write I2C Register operation, with Register ID at `buf[0]`.
/// TODO: Handle other kinds of I2C operations
Write `buf` to I2C Port.
We assume this is a Write I2C Register operation, with Register ID at `buf[0]`.
TODO: Handle other kinds of I2C operations
Write ` buf ` to I2C Port . We assume this is a Write I2C Register operation with Register ID at ` buf [ 0 ] ` . TODO : Handle other kinds of I2C operations
fn write(&mut self, addr: u8, buf: &[u8]) -> Result<(), Self::Error> {
        //  Copy to local buffer because we need a mutable reference
        let mut buf2 = [0 ; 64];
        assert!(buf.len() <= buf2.len());
        buf2[..buf.len()].copy_from_slice(buf);
        //  Buffer for received I2C data
        let mut rbuf = [0 ; 1];
        //  Compose I2C Transfer
        let msg = [
            //  First I2C Message: Send Register ID and I2C Data as I2C Sub Address
            i2c_msg_s {
                frequency: self.frequency,  //  I2C Frequency
                addr:      addr as u16,     //  I2C Address
                buffer:    buf2.as_mut_ptr(),     //  Buffer to be sent
                length:    buf.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: Read I2C Data, because this forces BL602 to send the first message correctly
            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 to write I2C Registers
        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 to write I2C Registers
        let ret = unsafe { 
            ioctl(
                self.fd,          //  I2C Port
                I2CIOC_TRANSFER,  //  I2C Transfer
                &xfer             //  I2C Messages for the transfer
            )
        };
        assert!(ret >= 0);   
        Ok(())
    }
fn write ( & mut self , addr : u8 , buf : & [ u8 ] ) -> Result < ( ) , Self :: Error > { //  Copy to local buffer because we need a mutable reference let mut buf2 = [ 0 ; 64 ] ; assert ! ( buf len ( ) buf2 len ( ) ) ; buf2 [ .. buf . len ( ) ] . copy_from_slice ( buf ) ; //  Buffer for received I2C data let mut rbuf = [ 0 ; 1 ] ; //  Compose I2C Transfer let msg = [ //  First I2C Message: Send Register ID and I2C Data as I2C Sub Address i2c_msg_s { frequency : self . frequency , //  I2C Frequency addr : addr as u16 , //  I2C Address buffer : buf2 . as_mut_ptr ( ) , //  Buffer to be sent length : buf . 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: Read I2C Data, because this forces BL602 to send the first message correctly 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 to write I2C Registers 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 to write I2C Registers let ret = unsafe { ioctl ( self . fd , //  I2C Port I2CIOC_TRANSFER , //  I2C Transfer & xfer //  I2C Messages for the transfer ) } ; assert ! ( ret 0 ) ; Ok ( ( ) ) }
Write `buf` to I2C Port.
Write ` buf ` to I2C Port .
&mut self
addr
u8
buf
&[u8]
&mut self
addr
u8
buf
&[u8]