Android touch screen Input System

Source: Internet
Author: User

1. Touch Screen hardware Principle

1.1 resistive touch screen

Interrupt generation. When the touch screen chip is pressed, the resistor partial pressure value changes, causing interruption. The interrupt is input to the CPU. The generation conditions are very simple, mainly including VDD And Gnd signals. Therefore, when debugging, we can measure the interrupt foot without a drive, whether there is a change in touch, the quality of the previous verification module.

1.2 capacitive touch screen

The interrupt generation is similar to the resistance screen, except that the capacitive screen is caused by the coupling capacitor formed when the human body is in contact, and the current changes.

The interface of the capacitive screen usually has a nrst signal, which facilitates the resetting of the module in the driver.

2. Linux driver

Here, the I2C interface's resistance screen is used as an example, and the coordinate value is obtained using interrupt plus polling.

2.1 register I2C Devices

Register the i2c_board_info struct. In machine_xxx_board_init (located in the arch/ARM/Mach-xxx path), type (driver name), slave address, IRQ (Interrupt pin), and platform_data are included.

Register an I2C device. Fill in the i2c_driver struct in the driver file, including driver. Name, id_table, and probe. Then call i2c_add_driver to register an I2C device.

2.2 registration interrupted

Next, we will do some other initialization work in the probe function.

Initialize a delayed work. Call init_delayed_work.

Probe device. You can use i2c_smbus_read_byte_data to read the ID register of the device. Of course, if there is no ID register, you can also read a register. If the return value is less than 0, you can think that the device does not exist.

Registration interrupted. The process is to apply for gpio (that is, the interrupt pin) --> set the gpio direction --> set the gpio to pull up (or drop down) --> apply for IRQ. The call interface here is gpio_request --> gpio_direction_input --> gpio_pull_updown --> gpio_to_irq --> request_irq.

2.3 Register the input subsystem

Allocate memory. Call input_allocate_device.

Set touch screen parameters. Call input_set_abs_params to set parameters such as abs_x and abs_y.

Register input. Call input_register_device.

2.4 calibration parameter initialization

2.5 add sysfs Interface

You can add a sysfs interface as needed, for example, to print debugging information. Call driver_create_file.

2.6 Add Level 1 sleep Processing

Level-1 sleep is the sleep policy of Android. Fill in the early_suspend struct and call the register_early_suspend interface.

Finally, initialize the chip, such as configuring the device register.

3. Android layer Processing

The driver presents the input device to the upper layer with/dev/input nodes. For touch screen input events, the android layer is processed by eventhub processing of native framwork and keyinputdevice --> keyevent of Java framework (rawinputevent --> motionevent when sliding), and reported to the application, the reporting format is onkeydown/onkeyup or ontouchevent/ontrackballevent.

Source file:

Frameworks/base/libs/UI/eventhub. cpp

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.