Merge pull request #1426 from zhuangwei123/master
[bsp/ls1cdev]drv_gpio add interrupt ops
This commit is contained in:
commit
1cc3c58846
|
@ -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 <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)
|
||||
{
|
||||
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 */
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue