From 7b0a42374e1ae6a4ab3f756090c6f3b66e82acb5 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 20 Jan 2022 16:43:55 +1100 Subject: [PATCH] rp2/machine_i2c: Provide more specific error codes from I2C transfer. Signed-off-by: Damien George --- ports/rp2/machine_i2c.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ports/rp2/machine_i2c.c b/ports/rp2/machine_i2c.c index 3b895ba4d4..56f012a5e8 100644 --- a/ports/rp2/machine_i2c.c +++ b/ports/rp2/machine_i2c.c @@ -145,11 +145,20 @@ STATIC int machine_i2c_transfer_single(mp_obj_base_t *self_in, uint16_t addr, si ret = mp_machine_soft_i2c_transfer(&soft_i2c.base, addr, 1, &bufs, flags); gpio_set_function(self->scl, GPIO_FUNC_I2C); gpio_set_function(self->sda, GPIO_FUNC_I2C); + return ret; } else { ret = i2c_write_blocking(self->i2c_inst, addr, buf, len, nostop); } } - return (ret < 0) ? -MP_EIO : ret; + if (ret < 0) { + if (ret == PICO_ERROR_TIMEOUT) { + return -MP_ETIMEDOUT; + } else { + return -MP_EIO; + } + } else { + return ret; + } } STATIC const mp_machine_i2c_p_t machine_i2c_p = {