12. Input subsystem and touch¶
The touch screen belongs to the device of the input input subsystem, and more devices based on the input subsystem can also be analyzed by the method in this chapter.
12.1. Input subsystem¶
The input subsystem is a unified driver framework provided by Linux for input devices. The driving methods of input devices such as keys, keyboards, touch screens, and mice are similar. Input devices driven by the input subsystem can be submitted to the kernel through a unified data structure, which includes input time, type, code, and specific Key values or coordinates, the kernel passes to the user space through the file interface in the /dev/input directory.
The “Documentation/input” directory of the Linux kernel source contains instructions related to the input subsystem.
This chapter uses touch to explain the use of the input subsystem.
12.1.1. Input event directory¶
The information contained in the event file uses the kernel event data structure to record the content. When other programs use it, the read content needs to be formatted and converted according to the data structure. The definition of the data structure is as follows.
1 2 3 4 5 6 | struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
|
time: This variable is used to record the timestamp when the event was generated.
type: Enter the event type for the device. The default types commonly used by the system are EV_KEY, EV_REL and EV_ABS, which are respectively used to represent key state change events, relative coordinate change events and absolute coordinate change events. In particular, EV_SYN is used to separate events and has no special meaning. For related enumeration values, please refer to the kernel file include/uapi/linux/input-event-codes.h.
code: An event code, which represents an event in a more precise manner. For example, in the EV_KEY event type, the value of code is often used to indicate a specific key on the keyboard, and its value ranges from 0 to 127. For example, key Q corresponds to KEY_Q, and the value of this enumeration variable is 16. If the mouse is selected, the code of the evtest output content has ABS_X/ABS_Y respectively, indicating that the X or Y coordinates are reported.
value: The value of the event. For EV_KEY event type, when the key is pressed, the value is 1; when the key is released, the value is 0. If the mouse is selected, in the content output by evtest, the value value in the ABS_X event type represents the X coordinate, and the value value in the ABS_Y type represents the Y coordinate.
12.2. evtest¶
When using the screen, please make sure that the connection of the screen is correct. If the screen is not connected, there will be input devices, but no data will be generated.
First use the evtest command to obtain the driver device of the screen, and then select our device, taking lubancat1 as an example.
1 2 3 4 5 6 7 8 9 | root@lubancat:~# evtest
No device specified, trying to scan all of /dev/input/event*
Available devices:
/dev/input/event0: fdd70030.pwm
/dev/input/event1: rk805 pwrkey
/dev/input/event2: Goodix Capacitive TouchScreen
/dev/input/event3: adc-keys
/dev/input/event4: rk-headset
Select the device event number [0-4]:
|
You can see that “Goodix Capacitive TouchScreen” is our touch screen.
Its drive device is located at /dev/input/event2
Input ‘2’
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | Select the device event number [0-4]: 2
Input driver version is 1.0.1
Input device ID: bus 0x18 vendor 0x416 product 0x38f version 0x1060
Input device name: "Goodix Capacitive TouchScreen"
Supported events:
Event type 0 (EV_SYN)
Event type 1 (EV_KEY)
Event code 125 (KEY_LEFTMETA)
Event code 330 (BTN_TOUCH)
Event type 3 (EV_ABS)
Event code 0 (ABS_X)
Value 0
Min 0
Max 719
Event code 1 (ABS_Y)
Value 0
Min 0
Max 1279
Event code 47 (ABS_MT_SLOT)
Value 0
Min 0
Max 4
Event code 48 (ABS_MT_TOUCH_MAJOR)
Value 0
Min 0
Max 255
Event code 50 (ABS_MT_WIDTH_MAJOR)
Value 0
Min 0
Max 255
Event code 53 (ABS_MT_POSITION_X)
Value 0
Min 0
Max 719
Event code 54 (ABS_MT_POSITION_Y)
Value 0
Min 0
Max 1279
Event code 57 (ABS_MT_TRACKING_ID)
Value 0
Min 0
Max 65535
Properties:
Property type 1 (INPUT_PROP_DIRECT)
Testing ... (interrupt to exit)
|
After input, the basic input information will be printed out, and we can obtain the basic information of the touch screen based on this information.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #When I click on the screen, I can see the following information.
Testing ... (interrupt to exit)
vent: time 1661236971.556728, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 2
vent: time 1661236971.556728, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 370
vent: time 1661236971.556728, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 684
vent: time 1661236971.556728, type 3 (EV_ABS), code 48 (ABS_MT_TOUCH_MAJOR), value 50
vent: time 1661236971.556728, type 3 (EV_ABS), code 50 (ABS_MT_WIDTH_MAJOR), value 50
vent: time 1661236971.556728, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
vent: time 1661236971.556728, type 3 (EV_ABS), code 0 (ABS_X), value 370
vent: time 1661236971.556728, type 3 (EV_ABS), code 1 (ABS_Y), value 684
vent: time 1661236971.556728, -------------- SYN_REPORT ------------
vent: time 1661236971.629280, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
vent: time 1661236971.629280, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
vent: time 1661236971.629280, -------------- SYN_REPORT ------------
|
Line 9: Indicates that a key was pressed.
Lines 10 and 11: It means that the position where I press the screen is x_370, y_684.
Lines 12 and 15: Indicates that the screen has reported 2 complete data.
Line 14 means: the button is released.
Other lines are related to multi-touch, as well as the size of the touch range, strength, etc., If you want to know more, you can go to Baidu or test and explore by yourself. I won’t talk too much here.