ÆäÖÐʼþÇý¶¯¸ºÔðÓëÓû§³ÌÐò´ò½»µÀ£¬ÖîÈçÉ豸½Úµã/devÖ®ÀàµÄ£¬¶¼ÓÉËû¸ºÔð£¬ÎÒÃÇÔÚдÇý¶¯Ê±¾Í²»ÓÃʵÏÖÕâ¸öÁË£»É豸Çý¶¯¸ºÔðÓëÓ²¼þÉ豸´ò½»µÀ£¬ÕâÀïµÄ½»»¥ºÜ¼òµ¥£¬Ö»ÐèÒª¶ÁÈ¡Ïà¹ØÓ²¼þµÄÊý¾Ý£¬È»ºóÅ׸øinputºËÐľͿÉÒÔÁË£»
¾Ù¸öÀý×Ó£¬ÒÔ°´¼ükeyΪÀý£¬¶¨ÒåÁËÉ豸É豸ºÅ¡¢°´¼üÖµ£¬ÅäÖùܽźÍÖжϷ½Ê½£¬È»ºóÉêÇëÖжϡ£ÔÚÖжϷþÎñº¯ÊýÖУ¬¶ÁÈ¡¶ÔÓ¦¹Ü½ÅÖµ£¬ÓÃinput_reportº¯Êý·¢Ë͸øinputºËÐÄ£¬²¢ÓÃinput_sync֪ͨ·¢ËͽáÊø¼´¿É¡£ÁíÍ⣬ÔÚÄ£¿é³õʼ»¯Ê±£¬¶¨ÒåÒ»¸öinput_devµÄ½á¹¹Ì壬Õâ¸öinput_devÊÇinput×ÓϵͳÉ豸Çý¶¯¶ËµÄºËÐÄÊý¾Ý½á¹¹£¬ÓÉÓÚÊäÈëÉ豸¶àÖÖ¶àÑù£¬¾ÍÊÇͨ¹ýÕâ¸ö½á¹¹Ìå¸æËߺËÐÄÄãµÄÊäÈëÉ豸ÀàÐÍ¡£
ÆäÖеÄÁ½¸öÖØÒª³ÉÔ±£¬ÕâЩºê¾ßÌåÔÚlinux/input.hÖж¨Òå¡£
Ò»¸öÊÇ£¬evbit£¬´ú±íʼþÀàÐ͵Äָʾ룬³£ÓõÄÈç
EV_SYN 0x00 ͬ²½Ê¼þ
EV_KEY 0x01 °´¼üʼþ
EV_REL 0x02 Ïà¶Ô×ø±ê
EV_ABS 0x03 ¾ø¶Ô×ø±ê
EV_MSC 0x04 ÆäËü
EV_LED 0x11 LED
EV_SND 0x12 ÉùÒô
EV_REP 0x14 Repeat
EV_FF 0x15 Á¦·´À¡
EV_PWR µçÔ´
EV_FF_STATUS ״̬
ÁíÒ»¸öÊÇkeybit£¬´ú±í¼üÖµ´úÂë
ÆäËûµÄ»¹ÓÐ
relbit Ïà¶Ô¶¨Î»
absbit ¾ø¶Ô¶¨Î»
mscbit Mouse Systems Corporation£¬´óÒâÊÇһЩ³§ÉÌʹÓÃÁË5×ֽڵĴ®¿ÚÊó±êÐÒ飬µ«Î¢ÈíʹÓÃÁËÒ»ÖÖÈý×Ö½ÚÐÒ飬ÓÚÊdz§ÉÌÔì´®¿ÚÊó±êʱ£¬ÈÃÉ豸ÓÐÁ½ÖÖ¹¤×÷ģʽ£¬Ò»ÖÖÊÇMSCģʽ£¬Ò»ÖÖÊÇ΢ÈíµÄģʽ¡£
ledbit ¼üÅÌָʾµÆʼþµÄָʾλ
sndbit ¼üÅÌ·¢³öÉùÒôµÄָʾλ
ffbit force feedback£¬Ç¿ÖÆ·´À¡É豸
swbit switch£¬É豸Çл»Ê±²úÉúµÄʼþ
ÏÂÃæ¾Í·Ö±ð¸ø³öÇý¶¯´úÂëºÍ²âÊÔ³ÌÐò£¬ÒÔ¹©²Î¿¼¡£
Çý¶¯´úÂ룺
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
// ¶¨Òåkey¶ÔÓ¦µÄGPIO
#define GPF0 (S3C2410_GPF(0))
#define GPF1 (S3C2410_GPF(1))
#define GPF2 (S3C2410_GPF(2))
#define GPF4 (S3C2410_GPF(4))
#define KEY_NUM 4
struct input_dev *key_dev;
static struct key_info
{
int irq_no;
int pin;
int pin_setting;
int key_no;
char *name;
}key_info_tab[KEY_NUM]=
{
{IRQ_EINT0,GPF0,S3C2410_GPF0_EINT0,1,"key_1"},
{IRQ_EINT1,GPF1,S3C2410_GPF1_EINT1,2,"key_2"},
{IRQ_EINT2,GPF2,S3C2410_GPF2_EINT2,3,"key_3"},
{IRQ_EINT4,GPF4,S3C2410_GPF4_EINT4,4,"key_4"},
};
// Öжϴ¦Àí³ÌÐò
static irqreturn_t hq_eint_key(int irq,void *dev_id)
{
if(irq==17)
{
input_report_key(key_dev,KEY_1,s3c2410_gpio_getpin(GPF1));
}
else if(irq==48)
{
input_report_key(key_dev,KEY_4,s3c2410_gpio_getpin(GPF4));
}
else if(irq==18)
{
input_report_key(key_dev,KEY_2,s3c2410_gpio_getpin(GPF2));
}
else if(irq==16)
{
input_report_key(key_dev,KEY_0,s3c2410_gpio_getpin(GPF0));
}
input_sync(key_dev);input_sync(key_dev);
return IRQ_HANDLED;
}
// ´ò¿ªÉ豸
static int hq_key_open(struct input_dev *dev)
{
int i;
int err=0;
for(i=0;i
err=request_irq(key_info_tab.irq_no,hq_eint_key,IRQF_SAMPLE_RANDOM,key_info_tab.name,(void *)(&key_info_tab));
if(err)
{
return -1;
}
return 0;
}
// ¹Ø±ÕÉ豸
static void hq_key_release(struct input_dev *dev)
{
int i;
for(i=0;i
free_irq(key_info_tab.irq_no,(void *)(&key_info_tab));
}
}
//Ä£¿é³õʼ»¯
static int __init hq_key_init(void)
{
int err;
key_dev=input_allocate_device();
if(!key_dev){
return -ENOMEM;
}
set_bit(EV_KEY,key_dev->evbit);
set_bit(KEY_1,key_dev->keybit);
set_bit(KEY_2,key_dev->keybit);
set_bit(KEY_3,key_dev->keybit);
set_bit(KEY_4,key_dev->keybit);
key_dev->name="input_key_demo";
key_dev->dev.init_name="input_key";
key_dev->open=hq_key_open;
key_dev->close=hq_key_release;
err=input_register_device(key_dev);
if(err){
return err;
}
return 0;
}
// Ä£¿éжÔØ
static void __exit hq_key_exit(void)
{
input_unregister_device(key_dev);
}
MODULE_AUTHOR("www.embedhq.org");
MODULE_LICENSE("Dual BSD/GPL");
module_init(hq_key_init);
module_exit(hq_key_exit);
²âÊÔ³ÌÐò£º
#include
#include
#include
#include
#include
int main(void )
{
int fd;
int key_value,i=0,count;
struct input_event ev_key;
fd=open("/dev/input/event0",0666);
if(fd<0){
perror("open device");
exit(1);
}
while(1){
count=read(fd,&ev_key,sizeof(struct input_event));
for(i=0;i<(int)count/sizeof(struct input_event);i++)
{
if(EV_KEY==ev_key.type)
{
int num=ev_key.code%10-1;
printf("type:%d,code:%d ,value:%d\n key%d pressed!\n",ev_key.type,ev_key.code,ev_key.value,num);
}
if(EV_SYN==ev_key.type)
printf("syn event\n");
}
}
close(fd);
return 0;
}
±àÒëºó£¬¼ÓÔØÇý¶¯£¬È»ºóÔËÐвâÊÔ³ÌÐò£¬µ±°´ÏÂij¸ö°´¼üʱ£¬¿ÉÒÔÔÚÖÕ¶ËÉÏ¿´µ½¶ÔÓ¦µÄ´òÓ¡ÐÅÏ¢¡£