- All Superinterfaces:
AutoCloseable
,DeviceInterface
,I2CSMBusInterface
- All Known Subinterfaces:
InternalI2CDeviceInterface
- All Known Implementing Classes:
I2CDevice
,NativeI2CDeviceJavaRaf
,NativeI2CDeviceSMBus
Methods for interacting with I2C devices that do not use the SMBus interface.
Inter-Integrated Circuit (I2C)
Interface
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
static class
static class
static class
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
Fields inherited from interface com.diozero.api.I2CSMBusInterface
MAX_I2C_BLOCK_SIZE
-
Method Summary
Modifier and TypeMethodDescriptionint
readBytes
(byte[] buffer) Read the specified number of bytes from the device without the 32 byte limit imposed by SMBus.default byte[]
readBytes
(int length) Utility method that wrapsreadBytes(byte[])
to read the specified number of bytes.default ByteBuffer
readBytesAsByteBuffer
(int length) Utility method that wraps the response fromreadBytes(int)
in aByteBuffer
that is configured to use thebyte order
specified in the constructor.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.default void
writeBytes
(ByteBuffer buffer) Utility method that wrapsI2CDevice.writeBytes(byte[])
to write the available bytes in the specifiedByteBuffer
.Methods inherited from interface com.diozero.api.DeviceInterface
close
Methods inherited from interface com.diozero.api.I2CSMBusInterface
blockProcessCall, getAddress, getByteOrder, getController, probe, probe, processCall, readBit, readBlockData, readByte, readByteData, readI2CBlockData, readI2CBlockDataByteArray, readI2CBlockDataByteBuffer, readInt, readShort, readUByte, readUInt, readUInt, readUShort, readWordData, readWordSwapped, writeBit, writeBlockData, writeByte, writeByteData, writeByteData, writeI2CBlockData, writeQuick, writeWordData, writeWordSwapped
-
Field Details
-
I2C_FUNC_I2C
static final int I2C_FUNC_I2C- See Also:
-
I2C_FUNC_10BIT_ADDR
static final int I2C_FUNC_10BIT_ADDR- See Also:
-
I2C_FUNC_PROTOCOL_MANGLING
static final int I2C_FUNC_PROTOCOL_MANGLING- See Also:
-
I2C_FUNC_SMBUS_PEC
static final int I2C_FUNC_SMBUS_PEC- See Also:
-
I2C_FUNC_NOSTART
static final int I2C_FUNC_NOSTART- See Also:
-
I2C_FUNC_SMBUS_BLOCK_PROC_CALL
static final int I2C_FUNC_SMBUS_BLOCK_PROC_CALL- See Also:
-
I2C_FUNC_SMBUS_QUICK
static final int I2C_FUNC_SMBUS_QUICK- See Also:
-
I2C_FUNC_SMBUS_READ_BYTE
static final int I2C_FUNC_SMBUS_READ_BYTE- See Also:
-
I2C_FUNC_SMBUS_WRITE_BYTE
static final int I2C_FUNC_SMBUS_WRITE_BYTE- See Also:
-
I2C_FUNC_SMBUS_READ_BYTE_DATA
static final int I2C_FUNC_SMBUS_READ_BYTE_DATA- See Also:
-
I2C_FUNC_SMBUS_WRITE_BYTE_DATA
static final int I2C_FUNC_SMBUS_WRITE_BYTE_DATA- See Also:
-
I2C_FUNC_SMBUS_READ_WORD_DATA
static final int I2C_FUNC_SMBUS_READ_WORD_DATA- See Also:
-
I2C_FUNC_SMBUS_WRITE_WORD_DATA
static final int I2C_FUNC_SMBUS_WRITE_WORD_DATA- See Also:
-
I2C_FUNC_SMBUS_PROC_CALL
static final int I2C_FUNC_SMBUS_PROC_CALL- See Also:
-
I2C_FUNC_SMBUS_READ_BLOCK_DATA
static final int I2C_FUNC_SMBUS_READ_BLOCK_DATA- See Also:
-
I2C_FUNC_SMBUS_WRITE_BLOCK_DATA
static final int I2C_FUNC_SMBUS_WRITE_BLOCK_DATA- See Also:
-
I2C_FUNC_SMBUS_READ_I2C_BLOCK
static final int I2C_FUNC_SMBUS_READ_I2C_BLOCK- See Also:
-
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
static final int I2C_FUNC_SMBUS_WRITE_I2C_BLOCK- See Also:
-
-
Method Details
-
readBytes
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
-
readBytesAsByteBuffer
Utility method that wraps the response fromreadBytes(int)
in aByteBuffer
that is configured to use thebyte order
specified in the constructor.- Parameters:
length
- number of bytes to read- Returns:
- A
ByteBuffer
containing the bytes read using the byte order specified in the constructor - Throws:
RuntimeIOException
- if an I/O error occurs- See Also:
-
readBytes
Utility method that wrapsreadBytes(byte[])
to read the specified number of bytes.- Parameters:
length
- the number of bytes to read- Returns:
- the bytes read from the device
- Throws:
RuntimeIOException
- if an I/O error occurs- See Also:
-
writeBytes
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
-
writeBytes
Utility method that wrapsI2CDevice.writeBytes(byte[])
to write the available bytes in the specifiedByteBuffer
. The byte order of data in the ByteBuffer is unchanged.- Parameters:
buffer
- theByteBuffer
containing the data to write- Throws:
RuntimeIOException
- if an I/O error occurs- See Also:
-
readWrite
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
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
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
-