Android add key value and report from driver to upper layer

Reprinted: https://blog.csdn.net/weixin_43854010/article/details/94390803

Android add key value and report from driver to upper layer

Platform: RK3288

OS:Android7.1

Add key value in kernel part:

1. Add key-value properties in dts (kernel / arch / arm / boot / dts / rk3288-android.dtsi), which can be modeled after the power button configuration

 

Because the key value operation we use is triggered by gpio, it is configured as gpio-key.
Linux, code key code can be selected by viewing the kernel custom key code. Defined under kernel / include / uapi / linux / input-event-codes.h.

 

 

 

Because there are many key values, only a part is listed. When defining the key code, be careful not to duplicate the key code currently in use. If you are not sure which key codes are already used, you can add a custom key code in this file.
After adding the key-value attribute in dts, you need to do dts parsing in the driver (mine is in /kernel/drivers/input/keyboard/rk_reys.c):

 

 

If the button needs to be triggered by an interrupt, you can request an interrupt for this button:

 

 

Key value reporting:
1. Register input events: Register input events
to the kernel through the input_register_device () function.
2. Input event reporting: The
input event reporting is reported through the input_event () or input_report_key () function.

Introduction of input_event () function:
function prototype:

 

 

Parameter introduction:
struct input_dev * dev: the event to be reported
unsigned int type: the reported event type (defined in the previous input-event-codes.h file)
unsigned int code: the reported key code
int value: the reported key value

Examples of use:

 

 

Note: To report key events, input_event () must first report 1 (meaning pressed), and then report 0 (meaning bounce). You cannot report 1 or 0 independently.

After the kernel part is added, you can use the getevent command to confirm whether the event is reported successfully.

After the kernel part confirms that the debugging is successful, you need to report the key value to the upper layer:
1. Modify the key layout mapping file, all files ending in .kl, you can
view the layout currently in use by our system through the cat bus / input / devices command Which file is it.
I am using /device/rockchip/common/rk29-keypad.kl layout file
 

 

Adding key 117 F1 after this means that the 117 key value reported by the kernel is mapped to the key value of the system. The key value of the F1
system is defined under frameworks / base / core / java / android / view / KeyEvent.java.

After adding, you can add printing information in frameworks / base / services / core / java / com / android / server / policy / PhoneWindowManager.java to check whether the key value is reported successfully.

 

 The upper APK can intercept the key value by calling the interface in frameworks / base / core / java / android / view / KeyEvent.java

 

Guess you like

Origin www.cnblogs.com/cyqx/p/12699220.html