drivers: charger: i2c: replace use of i2c_burst_write
i2c_burst_write is not portable, as it is not supported by some drivers, replace its use with i2c_write. Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
This commit is contained in:
committed by
Henrik Brix Andersen
parent
f6558d5cdf
commit
e182730f7a
@@ -72,6 +72,7 @@ static int sbs_charger_emul_transfer_i2c(const struct emul *target, struct i2c_m
|
||||
/* Largely copied from emul_sbs_gauge.c */
|
||||
struct sbs_charger_emul_data *data;
|
||||
unsigned int val;
|
||||
uint16_t value;
|
||||
int reg;
|
||||
int rc;
|
||||
|
||||
@@ -79,6 +80,21 @@ static int sbs_charger_emul_transfer_i2c(const struct emul *target, struct i2c_m
|
||||
|
||||
i2c_dump_msgs_rw(target->dev, msgs, num_msgs, addr, false);
|
||||
switch (num_msgs) {
|
||||
case 1:
|
||||
if (msgs->flags & I2C_MSG_READ) {
|
||||
LOG_ERR("Unexpected single-message read");
|
||||
return -EIO;
|
||||
}
|
||||
if (msgs->len != 3) {
|
||||
LOG_ERR("Unexpected msg0 length %d", msgs->len);
|
||||
return -EIO;
|
||||
}
|
||||
reg = msgs->buf[0];
|
||||
|
||||
value = sys_get_le16(&(msgs->buf[1]));
|
||||
|
||||
rc = emul_sbs_charger_reg_write(target, reg, value);
|
||||
break;
|
||||
case 2:
|
||||
if (msgs->flags & I2C_MSG_READ) {
|
||||
LOG_ERR("Unexpected read");
|
||||
@@ -113,7 +129,7 @@ static int sbs_charger_emul_transfer_i2c(const struct emul *target, struct i2c_m
|
||||
if (msgs->len != 2) {
|
||||
LOG_ERR("Unexpected msg1 length %d", msgs->len);
|
||||
}
|
||||
uint16_t value = sys_get_le16(msgs->buf);
|
||||
value = sys_get_le16(msgs->buf);
|
||||
|
||||
rc = emul_sbs_charger_reg_write(target, reg, value);
|
||||
}
|
||||
|
||||
@@ -40,11 +40,12 @@ static int sbs_cmd_reg_read(const struct device *dev, uint8_t reg_addr, uint16_t
|
||||
static int sbs_cmd_reg_write(const struct device *dev, uint8_t reg_addr, uint16_t val)
|
||||
{
|
||||
const struct sbs_charger_config *config = dev->config;
|
||||
uint8_t buf[2];
|
||||
uint8_t buf[3];
|
||||
|
||||
sys_put_le16(val, buf);
|
||||
buf[0] = reg_addr;
|
||||
sys_put_le16(val, &buf[1]);
|
||||
|
||||
return i2c_burst_write_dt(&config->i2c, reg_addr, buf, sizeof(buf));
|
||||
return i2c_write_dt(&config->i2c, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
static int sbs_cmd_reg_update(const struct device *dev, uint8_t reg_addr, uint16_t mask,
|
||||
|
||||
Reference in New Issue
Block a user