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
+3 -9
View File
@@ -9,6 +9,7 @@ package mcp23017
import (
"errors"
"tinygo.org/x/drivers"
"tinygo.org/x/drivers/internal/legacy"
)
@@ -77,19 +78,12 @@ const (
// address pins).
var ErrInvalidHWAddress = errors.New("invalid hardware address")
// I2C represents an I2C bus. It is notably implemented by the
// machine.I2C type.
type I2C interface {
ReadRegister(addr uint8, r uint8, buf []byte) error
WriteRegister(addr uint8, r uint8, buf []byte) error
}
// New returns a new MCP23017 device at the given I2C address
// on the given bus.
// It returns ErrInvalidHWAddress if the address isn't possible for the device.
//
// By default all pins are configured as inputs.
func NewI2C(bus I2C, address uint8) (*Device, error) {
func NewI2C(bus drivers.I2C, address uint8) (*Device, error) {
if address&hwAddressMask != hwAddress {
return nil, ErrInvalidHWAddress
}
@@ -117,7 +111,7 @@ type Device struct {
// bus holds the reference the I2C bus that the device lives on.
// It's an interface so that we can write tests for it.
bus I2C
bus drivers.I2C
addr uint8
// pins caches the most recent pin values that have been set.
// This enables us to change individual pin values without
+3 -1
View File
@@ -1,5 +1,7 @@
package mcp23017
import "tinygo.org/x/drivers"
// All is a convenience value that represents all pins high (or all mask bits one).
var All = PinSlice{0xffff}
@@ -12,7 +14,7 @@ type Devices []*Device
// NewI2CDevices returns a Devices slice holding the Device values
// for all the given addresses on the given bus.
// When more than one bus is in use, create the slice yourself.
func NewI2CDevices(bus I2C, addrs ...uint8) (Devices, error) {
func NewI2CDevices(bus drivers.I2C, addrs ...uint8) (Devices, error) {
devs := make(Devices, len(addrs))
for i, addr := range addrs {
dev, err := NewI2C(bus, addr)