All Implemented Interfaces:
Describable, Identity, Lifecycle, Extension, I2C, I2CRegisterDataReader, I2CRegisterDataReaderWriter, I2CRegisterDataWriter, IO<I2C,I2CConfig,I2CProvider>, IODataReader, IODataWriter, AutoCloseable, Readable

public class LinuxFsI2C extends I2CBase implements I2C

PiGpioI2C class.

Version:
$Id: $Id
Author:
Robert Savage (http://www.savagehomeautomation.com)
  • Constructor Details

  • Method Details

    • write

      public int write(byte b)
      Specified by:
      write in interface IODataWriter
    • write

      public int write(byte[] data, int offset, int length)
      Specified by:
      write in interface IODataWriter
    • read

      public int read()
      Specified by:
      read in interface IODataReader
    • read

      public int read(byte[] buffer, int offset, int length)
      Specified by:
      read in interface IODataReader
    • writeRegister

      public int writeRegister(int register, byte b)
      Specified by:
      writeRegister in interface I2CRegisterDataWriter
    • writeRegister

      public int writeRegister(int register, byte[] data, int offset, int length)
      Specified by:
      writeRegister in interface I2CRegisterDataWriter
    • writeRegister

      public int writeRegister(byte[] register, byte[] data, int offset, int length)
      Specified by:
      writeRegister in interface I2CRegisterDataWriter
    • readRegister

      public int readRegister(int register)
      Specified by:
      readRegister in interface I2CRegisterDataReader
    • readRegister

      public int readRegister(int register, byte[] buffer, int offset, int length)
      Specified by:
      readRegister in interface I2CRegisterDataReader
    • readRegister

      public int readRegister(byte[] register, byte[] buffer, int offset, int length)

      This function uses the IOCTL interface to the LinuxFS. This is required so the I2C transaction uses an I2C RESTART. The following details explain creating the ByteBuffers used to create the 'C" structures for the IOCTL.

      i2c_msg: The space *buf will be used to set a pointer to the data buffer. This pointer must be aligned to the machines 4 or 8 byte alignment.

      This alignment is accomplished when the pointer is 'put' into the ByteBuffer

      • struct i2c_msg {
      • __u16 addr;
      • __u16 flags;
      • __u16 len;
      • __u8 *buf; wordSize
      • u8 buffer
      • };

      The ioctl command is I2CConstants.I2C_RDWR, this command requires two i2c_msg entries.

      The following describes the ByteBuffer, ioctlData, contents:

      • two byte address entry one
      • two byte len entry one
      • Possible padding for alignment
      • word size area for pointer to write data buffer
      • two byte address entry two
      • two byte flags entry two
      • two byte len entry two
      • Possible padding for alignment
      • word size area for pointer to read data buffer
      • Bytes required to contain write buffer contents
      • Bytes required to contain read data buffer

      There is a second byte buffer, offsets, this specifies the ByteBuffer offset of any pointer paired with the ByteBuffer offset of the data pointed to.

      This ByteBuffer contents
      • ByteBuffer position start of pointer to write data buffer
      • ByteBuffer position start of write buffer contents
      • ByteBuffer position start of pointer to read data buffer
      • ByteBuffer position start of read buffer contents
      Specified by:
      readRegister in interface I2CRegisterDataReader
    • writeReadRegisterWord

      public int writeReadRegisterWord(int register, int word)
      Specified by:
      writeReadRegisterWord in interface I2CRegisterDataReaderWriter
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface I2C
      Overrides:
      close in class I2CBase