summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2022-01-21 14:52:03 +1100
committerDamien George <damien@micropython.org>2022-01-21 15:10:29 +1100
commita707fe50b085ec83722106609f6fd219faf9f030 (patch)
treeaea7211b4fce20e5f3d1f9f523715461fcb9c632
parentbef26d4e3fee7f00758d6e3ae7aa187b80d7878c (diff)
rp2/machine_i2c: Use soft I2C only for len=0, and increase timeout.
The RP2040 I2C hardware can do writes of length 1 and 2, just not of length 0. So only use software I2C for writes of length 0, to improve performance. Also increase the software I2C timeout for zero-length writes to accommodate the behaviour of a wider range of I2C devices. Fixes issue #8167. Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/rp2/machine_i2c.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/ports/rp2/machine_i2c.c b/ports/rp2/machine_i2c.c
index 56f012a5e..f785ad7de 100644
--- a/ports/rp2/machine_i2c.c
+++ b/ports/rp2/machine_i2c.c
@@ -127,12 +127,12 @@ STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si
if (flags & MP_MACHINE_I2C_FLAG_READ) {
ret = i2c_read_blocking(self->i2c_inst, addr, buf, len, nostop);
} else {
- if (len <= 2) {
- // Workaround issue with hardware I2C not accepting short writes.
+ if (len == 0) {
+ // Workaround issue with hardware I2C not accepting zero-length writes.
mp_machine_soft_i2c_obj_t soft_i2c = {
.base = { &mp_machine_soft_i2c_type },
.us_delay = 500000 / self->freq + 1,
- .us_timeout = 255,
+ .us_timeout = 50000,
.scl = self->scl,
.sda = self->sda,
};