Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temporary fix for linuxfs-i2c IOException. Also fix return code for … #336

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public int readRegister(byte[] register, byte[] buffer, int offset, int length)
buffer[i] = ioctlData.get(readBuffPosition +i );
; }

return (ioctlData.limit());
return (readLength);
}


Expand All @@ -330,8 +330,6 @@ public int writeReadRegisterWord(int register, int word) {
reg[1] = (byte) (word & 0xff);
reg[2] = (byte) ((word >> 8) & 0xff);
byte buff[] = new byte[2];

int rCode = this.readRegister(reg, buff, 0, buff.length);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove this readRegister?

word = (buff[1] << 8) | buff[0];
return word;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public synchronized I2C create(I2CConfig config) {
LinuxFsI2CBus i2CBus = this.i2CBusMap.computeIfAbsent(config.getBus(), busNr -> new LinuxFsI2CBus(config));
// create new I/O instance based on I/O config
LinuxFsI2C i2C = new LinuxFsI2C(i2CBus, this, config);
// Workaround, needed if first LinuxFsI2C usage is ioctl (readRegister or writeRegister)
i2C.read();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there not an init of a buffer in this method, which then makes the ioctl work?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For instance i can see this:

    this.lastAddress = i2c.device();
    this.file.ioctl(I2CConstants.I2C_SLAVE, i2c.device() & 0xFF);

so the very first thing that happens, is that we set the lastAddress, then immediately perform an ioctl... So maybe this is missing?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, i do see that the readRegister() does this too...

this.context.registry().add(i2C);
return i2C;
}
Expand Down