Commit c7cbe917 authored by Francois Ramu's avatar Francois Ramu Committed by Mahesh Mahadevan
Browse files

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: default avatarFrancois Ramu <francois.ramu@st.com>
parent fe56ce5a
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -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);
		if (slave_cb->read_processed(slave_cfg, &val) < 0) {
			LOG_ERR("Error continuing reading");
		} else {
			LL_I2C_TransmitData8(i2c, val);
		}
		return;
	}

@@ -293,15 +296,21 @@ 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);
			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);
			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);
	}