mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-15 00:13:43 +00:00
Add per-byte timeout budget for rp2 I2C (#5189)
* Add per-byte timeout budget for rp2 I2C * run goimports
This commit is contained in:
@@ -280,8 +280,6 @@ func (i2c *I2C) deinit() (resetVal uint32) {
|
|||||||
|
|
||||||
// tx performs blocking write followed by read to I2C bus.
|
// tx performs blocking write followed by read to I2C bus.
|
||||||
func (i2c *I2C) tx(addr uint8, tx, rx []byte) (err error) {
|
func (i2c *I2C) tx(addr uint8, tx, rx []byte) (err error) {
|
||||||
const timeout_us = 4_000
|
|
||||||
deadline := ticks() + timeout_us
|
|
||||||
if addr >= 0x80 || isReservedI2CAddr(addr) {
|
if addr >= 0x80 || isReservedI2CAddr(addr) {
|
||||||
return errInvalidTgtAddr
|
return errInvalidTgtAddr
|
||||||
}
|
}
|
||||||
@@ -292,6 +290,14 @@ func (i2c *I2C) tx(addr uint8, tx, rx []byte) (err error) {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Base 4ms for small register pokes.
|
||||||
|
// Add per-byte budget. 100us/byte is conservative at 400kHz and still ok at 100kHz for modest sizes.
|
||||||
|
timeout_us := uint64(4_000) + uint64(txlen+rxlen)*100
|
||||||
|
// Cap so it doesn't go insane:
|
||||||
|
timeout_us = min(timeout_us, 500_000)
|
||||||
|
|
||||||
|
deadline := ticks() + timeout_us
|
||||||
|
|
||||||
err = i2c.disable()
|
err = i2c.disable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Reference in New Issue
Block a user