Class NativeI2CDeviceSMBus

    • Method Detail

      • getController

        public int getController()
      • getDeviceAddress

        public int getDeviceAddress()
      • probe

        public boolean probe​(I2CDevice.ProbeMode mode)
        Description copied from interface: I2CSMBusInterface
        Probe this I2C device to see if it is connected
        Specified by:
        probe in interface I2CSMBusInterface
        Parameters:
        mode - Probe mode
        Returns:
        True if the probe is successful and the device is connected
      • readByte

        public byte readByte()
                      throws I2CException,
                             UnsupportedOperationException
        Description copied from interface: I2CSMBusInterface

        SMBus Receive Byte: i2c_smbus_read_byte()

        This reads a single byte from a device, without specifying a device register. Some devices are so simple that this interface is enough; for others, it is a shorthand if you want to read the same register as in the previous SMBus command.

         S Addr Rd [A] [Data] NA P
         
        Specified by:
        readByte in interface I2CSMBusInterface
        Returns:
        The byte data read (note caller needs to handle conversion to unsigned)
        Throws:
        I2CException
        UnsupportedOperationException
      • processCall

        public short processCall​(int registerAddress,
                                 short data)
                          throws I2CException,
                                 UnsupportedOperationException
        Description copied from interface: I2CSMBusInterface

        SMBus Process Call

        This command selects a device register (through the Comm byte), sends 16 bits of data to it, and reads 16 bits of data in return.

         S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A]
                        S Addr Rd [A] [DataLow] A [DataHigh] NA P
         
        Specified by:
        processCall in interface I2CSMBusInterface
        Parameters:
        registerAddress - the register to write to / read from
        data - value to write
        Returns:
        the value read
        Throws:
        I2CException
        UnsupportedOperationException
      • readBlockData

        public byte[] readBlockData​(int registerAddress)
                             throws I2CException,
                                    UnsupportedOperationException
        Description copied from interface: I2CSMBusInterface

        SMBus Block Read: i2c_smbus_read_block_data()

        This command reads a block of up to 32 bytes from a device, from a designated register that is specified through the Comm byte. The amount of data is specified by the device in the Count byte.

         S Addr Wr [A] Comm [A]
                        S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P
         
        Specified by:
        readBlockData in interface I2CSMBusInterface
        Parameters:
        registerAddress - the register to read from
        Returns:
        the data read up to 32 bytes in length
        Throws:
        I2CException
        UnsupportedOperationException
      • blockProcessCall

        public byte[] blockProcessCall​(int registerAddress,
                                       byte... txData)
                                throws I2CException,
                                       UnsupportedOperationException,
                                       IllegalArgumentException
        Description copied from interface: I2CSMBusInterface

        SMBus Block Write - Block Read Process Call

        SMBus Block Write - Block Read Process Call was introduced in Revision 2.0 of the specification.
        This command selects a device register (through the Comm byte), sends 1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return.

         S Addr Wr [A] Comm [A] Count [A] Data [A] ...
                        S Addr Rd [A] [Count] A [Data] ... A P
         
        Specified by:
        blockProcessCall in interface I2CSMBusInterface
        Parameters:
        registerAddress - the register to write to and read from
        txData - the byte array from which the data is written (up to 32 bytes)
        Returns:
        the data read (up to 32 bytes)
        Throws:
        I2CException
        UnsupportedOperationException
        IllegalArgumentException
      • readI2CBlockData

        public int readI2CBlockData​(int registerAddress,
                                    byte[] buffer)
                             throws I2CException,
                                    UnsupportedOperationException
        Description copied from interface: I2CSMBusInterface

        I2C Block Read: i2c_smbus_read_i2c_block_data()

        This command reads a block of up to 32 bytes from a device, using the specified register address.

        I2C commands:
         S Addr Wr [A] Comm [A]
              S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
         
        Specified by:
        readI2CBlockData in interface I2CSMBusInterface
        Parameters:
        registerAddress - the register to read from
        buffer - the buffer to read the data into, the buffer length specifies the number of bytes to read up to a maximum of 32 bytes
        Returns:
        the number of bytes actually read
        Throws:
        I2CException
        UnsupportedOperationException
      • writeI2CBlockData

        public void writeI2CBlockData​(int registerAddress,
                                      byte... data)
                               throws I2CException,
                                      UnsupportedOperationException
        Description copied from interface: I2CSMBusInterface

        I2C Block Write: i2c_smbus_write_i2c_block_data()

        The opposite of the Block Read command, this writes up to 32 bytes of data to a device, to the specified register address.

         S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
         

        Note that command lengths of 0, 2, or more bytes are supported as they are indistinguishable from data.

        Specified by:
        writeI2CBlockData in interface I2CSMBusInterface
        Parameters:
        registerAddress - the register to write to
        data - values to write with a maximum length of 32 bytes
        Throws:
        I2CException
        UnsupportedOperationException
      • readBytes

        public int readBytes​(byte[] buffer)
                      throws I2CException
        Description copied from interface: I2CDeviceInterface
        Read the specified number of bytes from the device without the 32 byte limit imposed by SMBus. I2C commands:
         S Addr Rd [A] [Data] [A] [Data] [A] ... [A] [Data] NA P
         
        Specified by:
        readBytes in interface I2CDeviceInterface
        Parameters:
        buffer - byte array to populate, the length of the byte array indicates the number of bytes to read
        Returns:
        the number of bytes read
        Throws:
        I2CException
      • writeBytes

        public void writeBytes​(byte... data)
                        throws I2CException
        Description copied from interface: I2CDeviceInterface
        Write the specified byte array to the device without the 32 byte limit imposed by SMBus. I2C commands:
         S Addr Wr [A] [Data] [A] [Data] [A] ... [A] [Data] NA P
         
        Specified by:
        writeBytes in interface I2CDeviceInterface
        Parameters:
        data - the data to write
        Throws:
        I2CException
      • readWrite

        public void readWrite​(I2CDeviceInterface.I2CMessage[] messages,
                              byte[] buffer)
                       throws I2CException
        Description copied from interface: I2CDeviceInterface

        Low-level I2C interface to execute a series of commands in a single I2C transaction. Allows multiple read and write commands to be executed at the same time as well as control over the I2C flags that are sent with each command, e.g. NO-START.

        The data buffer MUST align with the commands that are being issued. For example, to read 2 bytes from register 0x40 and then write 3 bytes to register 0x50, the message array and buffer would be as follows:

         Message array and corresponding data buffer:
         Idx  Flags     Len  Buffer
         [0]  I2C_M_WR  1    [0] 0x40 - the register address to read from
         [1]  I2C_M_RD  2    [1..2] leave blank, will be overridden with the data read from the device
         [2]  I2C_M_WR  1    [3] 0x50 - the register address to write to
         [3]  I2C_M_WR  3    [4..6] the 3 bytes of data to write
         
        Specified by:
        readWrite in interface I2CDeviceInterface
        Parameters:
        messages - array of commands to send to the device
        buffer - the data buffer that is associated with the commands
        Throws:
        I2CException