@@ -101,22 +101,29 @@ void i2c_stm32_event(const struct device *dev)
101101 LL_I2C_ClearFlag_STOP (i2c );
102102 LL_I2C_DisableReloadMode (i2c );
103103 i2c_stm32_master_mode_end (dev );
104+
105+ if (i2c_rtio_complete (ctx , ret )) {
106+ i2c_stm32_start (dev );
107+ return ;
108+ }
104109 }
105110
106- /* TODO handle the reload separately from complete */
107- /* Transfer Complete or Transfer Complete Reload */
108111 if (LL_I2C_IsActiveFlag_TC (i2c ) ||
109112 LL_I2C_IsActiveFlag_TCR (i2c )) {
113+
110114 /* Issue stop condition if necessary */
111- /* TODO look at current sqe flags */
112115 if ((data -> xfer_flags & I2C_MSG_STOP ) != 0 ) {
113- LL_I2C_GenerateStopCondition (i2c );
116+ if (data -> xfer_len == 0 ) {
117+ LL_I2C_GenerateStopCondition (i2c );
118+ } else {
119+ LL_I2C_SetTransferSize (i2c , MIN (data -> xfer_len , UINT8_MAX ));
120+ }
114121 } else {
115122 i2c_stm32_disable_transfer_interrupts (dev );
116- }
117123
118- if ((data -> xfer_len == 0 ) && i2c_rtio_complete (ctx , ret )) {
119- i2c_stm32_start (dev );
124+ if ((data -> xfer_len == 0 ) && i2c_rtio_complete (ctx , ret )) {
125+ i2c_stm32_start (dev );
126+ }
120127 }
121128 }
122129}
@@ -162,12 +169,6 @@ int i2c_stm32_msg_start(const struct device *dev, uint8_t flags,
162169 transfer = LL_I2C_REQUEST_WRITE ;
163170 }
164171
165- /* TODO deal with larger than 255 byte transfers correctly */
166- if (buf_len > UINT8_MAX ) {
167- /* TODO LL_I2C_EnableReloadMode(i2c); */
168- return - EINVAL ;
169- }
170-
171172 if ((I2C_MSG_ADDR_10_BITS & flags ) != 0 ) {
172173 LL_I2C_SetMasterAddressingMode (i2c ,
173174 LL_I2C_ADDRESSING_MODE_10BIT );
@@ -178,9 +179,15 @@ int i2c_stm32_msg_start(const struct device *dev, uint8_t flags,
178179 LL_I2C_SetSlaveAddr (i2c , (uint32_t ) i2c_addr << 1 );
179180 }
180181
182+ if (buf_len > UINT8_MAX ) {
183+ LL_I2C_EnableReloadMode (i2c );
184+ } else {
185+ LL_I2C_DisableReloadMode (i2c );
186+ }
187+
181188 LL_I2C_DisableAutoEndMode (i2c );
182189 LL_I2C_SetTransferRequest (i2c , transfer );
183- LL_I2C_SetTransferSize (i2c , buf_len );
190+ LL_I2C_SetTransferSize (i2c , MIN ( buf_len , UINT8_MAX ) );
184191
185192 LL_I2C_Enable (i2c );
186193
0 commit comments