Skip to content

Commit

Permalink
linuxfs i2c compatibility with Pigpio and the i2c spec dictates these
Browse files Browse the repository at this point in the history
i2c interface should use a restart between the write and read operation.
--Combined format (see Figure 13). During a change of direction within a transfer,
the START condition and the target address are both repeated, but with the R/W bit
reversed.--
int i2cReadByteData(unsigned handle, unsigned i2cReg) int i2cReadWordData(unsigned handle, unsigned i2cReg)
  • Loading branch information
taartspi committed Mar 9, 2024
1 parent 48f8fb0 commit e4af636
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,27 +149,30 @@ public int writeRegister(byte[] register, byte[] data, int offset, int length) {
// -------------------------------------------------------------------



/**
* {@inheritDoc}
*/
@Override
public int readRegister(int register) {
return this.i2CBus.execute(this, file -> {
file.write(register);
return file.read();
});
byte reg[] = new byte[1];
reg[0] = (byte) (register & 0xff);
byte buffer[] = new byte[1];
this.readRegister(reg, buffer,0,buffer.length);
int rVal = buffer[0] & 0xff;
return rVal;
}

/**
* {@inheritDoc}
*/
@Override
@Override
public int readRegister(int register, byte[] buffer, int offset, int length) {
Objects.checkFromIndexSize(offset, length, buffer.length);
return this.i2CBus.execute(this, file -> {
file.write(register);
return file.read(buffer, offset, length);
});
byte reg[] = new byte[1];
reg[0] = (byte) (register & 0xff);
int rCode = this.readRegister(reg, buffer, offset, length);
return rCode;
}


Expand Down

0 comments on commit e4af636

Please sign in to comment.