@@ -79,11 +79,6 @@ static int i2c_stm32_transfer(struct device *dev, struct i2c_msg *msg,
7979 current -> flags |= I2C_MSG_RESTART ;
8080
8181 for (u8_t i = 1 ; i <= num_msgs ; i ++ ) {
82- /* Maximum length of a single message is 255 Bytes */
83- if (current -> len > 255 ) {
84- ret = - EINVAL ;
85- break ;
86- }
8782
8883 if (i < num_msgs ) {
8984 next = current + 1 ;
@@ -131,22 +126,44 @@ static int i2c_stm32_transfer(struct device *dev, struct i2c_msg *msg,
131126 next = current + 1 ;
132127 next_msg_flags = & (next -> flags );
133128 }
129+ while (current -> len > 0 ) {
130+ u32_t temp_len = current -> len ;
131+ u8_t tmp_msg_flags = current -> flags & ~I2C_MSG_RESTART ;
132+ u8_t tmp_next_msg_flags = next_msg_flags ?
133+ * next_msg_flags : 0 ;
134+
135+ if (current -> len > 255 ) {
136+ current -> len = 255 ;
137+ current -> flags &= ~I2C_MSG_STOP ;
138+ if (next_msg_flags ) {
139+ * next_msg_flags = current -> flags &
140+ ~I2C_MSG_RESTART ;
141+ }
142+ }
143+ if ((current -> flags & I2C_MSG_RW_MASK ) ==
144+ I2C_MSG_WRITE ) {
145+ ret = stm32_i2c_msg_write (dev , current ,
146+ next_msg_flags ,
147+ slave );
148+ } else {
149+ ret = stm32_i2c_msg_read (dev , current ,
150+ next_msg_flags , slave );
151+ }
134152
135- if ((current -> flags & I2C_MSG_RW_MASK ) == I2C_MSG_WRITE ) {
136- ret = stm32_i2c_msg_write (dev , current , next_msg_flags ,
137- slave );
138- } else {
139- ret = stm32_i2c_msg_read (dev , current , next_msg_flags ,
140- slave );
141- }
142-
143- if (ret < 0 ) {
144- break ;
153+ if (ret < 0 ) {
154+ goto exit ;
155+ }
156+ if (next_msg_flags ) {
157+ * next_msg_flags = tmp_next_msg_flags ;
158+ }
159+ current -> buf += current -> len ;
160+ current -> flags = tmp_msg_flags ;
161+ current -> len = temp_len - current -> len ;
145162 }
146-
147163 current ++ ;
148164 num_msgs -- ;
149165 }
166+ exit :
150167#if defined(CONFIG_I2C_STM32_V1 )
151168 LL_I2C_Disable (i2c );
152169#endif
0 commit comments