Skip to content

Commit e6c9e9a

Browse files
kasjernashif
authored andcommitted
i2c: target: eeprom_target: Fix buffer write
When larger buffer index was introduced only function: eeprom_target_write_received() was updated to handle address-width = 16 This adds the same functionality when buffered API is used, enabled by CONFIG_I2C_TARGET_BUFFER_MODE. Signed-off-by: Jerzy Kasenberg <[email protected]>
1 parent 2894c76 commit e6c9e9a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/i2c/target/eeprom_target.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,19 @@ static void eeprom_target_buf_write_received(struct i2c_target_config *config,
179179
struct i2c_eeprom_target_data *data = CONTAINER_OF(config,
180180
struct i2c_eeprom_target_data,
181181
config);
182-
/* The first byte is offset */
183-
data->buffer_idx = *ptr;
184-
memcpy(&data->buffer[data->buffer_idx], ptr + 1, len - 1);
182+
/* The first byte(s) is offset */
183+
uint32_t idx_write_cnt = 0;
184+
185+
data->buffer_idx = 0;
186+
while (idx_write_cnt < (data->address_width >> 3)) {
187+
data->buffer_idx = (data->buffer_idx << 8) | *ptr++;
188+
len--;
189+
idx_write_cnt++;
190+
}
191+
192+
if (len > 0) {
193+
memcpy(&data->buffer[data->buffer_idx], ptr, len);
194+
}
185195
}
186196

187197
static int eeprom_target_buf_read_requested(struct i2c_target_config *config,

0 commit comments

Comments
 (0)