Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[device]修改i2c读写函数返回类型为rt_ssize_t #7029

Merged
merged 4 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bsp/lpc54114-lite/drivers/drv_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static uint32_t get_i2c_freq(I2C_Type *base)

static rt_ssize_t master_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
{
rt_size_t ret = (0);
rt_ssize_t ret = (0);

rt_uint32_t index = 0;
struct lpc_i2c *lpc_i2c = RT_NULL;
Expand Down
26 changes: 10 additions & 16 deletions components/drivers/i2c/i2c_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ struct rt_i2c_bus_device *rt_i2c_bus_device_find(const char *bus_name)
return bus;
}

rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
rt_ssize_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
struct rt_i2c_msg msgs[],
rt_uint32_t num)
{
rt_size_t ret;
rt_ssize_t ret;

if (bus->ops->master_xfer)
{
Expand All @@ -78,7 +78,7 @@ rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
{
LOG_E("I2C bus operation not supported");

return 0;
return -RT_ERROR;
}
}

Expand All @@ -98,17 +98,17 @@ rt_err_t rt_i2c_control(struct rt_i2c_bus_device *bus,
{
LOG_E("I2C bus operation not supported");

return 0;
return -RT_ERROR;
}
}

rt_size_t rt_i2c_master_send(struct rt_i2c_bus_device *bus,
rt_ssize_t rt_i2c_master_send(struct rt_i2c_bus_device *bus,
rt_uint16_t addr,
rt_uint16_t flags,
const rt_uint8_t *buf,
rt_uint32_t count)
{
rt_size_t ret;
rt_ssize_t ret;
struct rt_i2c_msg msg;

msg.addr = addr;
Expand All @@ -118,16 +118,16 @@ rt_size_t rt_i2c_master_send(struct rt_i2c_bus_device *bus,

ret = rt_i2c_transfer(bus, &msg, 1);

return (ret > 0) ? count : ret;
return ret;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not back-compatible. It SHOULD return byte count value if sent an I2C message successfully.

}

rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
rt_ssize_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
rt_uint16_t addr,
rt_uint16_t flags,
rt_uint8_t *buf,
rt_uint32_t count)
{
rt_size_t ret;
rt_ssize_t ret;
struct rt_i2c_msg msg;
RT_ASSERT(bus != RT_NULL);

Expand All @@ -138,11 +138,5 @@ rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,

ret = rt_i2c_transfer(bus, &msg, 1);

return (ret > 0) ? count : ret;
return ret;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not back-compatible. It SHOULD return byte count value if received an I2C message successfully.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5.0.0不考虑向前兼容的问题,一些历史包袱需要在这个版本中逐步得到解决,返回值改为:如果返回值>=0 为成功传输的长度,<0为传输出现错误并返回错误码

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果返回值>=0 为成功传输的长度

所以這兩個 APIs 應該回傳成功传输 "byte count" 長度; 而不是"message number"。對嗎?
Caller 提交的是 send/receive byte length; 而成功回傳的是 message count。 不太合理。
這一改,又一堆 3rd contributed packages NG 了。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

噢噢 我理解你的意思了 这个地方有问题 返回应该是成功传输的长度,而不是message number。我落实下去来改。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Meco.

}

int rt_i2c_core_init(void)
{
return 0;
}
INIT_COMPONENT_EXPORT(rt_i2c_core_init);
6 changes: 3 additions & 3 deletions components/drivers/include/drivers/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@ struct rt_i2c_client
rt_err_t rt_i2c_bus_device_register(struct rt_i2c_bus_device *bus,
const char *bus_name);
struct rt_i2c_bus_device *rt_i2c_bus_device_find(const char *bus_name);
rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
rt_ssize_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
struct rt_i2c_msg msgs[],
rt_uint32_t num);
rt_err_t rt_i2c_control(struct rt_i2c_bus_device *bus,
rt_uint32_t cmd,
rt_uint32_t arg);
rt_size_t rt_i2c_master_send(struct rt_i2c_bus_device *bus,
rt_ssize_t rt_i2c_master_send(struct rt_i2c_bus_device *bus,
rt_uint16_t addr,
rt_uint16_t flags,
const rt_uint8_t *buf,
rt_uint32_t count);
rt_size_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
rt_ssize_t rt_i2c_master_recv(struct rt_i2c_bus_device *bus,
rt_uint16_t addr,
rt_uint16_t flags,
rt_uint8_t *buf,
Expand Down