linux mouse

Post on 27-Jun-2015

2.452 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

DESCRIPTION

Linux mouse driver

TRANSCRIPT

Linux Mouse Driver /PS2

By Sean Chen 2010/04/30

Agenda

• How and How to do it ?• Input sub System 4 Mouse• Flow Chart 4 Mouse• Trace code

– main();• module_init();

– mousedev_create();

– input_register_handler();

• Append References

How and How to do it ?

• Mouse– Event

• Mouse location (x,y)

• Mouse key (Left, Right, Wheel)

– Event handle• Display(X,Y);

• Left_Pros();

• How to do it ?– … Driver.

• Driver – Linux2.6.X/drivers/input

• Input sub system call

Input sub System 4 Mouse• Input sub System 4 Mouse

– Driver• Mouse detected (Physical)

– Input Core• Input Layer

– Event ( Event Handler)

– Connect ( set bit, .flags ….)

– Event Handler• Mouse location

– X, Y

• Key function (process)– Left, Right , Wheel

• Sequence– Driver -> InputCore -> Eventhandler -> userspace (user application)

Flow Chart 4 Mouse

Device Driver

input_handler .event = mousedev_event, .connect = mousedev_connect, .disconnect = mousedev_disconnect, .fops = &mousedev_fops, .minor = MOUSEDEV_MINOR_BASE, .name = "mousedev", .id_table = mousedev_ids,

mousedev_eventcase EV_ABS:case EV_REL:case EV_KEY:case EV_SYN:

mousedev_connect.flags :.evbit :.keybit :.relbit :.absbit : …

Create_mouse_device

User Application Input sub System 4 Mouse

Trace code/main()• Linux Kernel 2.6.X

– Path /linux-2.6.33.3/drivers/input/mousedev.c• Include

– #include <linux/init.h>• 宣告一些 macro 供 Linux 處理 initial function || section

– #include <linux/input.h>• subsystem for “ 鍵盤與滑鼠的輸入”• event define

– #include <linux/device.h>• Register device 2 Linux

– #include <linux/smp_lock.h>• Lock processor

– …• Define

– CONFIG_INPUT_MOUSEDEV_SCREEN_X– CONFIG_INPUT_MOUSEDEV_SCREEN_Y

• module_init(mousedev_init)• module_exit(mousedev_exit);

X

Y

Trace code/module_init();

• module_init(mousedev_init);– mousedev_create(&mousedev_handler);

• kzalloc(); // 動態產生記憶體位置給 mouse_dev• INIT_LIST_HEAD(); // 加入 List_head 中 , 讓 Linux kernel 能 ha

ndle• spin_lock_init(); // lock_init, 避免中斷• mutex_init(); // 同步處理 , 判斷是否 lock• init_waitqueue_head(); // 設定 wait time• mousedev->handle.dev • mousedev->handle.handler • ….• Error handle

– input_register_handler(&mousedev_handler);• 註冊滑鼠的 Handler • Event

– Error Handle

Trace code/mousedev_event()

• Event type– EV_ABS: Absolute axes (絕對座標)。 – EV_REL: Relative axes (相對座標)。 – EV_KEY: Keys and buttons (按鍵與按鈕)。 – EV_SYN:

• Sample – case REL_X:

» mousedev->packet.dx += value;

• Set– set_bit(index, &mousedev->packet.buttons);

Append References

• Linux Input Device 介紹 : APIs – http://www.jollen.org/blog/2009/04/linux_input_device_apis.html

• Linux mutex – http://blog.csdn.net/David_Henry/archive/2010/03/22/5404799.a

spx

• Linux Mouse Driver Sample– http://fred-zone.blogspot.com/2010/01/mouse-linux-kernel-driver.

html

• linux 输入子系统分析 – http://blog.chinaunix.net/u3/108121/showart_2122577.html

top related