ARM-Linux驅(qū)動(dòng)-觸摸屏驅(qū)動(dòng)分析
內(nèi)核版本:2.6.28
本文引用地址:http://m.butianyuan.cn/article/201611/318865.htm主機(jī)平臺(tái):Ubuntu 11.04
內(nèi)核版本:2.6.39
1、下面是ADC和觸摸屏接口的模塊圖
當(dāng)觸摸屏接口使用時(shí),XM或YM接觸摸屏接口的地
當(dāng)觸摸屏接口不使用時(shí),XM或YM接模擬信號(hào),做普通ADC使用。
2、觸摸屏接口的幾種操作模式
(1) 正常轉(zhuǎn)換模式
通過(guò)設(shè)置ADCCON(adc控制寄存器)來(lái)完成初始化,并對(duì)ADCDAT0數(shù)據(jù)寄存器進(jìn)行操作。
(2) 分離XY坐標(biāo)模式
X坐標(biāo)模式寫X坐標(biāo)轉(zhuǎn)換數(shù)據(jù)到ADCDAT0,觸摸屏接口產(chǎn)生中斷到中斷控制寄存器。Y坐標(biāo)模式寫Y坐標(biāo)轉(zhuǎn)換數(shù)據(jù)到ADCDAT1,觸摸屏接口產(chǎn)生中斷到中斷控制寄存器。兩種模
式可以選擇一種模式工作。
相應(yīng)的引腳連接:
(3) 自動(dòng)XY坐標(biāo)模式
觸摸屏控制器連續(xù)的轉(zhuǎn)換X和Y的坐標(biāo),在X坐標(biāo)轉(zhuǎn)換后的值存入ADCDAT0后,自動(dòng)將Y坐標(biāo)轉(zhuǎn)換后的值存入ADCDAT1,觸摸屏接口產(chǎn)生中斷到中斷控制器。
相應(yīng)的引腳連接:
(4) 等待中斷模式
當(dāng)光標(biāo)被按下,觸摸屏控制器產(chǎn)生中斷IRQ_TC,當(dāng)產(chǎn)生中斷信號(hào)時(shí),等待中斷模式必須被清除。
引腳定義如下:
3、下面是s3c2440觸摸屏驅(qū)動(dòng)的分析
- //#defineCONFIG_TOUCHSCREEN_S3C2410_DEBUG
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #include
- #defineTRUE1//CoAsiaadded
- #defineFALSE0//CoAsiaadded
- #defineFILTER_LIMIT25//CoAsiaadded
- /*Forts.dev.id.version*/
- #defineS3C2410TSVERSION0x0101
- #defineTSC_SLEEP(S3C2410_ADCTSC_PULL_UP_DISABLE|S3C2410_ADCTSC_XY_PST(0))
- #defineWAIT4INT(x)(((x)<<8)|
- S3C2410_ADCTSC_YM_SEN|S3C2410_ADCTSC_YP_SEN|S3C2410_ADCTSC_XP_SEN|
- S3C2410_ADCTSC_XY_PST(3))
- #defineAUTOPST(S3C2410_ADCTSC_YM_SEN|S3C2410_ADCTSC_YP_SEN|S3C2410_ADCTSC_XP_SEN|
- S3C2410_ADCTSC_AUTO_PST|S3C2410_ADCTSC_XY_PST(0))
- #defineDEBUG_LVL"<3>"http://KERN_DEBUG
- staticchar*s3c2440ts_name="s3c2440TouchScreen";
- /*
- *Per-touchscreendata.
- */
- //定義s3c2440觸摸屏使用的數(shù)據(jù)結(jié)構(gòu)體
- structs3c2440ts{
- structinput_dev*dev;
- longxp;
- longyp;
- intcount;
- intshift;
- };
- staticstructs3c2440tsts;
- staticstructclk*adc_clock;
- //__iomem聲明地址空間是設(shè)備地址映射空間
- staticvoid__iomem*base_addr;
- //函數(shù)聲明
- staticvoidtouch_timer_fire(unsignedlongdata);
- staticirqreturn_ttc_irq(intirq,void*dev_id);
- staticirqreturn_tadc_irq(intirq,void*dev_id);
- staticint__inits3c2440ts_probe(structplatform_device*pdev);
- staticints3c2440ts_remove(structplatform_device*pdev);
- staticints3c2440ts_resume(structplatform_device*pdev);
- //定義定時(shí)器
- staticstructtimer_listtouch_timer=
- TIMER_INITIALIZER(touch_timer_fire,0,0);
- //IRQ_TC中斷處理函數(shù)
- staticirqreturn_ttc_irq(intirq,void*dev_id)
- {
- //data0,data1用于存放讀取的ADCDAT數(shù)據(jù)寄存器的值
- unsignedlongdata0;
- unsignedlongdata1;
- intupdown;//用于存放光標(biāo)的按下或提起的狀態(tài)
- //讀取ADCDAT0、ADCDAT1數(shù)據(jù)寄存器的值
- data0=readl(base_addr+S3C2410_ADCDAT0);
- data1=readl(base_addr+S3C2410_ADCDAT1);
- //查看數(shù)據(jù)寄存器的第15位的值
- updown=(!(data0&S3C2410_ADCDAT0_UPDOWN))&&(!(data1&S3C2410_ADCDAT0_UPDOWN));
- /*TODOweshouldnevergetaninterruptwithupdownsetwhile
- *thetimerisrunning,butmaybeweoughttoverifythatthe
- *timerisntrunninganyways.*/
- //如果data0和data1的第15位都是0,則updown為1,則通過(guò)函數(shù)touch_timer_fire()函數(shù)來(lái)啟動(dòng)ADC轉(zhuǎn)換
- if(updown)
- touch_timer_fire(0);
- returnIRQ_HANDLED;
- }
- staticvoidtouch_timer_fire(unsignedlongdata)
- {
- //用于存儲(chǔ)數(shù)據(jù)寄存器ADCDAT0、ADCDAT1的值
- unsignedlongdata0;
- unsignedlongdata1;
- //用于存放光標(biāo)是否被按下
- intupdown;
- data0=readl(base_addr+S3C2410_ADCDAT0);
- data1=readl(base_addr+S3C2410_ADCDAT1);
- updown=(!(data0&S3C2410_ADCDAT0_UPDOWN))&&(!(data1&S3C2410_ADCDAT0_UPDOWN));
- //printk("Thenumberofupdownis%dn",updown);
- //如果光標(biāo)被按下,執(zhí)行
- if(updown)
- {
- //ts.count!=0表示ADC已經(jīng)轉(zhuǎn)換過(guò),下面就報(bào)告事件和光標(biāo)位置數(shù)據(jù)
- if(ts.count!=0)
- {
- ts.xp>>=ts.shift;//這里shift為2,這里實(shí)際上是求均值,四次的和/4,這樣定位更加準(zhǔn)確
- ts.yp>>=ts.shift;
- #ifdefCONFIG_TOUCHSCREEN_S3C2410_DEBUG
- {
- structtimevaltv;
- do_gettimeofday(&tv);
- printk(DEBUG_LVL"T:%06d,X:%03ld,Y:%03ldn",(int)tv.tv_usec,ts.xp,ts.yp);
- }
- #endif
- /*
- 下面的函數(shù)位于/include/linux/input.h,作用是報(bào)告事件
- staticinlinevoidinput_report_abs(structinput_dev*dev,unsignedintcode,intvalue)
- {
- input_event(dev,EV_ABS,code,value);
- }
- */
- //報(bào)告X,Y的絕對(duì)坐標(biāo)
- input_report_abs(ts.dev,ABS_X,ts.xp);
- input_report_abs(ts.dev,ABS_Y,ts.yp);
- //報(bào)告事件,1代表光標(biāo)被按下
- input_report_key(ts.dev,BTN_TOUCH,1);
- //報(bào)告觸摸屏狀態(tài),1代表觸摸屏被按下
- input_report_abs(ts.dev,ABS_PRESSURE,1);
- //等待接收方的確認(rèn),用于事件的同步
- input_sync(ts.dev);
- }
- //現(xiàn)在光標(biāo)被按下,并且ADC轉(zhuǎn)換沒(méi)有啟動(dòng)
- ts.xp=0;
- ts.yp=0;
- ts.count=0;
- //設(shè)置觸摸屏控制寄存器的值為0xdcB:11011100,設(shè)置控制寄存器上拉無(wú)效,自動(dòng)轉(zhuǎn)換X,Y坐標(biāo)
- //printk("S3C2410_ADCTSC:0x%xn",S3C2410_ADCTSC_PULL_UP_DISABLE|AUTOPST);
- writel(S3C2410_ADCTSC_PULL_UP_DISABLE|AUTOPST,base_addr+S3C2410_ADCTSC);
- //啟動(dòng)ADC轉(zhuǎn)換
- writel(readl(base_addr+S3C2410_ADCCON)|S3C2410_ADCCON_ENABLE_START,base_addr+S3C2410_ADCCON);
- }
- else//光標(biāo)沒(méi)有被按下
- {
- ts.count=0;
- //報(bào)告事件及光標(biāo)的位置狀態(tài)
- input_report_key(ts.dev,BTN_TOUCH,0);
- input_report_abs(ts.dev,ABS_PRESSURE,0);
- //等待接收方的應(yīng)答,用于同步
- input_sync(ts.dev);
- //設(shè)置觸摸屏控制寄存器為等待中斷模式
- writel(WAIT4INT(0),base_addr+S3C2410_ADCTSC);
- }
- }
- staticirqreturn_tadc_irq(intirq,void*dev_id)
- {
- //用于存放數(shù)據(jù)寄存器的數(shù)據(jù)
- unsignedlongdata0;
- unsignedlongdata1;
- //讀取數(shù)據(jù),這次主要讀取的是位置數(shù)據(jù)
- data0=readl(base_addr+S3C2410_ADCDAT0);
- data1=readl(base_addr+S3C2410_ADCDAT1);
- ts.xp+=data0&S3C2410_ADCDAT0_XPDATA_MASK;//累加四次準(zhǔn)換結(jié)果的X坐標(biāo)和
- ts.yp+=data1&S3C2410_ADCDAT1_YPDATA_MASK;//累加四次準(zhǔn)換結(jié)果的Y坐標(biāo)和
- ts.count++;//轉(zhuǎn)換次數(shù)加一
- //如果轉(zhuǎn)換次數(shù)小于4
- if(ts.count<(1<
- {
- //再次設(shè)置觸摸屏控制寄存器上拉不使能、自動(dòng)X、Y轉(zhuǎn)換模式
- writel(S3C2410_ADCTSC_PULL_UP_DISABLE|AUTOPST,base_addr+S3C2410_ADCTSC);
- //再次啟動(dòng)ADC轉(zhuǎn)換
- writel(readl(base_addr+S3C2410_ADCCON)|S3C2410_ADCCON_ENABLE_START,base_addr+S3C2410_ADCCON);
- }
- else//這時(shí),ADC轉(zhuǎn)換四次完成,延遲一個(gè)系統(tǒng)滴答,執(zhí)行touch_timer_fire()函數(shù)
- {
- mod_timer(&touch_timer,jiffies+1);
- writel(WAIT4INT(1),base_addr+S3C2410_ADCTSC);
- }
- returnIRQ_HANDLED;
- }
- /*
- *Thefunctionsforinserting/removingusasamodule.
- */
- /*
- 該結(jié)構(gòu)體定義在/include/linux/platform_device.h
- structplatform_device{
- constchar*name;
- intid;
- structdevicedev;
- u32num_resources;
- structresource*resource;
- };
- */
- staticint__inits3c2440ts_probe(structplatform_device*pdev)
- {
- intrc;
- /*
- 下面結(jié)構(gòu)體定義在/include/mach/s3c2410_ts.h
- structs3c2410_ts_mach_info{
- intdelay;
- intpresc;
- intoversampling_shift;
- };
- */
- structs3c2410_ts_mach_info*info;
- structinput_dev*input_dev;
- /*
- void*platform_data;//Platformspecificdata,devicecoredoesnttouchit
- */
- info=(structs3c2440_ts_mach_info*)pdev->dev.platform_data;
- if(!info)
- {
- printk(KERN_ERR"Hm...toobad:noplatformdatafortsn");
- return-EINVAL;
- }
- #ifdefCONFIG_TOUCHSCREEN_S3C2410_DEBUG
- printk(DEBUG_LVL"Enterings3c2440ts_initn");
- #endif
- //由于ADC轉(zhuǎn)換需要時(shí)鐘,這里獲取時(shí)鐘
- adc_clock=clk_get(NULL,"adc");
- if(!adc_clock){
- printk(KERN_ERR"failedtogetadcclocksourcen");
- return-ENOENT;
- }
- clk_enable(adc_clock);//使能時(shí)鐘
- #ifdefCONFIG_TOUCHSCREEN_S3C2410_DEBUG
- printk(DEBUG_LVL"gotandenabledclockn");
- #endif
- //通過(guò)ioremap實(shí)現(xiàn)物理地址到虛擬地址的轉(zhuǎn)換
- base_addr=ioremap(S3C2410_PA_ADC,0x20);
- if(base_addr==NULL){
- printk(KERN_ERR"Failedtoremapregisterblockn");
- return-ENOMEM;
- }
- //設(shè)置ADCCON控制寄存器為0x4c40,設(shè)置預(yù)分頻有效,預(yù)分頻值為B:110001D:49
- //printk("ADCCONis0x%xn",S3C2410_ADCCON_PRSCEN|S3C2410_ADCCON_PRSCVL(info->presc&0xFF));
- if((info->presc&0xff)>0)
- writel(S3C2410_ADCCON_PRSCEN|S3C2410_ADCCON_PRSCVL(info->presc&0xFF),
- base_addr+S3C2410_ADCCON);
- else
- writel(0,base_addr+S3C2410_ADCCON);
- /*Initialiseregisters*/
- /*
- 設(shè)置ADC開始延時(shí)寄存器ADCDLY:0x4e20
- */
- //printk("ADCDLY:0x%xn",info->delay&0xffff);
- if((info->delay&0xffff)>0)
- writel(info->delay&0xffff,base_addr+S3C2410_ADCDLY);
- /*
- 設(shè)置ADC觸摸屏控制寄存器ADC_TSC:0xd3B:11010011
- [8]檢測(cè)光標(biāo)按下中斷信號(hào)
- [7]YM輸出驅(qū)動(dòng)有效(GND)
- [6]YP輸出驅(qū)動(dòng)無(wú)效(AIN5)
- [5]XM輸出驅(qū)動(dòng)無(wú)效(Hi-z)
- [4]XP輸出驅(qū)動(dòng)無(wú)效(AIN7)
- [3]XP上拉有效
- [2]普通ADC轉(zhuǎn)換
- [0:1]等待中斷模式測(cè)量X和Y的坐標(biāo)
- */
- //printk("ADC_TSC:0x%xn",WAIT4INT(0));
- writel(WAIT4INT(0),base_addr+S3C2410_ADCTSC);
- /*Initialiseinputstuff*/
- memset(&ts,0,sizeof(structs3c2440ts));
- /*
- 下面的函數(shù)
- 為新的輸入設(shè)備分配內(nèi)存。
- 使用free_device()釋放沒(méi)有被注冊(cè)的函數(shù),使用input_unregister_device()解除已經(jīng)注冊(cè)的設(shè)備
- 定義在/drivers/input/input.c
- structinput_dev*input_allocate_device(void)
- {
- structinput_dev*dev;
- dev=kzalloc(sizeof(structinput_dev),GFP_KERNEL);
- if(dev){
- dev->dev.type=&input_dev_type;
- dev->dev.class=&input_class;
- device_initialize(&dev->dev);
- mutex_init(&dev->mutex);
- spin_lock_init(&dev->event_lock);
- INIT_LIST_HEAD(&dev->h_list);
- INIT_LIST_HEAD(&dev->node);
- __module_get(THIS_MODULE);
- }
- returndev;
- }
- */
- input_dev=input_allocate_device();
- if(!input_dev){
- printk(KERN_ERR"Unabletoallocatetheinputdevice!!n");
- return-ENOMEM;
- }
- //下面初始化輸入設(shè)備信息
- ts.dev=input_dev;
- ts.dev->evbit[0]=BIT_MASK(EV_SYN)|BIT_MASK(EV_KEY)|
- BIT_MASK(EV_ABS);
- ts.dev->keybit[BIT_WORD(BTN_TOUCH)]=BIT_MASK(BTN_TOUCH);
- input_set_abs_params(ts.dev,ABS_X,0,0x3FF,0,0);
- input_set_abs_params(ts.dev,ABS_Y,0,0x3FF,0,0);
- input_set_abs_params(ts.dev,ABS_PRESSURE,0,1,0,0);
- //ts.dev->private=&ts;
- ts.dev->name=s3c2440ts_name;
- ts.dev->id.bustype=BUS_RS232;
- ts.dev->id.vendor=0xDEAD;
- ts.dev->id.product=0xBEEF;
- ts.dev->id.version=S3C2410TSVERSION;
- ts.shift=info->oversampling_shift;
- //printk("shift:%dn",ts.shift);
- /*Getirqs*/
- //申請(qǐng)ADC中斷,注意,中斷類型為IRQF_SAMPLE_RANDOM|IRQF_SHARED,這樣在使用觸摸屏的時(shí)候
- //可以調(diào)試自己的ADC轉(zhuǎn)換驅(qū)動(dòng),中斷處理函數(shù)為adc_irq
- if(request_irq(IRQ_ADC,adc_irq,IRQF_SAMPLE_RANDOM|IRQF_SHARED,
- "s3c2440_action",ts.dev)){
- printk(KERN_ERR"s3c2440_ts.c:CouldnotallocatetsIRQ_ADC!n");
- iounmap(base_addr);
- return-EIO;
- }
- //申請(qǐng)TC中斷,中斷處理函數(shù)為tc_irq
- if(request_irq(IRQ_TC,tc_irq,IRQF_SAMPLE_RANDOM,
- "s3c2440_action",ts.dev)){
- printk(KERN_ERR"s3c2440_ts.c:CouldnotallocatetsIRQ_TC!n");
- free_irq(IRQ_ADC,ts.dev);
- iounmap(base_addr);
- return-EIO;
- }
- printk(KERN_INFO"%ssuccessfullyloadedn",s3c2440ts_name);
- /*Allwentok,soregistertotheinputsystem*/
- /*這里注冊(cè)設(shè)備
- 函數(shù)功能:
- *Thisfunctionregistersdevicewithinputcore.Thedevicemustbe
- *allocatedwithinput_allocate_device()andallitscapabilities
- *setupbeforeregistering.
- *Iffunctionfailsthedevicemustbefreedwithinput_free_device().
- *Oncedevicehasbeensuccessfullyregistereditcanbeunregistered
- *withinput_unregister_device();input_free_device()shouldnotbe
- *calledinthiscase.
- 函數(shù)原型如下:
- intinput_register_device(structinput_dev*dev)
- {
- staticatomic_tinput_no=ATOMIC_INIT(0);
- structinput_handler*handler;
- constchar*path;
- interror;
- __set_bit(EV_SYN,dev->evbit);
- init_timer(&dev->timer);
- if(!dev->rep[REP_DELAY]&&!dev->rep[REP_PERIOD]){
- dev->timer.data=(long)dev;
- dev->timer.function=input_repeat_key;
- dev->rep[REP_DELAY]=250;
- dev->rep[REP_PERIOD]=33;
- }
- if(!dev->getkeycode)
- dev->getkeycode=input_default_getkeycode;
- if(!dev->setkeycode)
- dev->setkeycode=input_default_setkeycode;
- snprintf(dev->dev.bus_id,sizeof(dev->dev.bus_id),
- "input%ld",(unsignedlong)atomic_inc_return(&input_no)-1);
- error=device_add(&dev->dev);
- if(error)
- returnerror;
- path=kobject_get_path(&dev->dev.kobj,GFP_KERNEL);
- printk(KERN_INFO"input:%sas%sn",
- dev->name?dev->name:"Unspecifieddevice",path?path:"N/A");
- kfree(path);
- error=mutex_lock_interruptible(&input_mutex);
- if(error){
- device_del(&dev->dev);
- returnerror;
- }
- list_add_tail(&dev->node,&input_dev_list);
- list_for_each_entry(handler,&input_handler_list,node)
- input_attach_handler(dev,handler);
- input_wakeup_procfs_readers();
- mutex_unlock(&input_mutex);
- return0;
- }
- */
- rc=input_register_device(ts.dev);
- if(rc){
- free_irq(IRQ_TC,ts.dev);
- free_irq(IRQ_ADC,ts.dev);
- clk_disable(adc_clock);
- iounmap(base_addr);
- return-EIO;
- }
- return0;
- }
- staticints3c2440ts_remove(structplatform_device*pdev)
- {
- disable_irq(IRQ_ADC);
- disable_irq(IRQ_TC);
- free_irq(IRQ_TC,ts.dev);
- free_irq(IRQ_ADC,ts.dev);
- if(adc_clock){
- clk_disable(adc_clock);
- clk_put(adc_clock);
- adc_clock=NULL;
- }
- input_unregister_device(ts.dev);
- iounmap(base_addr);
- return0;
- }
- #ifdefCONFIG_PM
- staticints3c2440ts_suspend(structplatform_device*pdev,pm_message_tstate)
- {
- writel(TSC_SLEEP,base_addr+S3C2410_ADCTSC);
- writel(readl(base_addr+S3C2410_ADCCON)|S3C2410_ADCCON_STDBM,
- base_addr+S3C2410_ADCCON);
- disable_irq(IRQ_ADC);
- disable_irq(IRQ_TC);
- clk_disable(adc_clock);
- return0;
- }
- staticints3c2440ts_resume(structplatform_device*pdev)
- {
- structs3c2440_ts_mach_info*info=
- (structs3c2440_ts_mach_info*)pdev->dev.platform_data;
- clk_enable(adc_clock);
- msleep(1);
- enable_irq(IRQ_ADC);
- enable_irq(IRQ_TC);
- if((info->presc&0xff)>0)
- writel(S3C2410_ADCCON_PRSCEN|S3C2410_ADCCON_PRSCVL(info->presc&0xFF),
- base_addr+S3C2410_ADCCON);
- else
- writel(0,base_addr+S3C2410_ADCCON);
- /*Initialiseregisters*/
- if((info->delay&0xffff)>0)
- writel(info->delay&0xffff,base_addr+S3C2410_ADCDLY);
- writel(WAIT4INT(0),base_addr+S3C2410_ADCTSC);
- return0;
- }
- #else
- #defines3c2440ts_suspendNULL
- #defines3c2440ts_resumeNULL
- #endif
- /*
- 下面是/linux/platform_device.h定義的platform_driver結(jié)構(gòu)體
- structplatform_driver{
- int(*probe)(structplatform_device*);//設(shè)備的檢測(cè),所以需要先前的設(shè)備注冊(cè)
- int(*remove)(structplatform_device*);//刪除該設(shè)備
- void(*shutdown)(structplatform_device*);//關(guān)閉該設(shè)備
- int(*suspend)(structplatform_device*,pm_message_tstate);
- int(*suspend_late)(structplatform_device*,pm_message_tstate);
- int(*resume_early)(structplatform_device*);
- int(*resume)(structplatform_device*);
- structpm_ext_ops*pm;
- structdevice_driverdriver;//設(shè)備驅(qū)動(dòng),定義在include/linux/device.h中
- };
- 內(nèi)核提供的platform_driver結(jié)構(gòu)體的注冊(cè)函數(shù)為platform_driver_register(),該函數(shù)定義在driver/base/platform.c中
- */
- staticstructplatform_drivers3c2440ts_driver={
- .driver={
- .name="s3c2440-ts",
- .owner=THIS_MODULE,
- },
- .probe=s3c2440ts_probe,
- .remove=s3c2440ts_remove,
- .suspend=s3c2440ts_suspend,
- .resume=s3c2440ts_resume,
- };
- staticint__inits3c2440ts_init(void)
- {
- intrc;
- rc=platform_driver_register(&s3c2440ts_driver);
- if(rc<0)
- printk(KERN_ERR"platform_driver_registererror!n");
- returnrc;
- }
- staticvoid__exits3c2440ts_exit(void)
- {
- platform_driver_unregister(&s3c2440ts_driver);
- }
- module_init(s3c2440ts_init);
- module_exit(s3c2440ts_exit);
- MODULE_AUTHOR("YANMING");
- MODULE_DESCRIPTION("Mys3c2440touchscreendriver");
- MODULE_LICENSE("GPL");
從觸摸屏被按下到系統(tǒng)相應(yīng)的過(guò)程如下:
(1) 當(dāng)觸摸屏感覺(jué)到觸摸,觸發(fā)IRQ_TC中斷,然后讀取觸摸屏控制寄存器的值,判斷是否被按下,如果被按下,啟動(dòng)定時(shí)器,執(zhí)行touch_timer_fire()函數(shù)啟動(dòng)ADC轉(zhuǎn)換。
(2) ADC轉(zhuǎn)換完成后,會(huì)觸發(fā)IRQ_ADC中斷,執(zhí)行相應(yīng)的中斷處理函數(shù),如果ADC轉(zhuǎn)換次數(shù)小于4,再次啟動(dòng)ADC轉(zhuǎn)換;如果ADC轉(zhuǎn)換次數(shù)為4,則啟動(dòng)一個(gè)系統(tǒng)滴答定時(shí)器,執(zhí)行touch_timer_fire()函數(shù)
(3) 執(zhí)行定時(shí)器服務(wù)程序時(shí),如果此時(shí)觸摸屏仍被按下,則上報(bào)事件和坐標(biāo)數(shù)據(jù),重復(fù)(2);如果沒(méi)有被按下,上報(bào)時(shí)間和坐標(biāo)數(shù)據(jù),將觸摸屏控制寄存器設(shè)置為中斷等待狀態(tài)
可見(jiàn),觸摸屏驅(qū)動(dòng)的服務(wù)是一個(gè)封閉的循環(huán)過(guò)程。
評(píng)論