Linux device driver Subsystem third bullet-Input__linux

Source: Internet
Author: User

1. General

2. Navigation

3. Examples

3.1 Keyboard

3.2 Touch Screen

1. General

The input subsystem provides a unified data escalation system for some commonly used small scale data transmission devices, and uploads the data to user space in a uniform format. The device for the input subsystem has a joystick, a mouse, a keyboard, a touch screen, a misc, etc.

2. Navigation

Input subsystem configuration steps are as follows, request and initialize input device settings input device-related bit bit registration input device escalation data

2.1 Application and initialization of input equipment input_allocate_device ();

A struct INPUT_DEV type structure is stored in the device's data structure for storing input devices. The structure is defined in/include/linux/input.c,

2.2 Set input device-related bit bit

Linux for input devices to provide the above different types of events, each type of event such as keybit[], each of which represents an event, such as the button on the top, bottom, left, right and so on.

In the driver, just set the corresponding bit bit for the device-related event.

2.3 Registered Input Equipment Input_register_device (INPUT_DEV);

2.4 Escalation Data input_report_xxx (Input_dev, code, value)

The driver reports the device data value through INPUT_REPORT_XXX () to the input core layer, and the core layer completes uploading the data from the kernel space to the user space.

XXX indicates the type of event, such as the keyboard event is Input_report_key (), the code represents the type of the key (as defined by the input system), and value represents the state of the key (by driving the data); The touch screen event is input_report_abs ( ), the code represents the type of touch (defined by the input system), such as pressure, or x-axis, y-axis, and value represents pressure or coordinate values (by driving the data).

Below enter the input core layer to see how the data is reported specifically, take Input_report_key () for example,

Finally called the callback function handle->handler->event (); Note that handle this data structure, which is a member of the struct Input_dev, and struct Input_dev is uniquely applied and registered when the device driver is initialized, where handle is used to refer to this input device, the keyboard, so that The callback function handle->handler->event () allows you to find the specified keyboard device through this handle.

The struct Evdev *evdev store is a device-driven data structure that is obtained by handle from the bottom.

struct Evdev_client *client A data structure that is accessible to end user space, where event type type, data type code, and data value value are stored.

The following figure is an example of a top application,

3. Examples

3.1 Keyboard

1 The orange part is the data of the platform_device structure obtained after the system initialization, including the physical address of the keyboard controller, the interrupt number, and the key value of the keyboard matrix.

2 The blue part is through the input subsystem registered keyboard device driver, respectively, completed the above mentioned 1,2,3 step, that is, the application input, set input related bit, registered input.

Note that the pink code implemented, the keyboard matrix corresponding to the key value (key type code) to the input subsystem in the corresponding bit bit, specifically,

As shown in the figure, the matrix coordinates of the confirmation key (0,0), the left key corresponding to the matrix coordinates (2,0),

First, the system initializes the key value (key type code) for these matrix coordinates, (0,0) is configured to confirm, (2,0) is configured to left, then the key value is stored in the Platform_device, and then the driver extracts the key value, and assigns it to the corresponding bit in the input system, these bits are defined in the/include/linux/input.h.

3 The Green section is the 4th step mentioned above-reporting data.

When a key is pressed or bounced, the driver throws an interrupt function, the keyboard scan function.

The keyboard controller registers the matrix coordinates (row, col) which presses or plays the key, then obtains the corresponding key value (the key type code) by the coordinates, finally by Input_report_key (input, code, value) completes the data to report. Note that when the data is reported, it is synchronized with Input_sync ().

3.2 Touch Screen

1 orange part for the system initialization after the platform_device structure of data, mainly for the chip on the PIN application Gpio, the circuit diagram as shown below,

2 The blue part is through the input subsystem registered touch screen device driver, that is, the application input, set input related bit, register input equipment. This mainly sets the touch screen pressure pressure and the Axis x,y event.

3) Report data.

The stylus presses the interrupt, triggers the interrupt handler function, wakes up a thread that reads and parses the touch-screen coordinate data (because the cost of reading and parsing the data is relatively large), and eventually the input subsystem is used to escalate the coordinate value. Again, synchronize with Input_sync ().

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.