Interface I2CSMBusInterface
-
- All Superinterfaces:
AutoCloseable
,DeviceInterface
- All Known Subinterfaces:
I2CDeviceInterface
,InternalI2CDeviceInterface
- All Known Implementing Classes:
I2CDevice
,NativeI2CDeviceJavaRaf
,NativeI2CDeviceSMBus
public interface I2CSMBusInterface extends DeviceInterface
I2C device interface Linux SMBus interface
-
-
Field Summary
Fields Modifier and Type Field Description static int
MAX_I2C_BLOCK_SIZE
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description byte[]
blockProcessCall(int register, byte... txData)
SMBus Block Write - Block Read Process Calldefault 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
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
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()
-
Methods inherited from interface com.diozero.api.DeviceInterface
close
-
-
-
-
Field Detail
-
MAX_I2C_BLOCK_SIZE
static final int MAX_I2C_BLOCK_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
probe
default boolean probe() throws RuntimeIOException
Probe this I2C device usingAuto
probe mode- Returns:
- True if the probe is successful
- Throws:
RuntimeIOException
- if an I/O error occurs
-
probe
boolean probe(I2CDevice.ProbeMode mode) throws RuntimeIOException
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
void writeQuick(byte bit) throws RuntimeIOException
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
byte readByte() throws RuntimeIOException
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
void writeByte(byte data) throws RuntimeIOException
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
byte readByteData(int register) throws RuntimeIOException
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
void writeByteData(int register, byte data) throws RuntimeIOException
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
short readWordData(int register) throws RuntimeIOException
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
void writeWordData(int register, short data) throws RuntimeIOException
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
default short readWordSwapped(int register) throws RuntimeIOException
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
default void writeWordSwapped(int register, short data) throws RuntimeIOException
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
short processCall(int register, short data) throws RuntimeIOException
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
byte[] readBlockData(int register) throws RuntimeIOException
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
void writeBlockData(int register, byte... data) throws RuntimeIOException
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
byte[] blockProcessCall(int register, byte... txData) throws RuntimeIOException
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
int readI2CBlockData(int register, byte[] buffer) throws RuntimeIOException
I2C Block Read:
i2c_smbus_read_i2c_block_data()
This command reads a block of up to 32 bytes from a device, using the specified register address.
I2C commands: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 up to a maximum of 32 bytes- Returns:
- the number of bytes actually read
- Throws:
RuntimeIOException
- if an I/O error occurs
-
writeI2CBlockData
void writeI2CBlockData(int register, byte... data) throws RuntimeIOException
I2C Block Write:
i2c_smbus_write_i2c_block_data()
The opposite of the Block Read command, this writes up to 32 bytes of data to a device, to the specified register address.
S Addr Wr [A] Comm [A] Data [A] Data [A] ... [A] Data [A] P
Note that command lengths of 0, 2, or more bytes are supported as they are indistinguishable from data.
- Parameters:
register
- the register to write todata
- values to write with a maximum length of 32 bytes- Throws:
RuntimeIOException
- if an I/O error occurs
-
-