i2c: target: eeprom_target: add address_width parameter
Add a parameter to allow the configuration of the number of address bytes used by the I2C master. This allows the driver to expose larger buffer sizes. Tested with standard linux at24 driver. Signed-off-by: Bram Vlerick <bram.vlerick@openpixelsystems.org>
This commit is contained in:
parent
6e2bf1bf10
commit
935e8c4b13
2 changed files with 23 additions and 7 deletions
|
@ -22,7 +22,8 @@ struct i2c_eeprom_target_data {
|
||||||
uint32_t buffer_size;
|
uint32_t buffer_size;
|
||||||
uint8_t *buffer;
|
uint8_t *buffer;
|
||||||
uint32_t buffer_idx;
|
uint32_t buffer_idx;
|
||||||
bool first_write;
|
uint32_t idx_write_cnt;
|
||||||
|
uint8_t address_width;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct i2c_eeprom_target_config {
|
struct i2c_eeprom_target_config {
|
||||||
|
@ -86,7 +87,7 @@ static int eeprom_target_write_requested(struct i2c_target_config *config)
|
||||||
|
|
||||||
LOG_DBG("eeprom: write req");
|
LOG_DBG("eeprom: write req");
|
||||||
|
|
||||||
data->first_write = true;
|
data->idx_write_cnt = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -121,9 +122,13 @@ static int eeprom_target_write_received(struct i2c_target_config *config,
|
||||||
* I2C controller support
|
* I2C controller support
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (data->first_write) {
|
if (data->idx_write_cnt < (data->address_width >> 3)) {
|
||||||
data->buffer_idx = val;
|
if (data->idx_write_cnt == 0) {
|
||||||
data->first_write = false;
|
data->buffer_idx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
data->buffer_idx = val | (data->buffer_idx << 8);
|
||||||
|
data->idx_write_cnt++;
|
||||||
} else {
|
} else {
|
||||||
data->buffer[data->buffer_idx++] = val;
|
data->buffer[data->buffer_idx++] = val;
|
||||||
}
|
}
|
||||||
|
@ -162,7 +167,7 @@ static int eeprom_target_stop(struct i2c_target_config *config)
|
||||||
|
|
||||||
LOG_DBG("eeprom: stop");
|
LOG_DBG("eeprom: stop");
|
||||||
|
|
||||||
data->first_write = true;
|
data->idx_write_cnt = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -246,7 +251,10 @@ static int i2c_eeprom_target_init(const struct device *dev)
|
||||||
|
|
||||||
#define I2C_EEPROM_INIT(inst) \
|
#define I2C_EEPROM_INIT(inst) \
|
||||||
static struct i2c_eeprom_target_data \
|
static struct i2c_eeprom_target_data \
|
||||||
i2c_eeprom_target_##inst##_dev_data; \
|
i2c_eeprom_target_##inst##_dev_data = { \
|
||||||
|
.address_width = DT_INST_PROP_OR(inst, \
|
||||||
|
address_width, 8), \
|
||||||
|
}; \
|
||||||
\
|
\
|
||||||
static uint8_t \
|
static uint8_t \
|
||||||
i2c_eeprom_target_##inst##_buffer[(DT_INST_PROP(inst, size))]; \
|
i2c_eeprom_target_##inst##_buffer[(DT_INST_PROP(inst, size))]; \
|
||||||
|
|
|
@ -5,3 +5,11 @@ description: Zephyr I2C target EEPROM
|
||||||
compatible: "zephyr,i2c-target-eeprom"
|
compatible: "zephyr,i2c-target-eeprom"
|
||||||
|
|
||||||
include: ["eeprom-base.yaml", i2c-device.yaml]
|
include: ["eeprom-base.yaml", i2c-device.yaml]
|
||||||
|
|
||||||
|
properties:
|
||||||
|
address-width:
|
||||||
|
type: int
|
||||||
|
enum: [8, 16]
|
||||||
|
description: |
|
||||||
|
Number of address bits used to address the EEPROM. If not specified
|
||||||
|
the EEPROM is assumed to have a 8-bit address.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue