TI内部自带了触摸屏控制器,但是注意需要设定其初始化 修改文件arch/arm/mach-omap2/board-am335xevm.c 注释其中的部分代码,然后增加设定模拟输入,如下所示 static void tsc_init(int evm_id, int profile) { int err; lsd_dbg(LSD_DBG,"Enterboard init:%s\n",__FUNCTION__); #if 0 if (gp_evm_revision == GP_EVM_REV_IS_1_1A){ am335x_touchscreen_data.analog_input= 1; pr_info("TSC connected to betaGP EVM\n"); } else { am335x_touchscreen_data.analog_input= 0; pr_info("TSC connected to alphaGP EVM\n"); } #endif am335x_touchscreen_data.analog_input = 1; pr_info("TSC connected to beta GPEVM\n"); setup_pin_mux(tsc_pin_mux); err =am33xx_register_tsc(&am335x_touchscreen_data); if (err) pr_err("failedto register touchscreen device\n"); } 增加以下红色字体部分 /* Beaglebone Rev A3 and after */ static struct evm_dev_cfg beaglebone_dev_cfg[] = { #if 0 {tps65217_init, DEV_ON_BASEBOARD, PROFILE_NONE}, {mii1_init, DEV_ON_BASEBOARD, PROFILE_NONE}, {usb0_init, DEV_ON_BASEBOARD, PROFILE_NONE}, {usb1_init, DEV_ON_BASEBOARD, PROFILE_NONE}, {mmc0_init, DEV_ON_BASEBOARD, PROFILE_NONE}, {i2c2_init, DEV_ON_BASEBOARD, PROFILE_NONE}, #endif //{mmc0_no_cd_init,DEV_ON_BASEBOARD,PROFILE_NONE}, {mmc0_init,DEV_ON_BASEBOARD,PROFILE_NONE}, {lcdc_init, DEV_ON_BASEBOARD, PROFILE_NONE}, {evm_nand_init,DEV_ON_BASEBOARD, PROFILE_NONE}, {mii1_init, DEV_ON_BASEBOARD, PROFILE_NONE}, {usb0_init, DEV_ON_BASEBOARD, PROFILE_NONE}, {usb1_init, DEV_ON_BASEBOARD, PROFILE_NONE}, {mcasp0_init, DEV_ON_BASEBOARD, PROFILE_NONE}, {tsc_init, DEV_ON_BASEBOARD,PROFILE_NONE}, {NULL, 0, 0}, }; 然后需要注意的是kernel的menuconfig中需要配置如下: 此时编译好的内核可以支持触摸屏,系统启动的时候会出现如下的log信息 [ 1.498332]mousedev: PS/2 mouse device common for all mice [ 1.505614] input: ti-tsc-adcc as/devices/platform/omap/tsc/input/input0 [ 1.514524]omap_rtc omap_rtc: rtc core: registered omap_rtc as rtc0 [ 1.521516] i2c/dev entries driver [ 1.525701]Linux video capture interface: v2.00 然后在/dev目录下可以看到event0设备,可以这么测试cat /dev/event0 此时敲击触摸屏会显示如下信息
因为终端下仅仅能接受ascii码,因此是乱码。 然后我们输入命令校准 [root@YuGe-AM1808 /]#ts_calibrate xres = 800, yres = 480 Took 22 samples... Top left : X = 3873 Y = 3558 Took 12 samples... Top right : X = 461 Y = 3537 Took 9 samples... Bot right : X = 450 Y = 608 Took 14 samples... Bot left : X = 3904 Y = 705 Took 13 samples... Center : X = 2186 Y = 2147 844.823242 -0.203881 -0.000673 512.416016 0.002273 -0.131387 Calibration constants: 55366336 -13361 -44 33581696 148-8610 65536 [root@YuGe-AM1808 /]#ls 然后运行您的qt应用程序 [root@YuGe-AM1808 /]#./pru-8uart-test –qws 此时可以看到触摸屏可以使用了 经过测试发现触摸屏稍微有些抖动,现在我们对其进行改进,当然根据需要可以不做修改,这个根据个人实际感觉。 修改文件drivers/input/touchscreen/ti_tscadc.c 修改其中的宏定义,如下所示 //#defineTSCADC_STEPCONFIG_SAMPLEDLY 0x88 #defineTSCADC_STEPCONFIG_SAMPLEDLY 0xF8 修改函数static irqreturn_t tscadc_interrupt(int irq, void,增加如下红色字体部分 unsigned int val_x = 0, val_y = 0, diffx = 0,diffy = 0; unsigned int z1 = 0, z2 = 0, z = 0; // nmyadd #if 1 static unsigned int temp[3][3]; static unsigned int temp_cnt = 0; static unsigned int temp_all[3] = {0,0,0}; #endif status = tscadc_readl(ts_dev,TSCADC_REG_IRQSTATUS); 然后注释掉如下红色代码部分,如下所示 if (pen == 0) { #if 0 if ((diffx < 15)&& (diffy < 15) &&(z <= MAX_12BIT)) { input_report_abs(input_dev,ABS_X, val_x); input_report_abs(input_dev,ABS_Y, val_y); input_report_abs(input_dev,ABS_PRESSURE, z); input_report_key(input_dev,BTN_TOUCH, 1); input_sync(input_dev); } #endif 在紧跟上面的代码后面增加如下红色字体代码部分 if((diffx < 30) && (diffy < 30) &&(z <= MAX_12BIT)) { // nmy modify temp[temp_cnt][0]= val_x; temp[temp_cnt][1]= val_y; temp[temp_cnt][2]= z; temp_all[0] +=temp[temp_cnt][0]; temp_all[1] +=temp[temp_cnt][1]; temp_all[2] +=temp[temp_cnt][2]; temp_cnt++; if(temp_cnt >=3) { temp_all[0]= temp_all[0]/3; temp_all[1]= temp_all[1]/3; temp_all[2]= temp_all[2]/3; #if 0 printk("x=%d,y=%d,p=%d\n",temp_all[0],temp_all[1],temp_all[2]); #endif input_report_abs(input_dev,ABS_X, temp_all[0]); input_report_abs(input_dev,ABS_Y, temp_all[1]); input_report_abs(input_dev,ABS_PRESSURE, temp_all[2]); input_report_key(input_dev,BTN_TOUCH, 1); input_sync(input_dev); temp_cnt =0; temp_all[0]= 0; temp_all[1]= 0; temp_all[2]= 0; } } 此时编译好uImage,就可以运行了,此时就可以看到触摸屏基本不抖动了,这里仅仅是取3次的平均数,很简单,当然欢迎更好的算法。
欢迎沟通交流。
|