i2c iface refactor: Resolve 559

This commit is contained in:
soypat
2023-05-28 18:03:19 -03:00
committed by Ron Evans
parent e20c6d05f8
commit e6f82fad2e
37 changed files with 313 additions and 247 deletions
+6 -3
View File
@@ -4,7 +4,10 @@
package tmp102 // import "tinygo.org/x/drivers/tmp102"
import "tinygo.org/x/drivers"
import (
"tinygo.org/x/drivers"
"tinygo.org/x/drivers/internal/legacy"
)
// Device holds the already configured I2C bus and the address of the sensor.
type Device struct {
@@ -36,7 +39,7 @@ func (d *Device) Configure(cfg Config) {
// Connected checks if the config register can be read and that the configuration is correct.
func (d *Device) Connected() bool {
configData := make([]byte, 2)
err := d.bus.ReadRegister(d.address, RegConfiguration, configData)
err := legacy.ReadRegister(d.bus, d.address, RegConfiguration, configData)
// Check the reset configuration values.
if err != nil || configData[0] != 0x60 || configData[1] != 0xA0 {
return false
@@ -50,7 +53,7 @@ func (d *Device) ReadTemperature() (temperature int32, err error) {
tmpData := make([]byte, 2)
err = d.bus.ReadRegister(d.address, RegTemperature, tmpData)
err = legacy.ReadRegister(d.bus, d.address, RegTemperature, tmpData)
if err != nil {
return