新聞中心

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

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

作者: 時(shí)間:2016-11-28 來源:網(wǎng)絡(luò) 收藏
  • if(status){
  • returnstatus;
  • }
  • count=3;
  • while(count--){
  • if(i2c_write_bytes(client,config,sizeof(config))<0){
  • dev_err(dev,"FailedtoconfiguretheGT811,tryagain...");
  • status=-EINVAL;
  • }
  • else{
  • dev_info(dev,"Gt811configuesucceed");
  • status=0;
  • break;
  • }
  • }
  • returnstatus;
  • }
  • staticstructgt811_ts_platdata*gt811_ts_parse_devtree(structi2c_client*client)
  • {
  • structdevice*dev=&client->dev;
  • structdevice_node*node;
  • structgt811_ts_platdata*pdata;
  • enumof_gpio_flagsflags;
  • node=dev->of_node;
  • if(!node){
  • dev_err(dev,"Theof_nodeisNULL.");
  • returnERR_PTR(-ENODEV);
  • }
  • pdata=devm_kzalloc(dev,sizeof(structdevice_node),GFP_KERNEL);
  • if(!pdata){
  • dev_err(dev,"Noenoughmemoryleft.");
  • returnERR_PTR(-ENOMEM);
  • }
  • pdata->reset_pin=of_get_gpio_flags(node,0,&flags);
  • if(pdata->reset_pin<0){
  • dev_err(dev,"GetRSTpinfailed!");
  • returnERR_PTR(-EINVAL);
  • }
  • if(of_property_read_u32(node,"touchscreen-size-x",&pdata->size_x)){
  • dev_err(dev,"Failedtogetthetouchscreenxsize.");
  • returnERR_PTR(-EINVAL);
  • }
  • if(of_property_read_u32(node,"touchscreen-size-y",&pdata->size_y)){
  • dev_err(dev,"Failedtogetthetouchscreenysize.");
  • returnERR_PTR(-EINVAL);
  • }
  • if(of_property_read_u32(node,"touchscreen-size-p",&pdata->size_p)){
  • pdata->size_p=255;
  • }
  • if(of_property_read_u32(node,"touchscreen-swap",&pdata->swap)){
  • pdata->swap=1;
  • }
  • if(of_property_read_u32(node,"touchscreen-revert-x",&pdata->revert_x)){
  • pdata->revert_x=1;
  • }
  • if(of_property_read_u32(node,"touchscreen-revert-x",&pdata->revert_y)){
  • pdata->revert_y=1;
  • }
  • returnpdata;
  • }
  • staticintgt811_ts_probe(structi2c_client*client,conststructi2c_device_id*id)
  • {
  • structdevice*dev=&client->dev;
  • structgt811_ts_platdata*pdata=dev_get_platdata(dev);
  • structinput_dev*input;
  • interror=0;
  • if(!of_match_device(of_match_ptr(gt811_ts_of_match),dev)){
  • dev_err(dev,"Failedtomatch.");
  • return-EINVAL;
  • }
  • if(!pdata){
  • pdata=gt811_ts_parse_devtree(client);
  • if(IS_ERR(pdata)){
  • dev_err(dev,"Getdevicedatafromdevicetreefailed!");
  • error=-EINVAL;
  • gotofailed_exit;
  • }
  • }
  • pdata->client=client;
  • i2c_set_clientdata(client,pdata);
  • input=devm_input_allocate_device(dev);
  • if(!input){
  • dev_err(dev,"Failedtoallocateinputdevice");
  • error=-ENOMEM;
  • gotopdata_free;
  • }
  • pdata->input=input;
  • input->name=client->name;
  • input->id.bustype=BUS_I2C;
  • input->id.product=0xBEEF;
  • input->id.vendor=0xDEAD;
  • input->dev.parent=&client->dev;
  • __set_bit(EV_KEY,input->evbit);
  • __set_bit(EV_ABS,input->evbit);
  • __set_bit(BTN_TOUCH,input->keybit);
  • input_set_abs_params(input,ABS_X,0,pdata->size_x,0,0);
  • input_set_abs_params(input,ABS_Y,0,pdata->size_y,0,0);
  • input_set_abs_params(input,ABS_MT_POSITION_X,0,pdata->size_x,0,0);
  • input_set_abs_params(input,ABS_MT_POSITION_Y,0,pdata->size_y,0,0);
  • error=input_mt_init_slots(input,5,INPUT_MT_DIRECT|INPUT_MT_DROP_UNUSED);
  • if(error){
  • dev_err(dev,"Failedtoinitializethemulti-touchslots.");
  • gotoinput_free;
  • }
  • input_set_drvdata(input,pdata);
  • error=input_register_device(input);
  • if(error){
  • dev_err(dev,"Registerinputdevicefailed!");
  • gotoinput_free;
  • }
  • if(gt811_ts_initilize(client)){
  • dev_err(dev,"FailedtoinitializeGT811.");
  • }
  • INIT_WORK(&pdata->work,gt811_ts_handler);
  • error=devm_request_any_context_irq(dev,client->irq,gt811_ts_isr,
  • IRQF_TRIGGER_FALLING,client->name,pdata);
  • if(error){
  • dev_err(dev,"Failedtorequestirq(number:%d)",client->irq);
  • gotoinput_free;
  • }
  • return0;
  • input_free:
  • devm_kfree(dev,input);
  • pdata_free:
  • devm_kfree(dev,pdata);
  • failed_exit:
  • returnerror;
  • }
  • staticintgt811_ts_remove(structi2c_client*client)
  • {
  • structgt811_ts_platdata*pdata=(structgt811_ts_platdata*)i2c_get_clientdata(client);
  • devm_free_irq(&client->dev,client->irq,i2c_get_clientdata(client));
  • input_unregister_device(pdata->input);
  • devm_kfree(&client->dev,pdata);
  • return0;
  • }
  • staticconststructi2c_device_idgt811_ts_id[]={
  • {"gt811_ts",0},
  • {}
  • };
  • staticstructi2c_drivergt811_ts_driver={
  • .driver={
  • .owner=THIS_MODULE,
  • .name="gt811_ts",
  • .of_match_table=of_match_ptr(gt811_ts_of_match),
  • },
  • .probe=gt811_ts_probe,
  • .remove=gt811_ts_remove,
  • .id_table=gt811_ts_id,
  • };
  • module_i2c_driver(gt811_ts_driver);
  • MODULE_AUTHOR("girlkoo");
  • MODULE_DESCRIPTION("Gt811I2CTouchscreenDriver");
  • MODULE_LICENSE("GPL");
  • (4) 使用tslib工具測試

    本文引用地址:http://m.butianyuan.cn/article/201611/322822.htm

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

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

    本文就不再重復(fù)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)閉