基於Windows CE6.0和 AK4182觸摸屏驅動實現

本驅動實現了FreescaleImx515平臺下的AK4182A 觸摸屏採樣功能。通過在WINDOWS CE平臺上按照WINDOWS CE TOUCH DDSI 接口標準完成了所有的12 bit精度的數據採樣功能。

該驅動實現了一個標準的WINDOWS CE 觸摸屏驅動,使用中斷(Interrupt)實現PEN DOWN 檢測,通過定時器(Timer)中斷採集Pen Move數據,並同時判斷是否PEN UP狀態。在此過程中,會通過點過濾算法和壓力檢測算法去除雜點和平滑,最後有效的原始位置數據會發給WINDOWS CE 高層接口進行屏幕校正處理。

該驅動完成了如下硬件條件下的採樣:

l  PEN DOWN中斷支持

l  IMX515 SPI接口

l  12BIT採樣

l  屏幕分辨率1024*768

l  四線電阻式觸摸屏

l  壓力檢測支持

 

 

1、Windows CE 6觸摸屏驅動模型

1.1 整體模型

觸摸屏驅動讀取用戶觸摸數據,並將其轉換爲內部格式發送給windowsce系統的GWES。驅動要負責把採樣的原始輸入數據(uncalibrated raw coordinates)轉換爲校正後的輸入數據(calibrated coordinates)。

用戶點觸觸摸屏幕,會產生PEN DOWN 中斷。該中斷激活觸摸屏驅動的自動採樣例程,該例程可以定時採樣數據和用戶PENUP事件,並將最後校正好的數據發送給GWES,從而讓GWES能夠獲取用戶位置並顯示出來。

模型邏輯圖示如下。

驅動模型分爲MDD層和PDD層。

MDD層負責和GWES接口,並完成校正算法和屏幕校正等相關工作。

PDD層負責具體的PEN DOWN、PEN UP中斷響應、數據採樣、壓力感應和算法平滑等相關工作。


1.2 模型數據接口定義

n  數據有效性說明

enum enumTouchPanelSampleFlags {

  TouchSampleValidFlag = 0x01, (該採樣點有效)

  TouchSampleDownFlag = 0x02, (PEN 狀態,與採樣點狀態“或”上後通知高層)

  TouchSampleIsCalibratedFlag = 0x04,

  TouchSamplePreviousDownFlag = 0x08,

  TouchSampleIgnore = 0x10,(無效點狀態)

  TouchSampleMouse = 0x40000000

};

 

n  Touch驅動的MDD層接口

Thefollowing table shows the touch screen driver functions.

 

Programming element

Description

ErrorAnalysis

This function provides information on the accuracy of the touch screen calibration.

TouchCalibrate

This function starts the touch screen calibration sequence.

TouchPanelCalibrateAPoint

This function converts noncalibrated points to calibrated points.

TouchPanelDisable

This function disables the touch screen.

TouchPanelEnable

This function enables and re-enables the touch screen.

TouchPanelGetDeviceCaps

This function returns information about the capabilities of the touch screen.

TouchPanelInitializeCursor

This function provides an opportunity for touch drivers to move the cursor at initialization time.

TouchPanelPowerHandler

This function handles power-state change notifications.

TouchPanelReadCalibrationAbort

This function aborts the currently active call to the TouchPanelCalibrateAPoint function.

TouchPanelReadCalibrationPoint

This function initiates the process of getting a calibration point.

TouchPanelSetCalibration

This function initializes calibration information in a global parameter vCalcParam, which you can use to convert noncalibrated points to calibrated points by the TouchPanelCalibrateAPoint function.

TouchPanelSetMode

This function sets mode information for a touch screen device.

 

n  Touch 驅動的PDD層接口

Programming element

Description

DdsiTouchPanelAttach

This function executes when the MDD's DLL entry point receives a DLL_PROCESS_ATTACH message.

DdsiTouchPanelDetach

This function executes when the MDD's DLL entry point receives a DLL_PROCESS_DETACH message.

DdsiTouchPanelDisable

This function disables the touch screen device.

DdsiTouchPanelEnable

This function applies power to the touch screen device and initializes it for operation.

DdsiTouchPanelGetDeviceCaps

This function queries capabilities of the touch screen device.

DdsiTouchPanelGetPoint

This function returns the most recently acquired point and its associated tip state information.

DdsiTouchPanelPowerHandler

This function indicates to the driver that the system is entering or leaving the suspend state.

DdsiTouchPanelSetMode

This function sets information about the touch screen device.

 

n  數據精度要求

值得注意的是Windows CE 要求傳遞的校驗後的座標信息是最靠近像素點的四分之一像素。

 

1.3 平滑算法

WINDOWS CE不限制採樣點怎麼做平滑,由各個OEM廠商去實現。

具體算法可以有:

1)三點平均

2)三點比較,取最近的做平均

。。。。。。

1.4 校正算法

WINDOWS CE實現了最重要的校正算法,該校正算法可以實現屏幕旋轉、不同尺寸的非線性處理工作。

具體可以參看如下目錄:

iMX51-EVK\SRC\DRIVERS\Touchp\Mdd\Calibrate

2、AK4182A 基本原理

AK4182A芯片是一款四線電阻屏觸摸控制器,它最高支持125khz的採樣率,輸出的數據寬度是12bit.

AK4182A芯片可以感知PEN DOWN事件,並且產生一箇中斷信號給CPU。CPU通過命令啓動AK4182A採樣,它會在啓動後的第4個時鐘後開始串行輸出12位的採樣數據。

3 數據採集

    X軸或者Y軸每次從AK4182A採樣的時候,都會直接連續採樣3次,以保證每個軸的數據變化不會太劇烈。

同時在X軸採樣的時候,先計算Z軸(壓力數據)是否符合要求,不符合則將點丟棄。經驗證明,壓力值在不大於1500爲宜。

 

總體上在採集3個X軸,3個Y軸數據後,送入平滑算法。根據X軸的Delta和Y軸Delta範圍決定該數據是否符合要求,符合則被當做好點,否則被當做壞點。

 

上述原則也決定了如果我們要根據硬件的實際情況調試,則需要細緻調節:

EADC_GetADCSample 中的dwPressure 數值

TSP_EvaluateSample()算法中的 DELTA_Y_COORD_VARIANCE/

                            DELTA_X_COORD_VARIANCE



4 SPI 接口的細節 

由於AK4182A的數據只有12位,並且不是標準的SPI接口。要求我們使用IMX51 SPI時注意:

1)可以設定SPI 的數據寬度是24位或者32位,24位比較節省時間,32位有些浪費。

2)要求CPU側發送完8個BIT後,必須不再發送數據

3)CPU側的數據接收,從CPU發送第1個BIT開始,就同步接收中,所以要對接收的數據做移位處理。

4)設定SPI的時鐘不是越高越好,由於本次屏幕分辨率較高,觸摸屏很大,15英寸,這要求一次採樣的時間不能太快,否則會導致數據精度不高。經過實際測量,在1.5ms - 2ms較爲妥當。可以通過設定SPI 的時鐘來控制DCLK(即採樣速度)





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章