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>
pull/4213/head
Damien George 2022-01-21 14:52:03 +11:00
rodzic bef26d4e3f
commit a707fe50b0
1 zmienionych plików z 3 dodań i 3 usunięć

Wyświetl plik

@ -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,
};