From c7cbe9176074bdd967fb36953c6936817187ee7e Mon Sep 17 00:00:00 2001 From: Francois Ramu Date: Wed, 6 Nov 2024 13:34:59 +0100 Subject: [PATCH] drivers: i2c: stm32 I2C V2 handles i2c_target processed_cb return code Check the return code of the i2c_target_read/write callback function is 0 before continuing the transmit/receive operation on I2C target When Transmitting: 0 if data has been provided, then continue When address matches: 0 if the write is accepted or if more data can be requested depending on the transfer direction. Signed-off-by: Francois Ramu --- drivers/i2c/i2c_ll_stm32_v2.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/i2c_ll_stm32_v2.c b/drivers/i2c/i2c_ll_stm32_v2.c index 2b96a89725c..8e97fffbf09 100644 --- a/drivers/i2c/i2c_ll_stm32_v2.c +++ b/drivers/i2c/i2c_ll_stm32_v2.c @@ -254,8 +254,11 @@ static void stm32_i2c_slave_event(const struct device *dev) if (LL_I2C_IsActiveFlag_TXIS(i2c)) { uint8_t val; - slave_cb->read_processed(slave_cfg, &val); - LL_I2C_TransmitData8(i2c, val); + if (slave_cb->read_processed(slave_cfg, &val) < 0) { + LOG_ERR("Error continuing reading"); + } else { + LL_I2C_TransmitData8(i2c, val); + } return; } @@ -293,14 +296,20 @@ static void stm32_i2c_slave_event(const struct device *dev) dir = LL_I2C_GetTransferDirection(i2c); if (dir == LL_I2C_DIRECTION_WRITE) { - slave_cb->write_requested(slave_cfg); - LL_I2C_EnableIT_RX(i2c); + if (slave_cb->write_requested(slave_cfg) < 0) { + LOG_ERR("Error initiating writing"); + } else { + LL_I2C_EnableIT_RX(i2c); + } } else { uint8_t val; - slave_cb->read_requested(slave_cfg, &val); - LL_I2C_TransmitData8(i2c, val); - LL_I2C_EnableIT_TX(i2c); + if (slave_cb->read_requested(slave_cfg, &val) < 0) { + LOG_ERR("Error initiating reading"); + } else { + LL_I2C_TransmitData8(i2c, val); + LL_I2C_EnableIT_TX(i2c); + } } stm32_i2c_enable_transfer_interrupts(dev);