diff options
| author | Bernard Xiong <[email protected]> | 2018-06-10 17:59:17 +0800 |
|---|---|---|
| committer | Bernard Xiong <[email protected]> | 2018-06-10 17:59:17 +0800 |
| commit | 884fb70fe9973eaf01a7df04941cbcb0475ba8d5 (patch) | |
| tree | 7c8e3f42629e46b3d7ecb0c8507f67934d9fae47 /components/drivers/misc | |
| parent | bca65f30a90857287dc1371ddbc8d5f165691c7f (diff) | |
[Kernel] Add device ops feature.
Diffstat (limited to 'components/drivers/misc')
| -rw-r--r-- | components/drivers/misc/pin.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/components/drivers/misc/pin.c b/components/drivers/misc/pin.c index 9ed827f0b5..dc2137eb17 100644 --- a/components/drivers/misc/pin.c +++ b/components/drivers/misc/pin.c @@ -76,18 +76,34 @@ static rt_err_t _pin_control(rt_device_t dev, int cmd, void *args) return 0; } +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops pin_ops = +{ + RT_NULL, + RT_NULL, + RT_NULL, + _pin_read, + _pin_write, + _pin_control +}; +#endif + int rt_device_pin_register(const char *name, const struct rt_pin_ops *ops, void *user_data) { _hw_pin.parent.type = RT_Device_Class_Miscellaneous; _hw_pin.parent.rx_indicate = RT_NULL; _hw_pin.parent.tx_complete = RT_NULL; +#ifdef RT_USING_DEVICE_OPS + _hw_pin.parent.ops = &pin_ops; +#else _hw_pin.parent.init = RT_NULL; _hw_pin.parent.open = RT_NULL; _hw_pin.parent.close = RT_NULL; _hw_pin.parent.read = _pin_read; _hw_pin.parent.write = _pin_write; _hw_pin.parent.control = _pin_control; +#endif _hw_pin.ops = ops; _hw_pin.parent.user_data = user_data; @@ -117,6 +133,7 @@ rt_err_t rt_pin_dettach_irq(rt_int32_t pin) } return RT_ENOSYS; } + rt_err_t rt_pin_irq_enable(rt_base_t pin, rt_uint32_t enabled) { RT_ASSERT(_hw_pin.ops != RT_NULL); @@ -126,6 +143,7 @@ rt_err_t rt_pin_irq_enable(rt_base_t pin, rt_uint32_t enabled) } return RT_ENOSYS; } + /* RT-Thread Hardware PIN APIs */ void rt_pin_mode(rt_base_t pin, rt_base_t mode) { |
