Skip to content

Commit 61f4ba2

Browse files
committed
drivers: i2c: add an option to skip auto-sending stop on last message
The I2C transfer API has been recently changed to always automatically set a STOP on the last message, which was well documented but implemented only by few drivers. Unfortunately, while documented, this is a change in the current behavior and it turns out that some applications depended on it for some complex operations. Add a flag to temporarily restore the old behavior, buying time to fix the application code depending on this. Signed-off-by: Fabio Baltieri <[email protected]>
1 parent 9335644 commit 61f4ba2

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

drivers/i2c/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ config I2C_CALLBACK
5454
help
5555
API and implementations of i2c_transfer_cb.
5656

57+
config I2C_ALLOW_NO_STOP_TRANSACTIONS
58+
bool "Allows I2C transfers with no STOP on the last transaction [DEPRECATED]"
59+
depends on !I2C_NRFX_TWI
60+
depends on !I2C_NRFX_TWIM
61+
depends on !I2C_STM32
62+
depends on !I2C_GD32
63+
depends on !I2C_ESP32
64+
depends on !I2C_DW
65+
select DEPRECATED
66+
help
67+
Allow I2C transactions with no STOP on the last message. This is
68+
unsupported and can leave the bus in an unexpected state. The option
69+
will be removed in Zephyr 4.1.
70+
5771
config I2C_RTIO
5872
bool "I2C RTIO API"
5973
select EXPERIMENTAL

include/zephyr/drivers/i2c.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,9 @@ static inline int z_impl_i2c_transfer(const struct device *dev,
801801
return 0;
802802
}
803803

804-
msgs[num_msgs - 1].flags |= I2C_MSG_STOP;
804+
if (!IS_ENABLED(CONFIG_I2C_ALLOW_NO_STOP_TRANSACTIONS)) {
805+
msgs[num_msgs - 1].flags |= I2C_MSG_STOP;
806+
}
805807

806808
int res = api->transfer(dev, msgs, num_msgs, addr);
807809

@@ -857,7 +859,9 @@ static inline int i2c_transfer_cb(const struct device *dev,
857859
return 0;
858860
}
859861

860-
msgs[num_msgs - 1].flags |= I2C_MSG_STOP;
862+
if (!IS_ENABLED(CONFIG_I2C_ALLOW_NO_STOP_TRANSACTIONS)) {
863+
msgs[num_msgs - 1].flags |= I2C_MSG_STOP;
864+
}
861865

862866
return api->transfer_cb(dev, msgs, num_msgs, addr, cb, userdata);
863867
}

0 commit comments

Comments
 (0)