#include <linux/kernel.h>/*内核头文件,含有内核一些常用函数的原型定义*/
6 i' B1 I7 @3 ]1 _#include <linux/slab.h>/*定义内存分配的一些函数*/
#include <linux/module.h>/*模块编译必须的头文件*/
( {6 G2 G: U4 L8 b( J#include <linux/input.h>/*输入设备相关函数的头文件*/
#include <linux/init.h>/*linux初始化模块函数定义*/
1 f8 B0 ?( i4 l. z#include <linux/usb.h> /*USB设备相关函数定义*/
/*使用第一套键盘扫描码表:A-1E;B-30;C-2E…*/
static unsigned char usb_kbd_keycode[256] = {
0, 0, 0, 0, 30, 48, 46, 32, 18, 33, 34, 35, 23, 36, 37, 38,
50, 49, 24, 25, 16, 19, 31, 20, 22, 47, 17, 45, 21, 44, 2, 3,
4, 5, 6, 7, 8, 9, 10, 11, 28, 1, 14, 15, 57, 12, 13, 26,
27, 43, 43, 39, 40, 41, 51, 52, 53, 58, 59, 60, 61, 62, 63, 64,
65, 66, 67, 68, 87, 88, 99, 70,119,110,102,104,111,107,109,106,
- B0 m) ?7 J- P105,108,103, 69, 98, 55, 74, 78, 96, 79, 80, 81, 75, 76, 77, 71,
6 R2 v- Q2 i: p4 N- Y72, 73, 82, 83, 86,127,116,117,183,184,185,186,187,188,189,190,
' L; [8 t0 ^8 U8 |8 ?4 F191,192,193,194,134,138,130,132,128,129,131,137,133,135,136,113,
2 o/ p0 u- @/ h- I7 z115,114, 0, 0, 0,121, 0, 89, 93,124, 92, 94, 95, 0, 0, 0,
* D+ N% W" M5 W- t122,123, 90, 91, 85, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7 {* N: s j* u3 t6 w* s4 ^+ c0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
) l, D# \8 V; o5 l4 W0 c9 `2 e0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
# w# I+ y* j$ b# ]* }4 g7 ]$ h0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
! q) k I3 ^4 v3 e0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
29, 42, 56,125, 97, 54,100,126,164,166,165,163,161,115,114,113,
( k, J2 d" i3 h150,158,159,128,136,177,178,176,142,152,173,140
, u. ]) |9 R5 v5 estatic struct usb_device_id usb_kbd_id_table [] = {
+ h% l/ [8 V; g7 Y4 ]' ~) K{ USB_INTERFACE_INFO(3, 1, 1) },/*3,1,1分别表示接口类,接口子类,接口协议;3,1,1为键盘接口类;鼠标为3,1,2*/
{ } /* Terminating entry */
};
struct usb_kbd {
struct input_dev *dev; /*定义一个输入设备*/
struct usb_device *usbdev;/*定义一个usb设备*/
* i/ d" y, \; u" D& E; D/ i# V. Eunsigned char old[8]; /*按键离开时所用之数据缓冲区*/
struct urb *irq/*usb键盘之中断请求块*/, *led/*usb键盘之指示灯请求块*/;
unsigned char newleds;/*目标指定灯状态*/
char name[128];/*存放厂商名字及产品名字*/
char phys[64];/*设备之节点*/
unsigned char *new;/*按键按下时所用之数据缓冲区*/
struct usb_ctrlrequest *cr;/*控制请求结构*/
4 q1 N6 R3 ~4 d0 U, O% ?unsigned char *leds;/*当前指示灯状态*/
dma_addr_t cr_dma; /*控制请求DMA缓冲地址*/
$ ?; S* u% Q! S8 F* {- `dma_addr_t new_dma; /*中断urb会使用该DMA缓冲区*/
dma_addr_t leds_dma; /*指示灯DAM缓冲地址*/
/*USB键盘驱动结构体*/
0 P7 V1 G4 I# o# s# N9 nstatic struct usb_driver usb_kbd_driver = {
.name = "usbkbd",/*驱动名字*/
( Z5 |/ Q* X4 Y! \# f9 C.probe = usb_kbd_probe,/*驱动探测函数,加载时用到*/
.disconnect = usb_kbd_disconnect,/*驱动断开函数,在卸载时用到*/
.id_table = usb_kbd_id_table,/*驱动设备ID表,用来指定设备或接口*/
- |" s( J; g! Z; n7 i};
. K9 [0 h. ?4 a, B( O/*驱动程序生命周期的开始点,向 USB core 注册这个键盘驱动程序。*/
static int __init usb_kbd_init(void)
{
$ y9 m8 w0 V2 r# h; |6 f N: Gint result = usb_register(&usb_kbd_driver);/*注册USB键盘驱动*/
if (result == 0) /*注册失败*/