Package com.diozero.api
Interface I2CDeviceInterface
-
- All Superinterfaces:
AutoCloseable
,DeviceInterface
,I2CSMBusInterface
- All Known Subinterfaces:
InternalI2CDeviceInterface
- All Known Implementing Classes:
I2CDevice
,NativeI2CDeviceJavaRaf
,NativeI2CDeviceSMBus
public interface I2CDeviceInterface extends I2CSMBusInterface
Methods for interacting with I2C devices that do not use the SMBus interface. Inter-Integrated Circuit (I2C) Interface
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
I2CDeviceInterface.Command
static class
I2CDeviceInterface.I2CMessage
static class
I2CDeviceInterface.ReadCommand
static class
I2CDeviceInterface.WriteCommand
-
Field Summary
Fields Modifier and Type Field Description static int
I2C_FUNC_10BIT_ADDR
static int
I2C_FUNC_I2C
static int
I2C_FUNC_NOSTART
static int
I2C_FUNC_PROTOCOL_MANGLING
static int
I2C_FUNC_SMBUS_BLOCK_PROC_CALL
static int
I2C_FUNC_SMBUS_PEC
static int
I2C_FUNC_SMBUS_PROC_CALL
static int
I2C_FUNC_SMBUS_QUICK
static int
I2C_FUNC_SMBUS_READ_BLOCK_DATA
static int
I2C_FUNC_SMBUS_READ_BYTE
static int
I2C_FUNC_SMBUS_READ_BYTE_DATA
static int
I2C_FUNC_SMBUS_READ_I2C_BLOCK
static int
I2C_FUNC_SMBUS_READ_WORD_DATA
static int
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
static int
I2C_FUNC_SMBUS_WRITE_BYTE
static int
I2C_FUNC_SMBUS_WRITE_BYTE_DATA
static int
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
static int
I2C_FUNC_SMBUS_WRITE_WORD_DATA
-
Fields inherited from interface com.diozero.api.I2CSMBusInterface
MAX_I2C_BLOCK_SIZE
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description int
readBytes(byte[] buffer)
Read the specified number of bytes from the device without the 32 byte limit imposed by SMBus.default int
readNoStop(byte registerAddress, byte[] rxData, boolean repeatedStart)
Utility I2C read method that allows control over the NO-START flag.default void
readWrite(int registerWriteFlags, I2CDeviceInterface.Command... commands)
Utility method to simplify thereadWrite(I2CMessage[], byte[])
method at the cost of a bit of performance.default void
readWrite(I2CDeviceInterface.Command... commands)
Utility method to simplify thereadWrite(I2CMessage[], byte[])
method at the cost of a bit of performance.void
readWrite(I2CDeviceInterface.I2CMessage[] messages, byte[] buffer)
Low-level I2C interface to execute a series of commands in a single I2C transaction.void
writeBytes(byte... data)
Write the specified byte array to the device without the 32 byte limit imposed by SMBus.-
Methods inherited from interface com.diozero.api.DeviceInterface
close
-
Methods inherited from interface com.diozero.api.I2CSMBusInterface
blockProcessCall, probe, probe, processCall, readBlockData, readByte, readByteData, readI2CBlockData, readWordData, readWordSwapped, writeBlockData, writeByte, writeByteData, writeI2CBlockData, writeQuick, writeWordData, writeWordSwapped
-
-
-
-
Field Detail
-
I2C_FUNC_I2C
static final int I2C_FUNC_I2C
- See Also:
- Constant Field Values
-
I2C_FUNC_10BIT_ADDR
static final int I2C_FUNC_10BIT_ADDR
- See Also:
- Constant Field Values
-
I2C_FUNC_PROTOCOL_MANGLING
static final int I2C_FUNC_PROTOCOL_MANGLING
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_PEC
static final int I2C_FUNC_SMBUS_PEC
- See Also:
- Constant Field Values
-
I2C_FUNC_NOSTART
static final int I2C_FUNC_NOSTART
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_BLOCK_PROC_CALL
static final int I2C_FUNC_SMBUS_BLOCK_PROC_CALL
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_QUICK
static final int I2C_FUNC_SMBUS_QUICK
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_READ_BYTE
static final int I2C_FUNC_SMBUS_READ_BYTE
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_WRITE_BYTE
static final int I2C_FUNC_SMBUS_WRITE_BYTE
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_READ_BYTE_DATA
static final int I2C_FUNC_SMBUS_READ_BYTE_DATA
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_WRITE_BYTE_DATA
static final int I2C_FUNC_SMBUS_WRITE_BYTE_DATA
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_READ_WORD_DATA
static final int I2C_FUNC_SMBUS_READ_WORD_DATA
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_WRITE_WORD_DATA
static final int I2C_FUNC_SMBUS_WRITE_WORD_DATA
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_PROC_CALL
static final int I2C_FUNC_SMBUS_PROC_CALL
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_READ_BLOCK_DATA
static final int I2C_FUNC_SMBUS_READ_BLOCK_DATA
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
static final int I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_READ_I2C_BLOCK
static final int I2C_FUNC_SMBUS_READ_I2C_BLOCK
- See Also:
- Constant Field Values
-
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
static final int I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
- See Also:
- Constant Field Values
-
-
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 thereadWrite(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 devicebuffer
- the data buffer that is associated with the commands
-
readWrite
default void readWrite(int registerWriteFlags, I2CDeviceInterface.Command... commands)
Utility method to simplify thereadWrite(I2CMessage[], byte[])
method at the cost of a bit of performance.- Parameters:
registerWriteFlags
- flags to apply to all register address writescommands
- 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, byte[] rxData, boolean repeatedStart)
Utility I2C read method that allows control over the NO-START flag.- Parameters:
registerAddress
- the register address to read fromrxData
- buffer to hold the data readrepeatedStart
- whether or not to use repeated starts- Returns:
- the number of bytes read
-
-