Skip to content

Commit 54c6e7d

Browse files
author
xieyangrun
committed
[dirver/i2c] i2c driver support bus lock, STOP control
1 parent d92fbba commit 54c6e7d

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

components/drivers/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ if RT_USING_I2C
9797
default y
9898

9999
if RT_USING_I2C_BITOPS
100-
config RT_I2C_BITOPS_DEBUG
100+
config RT_I2C_BITOPS_DEBUG
101101
bool "Use simulate I2C debug message"
102102
default n
103103
endif

components/drivers/i2c/i2c-bit-ops.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,6 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
375375
rt_int32_t i, ret;
376376
rt_uint16_t ignore_nack;
377377

378-
LOG_D("send start condition");
379-
i2c_start(ops);
380378
for (i = 0; i < num; i++)
381379
{
382380
msg = &msgs[i];
@@ -387,6 +385,11 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
387385
{
388386
i2c_restart(ops);
389387
}
388+
else
389+
{
390+
LOG_D("send start condition");
391+
i2c_start(ops);
392+
}
390393
ret = i2c_bit_send_address(bus, msg);
391394
if ((ret != RT_EOK) && !ignore_nack)
392395
{
@@ -423,8 +426,11 @@ static rt_size_t i2c_bit_xfer(struct rt_i2c_bus_device *bus,
423426
ret = i;
424427

425428
out:
426-
LOG_D("send stop condition");
427-
i2c_stop(ops);
429+
if (!(msg->flags & RT_I2C_NO_STOP))
430+
{
431+
LOG_D("send stop condition");
432+
i2c_stop(ops);
433+
}
428434

429435
return ret;
430436
}

components/drivers/include/drivers/i2c.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ extern "C" {
2323
#define RT_I2C_NO_START (1u << 4)
2424
#define RT_I2C_IGNORE_NACK (1u << 5)
2525
#define RT_I2C_NO_READ_ACK (1u << 6) /* when I2C reading, we do not ACK */
26+
#define RT_I2C_NO_STOP (1u << 7)
2627

2728
struct rt_i2c_msg
2829
{
@@ -83,6 +84,17 @@ rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
8384
rt_uint16_t flags,
8485
rt_uint8_t *buf,
8586
rt_uint32_t count);
87+
88+
rt_inline rt_err_t rt_i2c_bus_lock(struct rt_i2c_bus_device *bus, rt_tick_t timeout)
89+
{
90+
return rt_mutex_take(&bus->lock, timeout);
91+
}
92+
93+
rt_inline rt_err_t rt_i2c_bus_unlock(struct rt_i2c_bus_device *bus)
94+
{
95+
return rt_mutex_release(&bus->lock);
96+
}
97+
8698
int rt_i2c_core_init(void);
8799

88100
#ifdef __cplusplus

0 commit comments

Comments
 (0)