Linux input subsystem input_dev Overview

Source: Internet
Author: User

In Linux, the input subsystem is provided. input keys, touch screens, keyboards, and mouse can all be driven by the input interface function. Therefore, 12.1 ~ The buttons and touch screen device drivers in section 12.2 can be used as input device drivers.

In the Linux kernel, the input device uses the input_dev structure to describe the input device driver, the core work of the driver is to report input events (events, which are described by the input_event structure) such as buttons, touch screens, keyboards, and mouse to the system, and there is no need to care about file operation interfaces, because the input subsystem has completed the file operation interface. The events reported by the driver pass through inputcore and eventhandler and finally reach the user space.

Through the input subsystem, the specific input device driver only needs to complete the following work.

L events that can be reported by the input subsystem are notified in the module loading function.

The device driver uses set_bit () to tell the input subsystem what events it supports, as shown below:

Set_bit (ev_key, button_dev.evbit );
L register the input device in the module loading function.

The function for registering an input device is:

Int input_register_device (struct input_dev
* Dev );
L input _ report_xxx () report events and corresponding key values/coordinates.

The main event types include ev_key (key event), ev_rel (relative value, such as moving the cursor, reporting the offset relative to the last position), and ev_abs (absolute value, such as touch screen and joystick, they work in absolute coordinate systems ).

The functions used to report ev_key, ev_rel, and 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 );
Input_sync () is used for event synchronization. It notifies the receiver driver of the event that a complete report has been issued.

For example, in the driver of a touch screen device, the entire report process of one coordinate and one pressing state is as follows:

Input_report_abs (input_dev
, Abs_x, x); // X coordinate
Input_report_abs (input_dev
, Abs_y, Y); // y coordinate
Input_report_abs (input_dev
, Abs_pressure, Pres); // pressure
Input_sync (input_dev
); // Synchronize
Unregister the input device from the module uninstallation function. The function for logging out of the input device is:

Void input_unregister_device (struct input_dev
* Dev );
Code List 12.28 provides a simple example of using the input interface to implement the key device driver. It reports keys and synchronization events to the system in the interrupt service program.

Code List 12.28 simplest Input Device Driver

1/* report events during key interruption */
2 static void button_interrupt (int irq, void * dummy, struct pt_regs * FP)
3 {
4 input_report_key (& button_dev, btn_1, INB (button_port) & 1 );
5 input_sync (& button_dev );
6}
7
8 Static int _ init button_init (void)
9 {
10/* Application interrupted */
11 if (request_irq (button_irq, button_interrupt, 0, "button", null ))
12 {
13 printk (kern_err "button. C: Can't allocate IRQ % d", button_irq );
14 return-ebusy;
15}
16
17 button_dev.evbit [0] = bit (ev_key); // supports ev_key events.
18 button_dev.keybit [long (btn_0)] = bit (btn_0 );
19
20 input_register_device (& button_dev); // register the input device
21}
22
23 static void _ exit button_exit (void)
24 {
25 input_unregister_device (& button_dev); // cancel the input device
26 free_irq (button_irq, button_interrupt); // release interrupted
27}
This article from: Development Institute http://edu.codepub.com Source: http://edu.codepub.com/2010/0701/23935.php

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.