Skip to content

Commit

Permalink
Added word sized i2c write operation
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Agsjö <[email protected]>
  • Loading branch information
erkkah committed Feb 6, 2017
1 parent f41021c commit 0626b3b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions sysfs/i2c_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,21 @@ type i2cSmbusIoctlData struct {
data uintptr
}

type SMBusOperations interface {
type I2cOperations interface {
ReadByte() (val uint8, err error)
ReadByteData(reg uint8) (val uint8, err error)
ReadWordData(reg uint8) (val uint16, err error)
ReadBlockData(b []byte) (n int, err error)
WriteByte(val uint8) (err error)
WriteByteData(reg uint8, val uint8) (err error)
WriteWordData(reg uint8, val uint16) (err error)
WriteBlockData(b []byte) (err error)
}

// I2cDevice is the interface to a specific i2c bus
type I2cDevice interface {
io.ReadWriteCloser
SMBusOperations
I2cOperations
SetAddress(int) error
}

Expand Down Expand Up @@ -161,6 +162,12 @@ func (d *i2cDevice) WriteByteData(reg uint8, val uint8) (err error) {
return err
}

func (d *i2cDevice) WriteWordData(reg uint8, val uint16) (err error) {
var data uint16 = val
err = d.smbusAccess(I2C_SMBUS_WRITE, reg, I2C_SMBUS_WORD_DATA, uintptr(unsafe.Pointer(&data)))
return err
}

func (d *i2cDevice) WriteBlockData(b []byte) (err error) {
// Command byte - a data byte which often selects a register on the device:
// https://www.kernel.org/doc/Documentation/i2c/smbus-protocol
Expand Down

0 comments on commit 0626b3b

Please sign in to comment.