Third bullet-Input

Source: Internet
Author: User

1. Overview

2. Navigation

3. Instance

3.1-inch keyboard

3.2 Touch Screen

1. Overview

The input subsystem provides a unified data reporting system for some commonly used small-scale data transmission devices to upload data to the user space in a unified format. The device suitable for the input subsystem includes the joystick, mouse, keyboard, touch screen, and Misc.

 

2. Navigation

The input subsystem configuration steps are as follows,

  1. Apply for and initialize an input device
  2. Sets the device-related bit of input.
  3. Register an input device
  4. Report data

2.1 apply for and initialize the input device input_allocate_device ();

The data structure of the device contains a struct input_dev structure, which is used to store the input device. This structure is defined in/include/Linux/input. C,

2.2 set the bit related to the input and the device

Linux provides different types of events for input devices. Each type of events, such as keybit [], indicates an event, for example, top, bottom, left, and right buttons.

In the driver, you only need to set the corresponding bit for device-related events.

2.3 Register the input device input_register_device (input_dev );

2.4 reporting data input_report_xxx (input_dev, code, value)

 

The driver reports the device data value to the input core layer through input_report_xxx (). The core layer uploads the data from the kernel space to the user space.

Xxx indicates the event type. For example, the keyboard event is input_report_key (). Code indicates the type of the button (defined by the input system). value indicates the status of the button (data is obtained through the driver ); the touch screen event is input_report_abs (). Code indicates the touch type (defined by the input system), such as the pressure, or the X axis, Y axis, value indicates the pressure value or coordinate value (obtained through the driver ).

 

Next, go to the input core layer to see how the data is reported. Take input_report_key () as an example,

Finally, the callback function handle-> Handler-> event () is called. The data structure of handle is noticed. It is a member of struct input_dev, struct input_dev is uniquely applied for and registered during device driver initialization. The handle here is used to refer to the input device, that is, the keyboard, the callback function handle-> Handler-> event () can be used to find the specified keyboard device.

Struct evdev * evdev stores the device-Driven Data Structure Obtained from the underlying layer through handle.

Struct evdev_client * client is the data structure that can be accessed by the end user space. It stores the event type, data type code, and data value.

As an example of an upper-layer application,

 

 

3. Instance

3.1-inch keyboard

 

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

2) the blue part is the keyboard Device Driver registered through the input subsystem. the above steps 1, 2, and 3 are completed, that is, to apply for input, set input bit, and register input.

Note that the pink code is implemented, and the key value (key-type code) corresponding to the keyboard matrix is reported to the corresponding bit in the input subsystem. Specifically,

, Confirm the matrix coordinates of the key (), the left-click matrix coordinates ),

First, the system configures the key value (Key type code) for these matrix coordinates during initialization, () for confirm, () for left, store the key value in platform_device. Then, the driver extracts the key value and assigns it to the corresponding bits in the input system. These bits are defined in/include/Linux/input. h.

3) the green part refers to Step 1-Report data as mentioned above.

When a key is pressed or popped up, the driver triggers an interrupt function, that is, the Keyboard Scan function.

Use the registers of the keyboard controller to obtain the matrix coordinates (row, col) of the pressed or popped key, and then obtain the corresponding key value (Key type code) from the coordinates. Finally, input_report_key (input, code, value) to report data. Note that the data must be synchronized with input_sync () after being reported.

 

3.2 Touch Screen

1) The orange part is the platform_device structure data obtained after system initialization. It mainly applies for gpio ports for pins on the chip, as shown in the circuit diagram,

2) the blue part is the touch screen device driver registered through the input subsystem, that is, applying for input, setting input-related bit, and registering the input device. The pressure and coordinate axis X and Y events of the touch screen are mainly set here.

3) report data.

When a touch pen is pressed, the interrupt processing function is triggered to wake up a thread that reads and parses the touch screen coordinate data (the thread is used because the overhead of reading and parsing data is large ), finally, the coordinates are reported through the input subsystem. Similarly, use input_sync () for synchronization.

 

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.