sensors: tmp112: Fix breakage on stm32f4 platform

It makes no sense to set the restart condition flag on a first message
and some i2c bus drivers (like the stm32 v1 driver) actually reject
them by returning an error from i2c_transfer().

This patch fixes that by using i2c_burst_read() in tmp112_reg_read()
instead. For consistency, tmp112_reg_write() is also changed to use
i2c_burst_write().

Signed-off-by: Mark Vels <mark.vels@team-embedded.nl>
This commit is contained in:
Mark Vels 2018-01-07 15:40:45 +01:00 committed by Anas Nashif
commit 6324d11535

View file

@ -37,20 +37,8 @@ struct tmp112_data {
static int tmp112_reg_read(struct tmp112_data *drv_data,
u8_t reg, u16_t *val)
{
struct i2c_msg msgs[2] = {
{
.buf = &reg,
.len = 1,
.flags = I2C_MSG_WRITE | I2C_MSG_RESTART,
},
{
.buf = (u8_t *)val,
.len = 2,
.flags = I2C_MSG_READ | I2C_MSG_STOP,
},
};
if (i2c_transfer(drv_data->i2c, msgs, 2, TMP112_I2C_ADDRESS) < 0) {
if (i2c_burst_read(drv_data->i2c, TMP112_I2C_ADDRESS,
reg, (u8_t *) val, 2) < 0) {
return -EIO;
}
@ -62,10 +50,10 @@ static int tmp112_reg_read(struct tmp112_data *drv_data,
static int tmp112_reg_write(struct tmp112_data *drv_data,
u8_t reg, u16_t val)
{
u8_t tx_buf[3] = {reg, val >> 8, val & 0xFF};
u16_t val_be = sys_cpu_to_be16(val);
return i2c_write(drv_data->i2c, tx_buf, sizeof(tx_buf),
TMP112_I2C_ADDRESS);
return i2c_burst_write(drv_data->i2c, TMP112_I2C_ADDRESS,
reg, (u8_t *)&val_be, 2);
}
static int tmp112_reg_update(struct tmp112_data *drv_data, u8_t reg,