Skip to content

Commit

Permalink
sysfs: Should fix hybridgroup#272 by using first byte of data as comm…
Browse files Browse the repository at this point in the history
…and register for I2C reads

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Jan 2, 2017
1 parent 12a6d4d commit c432f50
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sysfs/i2c_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,17 @@ func (d *i2cDevice) Read(b []byte) (n int, err error) {
return d.file.Read(b)
}

data := make([]byte, len(b)+1)
data[0] = byte(len(b))
// Command byte - a data byte which often selects a register on the device:
// https://www.kernel.org/doc/Documentation/i2c/smbus-protocol
command := byte(b[0])
buf := b[1:]
data := make([]byte, len(buf)+1)
data[0] = byte(len(buf))
copy(data[1:], buf)

smbus := &i2cSmbusIoctlData{
readWrite: I2C_SMBUS_READ,
command: 0,
command: command,
size: I2C_SMBUS_I2C_BLOCK_DATA,
data: uintptr(unsafe.Pointer(&data[0])),
}
Expand Down

0 comments on commit c432f50

Please sign in to comment.