summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorRiceChen <[email protected]>2021-04-20 00:26:28 +0800
committerRiceChen <[email protected]>2021-04-20 00:26:28 +0800
commit0b9e01ccedc21a44fc87a7524b8eb17debb53315 (patch)
tree7852d940e03b181ba90275c84eccbbf0abee4726 /components
parentd3be5e4fcf64a34b992b22272c98f44d9d0aa8c4 (diff)
add I2C bus control api
Diffstat (limited to 'components')
-rw-r--r--components/drivers/i2c/i2c_core.c21
-rw-r--r--components/drivers/i2c/i2c_dev.c10
-rw-r--r--components/drivers/include/drivers/i2c.h4
-rw-r--r--components/drivers/include/drivers/i2c_dev.h2
4 files changed, 37 insertions, 0 deletions
diff --git a/components/drivers/i2c/i2c_core.c b/components/drivers/i2c/i2c_core.c
index 87178e37d5..47ba76d2be 100644
--- a/components/drivers/i2c/i2c_core.c
+++ b/components/drivers/i2c/i2c_core.c
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2012-04-25 weety first version
+ * 2021-04-20 RiceChen added support for bus control api
*/
#include <rtdevice.h>
@@ -81,6 +82,26 @@ rt_size_t rt_i2c_transfer(struct rt_i2c_bus_device *bus,
}
}
+rt_err_t rt_i2c_control(struct rt_i2c_bus_device *bus,
+ rt_uint32_t cmd,
+ rt_uint32_t arg)
+{
+ rt_err_t ret;
+
+ if(bus->ops->i2c_bus_control)
+ {
+ ret = bus->ops->i2c_bus_control(bus, cmd, arg);
+
+ return ret;
+ }
+ else
+ {
+ LOG_E("I2C bus operation not supported");
+
+ return 0;
+ }
+}
+
rt_size_t rt_i2c_master_send(struct rt_i2c_bus_device *bus,
rt_uint16_t addr,
rt_uint16_t flags,
diff --git a/components/drivers/i2c/i2c_dev.c b/components/drivers/i2c/i2c_dev.c
index 4f567f8227..c30bb62a92 100644
--- a/components/drivers/i2c/i2c_dev.c
+++ b/components/drivers/i2c/i2c_dev.c
@@ -7,6 +7,7 @@
* Date Author Notes
* 2012-04-25 weety first version
* 2014-08-03 bernard fix some compiling warning
+ * 2021-04-20 RiceChen added support for bus clock control
*/
#include <rtdevice.h>
@@ -66,6 +67,7 @@ static rt_err_t i2c_bus_device_control(rt_device_t dev,
rt_err_t ret;
struct rt_i2c_priv_data *priv_data;
struct rt_i2c_bus_device *bus = (struct rt_i2c_bus_device *)dev->user_data;
+ rt_uint32_t bus_clock;
RT_ASSERT(bus != RT_NULL);
@@ -89,6 +91,14 @@ static rt_err_t i2c_bus_device_control(rt_device_t dev,
return -RT_EIO;
}
break;
+ case RT_I2C_DEV_CTRL_CLK:
+ bus_clock = *(rt_uint32_t *)args;
+ ret = rt_i2c_control(bus, cmd, bus_clock);
+ if (ret < 0)
+ {
+ return -RT_EIO;
+ }
+ break;
default:
break;
}
diff --git a/components/drivers/include/drivers/i2c.h b/components/drivers/include/drivers/i2c.h
index 50ce021d53..7bf99d26cc 100644
--- a/components/drivers/include/drivers/i2c.h
+++ b/components/drivers/include/drivers/i2c.h
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2012-04-25 weety first version
+ * 2021-04-20 RiceChen added support for bus control api
*/
#ifndef __I2C_H__
@@ -74,6 +75,9 @@ 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,
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_uint16_t addr,
rt_uint16_t flags,
diff --git a/components/drivers/include/drivers/i2c_dev.h b/components/drivers/include/drivers/i2c_dev.h
index 94f110c055..080ff26f87 100644
--- a/components/drivers/include/drivers/i2c_dev.h
+++ b/components/drivers/include/drivers/i2c_dev.h
@@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2012-04-25 weety first version
+ * 2021-04-20 RiceChen added bus clock command
*/
#ifndef __I2C_DEV_H__
@@ -21,6 +22,7 @@ extern "C" {
#define RT_I2C_DEV_CTRL_ADDR 0x21
#define RT_I2C_DEV_CTRL_TIMEOUT 0x22
#define RT_I2C_DEV_CTRL_RW 0x23
+#define RT_I2C_DEV_CTRL_CLK 0x24
struct rt_i2c_priv_data
{