From 37a61a7088c051e0d7359b1f70baf59deafd8ad2 Mon Sep 17 00:00:00 2001 From: Peter Harper Date: Thu, 11 May 2023 15:28:03 +0100 Subject: [PATCH] Add last_abort_reason Fixes #1049 --- src/rp2_common/hardware_i2c/i2c.c | 4 +++- src/rp2_common/hardware_i2c/include/hardware/i2c.h | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/hardware_i2c/i2c.c b/src/rp2_common/hardware_i2c/i2c.c index c5cdbec3a..d1abac537 100644 --- a/src/rp2_common/hardware_i2c/i2c.c +++ b/src/rp2_common/hardware_i2c/i2c.c @@ -235,6 +235,7 @@ static int i2c_write_blocking_internal(i2c_inst_t *i2c, uint8_t addr, const uint // nostop means we are now at the end of a *message* but not the end of a *transfer* i2c->restart_on_next = nostop; + i2c->last_abort_reason = abort_reason; return rval; } @@ -268,7 +269,7 @@ static int i2c_read_blocking_internal(i2c_inst_t *i2c, uint8_t addr, uint8_t *ds bool abort = false; bool timeout = false; - uint32_t abort_reason; + uint32_t abort_reason = 0; int byte_ctr; int ilen = (int)len; for (byte_ctr = 0; byte_ctr < ilen; ++byte_ctr) { @@ -315,6 +316,7 @@ static int i2c_read_blocking_internal(i2c_inst_t *i2c, uint8_t addr, uint8_t *ds } i2c->restart_on_next = nostop; + i2c->last_abort_reason = abort_reason; return rval; } diff --git a/src/rp2_common/hardware_i2c/include/hardware/i2c.h b/src/rp2_common/hardware_i2c/include/hardware/i2c.h index 33454f02a..58caa8292 100644 --- a/src/rp2_common/hardware_i2c/include/hardware/i2c.h +++ b/src/rp2_common/hardware_i2c/include/hardware/i2c.h @@ -135,6 +135,7 @@ void i2c_set_slave_mode(i2c_inst_t *i2c, bool slave, uint8_t addr); struct i2c_inst { i2c_hw_t *hw; bool restart_on_next; + uint32_t last_abort_reason; }; /*! \brief Convert I2C instance to hardware instance number