summaryrefslogtreecommitdiff
path: root/bsp
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2019-11-12 22:52:36 +0800
committerGitHub <[email protected]>2019-11-12 22:52:36 +0800
commit939e2486c3e4f98be5a1ce0ec474e9b3e7cd9663 (patch)
treebdc40e0baa92b836093aa05abaff00b2f88f22ef /bsp
parentda7751c044491b85e2c3f9eebdaa1c4e7e5d153b (diff)
parenta24b8964431d53904a4ca1c36cac1b73eb2169e9 (diff)
Merge pull request #3195 from liweihao-cn/master
修改读写逻辑,解决i2c驱动无法读取的问题
Diffstat (limited to 'bsp')
-rw-r--r--bsp/lpc54114-lite/drivers/drv_i2c.c43
1 files changed, 23 insertions, 20 deletions
diff --git a/bsp/lpc54114-lite/drivers/drv_i2c.c b/bsp/lpc54114-lite/drivers/drv_i2c.c
index 0caee3453c..81be945067 100644
--- a/bsp/lpc54114-lite/drivers/drv_i2c.c
+++ b/bsp/lpc54114-lite/drivers/drv_i2c.c
@@ -40,7 +40,8 @@ static rt_size_t master_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg ms
rt_uint32_t index = 0;
struct lpc_i2c *lpc_i2c = RT_NULL;
struct rt_i2c_msg *msg = RT_NULL;
- i2c_master_transfer_t xfer = {0};
+ i2c_direction_t direction;
+ status_t result = kStatus_Success;
RT_ASSERT(bus != RT_NULL);
@@ -49,33 +50,35 @@ static rt_size_t master_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg ms
for(index = 0; index < num; index++)
{
msg = &msgs[index];
-
- xfer.slaveAddress = msg->addr;
- xfer.flags = kI2C_TransferDefaultFlag;
- xfer.subaddress = 0;
- xfer.subaddressSize = 0;
- xfer.data = msg->buf;
- xfer.dataSize = msg->len;
+ direction = ((msg->flags & RT_I2C_RD) ? kI2C_Read : kI2C_Write);
- if (msg->flags & RT_I2C_RD)
+ if (!(msg->flags & RT_I2C_NO_START))
{
- xfer.direction = kI2C_Read;
+ /* Start condition and slave address. */
+ result = I2C_MasterStart(lpc_i2c->base, msg->addr, direction);
}
- else
- {
- xfer.direction = kI2C_Write;
- }
-
- if(I2C_MasterTransferBlocking(lpc_i2c->base, &xfer) != kStatus_Success)
+
+ if (result == kStatus_Success)
{
- rt_kprintf("i2c bus write failed, i2c bus stop!\n");
- goto exit;
+ if (direction == kI2C_Write)
+ {
+ /* Transmit data. */
+ result = I2C_MasterWriteBlocking(lpc_i2c->base, msg->buf, msg->len, kI2C_TransferDefaultFlag);
+ }
+ else
+ {
+ /* Receive Data. */
+ result = I2C_MasterReadBlocking(lpc_i2c->base, msg->buf, msg->len, kI2C_TransferDefaultFlag);
+ }
}
}
- ret = index;
+ if (result == kStatus_Success)
+ {
+ ret = index;
+ }
-exit:
+ I2C_MasterStop(lpc_i2c->base);
return ret;
}