mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-17 05:13:23 +00:00
add correct Tx implementation for mock I2C interfaces
This commit is contained in:
+12
-2
@@ -75,6 +75,16 @@ func (d *I2CDevice16) WriteRegister(r uint8, buf []byte) error {
|
||||
|
||||
// Tx implements I2C.Tx.
|
||||
func (bus *I2CDevice16) Tx(w, r []byte) error {
|
||||
// TODO: implement this
|
||||
return nil
|
||||
switch len(w) {
|
||||
case 0:
|
||||
bus.c.Fatalf("i2c mock: need a write byte")
|
||||
return nil
|
||||
case 1:
|
||||
return bus.ReadRegister(w[0], r)
|
||||
default:
|
||||
if len(r) > 0 || len(w) == 1 {
|
||||
bus.c.Fatalf("i2c mock: unsupported lengths in Tx(%d, %d)", len(w), len(r))
|
||||
}
|
||||
return bus.WriteRegister(w[0], w[1:])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user