摘要:注:目前市面上很多6410开发板都存在触摸屏抖动的问题,tiny6410也不例外。友好的解决方案是使用一线触摸,即在LCD板上,一台单片计算机控制ADS7846芯片的AD转换,然后通过单个总线与6410通信数据。然而,我没有触摸板,所以我开始将ADS7846驱动程序移植到tiny6410。简介:有些人可能会问,6410的触摸屏为什么会抖动,是过滤做得不好,还是硬件布线是原因?是原装硬件吗
要:
目前,市面上很多6410开发板都存在触摸屏抖动的问题,tiny6410也不例外,友善的解决方法是采用一线触摸,即在LCD板上,用一个单片机控制ADS7846芯片AD转换,再将数据通过单总线的方式与6410通讯。可是,我这里没有一线触摸板,于是就开始移植ADS7846驱动到tiny6410。
介绍:
可能有人会问,6410的触摸屏为什么会抖动呢,是不是滤波没做好,或者是硬件走线的原因?是不是硬件的原因,我无法验证。我尝试过通过滤波来改善,但效果一般。不说别的,我在单独测试AD的时候,发现在输入不变的情况下,AD采样的跳幅最大达到25(0~1024范围),可见,跳动还是很大的,这样的情况下,即使再滤波也只是浪费时间。
mini6410-ts.c触摸屏驱动见:
先说说我的硬件:
TS_PEN ----- GPN9 EINT9
TS_MISO ---- GPC0 MISO0
TS_MOSI ---- GPC2 MOSI0
TS_SCK ----- GPC1 SCK0
TS_CS ----- GPC3 CS0
这些端子在核心板的CON1上可以找到,我这里是用的IO模拟的SPI。
下面的开始介绍移植的过程,代码,我在下面会全部帖出来,里面注释也很详细,一般都能看明白。
1、复制/opt/FriendlyARM/mini6410/linux-2.6.38/drivers/input/touchscreen/mini6410-ts.c为mini6410-ads7846.c。
修改后,如下:
001 | /* linux/drivers/input/touchscreen/s3c-ts.c |
003 |
* This program is free software; you can redistribute it and/or modify |
004 |
* it under the terms of the GNU General Public License as published by |
005 |
* the Free Software Foundation; either version 2 of the License, or |
006 |
* (at your option) any later version. |
008 |
* This program is distributed in the hope that it will be useful, |
009 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
010 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
011 |
* GNU General Public License for more details. |
013 |
* You should have received a copy of the GNU General Public License |
014 |
* along with this program; if not, write to the Free Software |
015 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
017 |
* a misc driver for mini6410 touch screen |
020 |
* Based on following software: |
022 |
** Copyright (c) 2004 Arnaud Patard <arnaud.patard@rtp-net.org> |
023 |
** iPAQ H1940 touchscreen support |
027 |
** 2004-09-05: Herbert Potzl <herbert@13thfloor.at> |
028 |
** - added clock (de-)allocation code |
030 |
** 2005-03-06: Arnaud Patard <arnaud.patard@rtp-net.org> |
031 |
** - h1940_ -> s3c24xx (this driver is now also used on the n30 |
033 |
** - Debug messages are now enabled with the config option |
034 |
** TOUCHSCREEN_S3C_DEBUG |
035 |
** - Changed the way the value are read |
036 |
** - Input subsystem should now work |
037 |
** - Use ioremap and readl/writel |
039 |
** 2005-03-23: Arnaud Patard <arnaud.patard@rtp-net.org> |
040 |
** - Make use of some undocumented features of the touchscreen |
043 |
** 2006-09-05: Ryu Euiyoul <ryu.real@gmail.com> |
044 |
** - added power management suspend and resume code |
046 |
* 2011-6-23: ADS7846触摸屏驱动程序 by liu_xf |
049 |
* 2011-6-29 改进滤波,并将AD连续转换8次的间隔缩小了 |
052 | #include <linux/errno.h> |
053 | #include <linux/kernel.h> |
054 | #include <linux/module.h> |
055 | #include <linux/slab.h> |
056 | #include <linux/input.h> |
057 | #include <linux/init.h> |
058 | #include <linux/serio.h> |
059 | #include <linux/delay.h> |
060 | #include <linux/platform_device.h> |
061 | #include <linux/clk.h> |
063 | #include <linux/poll.h> |
064 | #include <linux/irq.h> |
065 | #include <linux/interrupt.h> |
066 | #include <linux/cdev.h> |
067 | #include <linux/miscdevice.h> |
069 | #include <asm/uaccess.h> |
072 | #include <mach/hardware.h> |
075 | //#include <mach/irqs.h> |
077 | #include <mach/regs-clock.h> |
078 | #include <mach/regs-gpio.h> |
079 | #include <plat/gpio-cfg.h> |
080 | #include <mach/gpio-bank-n.h> |
081 | #include <mach/gpio-bank-c.h> |
084 | #define CONFIG_TOUCHSCREEN_ADS7846_DEBUG |
085 | #undef CONFIG_TOUCHSCREEN_ADS7846_DEBUG |
086 | #define DEBUG_LVL KERN_DEBUG |
090 |
* Definitions & global arrays. |
092 | #define DEVICE_NAME "touchscreen" |
093 | static DECLARE_WAIT_QUEUE_HEAD(ts_waitq); //定义并初始化一个等待队列 |
095 | typedef unsigned TS_EVENT; |
096 | #define NR_EVENTS 64 //触摸屏fifo大小 |
099 | static TS_EVENT events[NR_EVENTS]; |
100 | static int evt_head, evt_tail; //fifo的头的尾 |
101 |
//驱动写fifo时evt_head++,应用读fifo时 evt_tail++ |
103 | #define ts_evt_pending() ((volatile u8)(evt_head != evt_tail)) //相等就表示满了 |
104 | #define ts_evt_get() (events + evt_tail) |
105 | #define ts_evt_pull() (evt_tail = (evt_tail + 1) & (NR_EVENTS - 1)) |
106 | #define ts_evt_clear() (evt_head = evt_tail = 0) |
108 | #define ADS7846_CNV_NBR 8 //ADC连续转换的次数 |
109 | struct ads7846_ts_info { |
113 |
unsigned int xp; //x方向位置 |
114 |
unsigned int yp; //y方向位置 |
115 |
unsigned int count; //adc转换次数 |
117 |
unsigned int x_buf[ADS7846_CNV_NBR]; //ad转换buf |
118 |
unsigned int y_buf[ADS7846_CNV_NBR]; |
122 | static struct ads7846_ts_info *ts; |
127 | //ADS7846底层操作======================================================================== |
128 | #define ADS7846_GPIO_MISO 0 //gpc0 |
129 | #define ADS7846_GPIO_MOSI 2 //gpc2 |
130 | #define ADS7846_GPIO_CLK 1 //gpc1 |
131 | #define ADS7846_GPIO_CS 3 //gpc3 |
133 | // ADS7846 Control Byte bit defines |
134 | #define ADS7846_CMD_START 0x0080 |
135 | #define ADS7846_ADDR_BIT 4 |
136 | #define ADS7846_ADDR_MASK (0x7<<ADS7846_ADDR_BIT) |
137 | #define ADS7846_MEASURE_X (0x5<<ADS7846_ADDR_BIT) |
138 | #define ADS7846_MEASURE_Y (0x1<<ADS7846_ADDR_BIT) |
139 | #define ADS7846_MEASURE_Z1 (0x3<<ADS7846_ADDR_BIT) |
140 | #define ADS7846_MEASURE_Z2 (0x4<<ADS7846_ADDR_BIT) |
141 | #define ADS7846_8BITS (1<<3) |
142 | #define ADS7846_12BITS 0 |
143 | #define ADS7846_SER (1<<2) |
145 | #define ADS7846_PWR_BIT 0 |
147 | #define ADS7846_ADC_ON (0x1<<ADS7846_PWR_BIT) |
148 | #define ADS7846_REF_ON (0x2<<ADS7846_PWR_BIT) |
149 | #define ADS7846_REF_ADC_ON (0x3<<ADS7846_PWR_BIT) |
151 | #define MEASURE_8BIT_X\ |
152 |
(unsigned short )(ADS7846_CMD_START | ADS7846_MEASURE_X | ADS7846_8BITS | ADS7846_DFR | ADS7846_PD) |
153 | #define MEASURE_8BIT_Y\ |
154 |
(unsigned short )(ADS7846_CMD_START | ADS7846_MEASURE_Y | ADS7846_8BITS | ADS7846_DFR | ADS7846_PD) |
156 | #define MEASURE_12BIT_X \ |
157 |
(unsigned short )(ADS7846_CMD_START | ADS7846_MEASURE_X | ADS7846_12BITS | ADS7846_DFR | ADS7846_PD) |
158 | #define MEASURE_12BIT_Y \ |
159 |
(unsigned short )(ADS7846_CMD_START | ADS7846_MEASURE_Y | ADS7846_12BITS | ADS7846_DFR | ADS7846_PD) |
160 | #define MEASURE_12BIT_Z1 \ |
161 |
(unsigned char )(ADS7846_MEASURE_Z1 | ADS7846_12BITS | ADS7846_DFR | ADS7846_PD) |
162 | #define MEASURE_12BIT_Z2 \ |
163 |
(unsigned char )(ADS7846_MEASURE_Z2 | ADS7846_12BITS | ADS7846_DFR | ADS7846_PD) |
167 | static inline void set_miso_as_up( void ) //gpc0 |
170 |
tmp = readl(S3C64XX_GPCPUD); |
173 |
writel(tmp, S3C64XX_GPCPUD); |
176 | static inline void set_miso_as_input( void ) //gpc0 |
179 |
tmp = readl(S3C64XX_GPCCON); |
181 |
writel(tmp, S3C64XX_GPCCON); |
184 | static inline void set_cs_mosi_clk_as_output( void ) //gpc1 2 3 |
187 |
tmp = readl(S3C64XX_GPCCON); |
188 |
tmp = (tmp & ~0xfff0) | (0x1110); |
189 |
writel(tmp, S3C64XX_GPCCON); |
192 | static inline void set_cs_mosi_clk_as_up( void ) //gpc1 2 3 |
195 |
tmp = readl(S3C64XX_GPCPUD); |
196 |
tmp &= ~((3U <<2)|(3U <<4)|(3U <<6)); |
197 |
tmp |= (2U << 2) | (2U << 4) | (2U << 6); |
198 |
writel(tmp, S3C64XX_GPCPUD); |
202 | static inline void set_gpcx_value( int pinx , int v) |
205 |
tmp = readl(S3C64XX_GPCDAT); |
211 |
writel(tmp, S3C64XX_GPCDAT); |
214 | static inline int get_gpcx_value( int pinx) |
218 |
tmp = readl(S3C64XX_GPCDAT); |
219 |
v = !!(tmp & (1<<pinx)); |
224 | static unsigned int ads7846_Read_Data( void ) |
226 |
unsigned int i,temp=0x00; |
230 |
set_gpcx_value(ADS7846_GPIO_CLK, 1); udelay(10); |
231 |
set_gpcx_value(ADS7846_GPIO_CLK, 0); udelay(10); |
232 |
if (get_gpcx_value(ADS7846_GPIO_MISO) != 0)temp++; |
237 | static void ads7846_Write_Data(unsigned int n) |
240 |
set_gpcx_value(ADS7846_GPIO_CLK, 0); |
244 |
set_gpcx_value(ADS7846_GPIO_MOSI, 1); |
246 |
set_gpcx_value(ADS7846_GPIO_MOSI, 0); |
249 |
set_gpcx_value(ADS7846_GPIO_CLK, 1); udelay(10); |
250 |
set_gpcx_value(ADS7846_GPIO_CLK, 0); udelay(10); |
257 | static void ads7846_conver_start( void ) |
263 |
set_gpcx_value(ADS7846_GPIO_CS, 0); |
265 |
cmd[0] = MEASURE_12BIT_X; |
266 |
cmd[1] = MEASURE_12BIT_Y; |
269 |
set_gpcx_value(ADS7846_GPIO_CS, 0); |
272 |
for (ts->count=0; ts->count<ts->cnv_nbr;) |
276 |
ads7846_Write_Data(cmd[i]); |
278 |
data[i] = ads7846_Read_Data(); |
284 |
ts->x_buf[ts->count]= data[0]; |
285 |
ts->y_buf[ts->count]= data[1]; |
289 |
set_gpcx_value(ADS7846_GPIO_CS, 1); |
291 | #ifdef CONFIG_TOUCHSCREEN_ADS7846_DEBUG |
292 |
//printk("ts read pos: x = %d, y = %d\n", data[0], data[1]); |
298 | //----------------------------------------------------------------------------- |
301 | //触摸屏AD连续转换N次后,按升序排列,再取中间几位值求平均 |
302 | #define TS_AD_NBR_PJ 4 //取中间4位求平均值 |
303 | #define TS_AD_NBR_MAX_CZ 10 //最大与最小的差值 |
304 | static inline bool touch_ad_data_filter(unsigned int *buf0, unsigned int *buf1) |
306 |
unsigned int i,j,k,temp,temp1,nbr=(ADS7846_CNV_NBR); |
309 |
for (j= 0; j< nbr; j++) |
310 |
for (i = 0; i < nbr; i++) |
312 |
if (buf0[i]>buf0[i+1]) //升序排列 |
321 |
for (j= 0; j< nbr; j++) |
322 |
for (i = 0; i < nbr; i++) |
324 |
if (buf1[i]>buf1[i+1]) //升序排列 |
333 |
//for (j= 0; j< nbr; j++) |
334 |
// printk("buf0[%2d]=%4d, buf1[%2d]=%4d,\r\n",j,buf0[j],j,buf1[j]); |
336 |
k=((nbr-TS_AD_NBR_PJ)>>1); |
339 |
if ((buf0[k+TS_AD_NBR_PJ-1]-buf0[k]>TS_AD_NBR_MAX_CZ)||(buf1[k+TS_AD_NBR_PJ-1]-buf1[k]>TS_AD_NBR_MAX_CZ)) //无效值 |
346 |
for (i=0;i<TS_AD_NBR_PJ;i++) |
352 |
buf0[0]=temp/TS_AD_NBR_PJ; |
353 |
buf1[0] = temp1/TS_AD_NBR_PJ; |
362 | //只要有数据被添加进来,就会唤醒ts_waitq进程 |
363 | static void ts_evt_add(unsigned x, unsigned y, unsigned down) { |
367 |
ts_event = ((x << 16) | (y)) | (down << 31); |
368 |
next_head = (evt_head + 1) & (NR_EVENTS - 1); |
370 |
if (next_head != evt_tail) { |
371 |
events[evt_head] = ts_event; |
373 | #ifdef CONFIG_TOUCHSCREEN_ADS7846_DEBUG |
374 |
printk( "====>Add ... [ %4d, %4d ]%s\n" , x, y, down ? "" : " ~~~" ); |
376 |
/* wake up any read call */ |
377 |
if (waitqueue_active(&ts_waitq)) { //判斷等待隊列是否有進程睡眠 |
378 |
wake_up_interruptible(&ts_waitq); //唤醒ts_waitq等待队列中所有interruptible类型的进程 |
381 |
/* drop the event and try to wakeup readers */ |
382 |
printk(KERN_WARNING "mini6410-ads7846: touch event buffer full" ); |
383 |
wake_up_interruptible(&ts_waitq); |
387 | static unsigned int ads7846_ts_poll( struct file *file, struct poll_table_struct *wait) |
391 |
//将ts_waitq等待队列添加到poll_table里去 |
392 |
poll_wait(file, &ts_waitq, wait); |
395 |
mask |= POLLIN | POLLRDNORM; //返回设备可读 |
401 | static int ads7846_ts_read( struct file *filp, char __user *buff, size_t count, loff_t *offp) |
403 |
DECLARE_WAITQUEUE(wait, current); //把当前进程加到定义的等待队列头wait中 |
407 |
add_wait_queue(&ts_waitq, &wait); //把wait入到等待队列头中。该队列会在进程等待的条件满足时唤醒它。 |
408 |
//我们必须在其他地方写相关代码,在事件发生时,对等的队列执行wake_up()操作。 |
409 |
//这里是在ts_evt_add里wake_up |
410 |
while (count >= sizeof (TS_EVENT)) { |
415 |
if (ts_evt_pending()) { |
416 |
TS_EVENT *evt = ts_evt_get(); |
418 |
err = copy_to_user(ptr, evt, sizeof (TS_EVENT)); |
424 |
ptr += sizeof (TS_EVENT); |
425 |
count -= sizeof (TS_EVENT); |
429 |
set_current_state(TASK_INTERRUPTIBLE); //改变进程状态为可中断的睡眠 |
431 |
if (filp->f_flags & O_NONBLOCK) //如果上层调用是非阻塞方式,则不阻塞该进程,直接返回EAGAIN |
433 |
schedule(); //本进程在此处交出CPU控制权,等待被唤醒 |
434 |
//进程调度的意思侧重于把当前任务从CPU拿掉,再从就绪队列中按照调度算法取一就绪进程占用CPU |
436 |
current->state = TASK_RUNNING; |
437 |
remove_wait_queue(&ts_waitq, &wait); |
439 |
return ptr == buff ? err : ptr - buff; |
443 | static int ads7846_ts_open( struct inode *inode, struct file *filp) { |
444 |
/* flush event queue */ |
450 | //当应用程序操作设备文件时调用的open read等函数,最终会调用这个结构体中对应的函数 |
451 | static struct file_operations dev_fops = { |
453 |
.read = ads7846_ts_read, |
454 |
.poll = ads7846_ts_poll, //select系统调用 |
455 |
.open = ads7846_ts_open, |
460 | static struct miscdevice misc = { |
461 |
.minor = MISC_DYNAMIC_MINOR, //自动分配次设置号 |
473 |
* get_down - return the down state of the pen |
477 | static inline bool get_down( void ) |
480 |
tmp = readl(S3C64XX_GPNDAT); |
481 |
down = !(tmp & (1<<9)); |
486 | /*=========================================================================================== |
487 |
touch_timer_get_value这个函数的调用: |
489 |
1、 触摸笔开始点击的时候, 在中断函数touch_down里面被调用,不是直接调用,而是设置定时器超时后调用 |
492 |
2、 touch_timer_get_value被调用一次后,如果pendown信号有效,则touch_timer_get_value会被持续调用 |
495 |
touch_timer_get_value这个函数的功能: |
496 |
启动7846转换,直到连续转换8次后,再滤波处理,获得有效值,并向上报告触摸屏事件 |
498 | ============================================================================================*/ |
499 | static void touch_timer_get_value(unsigned long data); |
501 | static DEFINE_TIMER(touch_timer, touch_timer_get_value, 0, 0); |
503 | static void touch_timer_get_value(unsigned long data) { |
509 | #ifdef CONFIG_TOUCHSCREEN_ADS7846_DEBUG |
512 | // printk("touch is down!\n"); |
515 | // printk("touch is up!\n"); |
521 |
disable_irq(IRQ_EINT(9)); |
524 |
ads7846_conver_start(); |
526 |
enable_irq(IRQ_EINT(9)); |
529 |
//if (ts->count == ( ts->cnv_nbr)) { |
530 |
if (touch_ad_data_filter(ts->x_buf,ts->y_buf)) //滤波处理 |
533 |
ts->xp = ts->x_buf[0]; |
534 |
ts->yp = ts->y_buf[0]; |
536 |
ts_evt_add(ts->xp, ts->yp, 1); //向上报告触摸屏事件 |
546 |
mod_timer(&touch_timer, jiffies + 2); //重新设置系统定时器,超时后,又会调用touch_timer_get_value |
547 |
//jiffies变量记录了系统启动以来,系统定时器已经触发的次数。内核每秒钟将jiffies变量增加HZ次。 |
548 |
//因此,对于HZ值为100的系统,1个jiffy等于10ms,而对于HZ为1000的系统,1个jiffy仅为1ms |
551 |
} else { //如果是松开,报告其触摸笔状态 |
567 | static irqreturn_t touch_down( int irqno, void *param) |
572 |
//__raw_writel(0x0, ts_base + S3C_ADCCLRWK); |
573 |
//__raw_writel(0x0, ts_base + S3C_ADCCLRINT); |
575 |
//稍后调用touch_timer_get_value,去抖动 |
576 |
mod_timer(&touch_timer, jiffies + 2); //等ADS7846转换完成了再读 |
577 |
//同时还可以防抖动,如果定时器没有超时的这段时间里,发生了抬起和按下中断,则定时器的值会被重设,不会超时 |
578 |
//内核配置时HZ值设为100,即1个jiffy等于10ms, |
579 |
//touch_timer_get_value(1); //直接调用会有抖动 |
581 |
return IRQ_RETVAL(IRQ_HANDLED); |
587 | //------------------------------------------- |
591 |
* The functions for inserting/removing us as a module. |
593 | static int __init ads7846_ts_probe( struct platform_device *pdev) |
599 | #ifdef CONFIG_TOUCHSCREEN_ADS7846_DEBUG |
600 |
printk( "ads7846_ts_probe start!\n" ); |
602 |
//给ads7846_ts_info指针分配内存== |
603 |
ts = kzalloc( sizeof ( struct ads7846_ts_info), GFP_KERNEL); |
604 |
ts->cnv_nbr = ADS7846_CNV_NBR; |
611 |
//TS_PEN双边沿触发 EINT9 GPN9 |
612 |
ret = request_irq(IRQ_EINT(9), touch_down,IRQ_TYPE_EDGE_BOTH, |
616 |
dev_err(dev, "ads7846_ts.c: Could not allocate ts IRQ_EINT !\n" ); |
624 |
ret = misc_register(&misc); //注册这混杂字符设备 |
626 |
dev_err(dev, "ads7846_ts.c: Could not register device(mini6410 touchscreen)!\n" ); |
633 |
set_cs_mosi_clk_as_up(); |
634 |
set_cs_mosi_clk_as_output(); |
635 |
set_gpcx_value(ADS7846_GPIO_MOSI ,1); |
636 |
set_gpcx_value(ADS7846_GPIO_CS ,1); |
637 |
set_gpcx_value(ADS7846_GPIO_CLK ,1); |
640 | #ifdef CONFIG_TOUCHSCREEN_ADS7846_DEBUG |
641 |
printk( "ads7846_ts_probe end!\n" ); |
647 |
disable_irq(IRQ_EINT(9)); |
648 |
free_irq(IRQ_EINT(9), ts); |
654 | static int ads7846_ts_remove( struct platform_device *dev) |
656 |
printk(KERN_INFO "ads7846_ts_remove() of TS called !\n" ); |
658 |
disable_irq(IRQ_EINT(9)); |
659 |
free_irq(IRQ_EINT(9), ts); |
664 | static unsigned int adccon, adctsc, adcdly; |
666 | static int ads7846_ts_suspend( struct platform_device *dev, pm_message_t state) |
672 | static int ads7846_ts_resume( struct platform_device *pdev) |
677 | #define ads7846_ts_suspend NULL |
678 | #define ads7846_ts_resume NULL |
681 | static struct platform_driver ads7846_ts_driver = { |
682 |
.probe = ads7846_ts_probe, |
683 |
. remove = ads7846_ts_remove, |
684 |
.suspend = ads7846_ts_suspend, |
685 |
.resume = ads7846_ts_resume, |
692 | static char banner[] __initdata = KERN_INFO "mini6410 ads7846 Touchscreen driver,by liu_xf 20110622,\n" ; |
694 | static int __init ads7846_ts_init( void ) |
697 |
return platform_driver_register(&ads7846_ts_driver); |
700 | static void __exit ads7846_ts_exit( void ) |
702 |
platform_driver_unregister(&ads7846_ts_driver); |
705 | module_init(ads7846_ts_init); |
706 | module_exit(ads7846_ts_exit); |
708 | MODULE_AUTHOR( "Hunan Create Inc." ); |
709 | MODULE_LICENSE( "GPL" ); |
2、修改当前目录下的Kconfig和makefile,让它在menuconfig里可见,并能被编译。
在 Kconfig里添加:
01 | config TOUCHSCREEN_MINI6410_ADS7846 |
02 |
tristate "ADS7846 touchscreen driver for Mini6410" |
03 |
depends on MACH_MINI6410 |
06 |
Say Y here to enable the driver for the ADS7846 touchscreen on the |
07 |
FriendlyARM Mini6410 development board. |
11 |
To compile this driver as a module, choose M here: the |
12 |
module will be called mini6410-ads7846. |
makefile里添加
obj-$(CONFIG_TOUCHSCREEN_MINI6410_ADS7846) += mini6410-ads7846.o<BR> |
3、 ads7846_device_ts设备定义
复制 /opt/FriendlyARM/mini6410/linux-2.6.38/arch/arm/mach-s3c64xx/dev-ts-mini6410.c为dev-ads7846-mini6410.c,更改代码为
01 | /* linux/arch/arm/mach-s3c64xx/dev-ts-mini6410.c |
03 |
* Copyright (c) 2008 Simtec Electronics |
04 |
* Ben Dooks <ben@simtec.co.uk> |
07 |
* S3C series device definition for touchscreen devices |
09 |
* This program is free software; you can redistribute it and/or modify |
10 |
* it under the terms of the GNU General Public License version 2 as |
11 |
* published by the Free Software Foundation. |
14 | #include <linux/kernel.h> |
15 | #include <linux/platform_device.h> |
25 | static struct resource ads7846_ts_resource[] = { |
27 |
.start = SAMSUNG_PA_ADC, |
28 |
.end = SAMSUNG_PA_ADC + SZ_256 - 1, |
29 |
.flags = IORESOURCE_MEM, |
34 |
.flags = IORESOURCE_IRQ, |
39 |
.flags = IORESOURCE_IRQ, |
43 | struct platform_device ads7846_device_ts = { |
46 |
.num_resources = ARRAY_SIZE(ads7846_ts_resource), |
47 |
.resource = ads7846_ts_resource, |
50 | void __init ads7846_ts_set_platdata(struct s3c_ts_mach_info *pd) |
52 |
printk(KERN_ERR "%s: no platform data\n", __func__); |
4、在/opt/FriendlyARM/mini6410/linux-2.6.38/arch/arm/mach-s3c64xx/mach-mini6410.c的platform_device添加ads7846_device_ts设备(s3c_device_ts附近),注册设备时要用到它
#ifdef CONFIG_TOUCHSCREEN_MINI6410_ADS7846 |
5、添加设备声明
mach-mini6410里注册ads7846_device_ts设备,但在哪里mach-mini6410并不知道,需要在devs.h里声明,打开当前目录下的devs.h,添加如下代码:
extern struct platform_device ads7846_device_ts;<BR> |
6、然后再make,放到SD卡里运行
make menuconfig,在device drives-> input device support -> touch screens选择ADS7846 touchscreen driver for Mini6410 ,然后再make zImage。
完成后,再放到SD卡里运行,怎么样,一点也不抖动了吧!
结语:
这个驱动是由mini6410-ts.c修改而来的,那些系统调用的函数都没有改,只是将获取触摸屏数据的方式变了,可以直接用原来的tslib。经测试,效果良好。但是在移植的过程中,有一个问题还是没搞明白,之前,我是将TS_PEN接在EINT6上在的,但一接上去,就一直中断,把系统都弄死了,要按下触摸屏才能停止中断,不知道是什么原因,可能是EINT6被其它地方设置了,还是怎么回事,后来换成EINT9就好了,正好两个端子相邻。知道的大侠还请告诉我一声。