Linux Mouse Driver  /PS2 By Sean Chen 2010/04/30
Agenda <ul><li>How and How to do it ? </li></ul><ul><li>Input sub System 4 Mouse </li></ul><ul><li>Flow Chart 4 Mouse </li...
How and How to do it ? <ul><li>Mouse </li></ul><ul><ul><li>Event </li></ul></ul><ul><ul><ul><li>Mouse location (x,y) </li>...
Input sub System 4 Mouse <ul><li>Input sub System 4 Mouse </li></ul><ul><ul><li>Driver </li></ul></ul><ul><ul><ul><li>Mous...
Flow Chart 4 Mouse  Input  sub System  4 Mouse Device Driver input_handler . event  = mousedev_event,   . connect  = mouse...
Trace code/main() <ul><li>Linux Kernel 2.6.X </li></ul><ul><ul><li>Path  /linux-2.6.33.3/drivers/input/mousedev.c </li></u...
Trace code/module_init(); <ul><li>module_init(mousedev_init); </li></ul><ul><ul><li>mousedev_create(& mousedev_handler ); ...
Trace code /mousedev_event() <ul><li>Event type </li></ul><ul><ul><li>EV_ABS: Absolute axes (絕對座標)。  </li></ul></ul><ul><u...
Append References <ul><li>Linux Input Device  介紹 : APIs  </li></ul><ul><ul><li>http://www.jollen.org/blog/2009/04/linux_in...
Upcoming SlideShare
Loading in …5
×

Linux mouse

2,682 views
2,544 views

Published on

Linux mouse driver

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,682
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
29
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Linux mouse

  1. 1. Linux Mouse Driver /PS2 By Sean Chen 2010/04/30
  2. 2. Agenda <ul><li>How and How to do it ? </li></ul><ul><li>Input sub System 4 Mouse </li></ul><ul><li>Flow Chart 4 Mouse </li></ul><ul><li>Trace code </li></ul><ul><ul><li>main(); </li></ul></ul><ul><ul><ul><li>module_init(); </li></ul></ul></ul><ul><ul><ul><ul><li>mousedev_create(); </li></ul></ul></ul></ul><ul><ul><ul><ul><li>input_register_handler(); </li></ul></ul></ul></ul><ul><li>Append References </li></ul>
  3. 3. How and How to do it ? <ul><li>Mouse </li></ul><ul><ul><li>Event </li></ul></ul><ul><ul><ul><li>Mouse location (x,y) </li></ul></ul></ul><ul><ul><ul><li>Mouse key (Left, Right, Wheel) </li></ul></ul></ul><ul><ul><li>Event handle </li></ul></ul><ul><ul><ul><li>Display(X,Y); </li></ul></ul></ul><ul><ul><ul><li>Left_Pros(); </li></ul></ul></ul><ul><li>How to do it ? </li></ul><ul><ul><li>… Driver . </li></ul></ul><ul><li>Driver </li></ul><ul><ul><li>Linux2.6.X/ drivers/input </li></ul></ul><ul><ul><ul><li>Input sub system call </li></ul></ul></ul>
  4. 4. Input sub System 4 Mouse <ul><li>Input sub System 4 Mouse </li></ul><ul><ul><li>Driver </li></ul></ul><ul><ul><ul><li>Mouse detected (Physical) </li></ul></ul></ul><ul><ul><li>Input Core </li></ul></ul><ul><ul><ul><li>Input Layer </li></ul></ul></ul><ul><ul><ul><ul><li>Event ( Event Handler) </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Connect ( set bit, .flags ….) </li></ul></ul></ul></ul><ul><ul><li>Event Handler </li></ul></ul><ul><ul><ul><li>Mouse location </li></ul></ul></ul><ul><ul><ul><ul><li>X, Y </li></ul></ul></ul></ul><ul><ul><ul><li>Key function (process) </li></ul></ul></ul><ul><ul><ul><ul><li>Left, Right , Wheel </li></ul></ul></ul></ul><ul><li>Sequence </li></ul><ul><ul><li>Driver -> InputCore -> Eventhandler -> userspace (user application) </li></ul></ul>
  5. 5. Flow Chart 4 Mouse Input sub System 4 Mouse Device Driver input_handler . event = mousedev_event, . connect = mousedev_connect , .disconnect = mousedev_disconnect, .fops = &mousedev_fops, .minor = MOUSEDEV_MINOR_BASE, .name = &quot;mousedev&quot;, .id_table = mousedev_ids, mousedev_event case EV_ABS: case EV_REL: case EV_KEY: case EV_SYN: mousedev_connect .flags : .evbit : .keybit : .relbit : .absbit : … Create_mouse_device User Application
  6. 6. Trace code/main() <ul><li>Linux Kernel 2.6.X </li></ul><ul><ul><li>Path /linux-2.6.33.3/drivers/input/mousedev.c </li></ul></ul><ul><li>Include </li></ul><ul><ul><li>#include <linux/init.h> </li></ul></ul><ul><ul><ul><li>宣告一些 macro 供 Linux 處理 initial function || section </li></ul></ul></ul><ul><ul><li>#include <linux/input.h> </li></ul></ul><ul><ul><ul><li>subsystem for “ 鍵盤與滑鼠的輸入” </li></ul></ul></ul><ul><ul><ul><li>event define </li></ul></ul></ul><ul><ul><li>#include <linux/device.h> </li></ul></ul><ul><ul><ul><li>Register device 2 Linux </li></ul></ul></ul><ul><ul><li>#include <linux/smp_lock.h> </li></ul></ul><ul><ul><ul><li>Lock processor </li></ul></ul></ul><ul><ul><li>… </li></ul></ul><ul><li>Define </li></ul><ul><ul><li>CONFIG_INPUT_MOUSEDEV_SCREEN_ X </li></ul></ul><ul><ul><li>CONFIG_INPUT_MOUSEDEV_SCREEN_ Y </li></ul></ul><ul><li>module_init(mousedev_init) </li></ul><ul><li>module_exit(mousedev_exit); </li></ul>X Y
  7. 7. Trace code/module_init(); <ul><li>module_init(mousedev_init); </li></ul><ul><ul><li>mousedev_create(& mousedev_handler ); </li></ul></ul><ul><ul><ul><li>kzalloc(); // 動態產生記憶體位置給 mouse_dev </li></ul></ul></ul><ul><ul><ul><li>INIT_LIST_HEAD(); // 加入 List_head 中 , 讓 Linux kernel 能 handle </li></ul></ul></ul><ul><ul><ul><li>spin_lock_init(); // lock_init, 避免中斷 </li></ul></ul></ul><ul><ul><ul><li>mutex_init(); // 同步處理 , 判斷是否 lock </li></ul></ul></ul><ul><ul><ul><li>init_waitqueue_head(); // 設定 wait time </li></ul></ul></ul><ul><ul><ul><li>mousedev->handle.dev </li></ul></ul></ul><ul><ul><ul><li>mousedev->handle.handler </li></ul></ul></ul><ul><ul><ul><li>… . </li></ul></ul></ul><ul><ul><ul><li>Error handle </li></ul></ul></ul><ul><ul><li>input_register_handler (&mousedev_handler ); </li></ul></ul><ul><ul><ul><li>註冊滑鼠的 Handler </li></ul></ul></ul><ul><ul><ul><li>Event </li></ul></ul></ul><ul><ul><li>Error Handle </li></ul></ul>
  8. 8. Trace code /mousedev_event() <ul><li>Event type </li></ul><ul><ul><li>EV_ABS: Absolute axes (絕對座標)。 </li></ul></ul><ul><ul><li>EV_REL: Relative axes (相對座標)。 </li></ul></ul><ul><ul><li>EV_KEY: Keys and buttons (按鍵與按鈕)。 </li></ul></ul><ul><ul><li>EV_SYN: </li></ul></ul><ul><ul><ul><li>Sample </li></ul></ul></ul><ul><ul><ul><ul><li>case REL_X: </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>mousedev->packet.dx += value; </li></ul></ul></ul></ul></ul><ul><li>Set </li></ul><ul><ul><li>set_bit(index, &mousedev->packet.buttons); </li></ul></ul>
  9. 9. Append References <ul><li>Linux Input Device 介紹 : APIs </li></ul><ul><ul><li>http://www.jollen.org/blog/2009/04/linux_input_device_apis.html </li></ul></ul><ul><li>Linux mutex </li></ul><ul><ul><li>http://blog.csdn.net/David_Henry/archive/2010/03/22/5404799.aspx </li></ul></ul><ul><li>Linux Mouse Driver Sample </li></ul><ul><ul><li>http://fred-zone.blogspot.com/2010/01/mouse-linux-kernel-driver.html </li></ul></ul><ul><li>linux 输入子系统分析 </li></ul><ul><ul><li>http://blog.chinaunix.net/u3/108121/showart_2122577.html </li></ul></ul>

×