您的位置:首页 > 运维架构 > Linux

arm9+linux s3c2440 触摸屏驱动移植

2016-07-11 10:03 417 查看
----------------------------------------------------------------------------------------
                                    主机操作系统:centos 6.7

                                    交叉编译器版本:arm-linux-gcc-4.5.4

                                    开发板平台:fl2440

                                    linux内核版本:Linux-3.0

                                    Author:  shaocongshuai <916962705@qq.com>

-----------------------------------------------------------------------------------------------------------------

        触摸屏(touch screen)又称为“触控屏”、“触控面板”,是一种可接收触头等输入讯号的感应式液晶显示装置,当接触了屏幕上的图形按钮时,屏幕上的触觉反馈系统可根据预先编程的程式驱动各种连结装置,可用以取代机械式的按钮面板,并借由液晶显示画面制造出生动的影音效果。触摸屏作为一种最新的电脑输入设备,它是目前最简单、方便、自然的一种人机交互方式。

一、内核配置

Device Drivers  --->

Input device support  --->

[*]   Touchscreens  --->

              <*>   Samsung S3C2410/generic touchscreen input driver 
二、修改配置文件
[shaocongshuai@localhost linux-3.0.2]$ vim arch/arm/mach-s3c2440/mach-smdk2440.c

.....
 51 #include <plat/ts.h> //添加头文件

....
135  /*  Touch Screen driver info add by shaocongshuai 2016.07.11 */

136 static struct s3c2410_ts_mach_info smdk2440_ts_cfg __initdata = {

137         .delay = 10000,             

138         .presc = 49,                

139         .oversampling_shift = 2,    

140 }; 

....
182 static struct platform_device *smdk2440_devices[] __initdata = {

183     &s3c_device_ohci,

184     &s3c_device_lcd,

185     &s3c_device_wdt,

186     &s3c_device_i2c0,

187     &s3c_device_iis,

188     &s3c_device_dm9000,

189     &uda1340_codec,

190     &s3c24xx_uda134x,

191     &samsung_asoc_dma,

192     &s3c_device_adc,    /*   modify by shaocongshuai */

193     &s3c_device_ts,    /*    modify by shaocongshuai  */

194 };  

.....
204 static void __init smdk2440_machine_init(void)

205 {

206     s3c24xx_fb_set_platdata(&smdk2440_fb_info);

207     s3c_i2c0_set_platdata(NULL);

208     s3c24xx_ts_set_platdata(&smdk2440_ts_cfg);
/*  Add Touch Screen info by shaocongshuai */ 

209     platform_add_devices(smdk2440_devices, ARRAY_SIZE(smdk2440_devices));  

210     smdk_machine_init();                                                   

211 }

.....
[shaocongshuai@localhost linux-3.0.2]$ vim drivers/input/touchscreen/s3c2410_ts.c

......
128             input_report_key(ts.input, BTN_TOUCH, 1);

129             input_report_abs(ts.input, ABS_PRESSURE, 1);
/*   Add by shaocongshuai */

130             input_sync(ts.input); 

.....
143         input_report_key(ts.input, BTN_TOUCH, 0);        
      

144         input_report_abs(ts.input, ABS_PRESSURE, 0);
/*   Add by shaocongshuai  */

145         input_sync(ts.input);

......
319     //ts.input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);

320     ts.input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) | BIT(EV_SYN); /*   Modify by  shaocongshuai */

321     ts.input->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); 

322     input_set_abs_params(ts.input, ABS_X, 0, 0x3FF, 0, 0); 

323     input_set_abs_params(ts.input, ABS_Y, 0, 0x3FF, 0, 0);
                                     

324     input_set_abs_params(ts.input, ABS_PRESSURE, 0, 1, 0, 0); /*
  Add by shaocongshuai */

325                                                                           

326     ts.input->name = "S3C24XX TouchScreen";  

.....
三、编译内核下载到开发板上
内核打印如下信息:
.....
samsung-ts s3c2440-ts: driver attached, registering input device
input: S3C24XX TouchScreen as /devices/virtual/input/input0
     ......

~ >: cd dev/

/dev >: ls

......
dsp                 ptysb               tty18          
    ttyrf
event0              ptysc               tty19               ttys0 (多出了event0
    设备)

fb0                 ptysd               tty2                ttys1

....

说明已经移植成功了
四、编写测试程序测试
[shaocongshuai@localhost ~]$ /opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-gcc
ts.c -o ts

~ >: tftp -gr ts 192.168.1.93

~ >: chmod 777 ts 

~ >: ./ts

begin handle_event0...

当触摸屏幕会出现如下信息
begin handle_event0...

event(0):type:3; code:  0; value:476; realx:476; realy:  0

event(1):type:3; code:  1; value:538; realx:476; realy:538

event(2):type:1; code:330; value:  1; realx:476; realy:538

event(3):type:3; code: 24; value:  1; realx:476; realy:538

event(4):type:0; code:  0; value:  0; realx:476; realy:538

end handle_event0...

begin handle_event0...
测试代码ts.c
#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/event0",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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: