Android(4.4.2) Touch Driver Implement

要開發Android Touch driver,就軟體部分必須先了解以下幾點
.Linux Driver Architecture
.Linux Input Subsystem
.The User Level Input Subsystem

就硬體部分,必須了解Touch panel的運作原理
基本上Touch硬體的運作方式算是比較單純的,通常來說在Touch硬體介面來說都是走I2C或是SPI,其中又以I2C介面佔大宗。除了I2C之外,還會有Power pin用來提供電給touch panel,接著就是比較重要的 IRQ pin、RESET pin;當使用這觸摸到 Touch是,Touch硬體經過抖動他的IRQ pin讓HOST端知道Touch被觸摸了,接著HOST touch driver就必須經由 ISR 經由I2C介面去跟Touch module讀取x,y座標值等資料,並回報給OS讓OS知道座標相關資訊,進而移動滑鼠。

硬體工作原理說完了,接著來說說軟體部分

.Linux Driver Architecture
有關Linux Driver Architecture部分,這是屬於比較基本的linux driver架構,市面上很多書籍或是網站都可以找到相關資料,讀者可以自己嘗試去寫一隻簡單的 character device driver,嘗試秀出一些訊息玩玩看,基本上可以將 dirver compile出來並順利insmod,應該就沒有甚麼問題了。

.Linux Input Subsystem
至於input subsystem部分,我在網路上找的一個非常好的文章,讀者可以看看,並照著做做看
http://www.linuxjournal.com/article/6396
但因為linuxjournal這篇文章是在linux kernel還是在 2.5左右時寫的,如果你的linux kernel 已經是3.0左右的版本,有一些code的部分就必須修改,我把修改的 code放在 https://github.com/Ypsclub/register 有需要的人可以參考看看

基本上如果你讀完http://www.linuxjournal.com/article/6396 文章,你將會知道:

.Driver先跟input core註冊,input core透過 handler與 user space溝通。
.input.h中 input_event資料結構中time,type,code,value意義跟用法。
.在driver,input core, handler之間的互動是透過 events方式,這讓user space可以透過 event handlers方式來與硬體互動。
.input core exports有用的 /proc 檔案系統介面可用來看目前有哪些裝置與handler已經active, /proc/bus/input/devices
.當touch driver成功載起後,在/dev/input目錄下將會有與 /proc/bus/input/devices 中 handler相對應的device node出現,比如 mouse 0,event2。
.學會如何回報座標給OS,並讓鍵盤自動輸入字母與座標自動移動
.用 init_input_dev()跟input core註冊device.
.在device driver裡利用input_event送 events到 input_core。
.呼叫input_sync通知 event handler,裝置有資料要傳輸。

 

---待續---


.The User Level Input Subsystem
可以參考 http://thiemonge.org/getting-started-with-uinput 網站,裡面有詳細敘述如何寫一個user level input subsystem程式,

 

---待續---

arrow
arrow

    CuteParrot 發表在 痞客邦 留言(0) 人氣()