Class NativeI2CDeviceJavaRaf
- java.lang.Object
-
- com.diozero.internal.spi.AbstractDevice
-
- com.diozero.internal.provider.builtin.i2c.NativeI2CDeviceJavaRaf
-
- All Implemented Interfaces:
DeviceInterface
,I2CDeviceInterface
,I2CSMBusInterface
,InternalDeviceInterface
,InternalI2CDeviceInterface
,AutoCloseable
@Deprecated public class NativeI2CDeviceJavaRaf extends AbstractDevice implements InternalI2CDeviceInterface
Deprecated.Native Java implementation of the I2C SMBus commands using a Java
RandomAccessFile
to read to and write from the device. Makes use of a single native method to select the slave address.Reference Kernel I2C dev interface and SMBus Protocol.
Warning Not all methods have been tested!
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.diozero.api.I2CDeviceInterface
I2CDeviceInterface.Command, I2CDeviceInterface.I2CMessage, I2CDeviceInterface.ReadCommand, I2CDeviceInterface.WriteCommand
-
-
Field Summary
-
Fields inherited from interface com.diozero.api.I2CDeviceInterface
I2C_FUNC_10BIT_ADDR, I2C_FUNC_I2C, I2C_FUNC_NOSTART, I2C_FUNC_PROTOCOL_MANGLING, I2C_FUNC_SMBUS_BLOCK_PROC_CALL, I2C_FUNC_SMBUS_PEC, I2C_FUNC_SMBUS_PROC_CALL, I2C_FUNC_SMBUS_QUICK, I2C_FUNC_SMBUS_READ_BLOCK_DATA, I2C_FUNC_SMBUS_READ_BYTE, I2C_FUNC_SMBUS_READ_BYTE_DATA, I2C_FUNC_SMBUS_READ_I2C_BLOCK, I2C_FUNC_SMBUS_READ_WORD_DATA, I2C_FUNC_SMBUS_WRITE_BLOCK_DATA, I2C_FUNC_SMBUS_WRITE_BYTE, I2C_FUNC_SMBUS_WRITE_BYTE_DATA, I2C_FUNC_SMBUS_WRITE_I2C_BLOCK, I2C_FUNC_SMBUS_WRITE_WORD_DATA
-
Fields inherited from interface com.diozero.api.I2CSMBusInterface
MAX_I2C_BLOCK_SIZE
-
-
Constructor Summary
Constructors Constructor Description NativeI2CDeviceJavaRaf(DeviceFactoryInterface deviceFactory, String key, int controller, int address, I2CConstants.AddressSize addressSize, boolean force)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description byte[]
blockProcessCall(int register, byte... txData)
Deprecated.SMBus Block Write - Block Read Process Callvoid
closeDevice()
Deprecated.boolean
probe(I2CDevice.ProbeMode mode)
Deprecated.Probe this I2C device to see if it is connectedshort
processCall(int register, short data)
Deprecated.SMBus Process Callbyte[]
readBlockData(int register)
Deprecated.SMBus Block Read:i2c_smbus_read_block_data()
byte
readByte()
Deprecated.SMBus Receive Byte:i2c_smbus_read_byte()
byte
readByteData(int register)
Deprecated.SMBus Read Byte:i2c_smbus_read_byte_data()
int
readBytes(byte[] buffer)
Deprecated.Read the specified number of bytes from the device without the 32 byte limit imposed by SMBus.int
readI2CBlockData(int register, byte[] buffer)
Deprecated.I2C Block Read:i2c_smbus_read_i2c_block_data()
short
readWordData(int register)
Deprecated.SMBus Read Word:i2c_smbus_read_word_data()
short
readWordSwapped(int register)
Deprecated.SMBus Read Word Swapped:i2c_smbus_read_word_swapped()
void
readWrite(I2CDeviceInterface.I2CMessage[] messages, byte[] buffer)
Deprecated.Low-level I2C interface to execute a series of commands in a single I2C transaction.void
writeBlockData(int register, byte... data)
Deprecated.SMBus Block Write:i2c_smbus_write_block_data()
void
writeByte(byte data)
Deprecated.SMBus Send Byte:i2c_smbus_write_byte()
void
writeByteData(int register, byte data)
Deprecated.SMBus Write Byte:i2c_smbus_write_byte_data()
void
writeBytes(byte... data)
Deprecated.Write the specified byte array to the device without the 32 byte limit imposed by SMBus.void
writeI2CBlockData(int register, byte... data)
Deprecated.I2C Block Write:i2c_smbus_write_i2c_block_data()
void
writeQuick(byte bit)
Deprecated.SMBus Quick Commandvoid
writeWordData(int register, short data)
Deprecated.SMBus Write Word:i2c_smbus_write_word_data()
void
writeWordSwapped(int register, short data)
Deprecated.SMBus Write Word Swapped:i2c_smbus_write_word_swapped()
-
Methods inherited from class com.diozero.internal.spi.AbstractDevice
close, getDeviceFactory, getKey, isChild, isOpen, setChild
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.diozero.api.DeviceInterface
close
-
Methods inherited from interface com.diozero.api.I2CDeviceInterface
readNoStop, readWrite, readWrite
-
Methods inherited from interface com.diozero.api.I2CSMBusInterface
probe
-
Methods inherited from interface com.diozero.internal.spi.InternalDeviceInterface
getKey, isChild, isOpen, setChild
-
-
-
-
Constructor Detail
-
NativeI2CDeviceJavaRaf
public NativeI2CDeviceJavaRaf(DeviceFactoryInterface deviceFactory, String key, int controller, int address, I2CConstants.AddressSize addressSize, boolean force)
Deprecated.
-
-
Method Detail
-
closeDevice
public void closeDevice()
Deprecated.- Specified by:
closeDevice
in classAbstractDevice
-
probe
public boolean probe(I2CDevice.ProbeMode mode)
Deprecated.Description copied from interface:I2CSMBusInterface
Probe this I2C device to see if it is connected- Specified by:
probe
in interfaceI2CSMBusInterface
- Parameters:
mode
- Probe mode- Returns:
- True if the probe is successful and the device is connected
-
writeQuick
public void writeQuick(byte bit)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
writeQuick
in interfaceI2CSMBusInterface
- Parameters:
bit
- The bit to write
-
readByte
public byte readByte()
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
readByte
in interfaceI2CSMBusInterface
- Returns:
- The byte data read (note caller needs to handle conversion to unsigned)
-
writeByte
public void writeByte(byte data)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
writeByte
in interfaceI2CSMBusInterface
- Parameters:
data
- value to write
-
readByteData
public byte readByteData(int register)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
readByteData
in interfaceI2CSMBusInterface
- Parameters:
register
- the register to read from- Returns:
- data read as byte (note caller needs to handle conversion to unsigned)
-
writeByteData
public void writeByteData(int register, byte data)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
writeByteData
in interfaceI2CSMBusInterface
- Parameters:
register
- the register to write todata
- value to write
-
readWordData
public short readWordData(int register)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
readWordData
in interfaceI2CSMBusInterface
- Parameters:
register
- the register to read from- Returns:
- data read as a signed short in
Little Endian
byte order
-
writeWordData
public void writeWordData(int register, short data)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
writeWordData
in interfaceI2CSMBusInterface
- Parameters:
register
- the register to write todata
- value to write inLittle Endian
byte order
-
readWordSwapped
public short readWordSwapped(int register)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
readWordSwapped
in interfaceI2CSMBusInterface
- Parameters:
register
- the register to read from- Returns:
- data read as a signed short in
Big Endian
byte order
-
writeWordSwapped
public void writeWordSwapped(int register, short data)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
writeWordSwapped
in interfaceI2CSMBusInterface
- Parameters:
register
- the register to write todata
- value to write inBig Endian
byte order
-
processCall
public short processCall(int register, short data)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
processCall
in interfaceI2CSMBusInterface
- Parameters:
register
- the register to write to / read fromdata
- value to write- Returns:
- the value read
-
readBlockData
public byte[] readBlockData(int register)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
readBlockData
in interfaceI2CSMBusInterface
- Parameters:
register
- the register to read from- Returns:
- the data read up to 32 bytes in length
-
writeBlockData
public void writeBlockData(int register, byte... data)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
writeBlockData
in interfaceI2CSMBusInterface
- Parameters:
register
- the register to write todata
- the data to write (up to 32 bytes)
-
blockProcessCall
public byte[] blockProcessCall(int register, byte... txData)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
blockProcessCall
in interfaceI2CSMBusInterface
- 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)
-
readI2CBlockData
public int readI2CBlockData(int register, byte[] buffer)
Deprecated.Description copied from interface:I2CSMBusInterface
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
- Specified by:
readI2CBlockData
in interfaceI2CSMBusInterface
- 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
-
writeI2CBlockData
public void writeI2CBlockData(int register, byte... data)
Deprecated.Description copied from interface:I2CSMBusInterface
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.
- Specified by:
writeI2CBlockData
in interfaceI2CSMBusInterface
- Parameters:
register
- the register to write todata
- values to write with a maximum length of 32 bytes
-
readBytes
public int readBytes(byte[] buffer)
Deprecated.Description copied from interface:I2CDeviceInterface
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
- Specified by:
readBytes
in interfaceI2CDeviceInterface
- 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
-
writeBytes
public void writeBytes(byte... data)
Deprecated.Description copied from interface:I2CDeviceInterface
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
- Specified by:
writeBytes
in interfaceI2CDeviceInterface
- Parameters:
data
- the data to write
-
readWrite
public void readWrite(I2CDeviceInterface.I2CMessage[] messages, byte[] buffer)
Deprecated.Description copied from interface:I2CDeviceInterface
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
- Specified by:
readWrite
in interfaceI2CDeviceInterface
- Parameters:
messages
- array of commands to send to the devicebuffer
- the data buffer that is associated with the commands
-
-