Skip to content

Commit

Permalink
i2c: target: eeprom_target: Fix buffer write
Browse files Browse the repository at this point in the history
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]>
(cherry picked from commit e6c9e9a)
  • Loading branch information
kasjer authored and mmahadevan108 committed Dec 6, 2024
1 parent 2c5fb2d commit 98d9f3e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions drivers/i2c/target/eeprom_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,19 @@ static void eeprom_target_buf_write_received(struct i2c_target_config *config,
struct i2c_eeprom_target_data *data = CONTAINER_OF(config,
struct i2c_eeprom_target_data,
config);
/* The first byte is offset */
data->buffer_idx = *ptr;
memcpy(&data->buffer[data->buffer_idx], ptr + 1, len - 1);
/* The first byte(s) is offset */
uint32_t idx_write_cnt = 0;

data->buffer_idx = 0;
while (idx_write_cnt < (data->address_width >> 3)) {
data->buffer_idx = (data->buffer_idx << 8) | *ptr++;
len--;
idx_write_cnt++;
}

if (len > 0) {
memcpy(&data->buffer[data->buffer_idx], ptr, len);
}
}

static int eeprom_target_buf_read_requested(struct i2c_target_config *config,
Expand Down

0 comments on commit 98d9f3e

Please sign in to comment.