[Beijing Xunwei] i.MX6ULL Terminator Linux INPUT subsystem experimental operation test

1 Compile the driver

A Makefile file is needed like the driver test program in the previous chapter, but the value of obj-m is changed to key_input.o. The contents of the Makefile file are as follows:

KERNELDIR := /home/topeet/kernel/linux-imx-rel_imx_4.1.15_2.1.0_ga
CURRENT_PATH := $(shell pwd)
obj-m := key_input.o

build: kernel_modules
kernel_modules: 
        $(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) modules
clean:
        $(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) clean

First, we enter two commands in the terminal (set two environment variables):

export ARCH=arm
export CROSS_COMPILE=arm-linux-gnueabihf-

Then execute the "make" command to compile the module, and the key_input.ko module file is generated after the compilation is completed.

2 Compile the application test program

Enter the following command to compile the application test program: After the
arm-linux-gnueabihf-gcc -o key_input_test key_input_test.c
compilation is complete, the key_input_test executable file will be generated.

3 Run the test

Start the development board, copy the compiled key_input.ko module file and key_input_test application to the /lib/modules/4.1.15 directory (check whether there is "/lib/modules/4.1.15" in the root file system of the development board Directory, if you don’t have one, you need to create it yourself. The development board uses the busybox file system provided in the CD data, and the CD data "i.MX6UL Terminator CD data\08_development board system image\03_file system image\ 01_Busybox file system” directory). Before loading the driver module files, take a look at what files are in the /dev/input directory. The result is shown in Figure 3.1:
Insert picture description here

Figure 3.1

There are many event events in the /dev/input directory, and then enter the following command to load the module:

depmod
modprobe key_input

After the driver is loaded successfully, let's take a look at the files in the /dev/input directory. The result is shown in Figure 3.2:
Insert picture description here

Figure 3.2

It can be seen that there is an additional event3 file, so /dev/input/event3 is the device file corresponding to the driver we registered. Then the key_input_test application obtains the input event information by reading the /dev/input/event3 device file. The test command is as follows:
./key_input_test /dev/input/event3
Press the key KEY0 on the development board, there is a phenomenon in Figure 3.3:
Insert picture description here

Figure 3.3

It can be seen that when we press or release the key on the development board, the corresponding content will be output on the terminal, prompting us which key was pressed or released. In the Linux kernel, KEY_0 is 11.
In addition, we can also test the drive without using the key_input_test application. You can directly use the hexdump command to view the contents of the /dev/input/event3 file, and enter the following command:
```hexdump /dev/input/event3````Press
development The button KEY0 on the board has the phenomenon shown in Figure 3.4:
Insert picture description here

Figure 3.4

The above picture is the original event data value of input_event type, expressed in hexadecimal, the meaning of these original data is as follows:

/*****************input_event 类型********************/ 
/* 编号 */  /* tv_sec */  /* tv_usec */  /* type */  /* code */  /* value */ 
0000000     1029 5d5e   2c16 0008     0001       000b     0001 0000
0000010     1029 5d5e   2c16 0008     0000       0000     0000 0000
0000020     1029 5d5e   761f 000a     0001       000b     0000 0000
0000030     1029 5d5e   761f 000a     0000       0000      0000 0000

type is the event type, the EV_KEY event value is 1, and the EV_SYN event value is 0. Therefore, the first line represents the EV_KEY event, and the second line represents the EV_SYN event. code is the event code, that is, the key number. The key number of KEY_0 is 11, and the corresponding hexadecimal number is 0xb. Therefore, the first line represents the key event of KEY_0, and the last value is the key value. 1 means press, which is 0 means release.
To sum up, the meaning of the original event value in the above figure is as follows:
Line 1, the key press (KEY_0) event.
Line 2, EV_SYN synchronization event, because every time a key event is reported, an EV_SYN event must be reported synchronously
.
In line 3, the key (KEY_0) release event.
Line 4, EV_SYN synchronization event, same as line 2.

Insert picture description here

Guess you like

Origin blog.csdn.net/BeiJingXunWei/article/details/112213266