One of Linux touch screens: Principle and APK debugging

Source: Internet
Author: User

(1) Principle: This article introduces the driver principle of Linux touch screen device based on the technical level. A touch screen uses an adconverter module to convert the touch signal on the screen into a digital signal. A touch screen is commonly used with a four-wire resistor. When a touch is made, the function module converts the analog signal to a digital signal, that is, the adconverter. In Linux, these numbers are usually read through interruptions. When the screen is touched, interruption occurs. in Linux, the converted numbers are read through the serial port or I2C, SPI or internal data channel, and then the values are transmitted to the input layer. When the TP enters sleep, the interruption of the CTP should be disabled to prevent accidental interruption and cause exceptions.

Why check? Cause A: the touch screen and LCD display are two different physical devices. LCD processing pixels. For example, the resolution we usually call is 600x800. Actually, the width of each line is 600 pixels, and the height is 800 pixels, the data processed by the touch screen is the physical coordinate of the point, which is collected by the touch screen controller. A certain degree of conversion is required between the two. B. When the touch screen is installed, some errors, such as rotation and translation, are inevitable, which also need to be corrected. C. Again, the materials of the resistive touch screen are different and their parameters will change over time. Therefore, regular correction is required (only one correction is required for the capacitive touch screen ).

The common verification program is tslib. After the tslib verification is passed, the application reads the values in tslib and can locate the values accurately. Correction Principle: Touch Screen correction process is generally: display a certain mark (such as "+") in several different positions on the screen in sequence, click these marks with a touch pen to complete the correction. If Pt (x, y) represents a point on the touch screen and PL (x, y) represents a point on the LCD, the correction result is a conversion matrix m, make pL (x, y) = m · Pt (x, y ). Finally, assume that the coordinates of the three LCD points are (xl1,
Yl1), (xl2, yl2), (xl2, yl2), the three points corresponding to the touch screen are (xt1, yt1), (xt2, yt2), (xt3, yt3), the two equations are:

In this way, the touch screen correction is actually to solve the above equations and obtain six coefficients: A, B, C, D, E, F. The above equations can be solved according to the Klein rule. After six coefficients are obtained, all the coordinates obtained through the touch screen are brought into formula (1) to obtain the coordinates represented by pixels on the LCD.

In fact, at school time, the captured touch screen coordinate has a certain error, that is, to collect three sets of coordinate points, calculate a, B, c, d, e, f, the results are different. In ts_calibrate of tslib, five group coordinate points are collected. For details about the code, see perform_calibration () in ts_calibrate.c (). In general, the more points collected, the higher the accuracy of correction. Only when there are too many collection points will be redundant, which has little effect on the accuracy of correction, but increases the computing time.

The process is as follows:

Coordinate Conversion for Android: this implementation is a linear transformation using 7 Parameters
(A, B, C, D, E, F and S) to transform the device coordinates (XD, YD) into screen coordinates (XS, ys) using the following equations:

S * xs = A * XD + B * YD + c
S * ys = D * XD + E * YD + F
Where: XS, YS: LCD coordinates; XD, YD: Touch screen coordinates.

(2) debugging: Touch screen positioning is always inaccurate, there will be offset. After a period of debugging, my colleagues solved the problem. The solution is as follows:

1. Principle: Calibrate: Download tslibonandroid and use it to display the five coordinates on the screen. Click these five coordinates to obtain the required seven parameters for coordinate transformation.
Process: icon (APK)-> JNI-> *. So (tslib)-> Generate correction parameters (A0 ~ A6 ). The driver must be notified when the correction is complete or when the correction fails. The Touch driver needs to read the correction parameters after each power-on. If the read fails, the default parameters are used.

2. Changes:

-In $ kernel/driver/input/touchscreen/s3c-ts.c, add a function with the upper-layer cupcake interface.
-Change $ kernel/dirver/Char/vt_ioctl.c
-Add the entire calibrate folder to $ cupcake/development/(implemented by Java icon and JNI). This folder generates an Android Application APK.
-Add the entire tslibonandroid folder to $ cupcake/external/to generate correction parameters)
-In $ cupcake/vendor/SEC/smdk6410/init. RC, modify the attribute permissions of files related to touch screen.

Compile the complete kernel and cupcake files and paste them into the template. Cupcake will generate a corresponding APK file under out/target/product/smdk6410/obj/apps/calibrate_intermediates, rename the APK file and install it on the platform, click to run the calibration process similar to that of wince.

3. Procedure:

A. Click APK to start running the program. In Calibrate. Java: oncreate-> tsmainloop. At the same time:

Public native void tsmainloop (); // JNI function declaration

System. loadlibrary ("calibrate-JNI"); // libcalibrate-jni.o

B. The C function prototype of JNI is defined in com_android_calibrate_calibrate.cpp:

# Include "../.../../external/tslibonandroid/tests/calibratejni. H" // The folder where the file is located is used as the current directory to go back to Layer 3 and enter other subdirectories

Static void tsmainloop (jnienv * ENV, jobject object)
{
Ts_main ();
}

In this file, the method and class are also defined:

Static const char * classpathname = "com/Android/calibrate"; // point to the class called by this CPP

Static jninativemethod methods [] = {
{"Tsmainloop", "() V", (void *) tsmainloop },
};

Complete JNI registration.

C. Complete the tslib process in ts_calibrate.c under the external/tslibonandroid/tests path as follows:

# Define tslib_tsdevice "/dev/input/event1" // input device name allocated to ts by the kernel
# Define device_name "/dev/myts" // The Name Of The ts character device to be accessed
# Define tslib_calibfile "/system/etc/pointercal"
# Define ts_pointercal "/system/etc/pointercal" // write 7 parameters to the final pointercal File

# Define tslib_conffile "/system/etc/tslib/ts. conf" // configuration file in tslib

Typedef struct {
Int X [5], xfb [5]; // touch screen parameters in the X direction, LCD Parameters
Int y [5], yfb [5]; // touch screen parameter in Y direction, LCD Parameter
Int A [7]; // store the seven parameters
} Calibration;

Ts_main ()

{

Calibration Cal;

Char cal_buffer [256];

Char buffer [5] = "OK ";
Int FD = open ("/dev/myts", o_rdwr); // open the ts character device defined by the kernel and write OK characters

Write (FD, buffer, 2 );
Close (FD );

 

Struct tsdev * Ts = ts_open (getenv ("tslib_tsdevice"), 0) // open the kernel ts Device

Ts_config (TS); // read ts. conf and configure TS

Open_framebuffer (); // open the display device and prepare for drawing

Put_string_center (xres/2, yres/4, "tslib calibration utility", 1); // place a string in the center of the screen
Put_string_center (xres/2, yres/4 + 20, "Touch crosshair to calibrate", 2); // indicates that the program is running.

Clearbuf (TS); // clear TS

 

Get_sample (TS, & Cal, 0, 50, 50, "top left ");
Get_sample (TS, & Cal, 1, xres-50, 50, "Top right ");
Get_sample (TS, & Cal, 2, xres-50, yres-50, "BOT right ");
Get_sample (TS, & Cal, 3, 50, yres-50, "BOT left"); // read the sample value in the upper left, upper right, lower right, lower left, and middle order, press
Get_sample (TS, & Cal, 4, xres/2, yres/2, "center"); // The index numbers 0, 1, 2, 3, 4 are stored in the Cal variable.

If (m_m_calibration (& Cal) // If the verification is successful

{

Cal_fd = open (getenv ("tslib_calibfile"), o_creat | o_rdwr, s_irusr | s_iwusr | s_irgrp | s_iroth );

// Open the system's pointercal File

Sprintf (cal_buffer, "% d", Cal. A [1], Cal. A [2], Cal. A [0], Cal. A [4], Cal. A [5], Cal. A [3], Cal. A [6]);

// Combine the seven parameters of Cal into the cal_buffer variable.

Write (cal_fd, cal_buffer, strlen (cal_buffer) + 1); // write seven parameters to the pointercal file.

}

Strcpy (buffer, "end ");
FD = open ("/dev/myts", o_rdwr );

Printf ("FD: % d/N", FD );
Write (FD, buffer, 3 );

Close (FD); // write end to myts

}

========================================================== ========================================================== ================================

When debugging the TP driver of melfas, it is found that I2C speed is a key factor. Either too fast or too slow has a problem, and 80 KB is the same. Otherwise, a strange phenomenon may occur, such as a point-and-multiple response and report data out of range.

========================================================== ========================================================== ================================

If the Android system of the horizontal screen turns 90 degrees to a vertical screen, this can be adjusted by the software. However, the origin of TP (0, 0) will not change (this is determined by the firmware). Although the start point of TP must be different for landscape and landscape screens, however, you can solve this problem by modifying the reported data. Method:

Reporting Function

Input_report_abs (TPD-> Dev, abs_mt_position_x, X );
Input_report_abs (TPD-> Dev, abs_mt_position_y, Y); // firmware of 800x133

Changed:

Input_report_abs (TPD-> Dev, abs_mt_position_x, 480-y );
Input_report_abs (TPD-> Dev, abs_mt_position_y, X );

Implements proxy of TP's XY inversion.

Corresponding, the TP virtual key area should also be reversed, that is, the value of each button's XY point. You may also need to adjust the value.

 

Http://blog.csdn.net/besthyq/archive/2007/10/01/1808762.aspx ()

Related Article

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.