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 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, int rxLength, 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
-
-
-
-
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, 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 fromrxLength
- the number of bytes to readrxData
- buffer to hold the data readrepeatedStart
- whether or not to use repeated starts- Returns:
- the number of bytes read
-
-