锐单电子商城 , 一站式电子元器件采购平台!
  • 电话:400-990-0325

linux android 电容 触摸屏驱动 差别,android 电容屏(三):驱动调试之驱动程序分析篇(1)...

时间:2023-10-30 02:07:02 v电容触摸屏

5.推荐工作条件(环境温度为 25°C,VDD=2.8V)

参数

最小值

典型值

最大值

单位

模拟AVDD(参考AGND)

2.5

2.8

3.6

V

数字DVDD(参考DGND)

2.5

2.8

3.6

V

电源纹波

50(注意电池和充电器的影响)

mV

工作温度

-20

25

85

工作湿度

-

-

95

%

三、硬件接口电路:

如下图:

a4c26d1e5885305701be709a3d33442f.png

SDA

IIC数据 上拉电阻,为1K;

SCL

IIC时钟(400KHz)

TP_EN

使能脚(gt8105为高电平)

INT

中断(中断一直发出到触摸屏)

VCC

3.3V这个电压一直存在

GND

软件部分如下:

a4c26d1e5885305701be709a3d33442f.png

三、IIC配置

从设备到芯片的数据和初始化值都是从这条总线传输的,首先要配置这条总线,

/linux/arch/arm/mach-exynos/mach-smdkv310.c,这只是因为平台,地址右移也取决于情况。如果是7bit地址不需要移位。

staticstructi2c_board_infoi2c_devs5[]__initdata={

#ifCONFIG_TOUCHSCREEN_GT8105

{

I2C_BOARD_INFO("Goodix-TS",(0xaa>>1)),

.irq=IRQ_EINT(5),

}

#endif

};

四、电源、复位(使能脚)

1、电源

3.3V一直都有电源,这个硬件就给了。

2.复位(时能脚)只是触摸屏,gt8105工作时要高电平。

在:linux3.0/drivers/input/touchscreen/goodix_touch.h中

#defineRESETPIN_CFGs3c_gpio_cfgpin(EXYNOS4_GPB(4),S3C_GPIO_OUTPUT)

#defineRESETPIN_SET0gpio_direction_output(EXYNOS4_GPB(4),0)

#defineRESETPIN_SET1gpio_direction_output(EXYNOS4_GPB(4),1)

staticvoidgoodix_reset(void)

{

interr;

err=gpio_request(EXYNOS4_GPB(4),"GPX1");

if(err)

printk(KERN_ERR"####failedtorequestGPB_4####\n");

RESETPIN_CFG;//配置管脚功能

RESETPIN_SET0;//管脚拉低

mdelay(20);//延时

RESETPIN_SET1;//管脚拉高

mdelay(60);

gpio_free(EXYNOS4_GPB(4));

}

五、中断配置

在:linux3.0/drivers/input/touchscreen/goodix_touch.h中

#defineINT_PORTEXYNOS4_GPX0(5)

#ifdefINT_PORT

#defineTS_INTIRQ_EINT(5)//中断引脚,中断号

#defineINT_CFGS3C_GPIO_SFN(0x0F)

#else

在:linux3.0/drivers/input/touchscreen/goodix_touch.h中中断申请

#ifdefINT_PORT

client->irq=TS_INT;

if(client->irq)

{

ret=request_irq(client->irq,goodix_ts_irq_handler,IRQ_TYPE_EDGE_RISING|IRQ_TYPE_EDGE_FALLING,client->name,ts);

#endif

以上三部分完成了触摸屏工作的最基本配置,以确保IIC、上电、INT正常情况下,触摸屏可以工作。

驱动有几个重要部分:probe函数分析;中断申请,调度工作队列;中断下半部函数的执行,计算和报告坐标值。

1、probe函数分析

staticintgoodix_ts_probe(structi2c_client*client,conststructi2c_device_id*id)

{

structgoodix_ts_data*ts;

…………

//1.分配触摸屏结构的核心空间;

ts=kzalloc(sizeof(*ts),GFP_KERNEL);

…………

//2.初始化队列更为重要。中断触发后,调用队列goodix_ts_work_func计算上报坐标值的函数;

INIT_WORK(&ts->work,goodix_ts_work_func);

…………

//3,触摸芯片摸芯片;

for(retry=0;retry<3;retry )

{

ret=goodix_init_panel(ts);

…………

}

//4、触摸屏复位,拉高;

goodix_reset();

#ifdefINT_PORT

//5,中断申请,TS_INT是我们设定的中断脚;

client->irq=TS_INT;

ret=request_irq(client->irq,goodix_ts_irq_handler,IRQ_TYPE_EDGE_RISING|IRQ_TYPE_EDGE_FALLING,

client->name,ts);

………………

#endif

//6、分配input驱动核心空间;

ts->input_dev=input_allocate_device();

//7,input我们前面提到了初始参数设置Linux与Android多点触摸协议中有这部分说明;

ts->input_dev->evbit[0]=BIT_MASK(EV_SYN)|BIT_MASK(EV_KEY)|BIT_MASK(EV_ABS);

ts->input_dev->keybit[BIT_WORD(BTN_TOUCH)]=BIT_MASK(BTN_TOUCH);

ts->input_dev->absbit[0]=BIT(ABS_X)|BT(ABS_Y) | BIT(ABS_PRESSURE); // absolute coor (x,y)

#ifdef HAVE_TOUCH_KEY

for(retry = 0; retry 

{

input_set_capability(ts->input_dev,EV_KEY,touch_key_array[retry]);

}

#endif

input_set_abs_params(ts->input_dev, ABS_X, 0, ts->abs_x_max, 0, 0);

input_set_abs_params(ts->input_dev, ABS_Y, 0, ts->abs_y_max, 0, 0);

input_set_abs_params(ts->input_dev, ABS_PRESSURE, 0, 255, 0, 0);

//8、这部分针对触摸屏参数设定;

#ifdef GOODIX_MULTI_TOUCH

input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);

input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);

input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0);

input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, ts->abs_y_max, 0, 0);

input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, ts->max_touch_num, 0, 0);

#endif

//9、触摸屏版本信息设定;

sprintf(ts->phys, "input/ts");

ts->input_dev->name = goodix_ts_name;

ts->input_dev->phys = ts->phys;

ts->input_dev->id.bustype = BUS_I2C;

ts->input_dev->id.vendor = 0xDEAD;

ts->input_dev->id.product = 0xBEEF;

ts->input_dev->id.version = 10427; //screen firmware version

//10,对于input子系统来说,这个是重头戏了,只有注册了input子系统,其他的才有做用;

ret = input_register_device(ts->input_dev);

………………

// 11,对睡眠唤醒操作;

#ifdef CONFIG_HAS_EARLYSUSPEND

ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;

ts->early_suspend.suspend = goodix_ts_early_suspend;

ts->early_suspend.resume = goodix_ts_late_resume;

register_early_suspend(&ts->early_suspend);

#endif

………………

}

(1)、分配触摸屏结构内核空间;

structgoodix_ts_data {

uint16_t addr;

uint8_t bad_data;

structi2c_client *client;

structinput_dev *input_dev;

intuse_reset;//use RESET flag

intuse_irq;//use EINT flag

intread_mode;//read moudle mode,20110221 by andrew

structhrtimer timer;

structwork_struct work;

charphys[32];

intretry;

structearly_suspend early_suspend;

int(*power)(structgoodix_ts_data * ts,inton);

uint16_t abs_x_max;

uint16_t abs_y_max;

uint8_t max_touch_num;

uint8_t int_trigger_type;

uint8_t green_wake_mode;

};

(2)、初始化工作队列,这个比较重要,中断触发后,调用队列中的goodix_ts_work_func函数,计算上报坐标值;这个和中断申请一起分析;

(3)、触摸芯片初始化;

对触摸芯片寄存器的初始化,这里面对中断方式设定等,一般芯片厂的FAE在调试的时候会修改这里面的值,这个也是因芯片而异,有的在驱动里做,可以直接改;有的直接做成固件了,那部分要FAE帮忙了。

uint8_t cfg_info_group1[] =

{

0x65,0x00,0x25,0x80,0x19,0x00,0x00,0x2C,0x11,0x11,0x32,0x02,0x08,0x10,0x20,0x00,

0x00,0x88,0x88,0x88,0x03,0x13,0x32,0x64,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,

0x08,0x09,0x0A,0x0B,0x0C,0xFF,0x0D,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,

0x17,0x18,0x19,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00

};

(4)、触摸屏复位,拉高;

gt8015在工作时要拉高,所以我们做一个拉低—延时--拉高的操作;

(5)、中断申请,TS_INT就是我们所设定的中断脚,和(2)一起后面分析;

(6)、分配input驱动内核空间;

ts->input_dev= input_allocate_device();

(7)、input初始化参数设定,我们在前面提到Linux与Android

多点触摸协议里有对这部分说明;(8)、这部分针对触摸屏参数设定;

(9)、触摸屏版本信息设定;

cat /proc/bus/input/devices时可以看到下面信息(这个是pixcir的触摸屏)

I: Bus=0018 Vendor=0000 Product=0000 Version=0000

N: Name="pixcir-ts"

P: Phys=

S: Sysfs=/devices/platform/s3c2440-i2c.5/i2c-5/5-005c/input/input3

U: Uniq=

H: Handlers=kbd event3

B: PROP=0

B: EV=b

B: KEY=400 0 0 0 0 1000 40000800 0 0 0 0

B: ABS=2650000 1000000

(10)、对于input子系统来说,这个是重头戏了,驱动注册到input子系统;

input_register_device(ts->input_dev);

(11),触摸屏睡眠唤醒操作,这部分不做详细说明,感兴趣的可以看下……

锐单商城拥有海量元器件数据手册IC替代型号,打造电子元器件IC百科大全!

相关文章