新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > S5PV210(TQ210)學習筆記——觸摸屏驅動編寫

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

作者: 時間:2016-11-28 來源:網絡 收藏
  • config_info[62]=480>>8;
  • config_info[61]=480&0xff;
  • config_info[64]=800>>8;
  • config_info[63]=800&0xff;
  • ret=i2c_write_bytes(client,config_info,sizeof(config_info)/sizeof(config_info[0]));
  • if(ret<0){
  • printk(KERN_ERR"GT811Sendconfigfailed!");
  • returnret;
  • }
  • return0;
  • }
  • staticirqreturn_tgt811_int_handler(intirq,void*devid){
  • disable_irq_nosync(this_client->irq);
  • queue_work(wq,&work);
  • returnIRQ_RETVAL(IRQ_HANDLED);
  • }
  • staticvoidts_work_func(structwork_struct*work){
  • intret;
  • unsignedcharpoint_data[19]={0x07,0x21,0};
  • unsignedshortinput_x=0;
  • unsignedshortinput_y=0;
  • unsignedshortinput_p=0;
  • ret=i2c_read_bytes(this_client,point_data,sizeof(point_data)/sizeof(point_data[0]));
  • if(ret<=0){
  • printk("Failed");
  • return;
  • }
  • if(point_data[2]&0x1){
  • status=1;
  • input_y=479-((point_data[4]<<8)|point_data[5]);
  • input_x=799-((point_data[6]<<8)|point_data[7]);
  • input_p=point_data[8];
  • printk("stat:%d,x:%d,y:%d,p:%d",point_data[2],input_x,input_y,
  • input_p);
  • }
  • elseif(status){
  • status=0;
  • printk("up");
  • }
  • enable_irq(this_client->irq);
  • }
  • staticintts_probe(structi2c_client*client,conststructi2c_device_id*id){
  • intretry,ret;
  • chartest_data;
  • printk("ts_probe");
  • test_data=0;
  • gt811_rst=S5PV210_GPD0(3);
  • gt811_int=S5PV210_GPH1(6);
  • gpio_request(gt811_rst,"reset");
  • gpio_request(gt811_rst,"tsint");
  • if(!i2c_check_functionality(client->adapter,I2C_FUNC_I2C))
  • {
  • dev_err(&client->dev,"MusthaveI2C_FUNC_I2C.");
  • return-ENODEV;
  • }
  • s3c_gpio_setpull(gt811_rst,S3C_GPIO_PULL_UP);
  • for(retry=0;retry<5;retry++)
  • {
  • gpio_direction_output(gt811_rst,0);
  • msleep(1);
  • gpio_direction_input(gt811_rst);
  • msleep(100);
  • ret=i2c_write_bytes(client,&test_data,1);
  • if(ret>0)
  • break;
  • dev_info(&client->dev,"GT811I2CTESTFAILED!PleasechecktheHARDWAREconnect");
  • }
  • if(ret<=0)
  • {
  • dev_err(&client->dev,"Warnning:I2CcommunicationmightbeERROR!");
  • return-ENODEV;
  • }
  • for(retry=0;retry!=5;++retry){
  • ret=ts_init_panel(client);
  • if(ret!=0){
  • continue;
  • }
  • else{
  • break;
  • }
  • }
  • if(ret!=0){
  • printk("GT811Configuefailed!");
  • return-ENODEV;
  • }
  • this_client=client;
  • ts_input=input_allocate_device();
  • if(IS_ERR(ts_input)){
  • printk("GT811allocatetsinputdevicefailed!");
  • return-ENOMEM;
  • }
  • ts_input->evbit[0]=BIT_MASK(EV_SYN)|BIT_MASK(EV_KEY)|BIT_MASK(EV_ABS);
  • ts_input->keybit[BIT_WORD(BTN_TOUCH)]=BIT_MASK(BTN_TOUCH);
  • ts_input->absbit[0]=BIT(ABS_X)|BIT(ABS_Y)|BIT(ABS_PRESSURE);
  • input_set_abs_params(ts_input,ABS_Y,0,799,0,0);
  • input_set_abs_params(ts_input,ABS_X,0,479,0,0);
  • input_set_abs_params(ts_input,ABS_PRESSURE,0,255,0,0);
  • ts_input->name="tq210-ts";
  • ts_input->phys="input/ts";
  • ts_input->id.bustype=BUS_I2C;
  • ts_input->id.product=0xBEEF;
  • ts_input->id.vendor=0xDEAD;
  • ret=input_register_device(ts_input);
  • if(ret<0){
  • printk("Unableregister%sinputdevice!",ts_input->name);
  • input_free_device(ts_input);
  • return-ENOMEM;
  • }
  • client->irq=IRQ_EINT(14);
  • s3c_gpio_setpull(gt811_int,S3C_GPIO_PULL_UP);
  • if(request_irq(IRQ_EINT(14),gt811_int_handler,IRQF_TRIGGER_FALLING,"gt811-int",NULL)<0){
  • printk("Requestirqforgt811failed!");
  • input_unregister_device(ts_input);
  • input_free_device(ts_input);
  • return-ENOMEM;
  • }
  • wq=create_workqueue("ts_handle_thread");
  • if(wq==NULL){
  • printk(KERN_ALERT"creteworkqueuefailed!");
  • input_unregister_device(ts_input);
  • input_free_device(ts_input);
  • free_irq(IRQ_EINT(14),NULL);
  • return-ENOMEM;
  • }
  • INIT_WORK(&work,ts_work_func);
  • return0;
  • }
  • staticintts_remove(structi2c_client*client){
  • free_irq(IRQ_EINT(14),NULL);
  • enable_irq(client->irq);
  • flush_workqueue(wq);
  • destroy_workqueue(wq);
  • input_unregister_device(ts_input);
  • input_free_device(ts_input);
  • gpio_free(gt811_rst);
  • gpio_free(gt811_int);
  • return0;
  • }

    評論


    技術專區(qū)

    關閉