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>
This commit is contained in:
parent
bef26d4e3f
commit
a707fe50b0
@ -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) {
|
if (flags & MP_MACHINE_I2C_FLAG_READ) {
|
||||||
ret = i2c_read_blocking(self->i2c_inst, addr, buf, len, nostop);
|
ret = i2c_read_blocking(self->i2c_inst, addr, buf, len, nostop);
|
||||||
} else {
|
} else {
|
||||||
if (len <= 2) {
|
if (len == 0) {
|
||||||
// Workaround issue with hardware I2C not accepting short writes.
|
// Workaround issue with hardware I2C not accepting zero-length writes.
|
||||||
mp_machine_soft_i2c_obj_t soft_i2c = {
|
mp_machine_soft_i2c_obj_t soft_i2c = {
|
||||||
.base = { &mp_machine_soft_i2c_type },
|
.base = { &mp_machine_soft_i2c_type },
|
||||||
.us_delay = 500000 / self->freq + 1,
|
.us_delay = 500000 / self->freq + 1,
|
||||||
.us_timeout = 255,
|
.us_timeout = 50000,
|
||||||
.scl = self->scl,
|
.scl = self->scl,
|
||||||
.sda = self->sda,
|
.sda = self->sda,
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user