add correct Tx implementation for mock I2C interfaces

This commit is contained in:
soypat
2023-05-28 22:04:10 -03:00
committed by Ron Evans
parent e6f82fad2e
commit 64029612e0
5 changed files with 40 additions and 22 deletions
+7 -8
View File
@@ -2,14 +2,13 @@ package legacy
import "tinygo.org/x/drivers"
type I2C struct {
i2c drivers.I2C
func ReadRegister(bus drivers.I2C, addr uint8, reg uint8, data []byte) error {
return bus.Tx(uint16(addr), []byte{reg}, data)
}
func ReadRegister(i2c drivers.I2C, addr uint8, reg uint8, buf []byte) error {
return i2c.Tx(uint16(addr), []byte{reg}, buf)
}
func WriteRegister(i2c drivers.I2C, addr uint8, reg uint8, buf []byte) error {
return i2c.Tx(uint16(addr), append([]byte{reg}, buf...), nil)
func WriteRegister(bus drivers.I2C, addr uint8, reg uint8, data []byte) error {
buf := make([]uint8, len(data)+1)
buf[0] = reg
copy(buf[1:], data)
return bus.Tx(uint16(addr), buf, nil)
}