触摸屏驱动笔记

这是我看韦东山第2期视频触摸屏驱动的一些笔记,记录方便以后学习。

触摸屏归纳为输入子系统,这里主要是针对电阻屏,其使用过程如下

当用触摸笔按下时,产生中断。

在中断处理函数处理函数中启动ADC转换x,y坐标。

ADC结束,产生ADC中断

在ADC中断处理函数里上报(input_event)启动定时器

再次启动定时器(可以处理滑动、长按)

松开按键

 

其驱动程序的写法和之前写输入子系统的写法基本上一致。

写出入口函数,出口函数并加以修饰,加入相关头文件,然后开始完善各函数,在入口函数中分配input_dev结构体,设置(能产生哪类事件,能产生这类事件中的哪些事件),注册设备,硬件相关的操作等。出口函数中主要对之前注册、分配的一些资源进行释放。

还应根据2440数据手册ADC转换和触摸屏那一章,对相关寄存器根据实际需要进行设置。

 

1. #include <linux/errno.h>

2. #include <linux/kernel.h>

3. #include <linux/module.h>

4. #include <linux/slab.h>

5. #include <linux/input.h>

6. #include <linux/init.h>

7. #include <linux/serio.h>

8. #include <linux/delay.h>

9. #include <linux/platform_device.h>

10. #include <linux/clk.h>

11. #include <asm/io.h>

12. #include <asm/irq.h>

13. 

14. #include <asm/plats3c24xx/ts.h>

15. 

16. #include <asm/arch/regsadc.h>

17. #include <asm/arch/regsgpio.h>

18. 

19. struct s3c_ts_regs {                     /* 相关的寄存器 */

20.     unsigned long adccon;

21.     unsigned long adctsc;

22.     unsigned long adcdly;

23.     unsigned long adcdat0;

24.     unsigned long adcdat1;

25.     unsigned long adcupdn;

26. };

27. 

28. static struct input_dev *s3c_ts_dev;

29. static volatile struct s3c_ts_regs *s3c_ts_regs;

30. 

31. static struct timer_list ts_timer;

32. 

33. void enter_wait_pen_down_mode(void) /* 进入等待触摸笔按下模式 */

34. {

35.     s3c_ts_regs->adctsc = 0xd3; /* 进入等待中断模式 bit[8]为0 2440手册P442 */

36. }

37. 

38. void enter_wait_pen_up_mode(void) /* 进入等待触摸笔松开模式 */

39. {

40.     s3c_ts_regs->adctsc = 0x1d3; /* 进入等待中断模式 bit[8]为1 2440手册P442 */

41. }

42. 

43. static void enter_measure_xy_mode(void) /* 进入xy测量模式 */

44. {

45.     s3c_ts_regs->adctsc = (1<<3) | (1<<2);

46. }

47. 

48. static void start_adc(void)

49. {

50.     s3c_ts_regs->adccon |= (1<<0); /* 启动ADC */

51. }

52. 

53. static int s3c_filter_ts(int x[], int y[]) /* 软件过滤 */

54. {

55. #define ERR_LIMIT 10      /* 经验值,容差值 */   

56. 

57.     int avr_x, avr_y;

58.     int det_x, det_y;

59.     

60.     avr_x = (x[0] + x[1])/2;

61.     avr_y = (y[0] + y[1])/2;

62. 

63.     det_x = (x[2] > avr_x) /span> (x[2]  avr_x) : (avr_x  x[2]);

64.     det_y = (y[2] > avr_y) /span> (y[2]  avr_y) : (avr_y  y[2]);

65. 

66.     if ((det_x > ERR_LIMIT) || (det_y > ERR_LIMIT))

67.         return 0;

68.     

69.     avr_x = (x[1] + x[2])/2;

70.     avr_y = (y[1] + y[2])/2;

71. 

72.     det_x = (x[3] > avr_x) /span> (x[3]  avr_x) : (avr_x  x[3]);

73.     det_y = (y[3] > avr_y) /span> (y[3]  avr_y) : (avr_y  y[3]);

74. 

75.     if ((det_x > ERR_LIMIT) || (det_y > ERR_LIMIT))

76.         return 1;

77. }

78. 

79. static void s3c_ts_timer_functions(unsigned long data)

80. {

81.     if (s3c_ts->adcdat0 & (1<<15)) /* 假设时间到 */ 

82.     {

83.         /* 如果触摸已经松开 */

84.         input_report_abs(s3c_ts_dev, ABS_PRESSURE, 0); /* 上报事件,压力值为0 */

85. &

来源:莫明888

声明:本站部分文章及图片转载于互联网,内容版权归原作者所有,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2015年4月4日
下一篇 2015年4月5日

相关推荐