AM335x(TQ335x)学习笔记——触摸屏驱动编写
时间:11-28
来源:互联网
点击:
驱动了,而且我真心的希望阅读本文的朋友不需要下载源码就能自己写出触摸驱动。
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- structgt811_ts_platdata
- {
- u32size_x;
- u32size_y;
- u32size_p;
- u32swap;
- u32revert_x;
- u32revert_y;
- u32reset_pin;
- u32interrupt_pin;
- u32ponits_max;
- structi2c_client*client;
- structinput_dev*input;
- structwork_structwork;
- };
- staticconststructof_device_idgt811_ts_of_match[]={
- {.compatible="gt811,gt811_ts",.data=NULL},
- {}
- };
- staticinti2c_write_bytes(structi2c_client*client,uint8_t*data,intlen){
- structi2c_msgmsg;
- msg.flags=!I2C_M_RD;
- msg.addr=client->addr;
- msg.len=len;
- msg.buf=data;
- returni2c_transfer(client->adapter,&msg,1);
- }
- staticinti2c_read_bytes(structi2c_client*client,uint8_t*buf,intlen){
- structi2c_msgmsgs[2];
- msgs[0].flags=!I2C_M_RD;
- msgs[0].addr=client->addr;
- msgs[0].len=2;
- msgs[0].buf=&buf[0];
- msgs[1].flags=I2C_M_RD;
- msgs[1].addr=client->addr;
- msgs[1].len=len-2;
- msgs[1].buf=&buf[2];
- returni2c_transfer(client->adapter,msgs,2);
- }
- staticvoidgt811_ts_handler(structwork_struct*work)
- {
- structgt811_ts_platdata*pdata=container_of(work,structgt811_ts_platdata,work);
- structdevice*dev=&pdata->client->dev;
- uint8_tbuffer[36]={0x07,0x21,0};
- uint8_tcount,index,flags,position;
- intx,y;
- buffer[0]=0x0f;
- buffer[1]=0xff;
- if(i2c_write_bytes(pdata->client,buffer,2)<0){
- dev_err(dev,"Failedtowritewakeupmessage.");
- gotoreenable_irq;
- }
- buffer[0]=0x07;
- buffer[1]=0x21;
- if(i2c_read_bytes(pdata->client,buffer,sizeof(buffer))<0){
- dev_err(dev,"Failedtoreadtouchmessage.");
- gotoreenable_irq;
- }
- buffer[0]=0x80;
- buffer[1]=0x00;
- if(i2c_write_bytes(pdata->client,buffer,2)<0){
- dev_err(dev,"Failedtowritesleepmessage.");
- gotoreenable_irq;
- }
- buffer[25]=buffer[19];
- buffer[19]=0;
- flags=buffer[2]&0x1f;
- while(flags){
- if(!(flags&0x1)){
- continue;
- }
- if(index<3){
- position=4+index*5;
- }
- else{
- position=25+(index-3)*5;
- }
- x=(buffer[position]<8)|buffer[position+1];
- y=(buffer[position+2]<8)|buffer[position+3];
- if(pdata->swap){
- swap(x,y);
- }
- if(pdata->revert_x){
- x=pdata->size_x-x;
- }
- if(pdata->revert_y){
- y=pdata->size_y-y;
- }
- printk("point:(x:%03d,y:%03d)",x,y);
- }
- //组织检测出来的触摸点信息上报到输入子系统节点即可
- reenable_irq:
- enable_irq(pdata->client->irq);
- }
- staticirqreturn_tgt811_ts_isr(intirq,void*dev_id)
- {
- structgt811_ts_platdata*pdata=(structgt811_ts_platdata*)dev_id;
- disable_irq_nosync(pdata->client->irq);
- schedule_work(&pdata->work);
- returnIRQ_HANDLED;
- }
- staticintgt811_ts_initilize(structi2c_client*client)
- {
- structdevice*dev=&client->dev;
- structgt811_ts_platdata*pdata=(structgt811_ts_platdata*)i2c_get_clientdata(client);
- intstatus=0,count=0;
- uint8_tversion[4]={0x7,0x17,0};
- uint8_tconfig[]={
- 0x06,0xA2,
- 0x12,0x10,0x0E,0x0C,0x0A,0x08,0x06,0x04,0x02,0x00,0xE2,0x53,0xD2,0x53,0xC2,0x53,
- 0xB2,0x53,0xA2,0x53,0x92,0x53,0x82,0x53,0x72,0x53,0x62,0x53,0x52,0x53,0x42,0x53,
- 0x32,0x53,0x22,0x53,0x12,0x53,0x02,0x53,0xF2,0x53,0x0F,0x13,0x40,0x40,0x40,0x10,
- 0x10,0x10,0x0F,0x0F,0x0A,0x35,0x25,0x0C,0x03,0x00,0x05,0x20,0x03,0xE0,0x01,0x00,
- 0x00,0x34,0x2C,0x36,0x2E,0x00,0x00,0x03,0x19,0x03,0x08,0x00,0x00,0x00,0x00,0x00,
- 0x14,0x10,0xEC,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0D,0x40,
- 0x30,0x3C,0x28,0x00,0x00,0x00,0x00,0xC0,0x12,0x01
- };
- config[62]=480>>8;
- config[61]=480&0xff;
- config[64]=800>>8;
- config[63]=800&0xff;
- if(!gpio_is_valid(pdata->reset_pin)){
- dev_err(dev,"Theresetpinnumberisinvalid.");
- return-EINVAL;
- }
- count=3;
- while(count--){
- gpio_direction_output(pdata->reset_pin,0);
- msleep(10);
- gpio_direction_output(pdata->reset_pin,1);
- msleep(100);
- if(i2c_read_bytes(client,version,sizeof(version))<0){
- dev_err(dev,"FailedtogettheversionofGT811,tryagain...");
- status=-ENODEV;
- }
- else{
- dev_info(dev,"Gt811detected,version(%04x)...",(version[2]<8)|version[3]);
- status=0;
- break;
- }
- }
- if(status){
- returnstatus;
- }
- count=3;
- while(count--){
- if(i2c_write_bytes(client,confi
AM335xTQ335x触摸屏驱动编 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)