input子系統學習筆記四 軟體設計流程及相關API

來源:互聯網
上載者:User

【感謝終結者投遞本文】

        接下來,我們就開始看Input子系統的軟體設計流程,我在閱讀的時候同時整理設計代碼中的相關API,並在下一篇文章詳細介紹input子系統的代碼實現。

input子系統的軟體設計流程

        軟體設計流程如下所示:

        分配一個輸入裝置——註冊一個輸入裝置——上報輸入事件——登出一個輸入裝置——釋放一個輸入裝置

設計有關的API

分配一個輸入裝置

C/C++代碼
  1. struct input_dev *input_allocate_device*(void);   

註冊一個輸入裝置

C/C++代碼
  1. int input_register_device(struct input_dev *dev);  

驅動實現-事件支援

C/C++代碼
  1. Set_bit(EV_KEY,button_dev.evbit)  
  2. //Set_bit告訴inout子系統它支援哪些事件  
  3. //Struct input_dev中有兩個成員,一個是evbit;一個是keybit;分別用來表示裝置所支援的事件類型和按鍵類型。  

         事件類型

        Linux中輸入裝置的事件類型有(這裡只列出了常用的一些,更多請看linux/input.h中):

C/C++代碼
  1. EV_SYN 0x00 同步事件  
  2. EV_KEY 0x01 按鍵事件  
  3. EV_REL 0x02 相對座標  
  4. EV_ABS 0x03 絕對座標  
  5. EV_MSC 0x04 其它  
  6. EV_LED 0x11 LED  
  7. EV_SND 0x12 聲音  
  8. EV_REP 0x14 Repeat  
  9. EV_FF 0x15 Force feedback事件  

        按鍵類型

        當事件類型為EV_KEY時,還需指明按鍵類型:

C/C++代碼
  1. BTN_LEFT 滑鼠左鍵  
  2. BTN_RIGHT 滑鼠右鍵  
  3. BTN_MIDDLE 滑鼠中鍵  
  4. BTN_0 數字0鍵  
  5. BTN_1 數字1鍵  

        上述set_bit函數實則完成了把EV_KEY賦值到button_dev.evbit

        驅動實現-報告事件

C/C++代碼
  1. Void input_event(struct input_dev *dev,unsigned int type,unsigned int code,int value);//報告指定type,code的輸入事件  
  2. Void input_report_key(struct input_dev *dev,unsigned int code,int value);/*報告索引值,code : 事件的代碼,如果事件是ev_key,該代碼則為裝置的鍵盤代碼。例如滑鼠按鍵代碼為0x110~0x116,其中0x110(BTN_LEFT),0x111(BTN_RIGHT),0x112(BTN_MIDDLE)。其它帶按摩含義參考include/linux/input.h檔案*/  
  3. value : 事件的值,如果事件的類型是EV_KEY,當按鍵按下時值為1,鬆開時為0。  
  4. Void input_report_rel(struct input_dev *dev,unsigned int code,int value);//報告相對座標  
  5. Void input_report_abs(struct input_dev *dev,unsigned int code,int value);//報告絕對座標  
  6. Void input_sync(struct input_dev *dev);/*報告同步事件,input_sync()用於高速input core 此次報告已經結束,能夠根據上報的資訊往後面處理了*/  

        在觸控螢幕驅動設計中,一次座標及按下狀態的整個報告過程如下:

C/C++代碼
  1. Input_report_abs(input_dev,ABS_X,x);//X座標  
  2. Input_report_abs(input_dev,ABS_Y,y);//Y座標  
  3. Input_report_abs(input_dev,ABS_PRESSURE,pres);//壓力  
  4. input_sync(struct input_dev *dev);//同步   

釋放與登出裝置

C/C++代碼
  1. Void input_free_device(struct input_dev *dev);  
  2. Void input_unregister_device(struct input_dev *);  

原文連結 http://www.ourunix.org/post/293.html

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.