最近为了HID类设备弄了半个把月。终于完成这个无线(红外)多媒体键盘,带鼠标功能。难就难在描述符上,不过在近4天的资料翻阅及多次的测试下,电脑不知道重启了多少次啊,的情况下
搞定了这个东西,大家可以看看图片:
下面为键盘的电路图,仅为一个遥控器!
M48接收器的电路就用USBASP的电路即可,但在PD3口加一个红外一体接收头!
遥控器大家可以自己做一个即可,NEC格式,客户码0x00ff,data从00--ff,自己定义,同时可以修改的可以自己改!以适应自己的遥控。
下面是源码: ourdev_401421.rar(文件大小:212K) (原文件名:KIE-PC KEYBOARD(M48).rar)
这是我鼠标与键盘都OK的,键盘带modifierkey的描述:
static const char hidReportDescriptor0[] PROGMEM = { 0x05, 0x01, // Usage Page (Generic Desktop), 0x09, 0x06, //Usage (Keyboard), 0xA1, 0x01, // Collection (Application), 0x85, 0x01, // Report Id (1) //报告类型为1 0x05, 0x07, // USAGE_PAGE (Keyboard) 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl) 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x01, // LOGICAL_MAXIMUM (1) 0x75, 0x01, // REPORT_SIZE (1) 0x95, 0x08, // REPORT_COUNT (8) 0x81, 0x02, // INPUT (Data,Var,Abs) 0x95, 0x04, // Report Count (4), // 一共4位+1 0x75, 0x08, // Report Size (8), // 每位8位 0x15, 0x00, // Logical Minimum (0), //从0--ff 0x25, 0xff, // Logical Maximum(101), 0x05, 0x07, // Usage Page (Key Codes), 0x19, 0x00, // Usage Minimum (0), 0x29, 0xff, // Usage Maximum (101), 0x81, 0x00, // Input (Data, Array), ;Key arrays (4 bytes) 0xC0, // // mouse 0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, 0x25, 0x01, 0x85, 0x02, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06, 0xC0, 0xC0, }; 这个键盘带有鼠标功能。然后在这个基础上修改,我先仅仅实现多媒体按键,看了 computer00的代码。 static const char hidReportDescriptor0[] PROGMEM = { 0x05, 0x0c, // USAGE_PAGE (Consumer Page) 0x09, 0x01, // USAGE (Consumer Control) 0xa1, 0x01, // COLLECTION (Application) 0x09, 0xea, // USAGE (Volume Decrement) 0x09, 0xe9, // USAGE (Volume Increment) 0x09, 0xe2, // USAGE (Mute) 0x09, 0xcd, // USAGE (Play/Pause) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x01, // LOGICAL_MAXIMUM (1) 0x95, 0x07, // REPORT_COUNT (4) 0x75, 0x01, // REPORT_SIZE (1) 0x81, 0x02, // INPUT (Data,Var,Abs) 0x75, 0x01, // REPORT_SIZE (1) 0x95, 0x01, // REPORT_COUNT (4) 0x81, 0x03, // INPUT (Cnst,Var,Abs) 0xc0 // END_COLLECTION }; 其他地方也适当修改,没有问题,这样修改后能出现 HID 用户控制设备。这就是多媒体键盘会出现的。 static const char hidReportDescriptor0[] PROGMEM = { 0x05, 0x01, // Usage Page (Generic Desktop), 0x09, 0x06, //Usage (Keyboard), 0xA1, 0x01, // Collection (Application), 0x85, 0x01, // Report Id (1) //报告类型为1 0x05, 0x07, // USAGE_PAGE (Keyboard) 0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl) 0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x01, // LOGICAL_MAXIMUM (1) 0x75, 0x01, // REPORT_SIZE (1) 0x95, 0x08, // REPORT_COUNT (8) 0x81, 0x02, // INPUT (Data,Var,Abs) 0x95, 0x04, // Report Count (4), // 一共4位+1 0x75, 0x08, // Report Size (8), // 每位8位 0x15, 0x00, // Logical Minimum (0), //从0--ff 0x25, 0xff, // Logical Maximum(101), 0x05, 0x07, // Usage Page (Key Codes), 0x19, 0x00, // Usage Minimum (0), 0x29, 0xff, // Usage Maximum (101), 0x81, 0x00, // Input (Data, Array), ;Key arrays (4 bytes) 0xC0, // 0x05, 0x0c, // USAGE_PAGE (Consumer Page) 0x09, 0x01, // USAGE (Consumer Control) 0xa1, 0x01, // COLLECTION (Application) 0x85, 0x02, 0x09, 0xea, // USAGE (Volume Decrement) 0x09, 0xe9, // USAGE (Volume Increment) 0x09, 0xe2, // USAGE (Mute) 0x09, 0xcd, // USAGE (Play/Pause) 0x0a, 0x83, 0x01, //USAGE (Windows Media Player(0x183)) 0x0a, 0x23, 0x02, //USAGE (AC Home(0x0223)) 0x0a, 0x92, 0x01, //USAGE (AL Calculator(0x192)) 0x15, 0x00, // LOGICAL_MINIMUM (0) 0x25, 0x01, // LOGICAL_MAXIMUM (1) 0x95, 0x07, // REPORT_COUNT (7) 0x75, 0x01, // REPORT_SIZE (1) 0x81, 0x02, // INPUT (Data,Var,Abs) 0x75, 0x01, // REPORT_SIZE (1) 0x95, 0x01, // REPORT_COUNT (1) 0x81, 0x03, // INPUT (Cnst,Var,Abs) 0xc0, // END_COLLECTION // mouse 0x05, 0x01, 0x09, 0x02, 0xA1, 0x01, 0x09, 0x01, 0xA1, 0x00, 0x05, 0x09, 0x19, 0x01, 0x29, 0x03, 0x15, 0x00, 0x25, 0x01, 0x85, 0x03, 0x95, 0x03, 0x75, 0x01, 0x81, 0x02, 0x95, 0x01, 0x75, 0x05, 0x81, 0x01, 0x05, 0x01, 0x09, 0x30, 0x09, 0x31, 0x15, 0x81, 0x25, 0x7F, 0x75, 0x08, 0x95, 0x02, 0x81, 0x06, 0xC0, 0xC0 };