Skip to content

Commit c7cbe91

Browse files
FRASTMmmahadevan108
authored andcommitted
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 <[email protected]>
1 parent fe56ce5 commit c7cbe91

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

drivers/i2c/i2c_ll_stm32_v2.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,11 @@ static void stm32_i2c_slave_event(const struct device *dev)
254254
if (LL_I2C_IsActiveFlag_TXIS(i2c)) {
255255
uint8_t val;
256256

257-
slave_cb->read_processed(slave_cfg, &val);
258-
LL_I2C_TransmitData8(i2c, val);
257+
if (slave_cb->read_processed(slave_cfg, &val) < 0) {
258+
LOG_ERR("Error continuing reading");
259+
} else {
260+
LL_I2C_TransmitData8(i2c, val);
261+
}
259262
return;
260263
}
261264

@@ -293,14 +296,20 @@ static void stm32_i2c_slave_event(const struct device *dev)
293296

294297
dir = LL_I2C_GetTransferDirection(i2c);
295298
if (dir == LL_I2C_DIRECTION_WRITE) {
296-
slave_cb->write_requested(slave_cfg);
297-
LL_I2C_EnableIT_RX(i2c);
299+
if (slave_cb->write_requested(slave_cfg) < 0) {
300+
LOG_ERR("Error initiating writing");
301+
} else {
302+
LL_I2C_EnableIT_RX(i2c);
303+
}
298304
} else {
299305
uint8_t val;
300306

301-
slave_cb->read_requested(slave_cfg, &val);
302-
LL_I2C_TransmitData8(i2c, val);
303-
LL_I2C_EnableIT_TX(i2c);
307+
if (slave_cb->read_requested(slave_cfg, &val) < 0) {
308+
LOG_ERR("Error initiating reading");
309+
} else {
310+
LL_I2C_TransmitData8(i2c, val);
311+
LL_I2C_EnableIT_TX(i2c);
312+
}
304313
}
305314

306315
stm32_i2c_enable_transfer_interrupts(dev);

0 commit comments

Comments
 (0)