Add per-byte timeout budget for rp2 I2C (#5189)

* Add per-byte timeout budget for rp2 I2C

* run goimports
This commit is contained in:
Matthew Hiles
2026-02-02 08:09:34 -05:00
committed by GitHub
parent e79cdc1122
commit bef0dc5d21
+8 -2
View File
@@ -280,8 +280,6 @@ func (i2c *I2C) deinit() (resetVal uint32) {
// tx performs blocking write followed by read to I2C bus.
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) {
return errInvalidTgtAddr
}
@@ -292,6 +290,14 @@ func (i2c *I2C) tx(addr uint8, tx, rx []byte) (err error) {
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()
if err != nil {
return err