Этот коммит содержится в:
Yurii Soldak 2022-02-05 00:43:05 +01:00 коммит произвёл Ron Evans
родитель 77ec9b6369
коммит ac7e370c72

Просмотреть файл

@ -6,7 +6,7 @@ package machine
import ( import (
"device/rp" "device/rp"
"errors" "errors"
"strconv" "internal/itoa"
) )
// I2C on the RP2040. // I2C on the RP2040.
@ -289,7 +289,6 @@ func (i2c *I2C) tx(addr uint8, tx []byte, nostop bool, timeout uint64) (err erro
for !i2c.interrupted(rp.I2C0_IC_RAW_INTR_STAT_TX_EMPTY) { for !i2c.interrupted(rp.I2C0_IC_RAW_INTR_STAT_TX_EMPTY) {
if ticks() > deadline { if ticks() > deadline {
i2c.restartOnNext = nostop i2c.restartOnNext = nostop
println(1)
return errI2CWriteTimeout // If there was a timeout, don't attempt to do anything else. return errI2CWriteTimeout // If there was a timeout, don't attempt to do anything else.
} }
} }
@ -308,7 +307,6 @@ func (i2c *I2C) tx(addr uint8, tx []byte, nostop bool, timeout uint64) (err erro
// to take care of the abort. // to take care of the abort.
for !i2c.interrupted(rp.I2C0_IC_RAW_INTR_STAT_STOP_DET) { for !i2c.interrupted(rp.I2C0_IC_RAW_INTR_STAT_STOP_DET) {
if ticks() > deadline { if ticks() > deadline {
println(2)
i2c.restartOnNext = nostop i2c.restartOnNext = nostop
return errI2CWriteTimeout return errI2CWriteTimeout
} }
@ -330,7 +328,7 @@ func (i2c *I2C) tx(addr uint8, tx []byte, nostop bool, timeout uint64) (err erro
fallthrough fallthrough
default: default:
// panic("unknown i2c abortReason:" + strconv.Itoa(abortReason) // panic("unknown i2c abortReason:" + strconv.Itoa(abortReason)
err = makeI2CBuffError(byteCtr) err = makeI2CAbortError(abortReason)
} }
} }
@ -396,7 +394,7 @@ func (i2c *I2C) rx(addr uint8, rx []byte, nostop bool, timeout uint64) (err erro
err = ErrI2CGeneric err = ErrI2CGeneric
default: default:
// undefined abort sequence // undefined abort sequence
err = makeI2CBuffError(byteCtr) err = makeI2CAbortError(abortReason)
} }
} }
@ -438,15 +436,15 @@ func (i2c *I2C) interrupted(mask uint32) bool {
return reg&mask == mask return reg&mask == mask
} }
type i2cBuffError int type i2cAbortError uint32
func (b i2cBuffError) Error() string { func (b i2cAbortError) Error() string {
return "i2c err after addr ack at data " + strconv.Itoa(int(b)) return "i2c abort, reason " + itoa.Uitoa(uint(b))
} }
//go:inline //go:inline
func makeI2CBuffError(idx int) error { func makeI2CAbortError(reason uint32) error {
return i2cBuffError(idx) return i2cAbortError(reason)
} }
//go:inline //go:inline