键盘的hid描述符例子

譬如有如下的Report Descriptor:


譬如有如下的Report Descriptor:

C/C++ code


?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

const u8 g_KeyboardReportDescriptor[] = 

{

    // Keyboard

    0x05, 0x01, /* Usage Page(Generic Desktop) */

    0x09, 0x06, /* Usage(Keyboard) */

    0xA1, 0x01, /* Collection(Application) */

        0x05, 0x07, /* Usage Page(Key Codes) */

        0x19, 0xE0, /* Usage Minimum(224) */

        0x29, 0xE7, /* Usage Maximum(231) */

        0x15, 0x00, /* Logical Minimum(0) */

        0x25, 0x01, /* Logical Maximum(1) */

        0x75, 0x01, /* Report Size(1) */

        0x95, 0x08, /* Report Count(8) */

        0x81, 0x02, /* Input(Data, Variable, Absolute), Modifier byte */       

        0x95, 0x01, /* Report Count(1) */

        0x75, 0x08, /* Report Size(8) */

        0x81, 0x01, /* Input(Constant), Reserved byte */

        0x95, 0x05, /* Report Count(5) */

        0x75, 0x01, /* Report Size(1) */

        0x05, 0x08, /* Usage Page(LED) */

        0x19, 0x01, /* Usage Minimum(1) */

        0x29, 0x05, /* Usage Minimum(5) */

        0x91, 0x02, /* Output(Data, Variable, Absolute), LED report */

        0x95, 0x01, /* Report Count(1) */

        0x75, 0x03, /* Report Size(3) */

        0x91, 0x01, /* Output(Constant), LED report padding */

        0x95, 0x06, /* Report Count(6) */

        0x75, 0x08, /* Report Size(8) */

           0x15, 0x00, /* Logical Minimum(0) */

        0x25, 0x65, /* Logical Maximum(101) */

        0x05, 0x07, /* Usage Page(Key Codes) */

        0x19, 0x00, /* Usage Minimum(0) */

        0x29, 0x65, /* Usage Minimum(101) */

        0x81, 0x00,    /* Input(Data, Array), Key arrays(6 bytes) */

    0xC0        /* End Collection */

};



就应该发送8个字节(发送到host的时候大于8字节,不过这些细节由usb硬件处理,我们只关心按键的内容就可以了)到host:

C/C++ code


?

1

2

3

4

5

6

7

8

9

u8 sendbuf[8];

// 如果有按键w按下,在sendbuf[2...7]中任一填入按键w的usage值

// sendbuf[0]用于shift,ctrl等这些modifier键的状态,更多细节可参考HID Usage Tables

// sendbuf[1]保留

// 更多按键的usage可参考 HID Usage Tables 的 第53页

memset(sendbuf, 0, sizeof(sendbuf));

//sendbuf[0] = 0x...; // 根据shift,ctrl等键的状态设置相应bit,bit位含义参考HID Usage Tables

sendbuf[2] = 0x1A; // 写入w 键 usage id 0x1A

// 更多其他按键


from:http://bbs.csdn.net/topics/390706443






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值