新聞中心

        EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應(yīng)用 > AM335x(TQ335x)學習筆記——觸摸屏驅(qū)動編寫

        AM335x(TQ335x)學習筆記——觸摸屏驅(qū)動編寫

        作者: 時間:2016-11-28 來源:網(wǎng)絡(luò) 收藏
      1. if(status){
      2. returnstatus;
      3. }
      4. count=3;
      5. while(count--){
      6. if(i2c_write_bytes(client,config,sizeof(config))<0){
      7. dev_err(dev,"FailedtoconfiguretheGT811,tryagain...");
      8. status=-EINVAL;
      9. }
      10. else{
      11. dev_info(dev,"Gt811configuesucceed");
      12. status=0;
      13. break;
      14. }
      15. }
      16. returnstatus;
      17. }
      18. staticstructgt811_ts_platdata*gt811_ts_parse_devtree(structi2c_client*client)
      19. {
      20. structdevice*dev=&client->dev;
      21. structdevice_node*node;
      22. structgt811_ts_platdata*pdata;
      23. enumof_gpio_flagsflags;
      24. node=dev->of_node;
      25. if(!node){
      26. dev_err(dev,"Theof_nodeisNULL.");
      27. returnERR_PTR(-ENODEV);
      28. }
      29. pdata=devm_kzalloc(dev,sizeof(structdevice_node),GFP_KERNEL);
      30. if(!pdata){
      31. dev_err(dev,"Noenoughmemoryleft.");
      32. returnERR_PTR(-ENOMEM);
      33. }
      34. pdata->reset_pin=of_get_gpio_flags(node,0,&flags);
      35. if(pdata->reset_pin<0){
      36. dev_err(dev,"GetRSTpinfailed!");
      37. returnERR_PTR(-EINVAL);
      38. }
      39. if(of_property_read_u32(node,"touchscreen-size-x",&pdata->size_x)){
      40. dev_err(dev,"Failedtogetthetouchscreenxsize.");
      41. returnERR_PTR(-EINVAL);
      42. }
      43. if(of_property_read_u32(node,"touchscreen-size-y",&pdata->size_y)){
      44. dev_err(dev,"Failedtogetthetouchscreenysize.");
      45. returnERR_PTR(-EINVAL);
      46. }
      47. if(of_property_read_u32(node,"touchscreen-size-p",&pdata->size_p)){
      48. pdata->size_p=255;
      49. }
      50. if(of_property_read_u32(node,"touchscreen-swap",&pdata->swap)){
      51. pdata->swap=1;
      52. }
      53. if(of_property_read_u32(node,"touchscreen-revert-x",&pdata->revert_x)){
      54. pdata->revert_x=1;
      55. }
      56. if(of_property_read_u32(node,"touchscreen-revert-x",&pdata->revert_y)){
      57. pdata->revert_y=1;
      58. }
      59. returnpdata;
      60. }
      61. staticintgt811_ts_probe(structi2c_client*client,conststructi2c_device_id*id)
      62. {
      63. structdevice*dev=&client->dev;
      64. structgt811_ts_platdata*pdata=dev_get_platdata(dev);
      65. structinput_dev*input;
      66. interror=0;
      67. if(!of_match_device(of_match_ptr(gt811_ts_of_match),dev)){
      68. dev_err(dev,"Failedtomatch.");
      69. return-EINVAL;
      70. }
      71. if(!pdata){
      72. pdata=gt811_ts_parse_devtree(client);
      73. if(IS_ERR(pdata)){
      74. dev_err(dev,"Getdevicedatafromdevicetreefailed!");
      75. error=-EINVAL;
      76. gotofailed_exit;
      77. }
      78. }
      79. pdata->client=client;
      80. i2c_set_clientdata(client,pdata);
      81. input=devm_input_allocate_device(dev);
      82. if(!input){
      83. dev_err(dev,"Failedtoallocateinputdevice");
      84. error=-ENOMEM;
      85. gotopdata_free;
      86. }
      87. pdata->input=input;
      88. input->name=client->name;
      89. input->id.bustype=BUS_I2C;
      90. input->id.product=0xBEEF;
      91. input->id.vendor=0xDEAD;
      92. input->dev.parent=&client->dev;
      93. __set_bit(EV_KEY,input->evbit);
      94. __set_bit(EV_ABS,input->evbit);
      95. __set_bit(BTN_TOUCH,input->keybit);
      96. input_set_abs_params(input,ABS_X,0,pdata->size_x,0,0);
      97. input_set_abs_params(input,ABS_Y,0,pdata->size_y,0,0);
      98. input_set_abs_params(input,ABS_MT_POSITION_X,0,pdata->size_x,0,0);
      99. input_set_abs_params(input,ABS_MT_POSITION_Y,0,pdata->size_y,0,0);
      100. error=input_mt_init_slots(input,5,INPUT_MT_DIRECT|INPUT_MT_DROP_UNUSED);
      101. if(error){
      102. dev_err(dev,"Failedtoinitializethemulti-touchslots.");
      103. gotoinput_free;
      104. }
      105. input_set_drvdata(input,pdata);
      106. error=input_register_device(input);
      107. if(error){
      108. dev_err(dev,"Registerinputdevicefailed!");
      109. gotoinput_free;
      110. }
      111. if(gt811_ts_initilize(client)){
      112. dev_err(dev,"FailedtoinitializeGT811.");
      113. }
      114. INIT_WORK(&pdata->work,gt811_ts_handler);
      115. error=devm_request_any_context_irq(dev,client->irq,gt811_ts_isr,
      116. IRQF_TRIGGER_FALLING,client->name,pdata);
      117. if(error){
      118. dev_err(dev,"Failedtorequestirq(number:%d)",client->irq);
      119. gotoinput_free;
      120. }
      121. return0;
      122. input_free:
      123. devm_kfree(dev,input);
      124. pdata_free:
      125. devm_kfree(dev,pdata);
      126. failed_exit:
      127. returnerror;
      128. }
      129. staticintgt811_ts_remove(structi2c_client*client)
      130. {
      131. structgt811_ts_platdata*pdata=(structgt811_ts_platdata*)i2c_get_clientdata(client);
      132. devm_free_irq(&client->dev,client->irq,i2c_get_clientdata(client));
      133. input_unregister_device(pdata->input);
      134. devm_kfree(&client->dev,pdata);
      135. return0;
      136. }
      137. staticconststructi2c_device_idgt811_ts_id[]={
      138. {"gt811_ts",0},
      139. {}
      140. };
      141. staticstructi2c_drivergt811_ts_driver={
      142. .driver={
      143. .owner=THIS_MODULE,
      144. .name="gt811_ts",
      145. .of_match_table=of_match_ptr(gt811_ts_of_match),
      146. },
      147. .probe=gt811_ts_probe,
      148. .remove=gt811_ts_remove,
      149. .id_table=gt811_ts_id,
      150. };
      151. module_i2c_driver(gt811_ts_driver);
      152. MODULE_AUTHOR("girlkoo");
      153. MODULE_DESCRIPTION("Gt811I2CTouchscreenDriver");
      154. MODULE_LICENSE("GPL");
      155. (4) 使用tslib工具測試

        本文引用地址:http://www.104case.com/article/201611/322822.htm

        tslib的編譯方法請參考本博客的另一片文章,鏈接如下:

        S5PV210(TQ210)學習筆記——觸摸屏驅(qū)動編寫

        本文就不再重復tslib的配置方法。

        (5)效果展示

        (6) 完整驅(qū)動代碼

        請到本人的資源中下載TQ335x的觸摸屏驅(qū)動源碼,鏈接如下:

        http://download.csdn.net/download/girlkoo/8202177


        上一頁 1 2 下一頁

        關(guān)鍵詞: AM335xTQ335x觸摸屏驅(qū)動編

        評論


        相關(guān)推薦

        技術(shù)專區(qū)

        關(guān)閉
        主站蜘蛛池模板: 肥城市| 滦平县| 吉水县| 嘉峪关市| 郓城县| 资源县| 大洼县| 扶风县| 嵊泗县| 偏关县| 邵阳市| 汝南县| 阿克苏市| 开平市| 鄢陵县| 中山市| 天峨县| 青川县| 舞阳县| 民权县| 河北区| 平原县| 兴山县| 宿迁市| 金华市| 普陀区| 台北市| 蕲春县| 浮梁县| 康乐县| 临武县| 五常市| 年辖:市辖区| 千阳县| 朝阳县| 栾川县| 大足县| 修文县| 黔西县| 靖边县| 鄂温|