嵌入式Linux中TP调试笔记

论坛 期权论坛 脚本     
已经匿名di用户   2022-7-2 21:50   2628   0

触摸屏一般是通过IIC来传输触摸点的坐标给Linux内核,一般而言,其步骤是:

当人触摸触摸屏时,触摸屏会产生一个中断信号给Linux内核,内核接收到中断信号后便会通过IIC去触摸IC里读取数据,因此调试TP驱动时,应该进行下列步骤(这里我以ft6x6为例):

步骤一:先通过dmesg来查看触摸驱动是否已经成功初始化,一般而言,在init函数里应该有printk或类似的函数来进行打印来判断i2c_add_driver函数是否成功地把tp驱动添加到IIC总线上;

步骤二:使用命令

cat /proc/interrupts

查看设备的中断IO口和其他信息,一般而言,如果设备中断出发后,当TP被触摸后与之对应的IO的数值会改变,如下图:



执行两次cat /proc/interrupts,可以看到数值由0变为130了,说明其识别到了中断信号,而且其终端端口为GPIOB。

步骤三:

参看具体的中断数据,

使用命令:cat /dev/input/event0里数据,如果每点击一次TP便有数据显示表示TP已与MCU成功通信起来了。

步骤四:

使用网上的一份TP代码来查看具体的坐标:

#include <stdio.h>  
#include <linux/input.h>  
  
static int event0_fd = -1;  
struct input_event ev0[64];  
  
static int handle_event0()  
{  
    int button = 0, realx=0, realy=0, i, rd;  
    rd = read(event0_fd, ev0, sizeof(struct input_event)* 64);  
    if(rd < sizeof(struct input_event)) return 0;  
    for(i=0;i<rd/sizeof(struct input_event); i++)  
    {  
        if(EV_ABS == ev0[i].type)  
        {  
            if(ev0[i].code == 0) {  
                realx = ev0[i].value;  
            } else if(ev0[i].code == 1) {  
                realy = ev0[i].value;  
            }  
        }  
        printf("event(%d):type:%d; code:%3d; value:%3d; realx:%3d; realy:%3d\n",i,ev0[i].type,ev0[i].code,ev0[i].value,realx,realy);  
          
    }  
    return 1;  
}  
  
  
int main(void)  
{  
    int done = 1;  
    event0_fd = open("/dev/event1",02);  
    if(event0_fd <0) {  
        printf("open input device error\n");  
        return -1;  
    }  
    while (done)  
    {  
        printf("begin handle_event0...\n");  
        done = handle_event0();  
        printf("end handle_event0...\n");  
    }  
    if(event0_fd > 0)  
    {  
        close(event0_fd);  
        event0_fd = -1;  
    }  
    return 0;  
} 


分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:81
帖子:4969
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP