本帖最后由 dzh_fly 于 2011-7-18 12:29 编辑
最近要做一个比较急的项目,需要使用STM32的USB模拟HID键盘,按照官方例程JoyStickMouse移植过来,进BIOS可以识别到USB MOUSE完全正常,然后将ENDP1的发送与接收大小改为8,1,修改报告描述符如下所示。修改好后,启动到Windows XP下,识别与控制均正常,可是转到BIOS下总是无法识别,确定BIOS是可以识别USB键盘的,接别的USB键盘没有问题。在网上搜索了好些天,发现也有人使用STM32的USB遇到同样的问题,也找到了一些资料,说是BIOS下的USB键盘有些特殊,需要修改Set Protocol之类的,但是不知从何下手,还望高手不吝赐教!
const uint8_t Joystick_ConfigDescriptor[JOYSTICK_SIZ_CONFIG_DESC] =
{
0x09, /* bLength: Configuation Descriptor size */
USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
JOYSTICK_SIZ_CONFIG_DESC,
/* wTotalLength: Bytes returned */
0x00,
0x01, /*bNumInterfaces: 1 interface*/
0x01, /*bConfigurationValue: Configuration value*/
0x00, /*iConfiguration: Index of string descriptor describing
the configuration*/
0xE0, /*bmAttributes: bus powered */
0x32, /*MaxPower 100 mA: this current is used for detecting Vbus*/
/************** Descriptor of Joystick Mouse interface ****************/
/* 09 */
0x09, /*bLength: Interface Descriptor size*/
USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType: Interface descriptor type*/
0x00, /*bInterfaceNumber: Number of Interface*/
0x00, /*bAlternateSetting: Alternate setting*/
0x02,//0x01 /*bNumEndpoints*/
0x03, /*bInterfaceClass: HID*/
0x01, /*bInterfaceSubClass : 1=BOOT, 0=no boot*/
0x01,//0x02 /*nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse*/
0, /*iInterface: Index of string descriptor*/
/******************** Descriptor of Joystick Mouse HID ********************/
/* 18 */
0x09, /*bLength: HID Descriptor size*/
HID_DESCRIPTOR_TYPE, /*bDescriptorType: HID*/
0x00, /*bcdHID: HID Class Spec release number*/
0x01,
0x00, /*bCountryCode: Hardware target country*/
0x01, /*bNumDescriptors: Number of HID class descriptors to follow*/
0x22, /*bDescriptorType*/
JOYSTICK_SIZ_REPORT_DESC,/*wItemLength: Total length of Report descriptor*/
0x00,
/******************** Descriptor of Joystick Mouse endpoint ********************/
/* 27 */
0x07, /*bLength: Endpoint Descriptor size*/
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
0x81, /*bEndpointAddress: Endpoint Address (IN)*/
0x03, /*bmAttributes: Interrupt endpoint*/
0x08,//0x04 /*wMaxPacketSize: 4 Byte max */
0x00,
0x20, /*bInterval: Polling Interval (32 ms)*/
/* 34 */
0x07, /*bLength: Endpoint Descriptor size*/
USB_ENDPOINT_DESCRIPTOR_TYPE, /*bDescriptorType:*/
0x01, /*bEndpointAddress: Endpoint Address (IN)*/
0x03, /*bmAttributes: Interrupt endpoint*/
0x01, /*wMaxPacketSize: 4 Byte max */
0x00,
0x20, /*bInterval: Polling Interval (32 ms)*/
/* 41 */
}
const uint8_t Joystick_ReportDescriptor[JOYSTICK_SIZ_REPORT_DESC] =
{
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x06, // USAGE (Keyboard)
0xa1, 0x01, // COLLECTION (Application)
0x05, 0x07, //USAGE_PAGE (Keyboard/Keypad)
0x19, 0xe0, //USAGE_MINIMUM (Keyboard LeftControl)
0x29, 0xe7, //USAGE_MAXIMUM (Keyboard Right GUI)
0x15, 0x00, //LOGICAL_MINIMUM (0)
0x25, 0x01, //LOGICAL_MAXIMUM (1)
0x95, 0x08, //REPORT_COUNT (8)
0x75, 0x01, //REPORT_SIZE (1)
0x81, 0x02, //INPUT (Data,Var,Abs)
0x95, 0x01, //REPORT_COUNT (1)
0x75, 0x08, //REPORT_SIZE (8)
0x81, 0x03, //INPUT (Cnst,Var,Abs)
0x95, 0x06, //REPORT_COUNT (6)
0x75, 0x08, //REPORT_SIZE (8)
0x15, 0x00, //LOGICAL_MINIMUM (0)
0x25, 0xFF, //LOGICAL_MAXIMUM (255)
0x05, 0x07, //USAGE_PAGE (Keyboard/Keypad)
0x19, 0x00, //USAGE_MINIMUM (Reserved (no event indicated))
0x29, 0x65, //USAGE_MAXIMUM (Keyboard Application)
0x81, 0x00, //INPUT (Data,Ary,Abs)
0x25, 0x01, //LOGICAL_MAXIMUM (1)
0x95, 0x05, //REPORT_COUNT (5)
0x75, 0x01, //REPORT_SIZE (1)
0x05, 0x08, //USAGE_PAGE (LEDs)
0x19, 0x01, //USAGE_MINIMUM (Num Lock)
0x29, 0x05, //USAGE_MAXIMUM (Kana)
0x91, 0x02, //OUTPUT (Data,Var,Abs)
0x95, 0x01, //REPORT_COUNT (1)
0x75, 0x03, //REPORT_SIZE (3)
0x91, 0x03, //OUTPUT (Cnst,Var,Abs)
0xc0, // END_COLLECTION
}
; /* Joystick_ReportDescriptor */ |
|