[i2c] fix the i2c device return error code (#7035)

* [i2c] fix the i2c device return error code
This commit is contained in:
Man, Jianting (Meco) 2023-03-10 23:44:03 -05:00 committed by GitHub
parent 50e1f6327d
commit 0275b23638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 13 deletions

View File

@ -84,12 +84,12 @@ static rt_ssize_t master_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg m
static rt_ssize_t slave_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num) static rt_ssize_t slave_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
{ {
return 0; return -RT_ENOSYS;
} }
static rt_err_t i2c_bus_control(struct rt_i2c_bus_device *bus, rt_uint32_t cmd, rt_uint32_t arg) static rt_err_t i2c_bus_control(struct rt_i2c_bus_device *bus, rt_uint32_t cmd, rt_uint32_t arg)
{ {
return RT_EOK; return -RT_EINVAL;
} }
static const struct rt_i2c_bus_device_ops ops = static const struct rt_i2c_bus_device_ops ops =

View File

@ -56,6 +56,7 @@ rt_ssize_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
rt_uint32_t num) rt_uint32_t num)
{ {
rt_ssize_t ret; rt_ssize_t ret;
rt_err_t err;
if (bus->ops->master_xfer) if (bus->ops->master_xfer)
{ {
@ -67,18 +68,23 @@ rt_ssize_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
msgs[ret].addr, msgs[ret].len); msgs[ret].addr, msgs[ret].len);
} }
#endif #endif
err = rt_mutex_take(&bus->lock, RT_WAITING_FOREVER);
rt_mutex_take(&bus->lock, RT_WAITING_FOREVER); if (err != RT_EOK)
{
return (rt_ssize_t)err;
}
ret = bus->ops->master_xfer(bus, msgs, num); ret = bus->ops->master_xfer(bus, msgs, num);
rt_mutex_release(&bus->lock); err = rt_mutex_release(&bus->lock);
if (err != RT_EOK)
{
return (rt_ssize_t)err;
}
return ret; return ret;
} }
else else
{ {
LOG_E("I2C bus operation not supported"); LOG_E("I2C bus operation not supported");
return -RT_EINVAL;
return -RT_ERROR;
} }
} }
@ -91,14 +97,12 @@ rt_err_t rt_i2c_control(struct rt_i2c_bus_device *bus,
if(bus->ops->i2c_bus_control) if(bus->ops->i2c_bus_control)
{ {
ret = bus->ops->i2c_bus_control(bus, cmd, arg); ret = bus->ops->i2c_bus_control(bus, cmd, arg);
return ret; return ret;
} }
else else
{ {
LOG_E("I2C bus operation not supported"); LOG_E("I2C bus operation not supported");
return -RT_EINVAL;
return -RT_ERROR;
} }
} }

View File

@ -97,8 +97,6 @@ rt_inline rt_err_t rt_i2c_bus_unlock(struct rt_i2c_bus_device *bus)
return rt_mutex_release(&bus->lock); return rt_mutex_release(&bus->lock);
} }
int rt_i2c_core_init(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif