Interface I2CDeviceInterface

    • Method Detail

      • readBytes

        int readBytes​(byte[] buffer)
               throws RuntimeIOException
        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
         
        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:
        RuntimeIOException - if an I/O error occurs
      • writeBytes

        void writeBytes​(byte... data)
                 throws RuntimeIOException
        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
         
        Parameters:
        data - the data to write
        Throws:
        RuntimeIOException - if an I/O error occurs
      • readWrite

        default void readWrite​(I2CDeviceInterface.Command... commands)
        Utility method to simplify the readWrite(I2CMessage[], byte[]) method at the cost of a bit of performance.
        Parameters:
        commands - list of logical commands to perform; note that for read commands the data read from the device will be copied into the command's data buffer
      • readWrite

        void readWrite​(I2CDeviceInterface.I2CMessage[] messages,
                       byte[] buffer)

        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
         
        Parameters:
        messages - array of commands to send to the device
        buffer - the data buffer that is associated with the commands
      • readWrite

        default void readWrite​(int registerWriteFlags,
                               I2CDeviceInterface.Command... commands)
        Utility method to simplify the readWrite(I2CMessage[], byte[]) method at the cost of a bit of performance.
        Parameters:
        registerWriteFlags - flags to apply to all register address writes
        commands - list of logical commands to perform; note that for read commands the data read from the device will be copied into the command's data buffer
      • readNoStop

        default int readNoStop​(byte registerAddress,
                               int rxLength,
                               byte[] rxData,
                               boolean repeatedStart)
        Utility I2C read method that allows control over the NO-START flag.
        Parameters:
        registerAddress - the register address to read from
        rxLength - the number of bytes to read
        rxData - buffer to hold the data read
        repeatedStart - whether or not to use repeated starts
        Returns:
        the number of bytes read