Merge pull request #1426 from zhuangwei123/master

[bsp/ls1cdev]drv_gpio add interrupt ops
This commit is contained in:
Bernard Xiong 2018-05-11 16:07:40 +08:00 committed by GitHub
commit 1cc3c58846
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 10 deletions

View File

@ -19,13 +19,17 @@
*
* Change Logs:
* Date Author Notes
* 2017-11-24 first version
* 2017-11-24 first version
* 2018-05-11 zhuangwei add gpio interrupt ops
*/
#include <rtthread.h>
#include <drivers/pin.h>
#include "../libraries/ls1c_gpio.h"
#include "ls1c_gpio.h"
#include "ls1c.h"
#include <rthw.h>
#ifdef RT_USING_PIN
void ls1c_pin_mode(struct rt_device *device, rt_base_t pin, rt_base_t mode)
{
@ -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];
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 */

View File

@ -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);