In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people do not understand the knowledge points of this article "what is the Linux input subsystem?", so the editor summarizes the following contents, detailed contents, clear steps, and certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the Linux input subsystem" article.
In order to deal with different types of input devices, such as touch screen, mouse, keyboard and joystick, the Linux kernel designs and implements a unified interface function for the implementation of the driver layer, and provides a unified abstraction layer for the upper layer applications, that is, the Linux input subsystem.
Driving layer
The underlying hardware input into a unified event form, want to enter the core (Input Core) to report.
Input Subsystem 3 Core layer
It provides the input device registration and operation interface for the driver layer, such as: input_register_device; notifies the event processing layer to deal with events; generates the corresponding device information under / Proc.
Event processing layer
Mainly interact with user space (Linux treats all devices as files in user space, because fops interfaces are provided in general drivers, and the corresponding device files nod are generated under / dev, these operations are completed by the event processing layer in the input subsystem).
Device description
Input_dev structure is to realize the core work of device driver: report input events such as keystrokes and touch screens to the system (event, described by input_event structure), and no longer need to care about the file operation interface. The driver reports events through inputCore and Eventhandler to user space.
Register input device function: int input_register_device (struct input_dev * dev) logout input device function: void input_unregister_device (struct input_dev * dev)
Driver implementation-initialization (event support) set_bit () tells the input input subsystem which events are supported and which keys are supported. For example:
Set_bit (EV_KEY,button_dev.evbit) (where button_dev is of type struct input_dev)
* * there are two members in struct input_dev**: * * 1) * * evbit event types (including EV_RST,EV_REL,EV_MSC,EV_KEY,EV_ABS,EV_REP, etc.). * * 2) * * keybit button type (including BTN_LEFT,BTN_0,BTN_1,BTN_MIDDLE when the event type is EV_KEY).
Driver implementation-reporting events the functions used to report EV_KEY,EV_REL,EV_ABS events are:
Void input_report_key (struct input_dev * dev,unsigned int code,int value) void input_report_rel (struct input_dev * dev,unsigned int code,int value) void input_report_abs (struct input_dev * dev,unsigned int code,int value)
Driver implementation-report ending input_sync () synchronization is used to tell the input core subsystem that the report is over. In the touchscreen device driver, the whole reporting process of one click is as follows:
Input_reprot_abs (input_dev,ABS_X,x); / / x coordinate input_reprot_abs (input_dev,ABS_Y,y); / / y coordinate input_reprot_abs (input_dev,ABS_PRESSURE,1); input_sync (input_dev) / / synchronous end instance analysis (key interrupt program): / / Press the key to initialize static int _ _ init button_init (void) {/ / apply for interrupt if (request_irq (BUTTON_IRQ,button_interrupt,0, "button", NUll)) return-EBUSY; set_bit (EV_KEY,button_dev.evbit); / / support EV_KEY event set_bit (BTN_0,button_dev.keybit) / / support device two keys set_bit (BTN_1,button_dev.keybit); / / input_register_device (& button_dev); / / register input device} / * report event during key interrupt * / Static void button_interrupt (int irq,void * dummy,struct pt_regs * fp) {input_report_key (& button_dev,BTN_0,inb (BUTTON_PORT0)) / / read the value of register BUTTON_PORT0 input_report_key (& button_dev,BTN_1,inb (BUTTON_PORT1)); input_sync (& button_dev);}
Summary: the input subsystem is still a character device driver, but the amount of code is much reduced, and the * input subsystem only needs to do two things: initialization and event reporting (here through interrupts in linux). *
Example
# include # include struct input_dev * button_dev;struct button_irq_desc {int irq; int pin; int pin_setting; int number; char * name;} / * define an array of structures * / static struct button_irq_desc button_irqs [] = {{IRQ_EINT8, S3C2410_GPG0, S3C2410_GPG0_EINT8, 0, "KEY0"}, {IRQ_EINT11, S3C2410_GPG3, S3C2410_GPG3_EINT11, 1, "KEY1"}, {IRQ_EINT13, S3C2410_GPG5, S3C2410_GPG5_EINT13, 2, "KEY2"}, {IRQ_EINT14, S3C2410_GPG6, S3C2410_GPG6_EINT14, 3, "KEY3"} {IRQ_EINT15, S3C2410_GPG7, S3C2410_GPG7_EINT15, 4, "KEY4"}, {IRQ_EINT19, S3C2410_GPG11, S3C2410_GPG11_EINT19, 5, "KEY5"},} Static int key_values = 0 position static irqreturn_t buttons_interrupt (int irq, void * dev_id) {struct button_irq_desc * button_irqs = (struct button_irq_desc *) dev_id; int down; udelay (0); / * get key value * / down =! s3c2410_gpio_getpin (button_irqs- > pin); / / down: 1 (press), 0 (pop up) if (! down) {/ * report event * / key_values = button_irqs- > number / / printk ("= = > rising key_values=%d\ n", key_values); if (key_values==0) input_report_key (button_dev, KEY_1, 0); if (key_values==1) input_report_key (button_dev, KEY_2, 0); if (key_values==2) input_report_key (button_dev, KEY_3, 0); if (key_values==3) input_report_key (button_dev, KEY_4, 0) If (key_values==4) input_report_key (button_dev, KEY_5, 0); if (key_values==5) input_report_key (button_dev, KEY_6, 0); / * end of report * / input_sync (button_dev);} else {key_values= button_irqs- > number; / / printk ("= = > falling key_values=%d\ n", key_values) If (key_values==0) input_report_key (button_dev, KEY_1, 1); if (key_values==1) input_report_key (button_dev, KEY_2, 1); if (key_values==2) input_report_key (button_dev, KEY_3, 1); if (key_values==3) input_report_key (button_dev, KEY_4, 1) If (key_values==4) input_report_key (button_dev, KEY_5, 1); if (key_values==5) input_report_key (button_dev, KEY_6, 1); input_sync (button_dev);} return IRQ_RETVAL (IRQ_HANDLED);} static int s3c24xx_request_irq (void) {int i; int err = 0; for (I = 0; I if (button_ irqs [I] .irq continue) } / * IRQ_TYPE_EDGE_FALLING,IRQ_TYPE_EDGE_RISING,IRQ_TYPE_EDGE_BOTH * / err = request_irq (button_ irqs.irq, buttons_interrupt, IRQ_TYPE_EDGE_BOTH, button_ irqs.name, (void *) & button_ irqs [I]); if (err) break } / * error handling * / if (err) {iSumi; for (; I > = 0; iMub -) {if (button_ irqs.irq continue;} disable_irq (button_ irqs.irq); free_irq (button_ irqs.irq, (void *) & button_ irqs [I]);} return-EBUSY } return 0;} static int _ init dev_init (void) {/ * request irq*/ s3c24xx_request_irq (); / * Initialise input stuff * / button_dev = input_allocate_device (); if (! button_dev) {printk (KERN_ERR "Unable to allocate the input device!!\ n"); return-ENOMEM;} button_dev- > name = "s3c2440_button"; button_dev- > id.bustype = BUS_RS232 Button_dev- > id.vendor = 0xDEAD; button_dev- > id.product = 0xBEEF; button_dev- > id.version = 0x0100; button_dev- > evbit [0] = BIT_MASK (EV_KEY) | BIT (EV_SYN); / / set_bit (EV_KEY, button_dev- > evbit) / / support EV_KEY events / * set which keys are supported * / set_bit (KEY_1, button_dev- > keybit); set_bit (KEY_2, button_dev- > keybit) Set_bit (KEY_3, button_dev- > keybit); set_bit (KEY_4, button_dev- > keybit); set_bit (KEY_5, button_dev- > keybit); set_bit (KEY_6, button_dev- > keybit); / / printk ("KEY_RESERVED=%d, KEY_1=%d", KEY_RESERVED,KEY_1); input_register_device (button_dev); / / Register input device printk ("initialized\ n"); return 0 } static void _ exit dev_exit (void) {int i; for (I = 0; I if (button_ irqs.irq continue;} free_irq (button_ irqs.irq, (void *) & button_ irqs [I]);} input_unregister_device (button_dev);} module_init (dev_init); module_exit (dev_exit); MODULE_LICENSE ("GPL"); MODULE_AUTHOR ("David Xie") The above is the content of this article about "what is the Linux input subsystem?" I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.