Tslib Android reference post

Source: Internet
Author: User
Reprinted 1: Tslib ported to Android for touchscreen calibration.

Since Android doesn' t provide a calibration tool,
Tslib can be used to calibrate the touchscreen. the values obtained from ts_calibrate in pointercal file can be used in Android frameworks/services/Java/COM/Android/Server/inputdevice. java to have the correct screen coordinates.

Ts_calibrate can be run from a serial console along with Android with the proper environment variables set (these variables are supported ented in Android. mk too), the default values are:


export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CONFFILE=/system/etc/ts.conf
export TSLIB_CALIBFILE=/etc/pointercal
export TSLIB_PLUGINDIR=/system/lib
export TSLIB_CONSOLEDEVICE=/dev/tty
export TSLIB_FBDEVICE=/dev/graphics/fb0

To compile tslib for your device make a link for Bionic/libc/include/fcntl. h To bionic/libc/include/sys/fcntl. h import build/envsetup. SH and execute make or M.

To make tslib build everytime you build your android distribution copy the Android-tslib folder to Android external/folder.

Download:
Git: git clone git: // git. linuxconsulting. ro/android-tslib.git
HTTP: http://git.linuxconsulting.ro

Reprinted 2: AndroidPorting (touch screen) I found there are so far questions of touch screen aksed
Android
Engineers, I have made the wm9713 touch screen work OK, so shared my experience out. this blog page is written by English, hope all engineers can read it. hardware: PXA270, wm9713 touch screen, LCD 480x272my kernel is the offical kernel from
Android
(2.6.25), but it does not support the wm97xx touch screen. it is luck that the kernel 2.6.26 is merged the wm97xx touch screen driver. so I shoshould porting the wm97xx touch screen driver from 2.6.26 to 2.6.25. first step, diff the other touch screen drivers in drivers/input/touchscreen, I found there are almost no changes, so it is safe to copy the wm97xx drivers from 2.6.26 to 2.6.25. modify the drivers/input/touchscreen/kconfig and makefile, copy the Linux/wm97xx. h.
But there is anothor problem, the wm9713 touch screen is dependent the ac97, so the ac97 Sound Bus shoshould be configured. it is easy to complie the driver successfully. (the mainstone accelate driver does not compiled in... it is the result of each tries !) Booting the kernel, the device for touch screen can be foud in/dev/event1 (event0 for the keypad). Write a test program for touch screen: # include <stdio. h>
# Include <unistd. h>
# Include <sys/types. h>
# Include <fcntl. h>
# Include <Linux/input. h> # define ts_dev "/dev/event1" static int ts_fd =-1; static int init_device ()
{
If (ts_fd = open (ts_dev, o_rdonly) <0)
{
Printf ("error open % s/n", ts_dev );
Return-1;
} Return ts_fd;
} Int main ()
{
Int I; struct input_event data; If (init_device () <0)
Return-1; while (1)
{
Read (ts_fd, & Data, sizeof (data ));
If (data. type = ev_key)
{
Printf ("type: ev_key, event = % s, value = % d/N ",
Data. Code = btn_touch? "Btn_touch": "unkown", Data. value );
}
Else if (data. type = ev_abs)
{
Printf ("type: ev_abs, event = % s, value = % d/N ",
Data. Code = abs_x? "Abs_x ":
Data. Code = abs_y? "Abs_y ":
Data. Code = abs_pressure? "Abs_pressure ":
"Unkown", Data. value );
}
Else if (data. type = ev_syn)
{
Printf ("type: ev_syn, event = % s, value = % d/N ",
Data. Code = syn_report? "Syn_report": "unkown", Data. value );
}
Else
{Printf ("type: 0x % x, event = 0x % x, value = % d/N", Data. type, Data. Code, Data. value );
}
} Return 0;
} The test program can catch the touch screen data (X, Y, pressure), The dirver seems work OK. Run AndroidSystem, but the system does not response to the touch screen .... according to the Google search, check/dev/input/event1,/proc/bus/input/devices... all seem OK. some very important hints from the talk between two
Android
Hackers:

Some important words http://androidzaurus.seesaa.net/article/90045743.htmlAnd: "It seems
Android
Wants to know not only pressure becomes zero but also pendown becomes zero. only two lines but very precious lines. "fromhttp: // androidzaurus.seesaa.net/article/96581331.html so check my driver and test again. the test program reports that the x y coordinate is very large (350-3900 for X, 320-3750 for Y, defined in driver), but the LCD is 480x270, and the adroid use the abusolute touch screen coordinate, Which is same to LCD. calibrate shocould be done, butAndroid
Doe not do this. downloadTslib-1.4.tar.gz, compile, run the ts_calibrate, and run ts_test, the touch screen works OK. And calibrate coefficent is record in/etc/pointercal. But how to use the calibrate result
Android
? Confused for hours... I cann't change the adroid input action, so I shocould do the calibrate in my driver. ReadingTslibSource code, got the idea. I found a formula inTslib/Plugins/linear. c xtemp = samp-> X; ytemp = samp-> Y;
Samp-> X = (Lin-> A [2] +
Lin-> A [0] * xtemp +
Lin-> A [1] * ytemp)/Lin-> A [6];
Samp-> Y = (Lin-> A [5] +
Lin-> A [3] * xtemp +
Lin-> A [4] * ytemp)/Lin-> A [6];
And the Lin-> A [] is read from the/etc/pointercal. but the division "/" is hard for Linux kernel. surprised that the [6] Is 65536, and can do the/65536 by> 16. coding in wm9713 DRIVER: Drivers/input/touchscreen/wm97xx-core.c, function: static int wm97xx_read_samples (struct wm97xx * WM) define the Coeficient table, change the last variable valure from 65536 to 16.int axis_table [] = {-8360, 32,327 53552, 24,498 3,-1685240, 16 }; // from/etc/pointercal by ts_calibrate # ifdef ts_abs_xy
Int xraw, yraw, xtmp, ytmp; dev_dbg (WM-> Dev,
"Pen down: x = % x: % d, y = % x: % d, pressure = % x: % d/N ",
Data. x> 12, Data. X & 0 xfff, Data. Y> 12,
Data. Y & 0 xfff, Data. P> 12, Data. P & 0 xfff );
Xraw = (data. X & 0 xfff );
Yraw = (data. Y & 0 xfff );
Xtmp = (axis_table [2] + axis_table [0] * xraw + axis_table [1] * yraw)
> Axis_table [6];
Ytmp = (axis_table [5] + axis_table [3] * xraw + axis_table [4] * yraw)
> Axis_table [6];
Input_report_abs (WM-> input_dev, abs_x, xtmp );
Input_report_abs (WM-> input_dev, abs_y, ytmp );
# Else
Input_report_abs (WM-> input_dev, abs_x, Data. X & 0 xfff );
Input_report_abs (WM-> input_dev, abs_y, Data. Y & 0 xfff );
# Endif run the test program again, it is great that the touch screen coordinate is same to the LCD, runAndroidSystem, but the system does not response to the touch screen. Hear broken... Check driver, input_report_key... is not added according

Http://androidzaurus.seesaa.net/article/96581331.html (1) if (RC & rc_penup ){
If (WM-> pen_is_down ){
Wm-> pen_is_down = 0;
Dev_dbg (WM-> Dev, "pen up/N ");
Input_report_abs (WM-> input_dev, abs_pressure, 0 );
Input_report_key (WM-> input_dev, btn_touch, Wm-> pen_is_down );
Input_sync (WM-> input_dev); (2) input_report_abs (WM-> input_dev, abs_pressure, Data. P & 0 xfff );
Wm-> pen_is_down = 1;
Input_report_key (WM-> input_dev, btn_touch, Wm-> pen_is_down );
Input_sync (WM-> input_dev); run test program again, but can't catch the ev_key event, confused... trace the kernel source code, found some bit map shoshould be masked. and in static int wm97xx_probe (struct device * Dev) set_bit (ev_abs, Wm-> input_dev-> evbit );
Set_bit (abs_x, Wm-> input_dev-> absbit );
Set_bit (abs_y, Wm-> input_dev-> absbit );
Set_bit (abs_pressure, Wm-> input_dev-> absbit); so, the bit mask shocould be done for ev_key set_bit (ev_key, Wm-> input_dev-> evbit );
Set_bit (btn_touch, Wm-> input_dev-> keybit); run the test program, the ev_key can be catched now. run Android, touch the screen, the icon can be actived by touch... great successfully... good lucky to all android workers!

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.