i2csoft: remove the return value

This commit is contained in:
sago35
2021-09-24 09:25:52 +09:00
committed by Ron Evans
parent a89a26112e
commit 2c9a05a413
+9 -26
View File
@@ -72,7 +72,6 @@ func (i2c *I2C) SetBaudRate(br uint32) {
// It clocks out the given address, writes the bytes in w, reads back len(r) // It clocks out the given address, writes the bytes in w, reads back len(r)
// bytes and stores them in r, and generates a stop condition on the bus. // bytes and stores them in r, and generates a stop condition on the bus.
func (i2c *I2C) Tx(addr uint16, w, r []byte) error { func (i2c *I2C) Tx(addr uint16, w, r []byte) error {
var err error
i2c.nack = false i2c.nack = false
if len(w) != 0 { if len(w) != 0 {
// send start/address for write // send start/address for write
@@ -88,16 +87,10 @@ func (i2c *I2C) Tx(addr uint16, w, r []byte) error {
// write data // write data
for _, b := range w { for _, b := range w {
err = i2c.WriteByte(b) i2c.writeByte(b)
if err != nil {
return err
}
} }
err = i2c.signalStop() i2c.signalStop()
if err != nil {
return err
}
} }
if len(r) != 0 { if len(r) != 0 {
// send start/address for read // send start/address for read
@@ -125,17 +118,14 @@ func (i2c *I2C) Tx(addr uint16, w, r []byte) error {
// Send NACK to end transmission // Send NACK to end transmission
i2c.sendNack() i2c.sendNack()
err = i2c.signalStop() i2c.signalStop()
if err != nil {
return err
}
} }
return nil return nil
} }
// WriteByte writes a single byte to the I2C bus. // writeByte writes a single byte to the I2C bus.
func (i2c *I2C) WriteByte(data byte) error { func (i2c *I2C) writeByte(data byte) {
// Send data byte // Send data byte
i2c.scl.Low() i2c.scl.Low()
i2c.sda.High() i2c.sda.High()
@@ -168,12 +158,10 @@ func (i2c *I2C) WriteByte(data byte) error {
i2c.wait() i2c.wait()
// wait until transmission successful // wait until transmission successful
return nil
} }
// sendAddress sends the address and start signal // sendAddress sends the address and start signal
func (i2c *I2C) sendAddress(address uint16, write bool) error { func (i2c *I2C) sendAddress(address uint16, write bool) {
data := (address << 1) data := (address << 1)
if !write { if !write {
data |= 1 // set read flag data |= 1 // set read flag
@@ -209,11 +197,9 @@ func (i2c *I2C) sendAddress(address uint16, write bool) error {
i2c.wait() i2c.wait()
// wait until bus ready // wait until bus ready
return nil
} }
func (i2c *I2C) signalStop() error { func (i2c *I2C) signalStop() {
i2c.scl.Low() i2c.scl.Low()
i2c.sda.Low() i2c.sda.Low()
i2c.sda.Configure(machine.PinConfig{Mode: machine.PinOutput}) i2c.sda.Configure(machine.PinConfig{Mode: machine.PinOutput})
@@ -225,10 +211,9 @@ func (i2c *I2C) signalStop() error {
i2c.sda.High() i2c.sda.High()
i2c.wait() i2c.wait()
i2c.wait() i2c.wait()
return nil
} }
func (i2c *I2C) signalRead() error { func (i2c *I2C) signalRead() {
i2c.wait() i2c.wait()
i2c.wait() i2c.wait()
i2c.scl.Low() i2c.scl.Low()
@@ -239,7 +224,6 @@ func (i2c *I2C) signalRead() error {
i2c.scl.High() i2c.scl.High()
i2c.wait() i2c.wait()
i2c.wait() i2c.wait()
return nil
} }
func (i2c *I2C) readByte() byte { func (i2c *I2C) readByte() byte {
@@ -259,7 +243,7 @@ func (i2c *I2C) readByte() byte {
return data return data
} }
func (i2c *I2C) sendNack() error { func (i2c *I2C) sendNack() {
i2c.wait() i2c.wait()
i2c.wait() i2c.wait()
i2c.scl.Low() i2c.scl.Low()
@@ -270,7 +254,6 @@ func (i2c *I2C) sendNack() error {
i2c.scl.High() i2c.scl.High()
i2c.wait() i2c.wait()
i2c.wait() i2c.wait()
return nil
} }
// WriteRegister transmits first the register and then the data to the // WriteRegister transmits first the register and then the data to the