rp2/machine_i2c: Add timeout parameter for machine.I2C().

This commit adds support for the `timeout` keyword argument to machine.I2C
on the rp2 port, following how it's done on other ports.

The main motivation here is avoid the interpreter crashing due to infinite
loops when SDA is stuck low, which is quite common if the board gets reset
while reading from an I2C device.

A default timeout of 50ms is chosen because it's consistent with:
- Commit a707fe50b0 which used a timeout of
  50,000us for zero-length writes on the rp2 port.
- The machine.SoftI2C class which uses 50,000us as the default timeout.
- The stm32 port's hardware I2C, which uses 50,000us for
  I2C_POLL_DEFAULT_TIMEOUT_US.

This commit also fixes the default timeout on the esp32 port to be
consistent with the above, and updates the documentation for machine.I2C to
document this keyword argument.
This commit is contained in:
David (Pololu)
2023-04-12 18:58:44 -07:00
committed by Damien George
parent b525f1c9ec
commit bf3eb9dc39
3 changed files with 14 additions and 8 deletions

View File

@@ -62,7 +62,7 @@
#error "unsupported I2C for ESP32 SoC variant"
#endif
#define I2C_DEFAULT_TIMEOUT_US (10000) // 10ms
#define I2C_DEFAULT_TIMEOUT_US (50000) // 50ms
typedef struct _machine_hw_i2c_obj_t {
mp_obj_base_t base;