一、Linux输入子系统的结构:

二、触摸屏驱动代码:

  s3c_ts.c

#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/input.h>
#include <linux/init.h>
#include <linux/serio.h>
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
#include <asm/io.h>
#include <asm/irq.h> #include <asm/plat-s3c24xx/ts.h> #include <asm/arch/regs-adc.h>
#include <asm/arch/regs-gpio.h> struct s3c_ts_regs {
unsigned long adccon;
unsigned long adctsc;
unsigned long adcdly;
unsigned long adcdat0;
unsigned long adcdat1;
unsigned long adcupdn;
}; static struct input_dev *s3c_ts_dev;
static volatile struct s3c_ts_regs *s3c_ts_regs; static struct timer_list ts_timer; static void enter_wait_pen_down_mode(void)
{
s3c_ts_regs->adctsc = 0xd3;
} static void enter_wait_pen_up_mode(void)
{
s3c_ts_regs->adctsc = 0x1d3;
} static void enter_measure_xy_mode(void)
{
s3c_ts_regs->adctsc = (<<)|(<<);
} static void start_adc(void)
{
s3c_ts_regs->adccon |= (<<);
} static int s3c_filter_ts(int x[], int y[])
{
#define ERR_LIMIT 10 int avr_x, avr_y;
int det_x, det_y; avr_x = (x[] + x[])/;
avr_y = (y[] + y[])/; det_x = (x[] > avr_x) ? (x[] - avr_x) : (avr_x - x[]);
det_y = (y[] > avr_y) ? (y[] - avr_y) : (avr_y - y[]); if ((det_x > ERR_LIMIT) || (det_y > ERR_LIMIT))
return ; avr_x = (x[] + x[])/;
avr_y = (y[] + y[])/; det_x = (x[] > avr_x) ? (x[] - avr_x) : (avr_x - x[]);
det_y = (y[] > avr_y) ? (y[] - avr_y) : (avr_y - y[]); if ((det_x > ERR_LIMIT) || (det_y > ERR_LIMIT))
return ; return ;
} static void s3c_ts_timer_function(unsigned long data)
{
if (s3c_ts_regs->adcdat0 & (<<))
{
/* 已经松开 */
input_report_abs(s3c_ts_dev, ABS_PRESSURE, );
input_report_key(s3c_ts_dev, BTN_TOUCH, );
input_sync(s3c_ts_dev);
enter_wait_pen_down_mode();
}
else
{
/* 测量X/Y坐标 */
enter_measure_xy_mode();
start_adc();
}
} static irqreturn_t pen_down_up_irq(int irq, void *dev_id)
{
if (s3c_ts_regs->adcdat0 & (<<))
{
//printk("pen up\n");
input_report_abs(s3c_ts_dev, ABS_PRESSURE, );
input_report_key(s3c_ts_dev, BTN_TOUCH, );
input_sync(s3c_ts_dev);
enter_wait_pen_down_mode();
}
else
{
//printk("pen down\n");
//enter_wait_pen_up_mode();
enter_measure_xy_mode();
start_adc();
}
return IRQ_HANDLED;
} static irqreturn_t adc_irq(int irq, void *dev_id)
{
static int cnt = ;
static int x[], y[];
int adcdat0, adcdat1; /* 优化措施2: 如果ADC完成时, 发现触摸笔已经松开, 则丢弃此次结果 */
adcdat0 = s3c_ts_regs->adcdat0;
adcdat1 = s3c_ts_regs->adcdat1; if (s3c_ts_regs->adcdat0 & (<<))
{
/* 已经松开 */
cnt = ;
input_report_abs(s3c_ts_dev, ABS_PRESSURE, );
input_report_key(s3c_ts_dev, BTN_TOUCH, );
input_sync(s3c_ts_dev);
enter_wait_pen_down_mode();
}
else
{
// printk("adc_irq cnt = %d, x = %d, y = %d\n", ++cnt, adcdat0 & 0x3ff, adcdat1 & 0x3ff);
/* 优化措施3: 多次测量求平均值 */
x[cnt] = adcdat0 & 0x3ff;
y[cnt] = adcdat1 & 0x3ff;
++cnt;
if (cnt == )
{
/* 优化措施4: 软件过滤 */
if (s3c_filter_ts(x, y))
{
//printk("x = %d, y = %d\n", (x[0]+x[1]+x[2]+x[3])/4, (y[0]+y[1]+y[2]+y[3])/4);
input_report_abs(s3c_ts_dev, ABS_X, (x[]+x[]+x[]+x[])/);
input_report_abs(s3c_ts_dev, ABS_Y, (y[]+y[]+y[]+y[])/);
input_report_abs(s3c_ts_dev, ABS_PRESSURE, );
input_report_key(s3c_ts_dev, BTN_TOUCH, );
input_sync(s3c_ts_dev);
}
cnt = ;
enter_wait_pen_up_mode(); /* 启动定时器处理长按/滑动的情况 */
mod_timer(&ts_timer, jiffies + HZ/);
}
else
{
enter_measure_xy_mode();
start_adc();
}
} return IRQ_HANDLED;
} static int s3c_ts_init(void)
{
struct clk* clk; /* 1. 分配一个input_dev结构体 */
s3c_ts_dev = input_allocate_device(); /* 2. 设置 */
/* 2.1 能产生哪类事件 */
set_bit(EV_KEY, s3c_ts_dev->evbit);
set_bit(EV_ABS, s3c_ts_dev->evbit); /* 2.2 能产生这类事件里的哪些事件 */
set_bit(BTN_TOUCH, s3c_ts_dev->keybit); input_set_abs_params(s3c_ts_dev, ABS_X, , 0x3FF, , );
input_set_abs_params(s3c_ts_dev, ABS_Y, , 0x3FF, , );
input_set_abs_params(s3c_ts_dev, ABS_PRESSURE, , , , ); /* 3. 注册 */
input_register_device(s3c_ts_dev); /* 4. 硬件相关的操作 */
/* 4.1 使能时钟(CLKCON[15]) */
clk = clk_get(NULL, "adc");
clk_enable(clk); /* 4.2 设置S3C2440的ADC/TS寄存器 */
s3c_ts_regs = ioremap(0x58000000, sizeof(struct s3c_ts_regs)); /* bit[14] : 1-A/D converter prescaler enable
* bit[13:6]: A/D converter prescaler value,
* 49, ADCCLK=PCLK/(49+1)=50MHz/(49+1)=1MHz
* bit[0]: A/D conversion starts by enable. 先设为0
*/
s3c_ts_regs->adccon = (<<)|(<<); request_irq(IRQ_TC, pen_down_up_irq, IRQF_SAMPLE_RANDOM, "ts_pen", NULL);
request_irq(IRQ_ADC, adc_irq, IRQF_SAMPLE_RANDOM, "adc", NULL); /* 优化措施1:
* 设置ADCDLY为最大值, 这使得电压稳定后再发出IRQ_TC中断
*/
s3c_ts_regs->adcdly = 0xffff; /* 优化措施5: 使用定时器处理长按,滑动的情况
*
*/
init_timer(&ts_timer);
ts_timer.function = s3c_ts_timer_function;
add_timer(&ts_timer); enter_wait_pen_down_mode(); return ;
} static void s3c_ts_exit(void)
{
free_irq(IRQ_TC, NULL);
free_irq(IRQ_ADC, NULL);
iounmap(s3c_ts_regs);
input_unregister_device(s3c_ts_dev);
input_free_device(s3c_ts_dev);
del_timer(&ts_timer);
} module_init(s3c_ts_init);
module_exit(s3c_ts_exit); MODULE_LICENSE("GPL");

  Makefile

KERN_DIR = /work/system/linux-2.6.22.6

all:
make -C $(KERN_DIR) M=`pwd` modules clean:
make -C $(KERN_DIR) M=`pwd` modules clean
rm -rf modules.order obj-m += s3c_ts.o

三、驱动测试:

1. make menuconfig  //去掉原来的触摸屏驱动程序
-> Device Drivers
  -> Input device support
    -> Generic input layer
      -> Touchscreens
      <>   S3C2410/S3C2440 touchscreens

2. ls /dev/input/event*    //确认当前event节点有哪些
3. insmod s3c_ts.ko  //加载触摸屏驱动模块
4. ls /dev/input/event*   //查看触摸屏节点
5. hexdump /dev/input/event0 //十六进制打印输入数据
            秒       微秒   type code    value
0000000 29a4 0000 8625 0008 0003 0000 0172 0000
0000010 29a4 0000 8631 0008 0003 0001 027c 0000
0000020 29a4 0000 8634 0008 0003 0018 0001 0000
0000030 29a4 0000 8638 0008 0001 014a 0001 0000
0000040 29a4 0000 863c 0008 0000 0000 0000 0000
0000050 29a4 0000 c85e 0008 0003 0000 0171 0000
0000060 29a4 0000 c874 0008 0003 0001 027d 0000
0000070 29a4 0000 c87b 0008 0000 0000 0000 0000
0000080 29a4 0000 ed37 0008 0003 0018 0000 0000
0000090 29a4 0000 ed48 0008 0001 014a 0000 0000
00000a0 29a4 0000 ed4a 0008 0000 0000 0000 0000

Linux学习: 触摸屏驱动的更多相关文章

  1. 基于FT5x06嵌入式Linux电容触摸屏驱动

    **************************************************************************************************** ...

  2. Linux学习: LCD驱动

    一.LCD驱动框架: 1.分配一个fb_info结构体:s3c_lcd = framebuffer_alloc(0,NULL); 2.设置fb_info(s3c_lcd): ID.固定参数.可变参数. ...

  3. Linux内核触摸屏驱动--多点触摸 【转】

      转自:http://blog.chinaunix.net/uid-24227137-id-3127126.html 简介 为了使用功能强大的多点触控设备,就需要一种方案去上报用户层所需的详细的手指 ...

  4. Linux下触摸屏驱动程序分析

    [摘要: 本文以linux3.5--Exynos4412仄台,剖析触摸屏驱动焦点内容.Linux下触摸屏驱动(以ft5x06_ts为例)须要懂得以下学问: 1. I2C协定 2. Exynos4412 ...

  5. i2c触摸屏驱动文件的实现

    转自:http://blog.chinaunix.net/uid-29507718-id-4314013.html Linux下I2C接口触摸屏驱动分析  分类: LINUX linux下触摸屏驱动的 ...

  6. AM335x(TQ335x)学习笔记——触摸屏驱动编写

    前面几篇文章已经通过配置DTS的方式完成了多个驱动的移植,接下来我们解决TQ335x的触摸驱动问题.由于种种原因,TQ335x的触摸屏驱动是以模块方式提供的,且Linux官方内核中也没有带该触摸屏的驱 ...

  7. linux 触摸屏驱动

    目录 linux 触摸屏驱动 输入子系统怎么写? 触摸屏事件 事件分类 事件设置 硬件配置 设计思路 完整程序 测试 ts_lib 使用 问题小结 title: linux 触摸屏驱动 tags: l ...

  8. 【Linux高级驱动】触摸屏驱动的移植

    触摸屏驱动的移植 流程 注意:看框架图 1.添加input.c组件 Device Drivers  ---> Input device support  --->  Generic inp ...

  9. linux 输入子系统之电阻式触摸屏驱动

    一.输入子系统情景回忆ING...... 在Linux中,输入子系统是由输入子系统设备驱动层.输入子系统核心层(Input Core)和输入子系统事件处理层(Event Handler)组成.其中设备 ...

随机推荐

  1. thinkphp5的Auth权限认证实战

    thinkphp5的Auth权限认证实战 一.总结 一句话总结:基于角色的权限管理(真正做一遍,就会发现很简单,不然一直都是半懂不懂的) 角色 权限 真正做一遍,就会发现很简单,不然一直都是半懂不懂的 ...

  2. WmiPrvSe.exe 的 cpu 占用

    经常会看到这个进程cpu升上去,然后播放视频卡顿,鼠标移动卡顿. 1) 首先怀疑公司的Mcafee, 然后竟然检索除了一篇文章,MCafee表示不背锅. 2)找到这篇文章,微软表示,不能看表面,你得查 ...

  3. 20181013xlVba成绩报表优化

    Public Sub 成绩报表优化() Application.ScreenUpdating = False Application.DisplayAlerts = False Application ...

  4. Ubuntu/Debian nginx 简介

    Linux运营维护(简称运维) 这里是简单的使用介绍: 参考:http://einverne.github.io/post/2017/06/ubuntu-debian-install-nginx.ht ...

  5. 十分钟搞定pandas内容

    目录 十分钟搞定pandas 一.创建对象 二.查看数据 三.选择器 十二.导入和保存数据 参考:http://pandas.pydata.org/pandas-docs/stable/whatsne ...

  6. python基础之小数据池,is和==区别 编码问题

    主要内容 小数据池,is和==区别 编码问题 小数据池 一种缓存机制,也称为驻留机制,是为了能更快提高一些字符串和整数的处理速度is 和 == 的区别 == 主要指对变量值是否相等的判断,只要数值相同 ...

  7. pyqt5安装命令

    第一步:安装qt5 pip install pyqt5==5.10.1 -i https://pypi.doubanio.com/simple pip install pyqt5-tools -i h ...

  8. 3月19 HTML静态网页的制作

    HTML :内容(Hyper Text Markup Language,超文本标记语言) <html>---开始标签 <head> 网页上的控制信息 <title> ...

  9. java动态代理机制

    首先了解代理设计模式,其思想是为其他对象提供一种代理以控制对这个对象的访问. java动态代理就是遵循这种思想,spring中的AOP实现原理就是java的动态代理. 在java的动态代理机制中,有两 ...

  10. bootstrap table导出功能无效报错Uncaught INVALID_CHARACTER_ERR: DOM Exception 5和导出中文乱码问题

    由于表格数据中含有中文导致的,在网页的开发者选项中报一个 Uncaught INVALID_CHARACTER_ERR: DOM Exception 5 问题.这个问题是由于BootStrap tab ...