微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > AM335x(TQ335x)学习笔记——触摸屏驱动编写

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

时间:11-28 来源:互联网 点击:

驱动了,而且我真心的希望阅读本文的朋友不需要下载源码就能自己写出触摸驱动。

  1. #include
  2. #include
  3. #include
  4. #include
  5. #include
  6. #include
  7. #include
  8. #include
  9. #include
  10. #include
  11. #include
  12. structgt811_ts_platdata
  13. {
  14. u32size_x;
  15. u32size_y;
  16. u32size_p;
  17. u32swap;
  18. u32revert_x;
  19. u32revert_y;
  20. u32reset_pin;
  21. u32interrupt_pin;
  22. u32ponits_max;
  23. structi2c_client*client;
  24. structinput_dev*input;
  25. structwork_structwork;
  26. };
  27. staticconststructof_device_idgt811_ts_of_match[]={
  28. {.compatible="gt811,gt811_ts",.data=NULL},
  29. {}
  30. };
  31. staticinti2c_write_bytes(structi2c_client*client,uint8_t*data,intlen){
  32. structi2c_msgmsg;
  33. msg.flags=!I2C_M_RD;
  34. msg.addr=client->addr;
  35. msg.len=len;
  36. msg.buf=data;
  37. returni2c_transfer(client->adapter,&msg,1);
  38. }
  39. staticinti2c_read_bytes(structi2c_client*client,uint8_t*buf,intlen){
  40. structi2c_msgmsgs[2];
  41. msgs[0].flags=!I2C_M_RD;
  42. msgs[0].addr=client->addr;
  43. msgs[0].len=2;
  44. msgs[0].buf=&buf[0];
  45. msgs[1].flags=I2C_M_RD;
  46. msgs[1].addr=client->addr;
  47. msgs[1].len=len-2;
  48. msgs[1].buf=&buf[2];
  49. returni2c_transfer(client->adapter,msgs,2);
  50. }
  51. staticvoidgt811_ts_handler(structwork_struct*work)
  52. {
  53. structgt811_ts_platdata*pdata=container_of(work,structgt811_ts_platdata,work);
  54. structdevice*dev=&pdata->client->dev;
  55. uint8_tbuffer[36]={0x07,0x21,0};
  56. uint8_tcount,index,flags,position;
  57. intx,y;
  58. buffer[0]=0x0f;
  59. buffer[1]=0xff;
  60. if(i2c_write_bytes(pdata->client,buffer,2)<0){
  61. dev_err(dev,"Failedtowritewakeupmessage.");
  62. gotoreenable_irq;
  63. }
  64. buffer[0]=0x07;
  65. buffer[1]=0x21;
  66. if(i2c_read_bytes(pdata->client,buffer,sizeof(buffer))<0){
  67. dev_err(dev,"Failedtoreadtouchmessage.");
  68. gotoreenable_irq;
  69. }
  70. buffer[0]=0x80;
  71. buffer[1]=0x00;
  72. if(i2c_write_bytes(pdata->client,buffer,2)<0){
  73. dev_err(dev,"Failedtowritesleepmessage.");
  74. gotoreenable_irq;
  75. }
  76. buffer[25]=buffer[19];
  77. buffer[19]=0;
  78. flags=buffer[2]&0x1f;
  79. while(flags){
  80. if(!(flags&0x1)){
  81. continue;
  82. }
  83. if(index<3){
  84. position=4+index*5;
  85. }
  86. else{
  87. position=25+(index-3)*5;
  88. }
  89. x=(buffer[position]<8)|buffer[position+1];
  90. y=(buffer[position+2]<8)|buffer[position+3];
  91. if(pdata->swap){
  92. swap(x,y);
  93. }
  94. if(pdata->revert_x){
  95. x=pdata->size_x-x;
  96. }
  97. if(pdata->revert_y){
  98. y=pdata->size_y-y;
  99. }
  100. printk("point:(x:%03d,y:%03d)",x,y);
  101. }
  102. //组织检测出来的触摸点信息上报到输入子系统节点即可
  103. reenable_irq:
  104. enable_irq(pdata->client->irq);
  105. }
  106. staticirqreturn_tgt811_ts_isr(intirq,void*dev_id)
  107. {
  108. structgt811_ts_platdata*pdata=(structgt811_ts_platdata*)dev_id;
  109. disable_irq_nosync(pdata->client->irq);
  110. schedule_work(&pdata->work);
  111. returnIRQ_HANDLED;
  112. }
  113. staticintgt811_ts_initilize(structi2c_client*client)
  114. {
  115. structdevice*dev=&client->dev;
  116. structgt811_ts_platdata*pdata=(structgt811_ts_platdata*)i2c_get_clientdata(client);
  117. intstatus=0,count=0;
  118. uint8_tversion[4]={0x7,0x17,0};
  119. uint8_tconfig[]={
  120. 0x06,0xA2,
  121. 0x12,0x10,0x0E,0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,0xE2,0x53,0xD2,0x53,0xC2,0x53,
  122. 0xB2,0x53,0xA2,0x53,0x92,0x53,0x82,0x53,0x72,0x53,0x62,0x53,0x52,0x53,0x42,0x53,
  123. 0x32,0x53,0x22,0x53,0x12,0x53,0x02,0x53,0xF2,0x53,0x0F,0x13,0x40,0x40,0x40,0x10,
  124. 0x10,0x10,0x0F,0x0F,0x0A,0x35,0x25,0x0C,0x03,0x00,0x05,0x20,0x03,0xE0,0x01,0x00,
  125. 0x00,0x34,0x2C,0x36,0x2E,0x00,0x00,0x03,0x19,0x03,0x08,0x00,0x00,0x00,0x00,0x00,
  126. 0x14,0x10,0xEC,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0x40,
  127. 0x30,0x3C,0x28,0x00,0x00,0x00,0x00,0xC0,0x12,0x01
  128. };
  129. config[62]=480>>8;
  130. config[61]=480&0xff;
  131. config[64]=800>>8;
  132. config[63]=800&0xff;
  133. if(!gpio_is_valid(pdata->reset_pin)){
  134. dev_err(dev,"Theresetpinnumberisinvalid.");
  135. return-EINVAL;
  136. }
  137. count=3;
  138. while(count--){
  139. gpio_direction_output(pdata->reset_pin,0);
  140. msleep(10);
  141. gpio_direction_output(pdata->reset_pin,1);
  142. msleep(100);
  143. if(i2c_read_bytes(client,version,sizeof(version))<0){
  144. dev_err(dev,"FailedtogettheversionofGT811,tryagain...");
  145. status=-ENODEV;
  146. }
  147. else{
  148. dev_info(dev,"Gt811detected,version(%04x)...",(version[2]<8)|version[3]);
  149. status=0;
  150. break;
  151. }
  152. }
  153. if(status){
  154. returnstatus;
  155. }
  156. count=3;
  157. while(count--){
  158. if(i2c_write_bytes(client,confi

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top