From cba34bd4d13f93087a5c873d7a15a059e54fb475 Mon Sep 17 00:00:00 2001 From: zhuangwei123 Date: Fri, 11 May 2018 14:36:18 +0800 Subject: [PATCH] [bsp/ls1cdev]drv_gpio add interrupt ops --- bsp/ls1cdev/drivers/drv_gpio.c | 56 +++++++++++++++++++++++++++++----- bsp/ls1cdev/drivers/drv_gpio.h | 7 +++-- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/bsp/ls1cdev/drivers/drv_gpio.c b/bsp/ls1cdev/drivers/drv_gpio.c index 28af13385d..a4be5b2e4d 100644 --- a/bsp/ls1cdev/drivers/drv_gpio.c +++ b/bsp/ls1cdev/drivers/drv_gpio.c @@ -19,18 +19,22 @@ * * Change Logs: * Date Author Notes - * 2017-11-24 ÇÚΪ±¾ first version + * 2017-11-24 勤为本 first version + * 2018-05-11 zhuangwei add gpio interrupt ops */ #include #include -#include "../libraries/ls1c_gpio.h" +#include "ls1c_gpio.h" +#include "ls1c.h" +#include +#ifdef RT_USING_PIN void ls1c_pin_mode(struct rt_device *device, rt_base_t pin, rt_base_t mode) { unsigned int gpio = pin; - + if (PIN_MODE_OUTPUT == mode) { gpio_init(gpio, gpio_mode_output); @@ -47,7 +51,7 @@ void ls1c_pin_mode(struct rt_device *device, rt_base_t pin, rt_base_t mode) void ls1c_pin_write(struct rt_device *device, rt_base_t pin, rt_base_t value) { unsigned int gpio = pin; - + if (PIN_LOW == value) { gpio_set(gpio, gpio_level_low); @@ -78,20 +82,58 @@ int ls1c_pin_read(struct rt_device *device, rt_base_t pin) return value; } +rt_err_t ls1c_pin_attach_irq(struct rt_device *device, rt_int32_t pin, + rt_uint32_t mode, void (*hdr)(void *args), void *args) +{ + unsigned int gpio = pin; + char irq_name[10]; -const static struct rt_pin_ops _ls1c_pin_ops = + gpio_set_irq_type(gpio, mode); + rt_sprintf(irq_name, "PIN_%d", gpio); + rt_hw_interrupt_install(LS1C_GPIO_TO_IRQ(gpio), (rt_isr_handler_t)hdr, args, irq_name); + + return RT_EOK; +} + +rt_err_t ls1c_pin_dettach_irq(struct rt_device *device, rt_int32_t pin) +{ + return RT_EOK; +} + +rt_err_t ls1c_pin_irq_enable(struct rt_device *device, rt_base_t pin, rt_uint32_t enabled) +{ + unsigned int gpio = pin; + + if (enabled) + rt_hw_interrupt_umask(LS1C_GPIO_TO_IRQ(gpio)); + else + rt_hw_interrupt_mask(LS1C_GPIO_TO_IRQ(gpio)); + return RT_EOK; +} + + +const static struct rt_pin_ops _ls1c_pin_ops = { ls1c_pin_mode, ls1c_pin_write, ls1c_pin_read, + + ls1c_pin_attach_irq, + ls1c_pin_dettach_irq, + ls1c_pin_irq_enable }; int hw_pin_init(void) { - rt_device_pin_register("pin", &_ls1c_pin_ops, RT_NULL); - return 0; + int ret = RT_EOK; + + ret = rt_device_pin_register("pin", &_ls1c_pin_ops, RT_NULL); + + return ret; } INIT_BOARD_EXPORT(hw_pin_init); +#endif /*RT_USING_PIN */ + diff --git a/bsp/ls1cdev/drivers/drv_gpio.h b/bsp/ls1cdev/drivers/drv_gpio.h index 7657eb000f..ab67d9f32a 100644 --- a/bsp/ls1cdev/drivers/drv_gpio.h +++ b/bsp/ls1cdev/drivers/drv_gpio.h @@ -19,11 +19,12 @@ * * Change Logs: * Date Author Notes - * 2017-11-24 ÇÚΪ±¾ first version + * 2017-11-24 勤为本 first version + * 2018-05-11 zhuangwei add gpio interrupt ops */ -#ifndef LS1C_DRV_GPIO_H -#define LS1C_DRV_GPIO_H +#ifndef __DRV_GPIO_H__ +#define __DRV_GPIO_H__ int hw_pin_init(void);