Interface I2CSMBusInterface
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Subinterfaces:
I2CDeviceInterface
- All Known Implementing Classes:
I2CDevice
,NativeI2CDeviceJavaRaf
,NativeI2CDeviceSMBus
public interface I2CSMBusInterface extends Closeable
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_I2C_BLOCK_SIZE
-
Method Summary
Modifier and Type Method Description byte[]
blockProcessCall(int register, byte... txData)
SMBus Block Write - Block Read Process Callvoid
close()
default boolean
probe()
Probe this I2C device usingAuto
probe modeboolean
probe(I2CDevice.ProbeMode mode)
Probe this I2C device to see if it is connectedshort
processCall(int register, short data)
SMBus Process Callbyte[]
readBlockData(int register)
SMBus Block Read:i2c_smbus_read_block_data()
byte
readByte()
SMBus Receive Byte:i2c_smbus_read_byte()
byte
readByteData(int register)
SMBus Read Byte:i2c_smbus_read_byte_data()
int
readBytes(byte[] buffer)
Diozero SMBus extension to read the specified number of bytes from the deviceint
readI2CBlockData(int register, byte[] buffer)
I2C Block Read:i2c_smbus_read_i2c_block_data()
short
readWordData(int register)
SMBus Read Word:i2c_smbus_read_word_data()
default short
readWordSwapped(int register)
SMBus Read Word Swapped:i2c_smbus_read_word_swapped()
void
writeBlockData(int register, byte... data)
SMBus Block Write:i2c_smbus_write_block_data()
void
writeByte(byte data)
SMBus Send Byte:i2c_smbus_write_byte()
void
writeByteData(int register, byte data)
SMBus Write Byte:i2c_smbus_write_byte_data()
void
writeBytes(byte... data)
Diozero SMBus extension to write the specified byte array to the devicevoid
writeI2CBlockData(int register, byte... data)
I2C Block Write:i2c_smbus_write_i2c_block_data()
void
writeQuick(byte bit)
SMBus Quick Commandvoid
writeWordData(int register, short data)
SMBus Write Word:i2c_smbus_write_word_data()
default void
writeWordSwapped(int register, short data)
SMBus Write Word Swapped:i2c_smbus_write_word_swapped()
-
Field Details
-
MAX_I2C_BLOCK_SIZE
static final int MAX_I2C_BLOCK_SIZE- See Also:
- Constant Field Values
-
-
Method Details
-
close
void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
probe
Probe this I2C device usingAuto
probe mode- Returns:
- True if the probe is successful
- Throws:
RuntimeIOException
- if an I/O error occurs
-
probe
Probe this I2C device to see if it is connected- Parameters:
mode
- Probe mode- Returns:
- True if the probe is successful and the device is connected
- Throws:
RuntimeIOException
- if an I/O error occurs
-
writeQuick
SMBus Quick Command
This sends a single bit to the device, at the place of the Rd/Wr bit.
A Addr Rd/Wr [A] P
- Parameters:
bit
- The bit to write- Throws:
RuntimeIOException
- if an I/O error occurs
-
readByte
SMBus Receive Byte:
i2c_smbus_read_byte()
This reads a single byte from a device, without specifying a device register. Some devices are so simple that this interface is enough; for others, it is a shorthand if you want to read the same register as in the previous SMBus command.
S Addr Rd [A] [Data] NA P
- Returns:
- The byte data read (note caller needs to handle conversion to unsigned)
- Throws:
RuntimeIOException
- if an I/O error occurs
-
writeByte
SMBus Send Byte:
i2c_smbus_write_byte()
This operation is the reverse of Receive Byte: it sends a single byte to a device. See Receive Byte for more information.
S Addr Wr [A] Data [A] P
- Parameters:
data
- value to write- Throws:
RuntimeIOException
- if an I/O error occurs
-
readByteData
SMBus Read Byte:
i2c_smbus_read_byte_data()
This reads a single byte from a device, from a designated register. The register is specified through the Comm byte.
S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] NA P
- Parameters:
register
- the register to read from- Returns:
- data read as byte (note caller needs to handle conversion to unsigned)
- Throws:
RuntimeIOException
- if an I/O error occurs
-
writeByteData
SMBus Write Byte:
i2c_smbus_write_byte_data()
This writes a single byte to a device, to a designated register. The register is specified through the Comm byte. This is the opposite of the Read Byte operation.
S Addr Wr [A] Comm [A] Data [A] P
- Parameters:
register
- the register to write todata
- value to write- Throws:
RuntimeIOException
- if an I/O error occurs
-
readWordData
SMBus Read Word:
i2c_smbus_read_word_data()
This operation is very like Read Byte; again, data is read from a device, from a designated register that is specified through the Comm byte. But this time, the data is a complete word (16 bits) in
Little Endian
order as per the SMBus specification.S Addr Wr [A] Comm [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
- Parameters:
register
- the register to read from- Returns:
- data read as a signed short in
Little Endian
byte order - Throws:
RuntimeIOException
- if an I/O error occurs
-
writeWordData
SMBus Write Word:
i2c_smbus_write_word_data()
This is the opposite of the Read Word operation. 16 bits of data is written to a device, to the designated register that is specified through the Comm byte. Note that the data is written in
Little Endian
byte order as per the SMBus specification.S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] P
- Parameters:
register
- the register to write todata
- value to write inLittle Endian
byte order- Throws:
RuntimeIOException
- if an I/O error occurs
-
readWordSwapped
SMBus Read Word Swapped:
i2c_smbus_read_word_swapped()
This operation is very like Read Byte; again, data is read from a device, from a designated register that is specified through the Comm byte. But this time, the data is a complete word (16 bits). Note this is the convenience function for reads where the two data bytes are the other way around (not SMBus compliant, but very popular.)
S Addr Wr [A] Comm [A] S Addr Rd [A] [DataHigh] A [DataLow] NA P
- Parameters:
register
- the register to read from- Returns:
- data read as a signed short in
Big Endian
byte order - Throws:
RuntimeIOException
- if an I/O error occurs
-
writeWordSwapped
SMBus Write Word Swapped:
i2c_smbus_write_word_swapped()
This is the opposite of the Read Word operation. 16 bits of data is written to a device, to the designated register that is specified through the Comm byte. Note that this is the convenience function for writes where the two data bytes are the other way around (not SMBus compliant, but very popular.)
S Addr Wr [A] Comm [A] DataHigh [A] DataLow [A] P
- Parameters:
register
- the register to write todata
- value to write inBig Endian
byte order- Throws:
RuntimeIOException
- if an I/O error occurs
-
processCall
SMBus Process Call
This command selects a device register (through the Comm byte), sends 16 bits of data to it, and reads 16 bits of data in return.
S Addr Wr [A] Comm [A] DataLow [A] DataHigh [A] S Addr Rd [A] [DataLow] A [DataHigh] NA P
- Parameters:
register
- the register to write to / read fromdata
- value to write- Returns:
- the value read
- Throws:
RuntimeIOException
- if an I/O error occurs
-
readBlockData
SMBus Block Read:
i2c_smbus_read_block_data()
This command reads a block of up to 32 bytes from a device, from a designated register that is specified through the Comm byte. The amount of data is specified by the device in the Count byte.
S Addr Wr [A] Comm [A] S Addr Rd [A] [Count] A [Data] A [Data] A ... A [Data] NA P
- Parameters:
register
- the register to read from- Returns:
- the data read up to 32 bytes in length
- Throws:
RuntimeIOException
- if an I/O error occurs
-
writeBlockData
SMBus Block Write:
i2c_smbus_write_block_data()
The opposite of the Block Read command, this writes up to 32 bytes to a device, to a designated register that is specified through the Comm byte. The amount of data is specified in the Count byte.
S Addr Wr [A] Comm [A] Count [A] Data [A] Data [A] ... [A] Data [A] P
- Parameters:
register
- the register to write todata
- the data to write (up to 32 bytes)- Throws:
RuntimeIOException
- if an I/O error occurs
-
blockProcessCall
SMBus Block Write - Block Read Process Call
SMBus Block Write - Block Read Process Call was introduced in Revision 2.0 of the specification.
This command selects a device register (through the Comm byte), sends 1 to 31 bytes of data to it, and reads 1 to 31 bytes of data in return.S Addr Wr [A] Comm [A] Count [A] Data [A] ... S Addr Rd [A] [Count] A [Data] ... A P
- Parameters:
register
- the register to write to and read fromtxData
- the byte array from which the data is written (up to 32 bytes)- Returns:
- the data read (up to 32 bytes)
- Throws:
RuntimeIOException
- if an I/O error occurs
-
readI2CBlockData
I2C Block Read:
i2c_smbus_read_i2c_block_data()
This command reads a block of bytes from a device, from a designated register that is specified through the Comm byte.
S Addr Wr [A] Comm [A] S Addr Rd [A] [Data] A [Data] A ... A [Data] NA P
- Parameters:
register
- the register to read frombuffer
- the buffer to read the data into, the buffer length specifies the number of bytes to read- Returns:
- the number of bytes actually read
- Throws:
RuntimeIOException
- if an I/O error occurs
-
writeI2CBlockData
I2C Block Write:
i2c_smbus_write_i2c_block_data()
The opposite of the Block Read command, this writes bytes to a device, to a designated register that is specified through the Comm byte. Note that command lengths of 0, 2, or more bytes are supported as they are indistinguishable from data.
S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
- Parameters:
register
- the register to write todata
- values to write- Throws:
RuntimeIOException
- if an I/O error occurs
-
readBytes
Diozero SMBus extension to read the specified number of bytes from the device- 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
Diozero SMBus extension to write the specified byte array to the device- Parameters:
data
- the data to write- Throws:
RuntimeIOException
- if an I/O error occurs
-