-
#include <linux/input.h>
-
#include <linux/module.h>
-
#include <linux/init.h>
-
#include <linux/kernel.h>
-
#include <linux/irq.h>
-
#include <linux/interrupt.h>
-
#include <mach/gpio.h>
-
#include <mach/regs-gpio.h>
-
#include <asm/irq.h>
-
#include <asm/io.h>
-
-
#define DEV_NAME "KEY1"
-
#define DEV_NAME1 "KEY2"
-
#define BUTTON_IRQ IRQ_EINT0
-
#define BUTTON_IRQ1 IRQ_EINT0
-
-
static struct input_dev *button_dev;
-
void delay()
-
{
-
unsigned int i,j;
-
for(i=5000;i>0;i--)
-
{
-
for(j=5000;j>0;j--);
-
}
-
}
-
-
static irqreturn_t button_interrupt(int irq, void *p)
-
{
-
/*get pin value <down 0, up 1> */
-
int val = gpio_get_value (S5PV210_GPH0(0)); // s3c2410_gpio_getpin(S3C2410_GPG(0));
-
/* val must a variable */
-
printk("Enter EIENT0 ! \n");
-
input_report_key(button_dev,KEY_5, val);
-
input_sync(button_dev);
-
-
input_report_key(button_dev,KEY_5, !val);
-
input_sync(button_dev);
-
-
delay();
-
input_report_key(button_dev,KEY_LEFT, val);
-
input_sync(button_dev);
-
-
input_report_key(button_dev,KEY_LEFT, !val);
-
input_sync(button_dev);
-
-
return IRQ_RETVAL(IRQ_HANDLED);
-
}
-
-
//--------------------------------------------------------------------------------------------
-
static int __init button_init(void)
-
{
-
int err;
-
-
gpio_direction_input(S5PV210_GPH0(0));
-
s3c_gpio_cfgpin(S5PV210_GPH0(0), S3C_GPIO_SFN(0x0000000f)); //设置为外部中断 eint0 ,参考GP0CON【】
-
set_irq_type(IRQ_EINT0, IRQ_TYPE_EDGE_FALLING);
-
gpio_direction_input(S5PV210_GPH0(1));
-
s3c_gpio_cfgpin(S5PV210_GPH0(1), S3C_GPIO_SFN(0x000000f0)); //设置为外部中断 eint1 ,参考GP0CON【】
-
set_irq_type(IRQ_EINT1, IRQ_TYPE_EDGE_FALLING);
-
-
if(request_irq(BUTTON_IRQ, button_interrupt,IRQ_TYPE_EDGE_FALLING,DEV_NAME, button_dev))
-
{
-
input_free_device(button_dev);
-
printk(KERN_ERR"cannot allocate irq0");
-
return- EBUSY;
-
}
-
-
-
//--------------------------------------------------------------------------------------
-
button_dev= input_allocate_device();
-
if(button_dev == NULL)
-
{
-
printk(KERN_ERR"not enough memory\n");
-
err= - ENOMEM;
-
goto err_free_irq;
-
}
-
//-----------------------------------------------------------------------------------------
-
button_dev->name = "Mini Button Optical Finger Navigation Module ";
-
printk("1");
-
button_dev->phys = "OFN/OFN0";
-
printk("2");
-
button_dev->id.bustype = BUS_HOST;
-
printk("3");
-
button_dev->id.vendor = 0x0001;
-
printk("4");
-
button_dev->id.product = 0x0001;
-
printk("5");
-
button_dev->id.version = 0x0100;
-
printk("6");
-
-
//-----------------------------------------------------------------------------------------
-
// __set_bit(EV_REP, button_dev->evbit);
-
set_bit(EV_KEY,button_dev->evbit);
-
set_bit(KEY_5,button_dev->keybit);
-
set_bit(KEY_LEFT,button_dev->keybit);
-
//------------------------------------------------------------------------------------------
-
-
err= input_register_device(button_dev);
-
if(err)
-
{
-
printk(KERN_ERR"failed to register device\n");
-
goto err_free_dev;
-
}
-
printk("initialized\n");
-
return 0;
-
-
err_free_dev:
-
input_free_device(button_dev);
-
return err;
-
err_free_irq:
-
free_irq(BUTTON_IRQ,NULL);
-
return err;
-
}
-
-
static void __exit button_exit(void)
-
{
-
input_unregister_device(button_dev);
-
free_irq(BUTTON_IRQ,NULL);
-
}
-
-
module_init(button_init);
-
module_exit(button_exit);
-
-
MODULE_LICENSE("GPL");
-
MODULE_AUTHOR("light>");
三 、驱动程序例子
[html]view plaincopyprint?