Input event驅動 Andrew Huang <bluedrum@163.com>
Linux 專門對輸入設備。 鍵盤,鼠標,手柄,觸摸屏。按鍵。封裝一個類驅動。 主要統(tǒng)一與應用程序接口。這一類的設備結點都是在/dev/input/eventn( 0<=n) 用戶程序讀驅動的輸入都采用統(tǒng)一格式,即struct input_event,方便應用程序來讀寫
Linux/input.h
struct input_event { struct timeval time; __u16 type; __u16 code; __s32 value; };
INPUT驅動查看
查看設備結點 ls -l /dev/input 查看設備信息 ls -l /proc/bus/input/ cat /proc/bus/input/devices 查看input class信息
ls /sys/class/input
input device 優(yōu)點 統(tǒng)一應用程序使用外部輸入設備的接口。這樣簡化編程。 Input core是沒有緩存隊列的,如果應用程序沒有及時取事件,則事件被丟棄。
input輸入驅動編程
輸入驅動數(shù)據(jù)結構 struct input_dev *input_dev; 在驅動中必須動態(tài)分配input_dev結構,這里使用 input_allocate_device(); 初始化input_dev的參數(shù) 調用 input_register_device()注冊, 退出時調用 input_unregister_device()
與應用程序的交互
Input 驅動的子系統(tǒng)已經控制I/O,換句話read/write不需要驅動直接. 驅動只需要input_report_xxx()上傳信息 input_report_key()上傳按鍵 input_report_abs() 絕對坐標 它們最終調用input_event來向input core上傳信息,并最后轉交給應用程序. Input core沒有緩存事件信息,這樣在應用程序開始read前的信息全部被丟棄.
input_dev 的初始化
evbit 表示這個驅動支持哪一些事件,有兩種等效的方法 set_bit(EV_KEY, input_dev->evbit); set_bit(EV_REL, input_dev->evbit); input_dev->evbit = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
初始化/proc/bus/input/devices的信息
#define DEVICE_NAME "s3c6410 gpio button"
myinput_dev->name = DEVICE_NAME; myinput_dev->phys = "gpio-button/input100"; myinput_dev->id.bustype = BUS_HOST; //設備 myinput_dev->id.vendor = 0x0001; myinput_dev->id.product = 0x0001; myinput_dev->id.version = 0x0001;
cat /proc/bus/input/devices
I: Bus=0019 Vendor=0001 Product=0001 Version=0001 N: Name="s3c6410 gpio button" P: Phys=gpio-button/input100 S: Sysfs=/class/input/input2 U: Uniq= H: Handlers=kbd event2 B: EV=3 B: KEY=1680 0 0 10000002
[root@urbetter 01]# insmod myinput.ko myinput_init 08: myinput_register_irq: rquest_irq: irq 101,name KYE1-UP myinput_register_irq: rquest_irq: irq 102,name KYE2-LEFT myinput_register_irq: rquest_irq: irq 103,name KYE3-RIGHT myinput_register_irq: rquest_irq: irq 104,name KYE4-DOWN myinput_register_irq: rquest_irq: irq 105,name KYE5-ESC myinput_register_irq: rquest_irq: irq 106,name KYE6-RETURN myinput_init: sizeof(evbit)=4,EV_CNT 32,BITS_LONGS 1 myinput_init: sizeof(keybit)=96,KEY_CNT 768,BITS_LONGS 24 input: s3c6410 gpio button as /class/input/input2 [root@urbetter 01]# ls -l /dev/input crw-rw---- 1 root root 13, 64 Mar 23 2000 event0 crw-rw---- 1 root root 13, 65 Mar 23 2000 event1 crw-rw---- 1 root root 13, 66 Mar 23 12:08 event2 crw-rw---- 1 root root 13, 63 Mar 23 2000 mice crw-rw---- 1 root root 13, 32 Mar 23 2000 mouse0
USB鍵盤測試
USB鍵盤是在 hid/usbhid/usbkbd.c
I: Bus=0003 Vendor=413c Product=2003 Version=0110 N: Name="Dell Dell USB Keyboard" P: Phys=usb-s3c24xx-1/input0 S: Sysfs=/class/input/input2 U: Uniq= H: Handlers=kbd event2 B: EV=120013 B: KEY=10000 7 ff9f207a c14057ff febeffdf ffefffff ffffffff fffffffe B: MSC=10 B: LED=7
[root@urbetter 01]# ls -l /dev/input crw-rw---- 1 root root 13, 64 Mar 23 2000 event0 crw-rw---- 1 root root 13, 65 Mar 23 2000 event1 crw-rw---- 1 root root 13, 66 Mar 23 14:17 event2 crw-rw---- 1 root root 13, 67 Mar 23 14:19 event3 crw-rw---- 1 root root 13, 63 Mar 23 2000 mice crw-rw---- 1 root root 13, 32 Mar 23 2000 mouse0
usb 1-1: new low speed USB device using s3c2410-ohci and address 2 usb 1-1: configuration #1 chosen from 1 choice input: Dell Dell USB Keyboard as /class/input/input2 generic-usb 0003:413C:2003.0001: input: USB HID v1.10 Keyboard [Dell Dell USB Ke yboard] on usb-s3c24xx-1/input0
|