summaryrefslogtreecommitdiff
path: root/components/drivers/i2c
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2018-06-10 17:59:17 +0800
committerBernard Xiong <[email protected]>2018-06-10 17:59:17 +0800
commit884fb70fe9973eaf01a7df04941cbcb0475ba8d5 (patch)
tree7c8e3f42629e46b3d7ecb0c8507f67934d9fae47 /components/drivers/i2c
parentbca65f30a90857287dc1371ddbc8d5f165691c7f (diff)
[Kernel] Add device ops feature.
Diffstat (limited to 'components/drivers/i2c')
-rw-r--r--components/drivers/i2c/fm24clxx.c17
-rw-r--r--components/drivers/i2c/i2c_dev.c16
2 files changed, 33 insertions, 0 deletions
diff --git a/components/drivers/i2c/fm24clxx.c b/components/drivers/i2c/fm24clxx.c
index c37a62973a..bb77d707bf 100644
--- a/components/drivers/i2c/fm24clxx.c
+++ b/components/drivers/i2c/fm24clxx.c
@@ -132,6 +132,18 @@ static rt_size_t fm24clxx_write(rt_device_t dev, rt_off_t pos, const void *buffe
return (ret == 2) ? size : 0;
}
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device fm24clxx_ops =
+{
+ fm24clxx_init,
+ fm24clxx_open,
+ fm24clxx_close,
+ fm24clxx_read,
+ fm24clxx_write,
+ fm24clxx_control
+};
+#endif
+
rt_err_t fm24clxx_register(const char *fm_device_name, const char *i2c_bus, void *user_data)
{
static struct fm24clxx_device fm24clxx_drv;
@@ -145,12 +157,17 @@ rt_err_t fm24clxx_register(const char *fm_device_name, const char *i2c_bus, void
fm24clxx_drv.bus = bus;
fm24clxx_drv.parent.type = RT_Device_Class_Block;
+#ifdef RT_USING_DEVICE_OPS
+ fm24clxx_drv.parent.ops = &fm24clxx_ops;
+#else
fm24clxx_drv.parent.init = fm24clxx_init;
fm24clxx_drv.parent.open = fm24clxx_open;
fm24clxx_drv.parent.close = fm24clxx_close;
fm24clxx_drv.parent.read = fm24clxx_read;
fm24clxx_drv.parent.write = fm24clxx_write;
fm24clxx_drv.parent.control = fm24clxx_control;
+#endif
+
fm24clxx_drv.parent.user_data = user_data;
return rt_device_register(&fm24clxx_drv.parent, fm_device_name, RT_DEVICE_FLAG_RDWR);
diff --git a/components/drivers/i2c/i2c_dev.c b/components/drivers/i2c/i2c_dev.c
index 5713a28936..042b7b743a 100644
--- a/components/drivers/i2c/i2c_dev.c
+++ b/components/drivers/i2c/i2c_dev.c
@@ -102,6 +102,18 @@ static rt_err_t i2c_bus_device_control(rt_device_t dev,
return RT_EOK;
}
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device_ops i2c_ops =
+{
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ i2c_bus_device_read,
+ i2c_bus_device_write,
+ i2c_bus_device_control
+};
+#endif
+
rt_err_t rt_i2c_bus_device_device_init(struct rt_i2c_bus_device *bus,
const char *name)
{
@@ -115,12 +127,16 @@ rt_err_t rt_i2c_bus_device_device_init(struct rt_i2c_bus_device *bus,
/* set device type */
device->type = RT_Device_Class_I2CBUS;
/* initialize device interface */
+#ifdef RT_USING_DEVICE_OPS
+ device->ops = &i2c_ops;
+#else
device->init = RT_NULL;
device->open = RT_NULL;
device->close = RT_NULL;
device->read = i2c_bus_device_read;
device->write = i2c_bus_device_write;
device->control = i2c_bus_device_control;
+#endif
/* register to device manager */
rt_device_register(device, name, RT_DEVICE_FLAG_RDWR);