mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-10 18:03:41 +00:00
add correct Tx implementation for mock I2C interfaces
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user