i2c: make i2c_transfer() really generic

Make the i2c_transfer() to transact messages through the I2C bus.

It is useful for I2C storage devices, as now we can send one message
containing the destination byte/block address, then send the data
in another message. There is no need to construct one continuous
data buffer to send both address and data anymore.

The drivers and sample apps have been updated to utilize updated
API when appropriate. For i2c_dw, only master mode has been updated.
Slave mode will be updated once we can adequately test it.

Change-Id: I0a811d60567367817fcc8d15f5454e5c933722e2
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
Daniel Leung 2016-01-11 15:35:39 -08:00 committed by Anas Nashif
commit dff5f6a038
7 changed files with 376 additions and 261 deletions

View file

@ -102,8 +102,17 @@ static int _read_port_regs(struct device *dev, uint8_t reg,
uint16_t i2c_addr = config->i2c_slave_addr;
int ret;
uint8_t cmd[] = { reg };
struct i2c_msg msgs[2];
ret = i2c_transfer(i2c_master, cmd, 1, buf->byte, 2, i2c_addr, 0);
msgs[0].buf = cmd;
msgs[0].len = 1;
msgs[0].flags = I2C_MSG_WRITE;
msgs[1].buf = buf->byte;
msgs[1].len = 2;
msgs[1].flags = I2C_MSG_READ | I2C_MSG_RESTART;
ret = i2c_transfer(i2c_master, msgs, 2, i2c_addr);
if (ret) {
DBG("PCAL9535A[0x%X]: error reading register 0x%X (%d)\n",
i2c_addr, reg, ret);