Analysis of MSM8909 + Android5.1.1 keyboard driver
MSM8909 + Android5.1.1 keyboard driver ------ Overview
The SN7326 keyboard extension chip with smart finger scanning can read the value of its status register through the I2C interface to know whether it is a single button or multiple buttons. You can know which button is pressed. Then the keyboard driver calls input_event () to report the linux scan code, such as KEY_RIGHT, and then passes it to the android framework layer. The process is as follows:
Figure 1
The following describes how to implement a keyboard driver.
1. Input subsystem
Linux input devices include buttons, keyboards, touch screens, mouse, and joystick. They are character devices, and the Linux kernel abstracts the commonality of these devices, simplified driver development creates an input subsystem. The Input subsystem consists of three parts: the Input Core, the driver layer, and the event processing layer (EventHandler. An input event, such as moving the mouse, pressing the keyboard, and moving joystick
Input driver-> Input core-> Eventhandler-> userspace arrives at the user space and passes it to the application.
Figure 2
In addition to the input driver, other kernels have been written and basically do not need to be modified. Therefore, we need to write an I2C input driver.
2. Linux kernel I2C Device Driver
Because we use the sn7326 Chip Based on I2C interface to scan keys, we need to write the I2C device driver.
Linux Kernel I2C device drivers include Layer 3 [10]: I2C bus driver (I2C core), I2C controller driver (I2C adapter), and I2C driver (I2C driver ). The I2C bus driver manages the I2C bus, controllers, and device drivers. This part of the code is a common part, and the Linux kernel has been improved and does not need to be modified. The I2C controller driver is related to hardware. It mainly constructs a data structure with the I2C bus layer interface, and registers a controller with the I2C bus through the interface function. At the same time, the I2C controller interrupt processing function is implemented to complete the realization of the specific functions of the I2C device. The I2C Device Driver constructs a data structure that interfaces with the I2C bus layer, and registers an I2C device driver with the I2C bus layer through the interface function. At the same time, construct a data structure with the user-layer interface, and register a kernel-type device with the kernel through the interface function.
Here we want to develop an I2C device driver.
3. Key hardware code, Linux scan code, and android keyboard code
3.1 Key hardware code
The hardware code is my name. It refers to the encoding value of the initial key ID when the key is pressed. This is related to the specific key design and the design of the keyboard extension IC chip, such as sn7326.
Figure 3
The ing table here is the hardware code value.
3.2Linux scan code
The scan code is the code value specified in the LinuxInput system, such as the key value of each key on the PC keyboard. All are numbers. Enter the command on the device and press the key to detect the scan Code for each key.
The Linux scan code is \ kernel \ include \ uapi \ linux \ input. h definition, such as:/** Keys and buttons ** Most of the keys/buttons are modeled after usb hut 1.12 * (see http://www.usb.org/developers/hidpage ). * Abbreviations in the comments: * AC-Application Control * AL-Application Launch Button * SC-System Control */# define KEY_RESERVED 0 # define KEY_ESC 1 # define KEY_1 2 # define KEY_2 3 # define KEY_3 4 # define KEY_4 5 # define KEY_5 6 # define KEY_6 7 # define KEY_7 8 # define KEY_8 9 # define KEY_9 10 # define KEY_0 11
3.3Android keyboard code
Android also defines a set of codes, called a keyboard code. Two sets of codes are matched by one/system/usr/keylayout. Sn7326.kl is used here. (If there is no other *. kl, It is the default qwerty. kl)
/Frameworks/base/data/keyboards/Generic. kl definition, for example:
## Generic key layout file for fullalphabetic US English PC style external keyboards.## This file is intentionally very genericand is intended to support a broad rang of keyboards.# Do not edit the generic key layout tosupport a specific keyboard; instead, create# a new key layout file with the requiredkeyboard configuration.# key 1 ESCAPEkey 2 1key 3 2key 4 3key 5 4key 6 5key 7 6key 8 7key 9 8key 10 9key 11 0