Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/machine/machine_rp2_i2c.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down
Loading