void input_unregister_device(struct input_dev *dev)<\/pre>\n\u9a71\u52a8\u5b9e\u73b0\u2014\u2014\u521d\u59cb\u5316(\u4e8b\u4ef6\u652f\u6301)set_bit()\u544a\u8bc9input\u8f93\u5165\u5b50\u7cfb\u7edf\u652f\u6301\u54ea\u4e9b\u4e8b\u4ef6\uff0c\u54ea\u4e9b\u6309\u952e\u3002\u4f8b\u5982\uff1a<\/p>\n
set_bit(EV_KEY,button_dev.evbit)\u00a0 (\u5176\u4e2dbutton_dev\u662fstruct input_dev\u7c7b\u578b)<\/pre>\nstruct input_dev<\/strong>\u4e2d\u6709\u4e24\u4e2a\u6210\u5458\u4e3a\uff1a<\/strong>
\n1)<\/strong>evbit\u4e8b\u4ef6\u7c7b\u578b\uff08\u5305\u62ecEV_RST,EV_REL,EV_MSC,EV_KEY,EV_ABS,EV_REP\u7b49\uff09\u3002
\n2)<\/strong>keybit\u6309\u952e\u7c7b\u578b\uff08\u5f53\u4e8b\u4ef6\u7c7b\u578b\u4e3aEV_KEY\u65f6\u5305\u62ecBTN_LEFT,BTN_0,BTN_1,BTN_MIDDLE\u7b49\uff09\u3002<\/p>\n\u9a71\u52a8\u5b9e\u73b0\u2014\u2014\u62a5\u544a\u4e8b\u4ef6\u7528\u4e8e\u62a5\u544aEV_KEY,EV_REL,EV_ABS\u4e8b\u4ef6\u7684\u51fd\u6570\u5206\u522b\u4e3a:<\/p>\n
void input_report_key(struct input_dev *dev,unsigned int code,int value)\r\nvoid input_report_rel(struct input_dev *dev,unsigned int code,int value)\r\nvoid input_report_abs(struct input_dev *dev,unsigned int code,int value)<\/pre>\n\u9a71\u52a8\u5b9e\u73b0\u2014\u2014\u62a5\u544a\u7ed3\u675finput_sync()\u540c\u6b65\u7528\u4e8e\u544a\u8bc9input core\u5b50\u7cfb\u7edf\u62a5\u544a\u7ed3\u675f\uff0c\u89e6\u6478\u5c4f\u8bbe\u5907\u9a71\u52a8\u4e2d\uff0c\u4e00\u6b21\u70b9\u51fb\u7684\u6574\u4e2a\u62a5\u544a\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n
input_reprot_abs(input_dev,ABS_X,x);\u00a0\u00a0 \/\/x\u5750\u6807\r\ninput_reprot_abs(input_dev,ABS_Y,y);\u00a0\u00a0 \/\/ y\u5750\u6807\r\ninput_reprot_abs(input_dev,ABS_PRESSURE,1);\r\ninput_sync(input_dev);\/\/\u540c\u6b65\u7ed3\u675f<\/pre>\n\u5b9e\u4f8b\u5206\u6790\uff08\u6309\u952e\u4e2d\u65ad\u7a0b\u5e8f\uff09\uff1a<\/strong><\/p>\n\/\/\u6309\u952e\u521d\u59cb\u5316\r\nstatic int __init button_init(void)\r\n{\/\/\u7533\u8bf7\u4e2d\u65ad\r\n if(request_irq(BUTTON_IRQ,button_interrupt,0,\u201dbutton\u201d,NUll))\r\n return \u2013EBUSY;\r\n set_bit(EV_KEY,button_dev.evbit); \/\/\u652f\u6301EV_KEY\u4e8b\u4ef6\r\n set_bit(BTN_0,button_dev.keybit); \/\/\u652f\u6301\u8bbe\u5907\u4e24\u4e2a\u952e\r\n set_bit(BTN_1,button_dev.keybit); \/\/\r\n input_register_device(&button_dev);\/\/\u6ce8\u518cinput\u8bbe\u5907\r\n}<\/pre>\n\/*\u5728\u6309\u952e\u4e2d\u65ad\u4e2d\u62a5\u544a\u4e8b\u4ef6*\/\r\nStatic void button_interrupt(int irq,void *dummy,struct pt_regs *fp)\r\n{\r\n input_report_key(&button_dev,BTN_0,inb(BUTTON_PORT0));\/\/\u8bfb\u53d6\u5bc4\u5b58\u5668BUTTON_PORT0\u7684\u503c\r\n input_report_key(&button_dev,BTN_1,inb(BUTTON_PORT1));\r\n input_sync(&button_dev);\r\n}<\/pre>\n\u603b\u7ed3\uff1a<\/strong>input<\/strong>\u5b50\u7cfb\u7edf\u4ecd\u7136\u662f\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u7a0b\u5e8f\uff0c\u4f46\u662f\u4ee3\u7801\u91cf\u51cf\u5c11\u5f88\u591a\uff0c<\/strong>input<\/strong>\u5b50\u7cfb\u7edf\u53ea\u9700\u8981\u5b8c\u6210\u4e24\u4e2a\u5de5\u4f5c\uff1a\u521d\u59cb\u5316\u548c\u4e8b\u4ef6\u62a5\u544a\uff08\u8fd9\u91cc\u5728<\/strong>linux<\/strong>\u4e2d\u662f\u901a\u8fc7\u4e2d\u65ad\u6765\u5b9e\u73b0\u7684\uff09\u3002<\/strong><\/p>\n\u5b9e\u4f8b<\/strong><\/div>\n#include <linux\/module.h>\r\n#include <linux\/kernel.h>\r\n#include <linux\/fs.h>\r\n#include <linux\/init.h>\r\n#include <linux\/delay.h>\r\n#include <linux\/poll.h>\r\n#include <linux\/irq.h>\r\n#include <asm\/irq.h>\r\n#include <linux\/interrupt.h>\r\n#include <asm\/uaccess.h>\r\n#include <mach\/regs-gpio.h>\r\n#include <mach\/hardware.h>\r\n#include <linux\/platform_device.h>\r\n#include <linux\/cdev.h>\r\n#include <linux\/miscdevice.h>\r\n#include <linux\/input.h>\r\n\r\nstruct input_dev *button_dev;\r\nstruct button_irq_desc {\r\n int irq;\r\n int pin;\r\n int pin_setting;\r\n int number;\r\n char *name;\r\n};\r\n\r\n\/*\u5b9a\u4e49\u4e00\u4e2a\u7ed3\u6784\u4f53\u6570\u7ec4*\/\r\nstatic struct button_irq_desc button_irqs [] = {\r\n {IRQ_EINT8 , S3C2410_GPG0 , S3C2410_GPG0_EINT8 , 0, \"KEY0\"},\r\n {IRQ_EINT11, S3C2410_GPG3 , S3C2410_GPG3_EINT11 , 1, \"KEY1\"},\r\n {IRQ_EINT13, S3C2410_GPG5 , S3C2410_GPG5_EINT13 , 2, \"KEY2\"},\r\n {IRQ_EINT14, S3C2410_GPG6 , S3C2410_GPG6_EINT14 , 3, \"KEY3\"},\r\n {IRQ_EINT15, S3C2410_GPG7 , S3C2410_GPG7_EINT15 , 4, \"KEY4\"},\r\n {IRQ_EINT19, S3C2410_GPG11, S3C2410_GPG11_EINT19, 5, \"KEY5\"},\r\n};\r\n\r\nstatic int key_values = 0;\r\nstatic irqreturn_t buttons_interrupt(int irq, void *dev_id)\r\n{\r\n struct button_irq_desc *button_irqs = (struct button_irq_desc *)dev_id;\r\n int down;\r\n udelay(0);\r\n\/*\u83b7\u53d6\u6309\u952e\u503c*\/\r\ndown = !s3c2410_gpio_getpin(button_irqs->pin); \/\/down: 1(\u6309\u4e0b)\uff0c0\uff08\u5f39\u8d77\uff09\r\nif (!down) {\r\n \/*\u62a5\u544a\u4e8b\u4ef6*\/\r\n key_values = button_irqs->number;\r\n \/\/printk(\"====>rising key_values=%d\\n\",key_values);\r\n if(key_values==0)\r\n input_report_key(button_dev, KEY_1, 0);\r\n if(key_values==1)\r\n input_report_key(button_dev, KEY_2, 0);\r\n if(key_values==2)\r\n input_report_key(button_dev, KEY_3, 0);\r\n if(key_values==3)\r\n input_report_key(button_dev, KEY_4, 0);\r\n if(key_values==4)\r\n input_report_key(button_dev, KEY_5, 0);\r\n if(key_values==5)\r\n input_report_key(button_dev, KEY_6, 0);\r\n \/*\u62a5\u544a\u7ed3\u675f*\/\r\n input_sync(button_dev);\r\n }\r\nelse {\r\n key_values = button_irqs->number;\r\n \/\/printk(\"====>falling key_values=%d\\n\",key_values);\r\n if(key_values==0)\r\n input_report_key(button_dev, KEY_1, 1);\r\n if(key_values==1)\r\n input_report_key(button_dev, KEY_2, 1);\r\n if(key_values==2)\r\n input_report_key(button_dev, KEY_3, 1);\r\n if(key_values==3)\r\n input_report_key(button_dev, KEY_4, 1);\r\n if(key_values==4)\r\n input_report_key(button_dev, KEY_5, 1);\r\n if(key_values==5)\r\n input_report_key(button_dev, KEY_6, 1);\r\n input_sync(button_dev);\r\n }\r\n return IRQ_RETVAL(IRQ_HANDLED);\r\n}\r\nstatic int s3c24xx_request_irq(void)\r\n{\r\n int i;\r\n int err = 0;\r\n for (i = 0; i < sizeof(button_irqs)\/sizeof(button_irqs[0]); i++) {\r\n if (button_irqs[i].irq < 0) {\r\n continue;\r\n }\r\n \/* IRQ_TYPE_EDGE_FALLING,IRQ_TYPE_EDGE_RISING,IRQ_TYPE_EDGE_BOTH *\/\r\n err = request_irq(button_irqs[i].irq, buttons_interrupt, IRQ_TYPE_EDGE_BOTH,\r\n button_irqs[i].name, (void *)&button_irqs[i]);\r\n if (err)\r\n break;\r\n }\r\n \/*\u9519\u8bef\u5904\u7406*\/\r\n if (err) {\r\n i--;\r\n for (; i >= 0; i--) {\r\n if (button_irqs[i].irq < 0) {\r\n continue;\r\n }\r\n disable_irq(button_irqs[i].irq);\r\n free_irq(button_irqs[i].irq, (void *)&button_irqs[i]);\r\n }\r\n return -EBUSY;\r\n }\r\n return 0;\r\n}\r\nstatic int __init dev_init(void)\r\n{\r\n \/*request irq*\/\r\n s3c24xx_request_irq();\r\n \/* Initialise input stuff *\/\r\n button_dev = input_allocate_device();\r\n if (!button_dev) {\r\n printk(KERN_ERR \"Unable to allocate the input device !!\\n\");\r\n return -ENOMEM;\r\n }\r\n button_dev->name = \"s3c2440_button\";\r\n button_dev->id.bustype = BUS_RS232;\r\n button_dev->id.vendor = 0xDEAD;\r\n button_dev->id.product = 0xBEEF;\r\n button_dev->id.version = 0x0100;\r\n\r\n button_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT(EV_SYN);\r\n \/\/set_bit(EV_KEY, button_dev->evbit)\/\/\u652f\u6301EV_KEY\u4e8b\u4ef6\r\n \/*\u8bbe\u7f6e\u652f\u6301\u54ea\u4e9b\u6309\u952e*\/\r\n set_bit(KEY_1, button_dev->keybit);\r\n set_bit(KEY_2, button_dev->keybit);\r\n set_bit(KEY_3, button_dev->keybit);\r\n set_bit(KEY_4, button_dev->keybit);\r\n set_bit(KEY_5, button_dev->keybit);\r\n set_bit(KEY_6, button_dev->keybit);\r\n \/\/printk(\"KEY_RESERVED=%d ,KEY_1=%d\",KEY_RESERVED,KEY_1);\r\n input_register_device(button_dev); \/\/\u6ce8\u518cinput\u8bbe\u5907\r\n\r\n printk (\"initialized\\n\");\r\n\r\n return 0;\r\n}\r\n\r\nstatic void __exit dev_exit(void)\r\n{\r\n int i;\r\n\r\n for (i = 0; i < sizeof(button_irqs)\/sizeof(button_irqs[0]); i++) {\r\n if (button_irqs[i].irq < 0) {\r\n continue;\r\n }\r\n free_irq(button_irqs[i].irq, (void *)&button_irqs[i]);\r\n }\r\n\r\n input_unregister_device(button_dev);\r\n}\r\n\r\nmodule_init(dev_init);\r\nmodule_exit(dev_exit);\r\nMODULE_LICENSE(\"GPL\");\r\nMODULE_AUTHOR(\"David Xie\");<\/pre>\n\n\u539f\u6587\u6765\u81ea\uff1ahttp:\/\/www.cnblogs.com\/myblesh\/articles\/2367648.html<\/a><\/p>\n\u672c\u6587\u5730\u5740\uff1a http:\/\/lrxjmw.cn\/linux-input-subsystem.html<\/a>\u7f16\u8f91\uff1a\u738b\u663e\u707f\uff0c\u5ba1\u6838\u5458\uff1a\u51af\u742a<\/span><\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"\u5bfc\u8bfb linux\u8f93\u5165\u5b50\u7cfb\u7edf\u7531\u9a71\u52a8\u5c42\u3001\u8f93\u5165\u5b50\u7cfb\u7edf\u6838\u5fc3\u3001\u4e8b\u4ef6\u5904\u7406\u5c42\u4e09\u90e8\u5206\u7ec4\u6210\u3002\u4e00\u4e2a\u8f93\u5165\u4e8b\u4ef6\uff0c\u5982\u9f20\u6807\u79fb\u52a8\u3001\u952e\u76d8\u6309\u4e0b\u7b49 […]<\/p>\n","protected":false},"author":402,"featured_media":52716,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-52119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/52119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/402"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=52119"}],"version-history":[{"count":12,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/52119\/revisions"}],"predecessor-version":[{"id":274002,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/52119\/revisions\/274002"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/52716"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=52119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=52119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=52119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}