收藏 分享(赏)

基于ilitek的电容屏驱动程序的分析精品资料.doc

上传人:风样花鼓 文档编号:21124643 上传时间:2023-07-07 格式:DOC 页数:62 大小:215.50KB
下载 相关 举报
基于ilitek的电容屏驱动程序的分析精品资料.doc_第1页
第1页 / 共62页
基于ilitek的电容屏驱动程序的分析精品资料.doc_第2页
第2页 / 共62页
基于ilitek的电容屏驱动程序的分析精品资料.doc_第3页
第3页 / 共62页
亲,该文档总共62页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

1、基于ilitek的电容屏驱动程序的分析首先,将驱动的代码粘贴出来先,在第二篇我再对整个驱动程序进行进一步的分析(/*Copyright (c) 2010 by ilitek Technology.All rights reserved.ilitek I2C touch screen driver for Android platformAuthor: Steward FuVersion: 1History:2010/10/26 Firstly released2010/10/28 Combine both i2c and hid function together2010/11/02 Supp

2、ort interrupt trigger for I2C interface2010/11/10 Rearrange code and add new IOCTL command2010/11/23 Support dynamic to change I2C address2010/12/21 Support resume and suspend functions2010/12/23 Fix synchronous problem when application and driver work at the same time2010/12/28 Add erasing backgrou

3、nd before calibrating touch panel2011/01/13 Rearrange code and add interrupt with polling method2011/01/14 Add retry mechanism2011/01/17 Support multi-point touch2011/01/21 Support early suspend function2011/02/14 Support key button function2011/02/18 Rearrange code2011/03/21 Fix counld not report f

4、irst point2011/03/25 Support linux 2.36.x */#include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef CONFIG_HAS_EARLYSUSPEND#include #include #endif/#define COORDINATE_KEY/#define ILITEK_SLEEP_MODEint touch_key_hold_press = 0;int tou

5、ch_key_code = KEY_SEARCH, KEY_MENU, KEY_BACK, KEY_HOME;int touch_key_press = 0, 0, 0, 0;/ definitions#define ILITEK_I2C_RETRY_COUNT3#define ILITEK_I2C_DRIVER_NAMEilitek_i2c#define ILITEK_FILE_DRIVER_NAMEilitek_file#define ILITEK_DEBUG_LEVELKERN_INFO#define ILITEK_ERROR_LEVELKERN_ALERT/ i2c command f

6、or ilitek touch screen#define ILITEK_TP_CMD_READ_DATA 0x10#define ILITEK_TP_CMD_READ_SUB_DATA 0x11#define ILITEK_TP_CMD_GET_RESOLUTION 0x20#define ILITEK_TP_CMD_GET_FIRMWARE_VERSION0x40#define ILITEK_TP_CMD_GET_PROTOCOL_VERSION0x42#defineILITEK_TP_CMD_CALIBRATION 0xCC#define ILITEK_TP_CMD_ERASE_BACK

7、GROUND 0xCE#ifdef ILITEK_SLEEP_MODE#define ILITEK_TP_CMD_SLEEP_MODE 0x30#endif/ define the application command#define ILITEK_IOCTL_BASE 100#define ILITEK_IOCTL_I2C_WRITE_DATA _IOWR(ILITEK_IOCTL_BASE, 0, unsigned char*)#define ILITEK_IOCTL_I2C_WRITE_LENGTH _IOWR(ILITEK_IOCTL_BASE, 1, int)#define ILIT

8、EK_IOCTL_I2C_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 2, unsigned char*)#define ILITEK_IOCTL_I2C_READ_LENGTH _IOWR(ILITEK_IOCTL_BASE, 3, int)#define ILITEK_IOCTL_USB_WRITE_DATA _IOWR(ILITEK_IOCTL_BASE, 4, unsigned char*)#define ILITEK_IOCTL_USB_WRITE_LENGTH _IOWR(ILITEK_IOCTL_BASE, 5, int)#define ILITEK_I

9、OCTL_USB_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 6, unsigned char*)#define ILITEK_IOCTL_USB_READ_LENGTH _IOWR(ILITEK_IOCTL_BASE, 7, int)#define ILITEK_IOCTL_I2C_UPDATE_RESOLUTION _IOWR(ILITEK_IOCTL_BASE, 8, int)#define ILITEK_IOCTL_USB_UPDATE_RESOLUTION _IOWR(ILITEK_IOCTL_BASE, 9, int)#define ILITEK_IOCT

10、L_I2C_SET_ADDRESS _IOWR(ILITEK_IOCTL_BASE, 10, int)#define ILITEK_IOCTL_I2C_UPDATE _IOWR(ILITEK_IOCTL_BASE, 11, int)#define ILITEK_IOCTL_STOP_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 12, int)#define ILITEK_IOCTL_START_READ_DATA _IOWR(ILITEK_IOCTL_BASE, 13, int)/ module informationMODULE_AUTHOR(Steward_Fu)

11、;MODULE_DESCRIPTION(ILITEK I2C touch driver for Android platform);MODULE_LICENSE(GPL);/ all implemented global functions must be defined in here / in order to know how many function we had implementedstatic int ilitek_i2c_register_device(void);static void ilitek_set_input_param(struct input_dev*, in

12、t, int, int);static int ilitek_i2c_read_tp_info(void);static int ilitek_init(void);static void ilitek_exit(void);/ i2c functionsstatic int ilitek_i2c_transfer(struct i2c_client*, struct i2c_msg*, int);static int ilitek_i2c_read(struct i2c_client*, uint8_t, uint8_t*, int);static int ilitek_i2c_proces

13、s_and_report(void);static int ilitek_i2c_suspend(struct i2c_client*, pm_message_t);static int ilitek_i2c_resume(struct i2c_client*);static void ilitek_i2c_shutdown(struct i2c_client*);static int ilitek_i2c_probe(struct i2c_client*, const struct i2c_device_id*);static int ilitek_i2c_remove(struct i2c

14、_client*);#ifdef CONFIG_HAS_EARLYSUSPEND static void ilitek_i2c_early_suspend(struct early_suspend *h); static void ilitek_i2c_late_resume(struct early_suspend *h);#endifstatic int ilitek_i2c_polling_thread(void*);static irqreturn_t ilitek_i2c_isr(int, void*);static void ilitek_i2c_irq_work_queue_fu

15、nc(struct work_struct*);/ file operation functionsstatic int ilitek_file_ioctl(struct inode*, struct file*, unsigned int, unsigned long);static int ilitek_file_open(struct inode*, struct file*);static ssize_t ilitek_file_write(struct file*, const char*, size_t, loff_t*);static ssize_t ilitek_file_re

16、ad(struct file*, char*, size_t, loff_t*);static int ilitek_file_close(struct inode*, struct file*);/ declare touch point datastruct touch_data / x, y valueint x, y;/ check wehther this point is valid or notint valid;/ id informationint id;/ declare i2c data memberstruct i2c_data / input device struc

17、t input_dev *input_dev; / i2c client struct i2c_client *client; / polling thread struct task_struct *thread; / maximum x int max_x; / maximum y int max_y;/ maximum touch pointint max_tp;/ maximum key buttonint max_btn; / the total number of x channel int x_ch; / the total number of y channel int y_c

18、h; / check whether i2c driver is registered success int valid_i2c_register; / check whether input driver is registered success int valid_input_register;/ check whether the i2c enter suspend or notint stop_polling;/ read semaphorestruct semaphore wr_sem;/ protocol versionint protocol_ver;/ valid irq

19、requestint valid_irq_request;/ work queue for interrupt use onlystruct workqueue_struct *irq_work_queue;/ work struct for work queuestruct work_struct irq_work; struct timer_list timer;#ifdef CONFIG_HAS_EARLYSUSPENDstruct early_suspend early_suspend;#endif;/ device datastruct dev_data / device numbe

20、r dev_t devno; / character device struct cdev cdev; / class device struct class *class;/ global variablesstatic struct i2c_data i2c;static struct dev_data dev;/ i2c id tablestatic const struct i2c_device_id ilitek_i2c_id =ILITEK_I2C_DRIVER_NAME, 0, ;MODULE_DEVICE_TABLE(i2c, ilitek_i2c_id);/ declare

21、i2c function tablestatic struct i2c_driver ilitek_i2c_driver = .id_table = ilitek_i2c_id,.driver = .name = ILITEK_I2C_DRIVER_NAME,.resume = ilitek_i2c_resume, .suspend = ilitek_i2c_suspend,.shutdown = ilitek_i2c_shutdown,.probe = ilitek_i2c_probe,.remove = ilitek_i2c_remove,;/ declare file operation

22、sstruct file_operations ilitek_fops = #if LINUX_VERSION_CODE = KERNEL_VERSION(2, 6, 36).unlocked_ioctl = ilitek_file_ioctl,#else.ioctl = ilitek_file_ioctl,#endif.read = ilitek_file_read,.write = ilitek_file_write,.open = ilitek_file_open,.release = ilitek_file_close,;/*descriptionopen function for c

23、haracter device driverprarmetersinode inodefilp file pointerreturnstatus*/static int ilitek_file_open(struct inode *inode, struct file *filp)return 0; /*descriptionwrite function for character device driverprarmetersfilp file pointerbuf buffercount buffer lengthf_pos offsetreturnstatus*/static ssize

24、_t ilitek_file_write(struct file *filp, const char *buf, size_t count, loff_t *f_pos)int ret;unsigned char buffer128=0; struct i2c_msg msgs = .addr = i2c.client-addr, .flags = 0, .len = count, .buf = buffer,; / before sending data to touch device, we need to check whether the device is working or no

25、tif(i2c.valid_i2c_register = 0)printk(ILITEK_ERROR_LEVEL %s, i2c device driver doesnt be registeredn, _func_);return -1;/ check the buffer size whether it exceeds the local buffer size or notif(count 128)printk(ILITEK_ERROR_LEVEL %s, buffer exceed 128 bytesn, _func_);return -1;/ copy data from user

26、spaceret = copy_from_user(buffer, buf, count-1);if(ret 0)printk(ILITEK_ERROR_LEVEL %s, copy data from user space, failed, _func_);return -1;/ parsing command if(strcmp(buffer, calibrate) = 0)buffer0 = ILITEK_TP_CMD_ERASE_BACKGROUND; msgs0.len = 1; ret = ilitek_i2c_transfer(i2c.client, msgs, 1); if(r

27、et 0) printk(ILITEK_DEBUG_LEVEL %s, i2c erase background, failedn, _func_); else printk(ILITEK_DEBUG_LEVEL %s, i2c erase background, successn, _func_); buffer0 = ILITEK_TP_CMD_CALIBRATION; msgs0.len = 1; msleep(2000); ret = ilitek_i2c_transfer(i2c.client, msgs, 1);if(ret addr, .flags = 0, .len = len

28、, .buf = buffer, ;/ parsing ioctl commandswitch(cmd)case ILITEK_IOCTL_I2C_WRITE_DATA:ret = copy_from_user(buffer, (unsigned char*)arg, len);if(ret 0) printk(ILITEK_ERROR_LEVEL %s, copy data from user space, failedn, _func_); return -1; ret = ilitek_i2c_transfer(i2c.client, msgs, 1);if(ret 0)printk(I

29、LITEK_ERROR_LEVEL %s, i2c write, failedn, _func_);return -1;break;case ILITEK_IOCTL_I2C_READ_DATA:msgs0.flags = I2C_M_RD;ret = ilitek_i2c_transfer(i2c.client, msgs, 1);if(ret 0) printk(ILITEK_ERROR_LEVEL %s, i2c read, failedn, _func_);return -1; ret = copy_to_user(unsigned char*)arg, buffer, len);if

30、(ret evbit0 = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);input-keybitBIT_WORD(BTN_TOUCH) = BIT_MASK(BTN_TOUCH); input_set_abs_params(input, ABS_MT_POSITION_X, 0, max_x, 0, 0); input_set_abs_params(input, ABS_MT_POSITION_Y, 0, max_y, 0, 0); input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0); inpu

31、t_set_abs_params(input, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);input_set_abs_params(input, ABS_MT_TRACKING_ID, 0, max_tp, 0, 0);for(key=0; keysizeof(touch_key_code); key+) if(touch_key_codekey keybit);input-name = ILITEK_I2C_DRIVER_NAME;input-id.bustype = BUS_I2C;input-dev.parent = &(i2c.client)-dev;/*de

32、scriptionsend message to i2c adaptorparameterclienti2c clientmsgsi2c messagecnti2c message countreturn= 0 if successothers if error*/static int ilitek_i2c_transfer(struct i2c_client *client, struct i2c_msg *msgs, int cnt)int ret, count=ILITEK_I2C_RETRY_COUNT;while(count = 0)count-= 1;ret = down_inte

33、rruptible(&i2c.wr_sem); ret = i2c_transfer(client-adapter, msgs, cnt); up(&i2c.wr_sem); if(ret addr, .flags = 0, .len = 1, .buf = &cmd,.addr = client-addr, .flags = I2C_M_RD, .len = length, .buf = data, ; ret = ilitek_i2c_transfer(client, msgs, 2);if(ret 0)printk(ILITEK_ERROR_LEVEL %s, i2c read error, ret %dn, _func_, ret);return ret;/*descriptionpr

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 网络科技 > 其他相关文档

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报