windows(HidLibrary.dll)可以发送数据包到USB HID(键盘+供应商定义)吗?

问题描述 投票:0回答:1

我正在尝试通过stm32f103c8t6编写一个USB设备,它被检测为键盘以将关键代码发送到Windows,并由供应商定义来发送-接收自定义数据。

但只有键盘可以工作。

这是 USB 树视图: USB 视图

这里是描述符:

static __code const unsigned char _USB_HID_Custom_ReportDecriptor_Data[] = {
/*Usage Page (vendor define),                        */ 0x06, 0x00, 0xFF,
/*Usage (id 1),                                      */ 0x09, 1,
/*Collection (Application),                          */ 0xA1, 0x01,
/*  Usage Minimum (1),                               */ 0x19, 1,
/*  Usage Maximum (1),                               */ 0x29, 1,
/*  Logical Minimum (0),                             */ 0x15, 0,
/*  Logical Maximum (255),                           */ 0x25, 255,
/*  Report Size (8),                                 */ 0x75, 8,
/*  Report Count (8),                                */ 0x95, 8,
/*  Input (Data, Variable, Absolute), ;Modifier byte */ 0x81, 0x02,
/*  Usage Minimum (1),                               */ 0x19, 1,
/*  Usage Maximum (1),                               */ 0x29, 1,
/*  Output(Data, Variable, Absolute), ;Modifier byte */ 0x91, 0x02,
/*End Collection                                     */ 0xC0,
};

static __code const unsigned char _USB_HID_Keyboard_ReportDecriptor_Data[] = {
/*Usage Page (Generic Desktop),                      */ 0x05, 0x01,
/*Usage (Keyboard),                                  */ 0x09, 0x06,
/*Collection (Application),                          */ 0xA1, 0x01,
/*  Usage Page (Key Codes);                          */ 0x05, 0x07,
/*  Report ID (0x01)                                 */ 0x85, 0x01,
/*  Usage Minimum (224),                             */ 0x19, 0xE0,
/*  Usage Maximum (231),                             */ 0x29, 0xE7,
/*  Logical Minimum (0),                             */ 0x15, 0x00,
/*  Logical Maximum (1),                             */ 0x25, 0x01,
/*  Report Size (1),                                 */ 0x75, 0x01,
/*  Report Count (8),                                */ 0x95, 0x08,
/*  Input (Data, Variable, Absolute), ;Modifier byte */ 0x81, 0x02,
/*  Usage Page (Key Codes),                          */ 0x05, 0x07,
/*  Usage Minimum (0),                               */ 0x19, 0x00,
/*  Usage Maximum (101),                             */ 0x29, 0x65,
/*  Logical Minimum (0),                             */ 0x15, 0x00,
/*  Logical Maximum(101),                            */ 0x25, 0x65,
/*  Report Count (6),                                */ 0x95, 0x06,
/*  Report Size (8),                                 */ 0x75, 0x08,
/*  Input (Data, Array), ;Key arrays (6 bytes)       */ 0x81, 0x00,
/*End Collection                                     */ 0xC0,
};
static __code const unsigned char _USB_DeviceDescriptor_Data[] = {
/*bLength                  */ 0x12,             //(18 bytes)
/*bDescriptorType          */ 0x01,             //(Device Descriptor)
/*bcdUSB                   */ 0x00, 0x02,       //(USB Version 2.0) -> but device is Low-Speed only
/*bDeviceClass             */ 0x00,             //(defined by the interface descriptors)
/*bDeviceSubClass          */ 0x00,
/*bDeviceProtocol          */ 0x00,
/*bMaxPacketSize0          */ 0x40,              //(64 bytes)
/*idVendor                 */ 'M', 'S',
/*idProduct                */ 0, 'D',
/*bcdDevice                */ 0x01, 0x00,
/*iManufacturer            */ 0x01,             //(String Descriptor 1)
/*iProduct                 */ 0x02,             //(String Descriptor 2)
/*iSerialNumber            */ 0x00,             //(No String Descriptor)
/*bNumConfigurations       */ 0x01,             //(1 Configuration)
};
static __code const unsigned char _USB_ConfigurationDescription_Data[] = {
/*bLength                  */ 0x09,             //(9 bytes)
/*bDescriptorType          */ 0x02,             //(Configuration Descriptor)
/*wTotalLength             */ 9   + 9 + 9 + 7   + 9 + 9 + 7, 0x00,
/*bNumInterfaces           */ 0x02,             //(2 Interfaces)
/*bConfigurationValue      */ 0x01,             //(Configuration 1)
/*iConfiguration           */ 0x00,             //(No String Descriptor)
/*bmAttributes             */ 0x00,
/*MaxPower                 */ 0x32,             //(100 mA)
//-----------------------------------
//-----------------------------------
//-----------------------------------
/*bLength                  */ 0x09,             //(9 bytes)
/*bDescriptorType          */ 0x04,             //(Interface Descriptor)
/*bInterfaceNumber         */ 0x00,             //(Interface 0)
/*bAlternateSetting        */ 0x00,
/*bNumEndpoints            */ 0x01,             //(1 Endpoint)
/*bInterfaceClass          */ 0x03,             //(HID - Human Interface Device)
/*bInterfaceSubClass       */ 0x01,             //(Boot Interface)
/*bInterfaceProtocol       */ 0x01,             //(Keyboard)
/*iInterface               */ 0x00,             //(No String Descriptor)
//-----------------------------------
/*bLength                  */ 0x09,             //(9 bytes)
/*bDescriptorType          */ 0x21,             //(HID Descriptor)
/*bcdHID                   */ 0x11, 0x01,       //(HID Version 1.11)
/*bCountryCode             */ 0x00,             //(00 = not localized)
/*bNumDescriptors          */ 0x01,
/*bDescriptorType          */ 0x22,             //(Class=Report)
/*wDescriptorLength        */ sizeof(_USB_HID_Keyboard_ReportDecriptor_Data), 0x00,
//-----------------------------------
/*bLength                  */ 0x07,             //(7 bytes)
/*bDescriptorType          */ 0x05,             //(Endpoint Descriptor)
/*bEndpointAddress         */ 0x81,             //(Direction=IN EndpointID=1)
/*bmAttributes             */ 0x03,             //(TransferType=Interrupt)
/*wMaxPacketSize           */ 0x08, 0x00,
/*bInterval                */ 0x0A,             //(10 ms)
//-----------------------------------
//-----------------------------------
//-----------------------------------
/*bLength                  */ 0x09,             //(9 bytes)
/*bDescriptorType          */ 0x04,             //(Interface Descriptor)
/*bInterfaceNumber         */ 0x01,             //(Interface 1)
/*bAlternateSetting        */ 0x00,
/*bNumEndpoints            */ 0x01,             //(1 Endpoint)
/*bInterfaceClass          */ 0x03,             //(HID - Human Interface Device)
/*bInterfaceSubClass       */ 0x00,             //(None)
/*bInterfaceProtocol       */ 0x00,             //(None)
/*iInterface               */ 0x00,             //(No String Descriptor)
//-----------------------------------
/*bLength                  */ 0x09,             //(9 bytes)
/*bDescriptorType          */ 0x21,             //(HID Descriptor)
/*bcdHID                   */ 0x11, 0x01,       //(HID Version 1.11)
/*bCountryCode             */ 0x00,             //(00 = not localized)
/*bNumDescriptors          */ 0x01,
/*bDescriptorType          */ 0x22,             //(Class=Report)
/*wDescriptorLength        */ sizeof(_USB_HID_Custom_ReportDecriptor_Data), 0x00,
//-----------------------------------
/*bLength                  */ 0x07,             //(7 bytes)
/*bDescriptorType          */ 0x05,             //(Endpoint Descriptor)
/*bEndpointAddress         */ 0x01,             //(Direction=OUT EndpointID=1)
/*bmAttributes             */ 0x03,             //(TransferType=Interrupt)
/*wMaxPacketSize           */ 0x08, 0x00,
/*bInterval                */ 0x0A,             //(10 ms)
};

如果仅使用供应商定义也可以:HidDevice 发送到 stm32

有办法从电脑发送到stm32设备吗?

c# c keyboard hid stm32f1
1个回答
0
投票

天哪,我找到解决方案了

在键盘接口之前引入供应商定义的描述符接口,就完成了 =))

难以置信

static __code const unsigned char _USB_HID_Custom_ReportDecriptor_Data[] = {
/*Usage Page (vendor define),                        */ 0x06, 0x00, 0xFF,
/*Usage (id 1),                                      */ 0x09, 1,
/*Collection (Application),                          */ 0xA1, 0x01,
/*  Usage Minimum (1),                               */ 0x19, 1,
/*  Usage Maximum (1),                               */ 0x29, 1,
/*  Logical Minimum (0),                             */ 0x15, 0,
/*  Logical Maximum (255),                           */ 0x25, 255,
/*  Report Size (8),                                 */ 0x75, 8,
/*  Report Count (8),                                */ 0x95, 8,
/*  Input (Data, Variable, Absolute), ;Modifier byte */ 0x81, 0x02,
/*  Usage Minimum (1),                               */ 0x19, 1,
/*  Usage Maximum (1),                               */ 0x29, 1,
/*  Output(Data, Variable, Absolute), ;Modifier byte */ 0x91, 0x02,
/*End Collection                                     */ 0xC0,
};

static __code const unsigned char _USB_HID_Keyboard_ReportDecriptor_Data[] = {
/*Usage Page (Generic Desktop),                      */ 0x05, 0x01,
/*Usage (Keyboard),                                  */ 0x09, 0x06,
/*Collection (Application),                          */ 0xA1, 0x01,
/*  Usage Page (Key Codes);                          */ 0x05, 0x07,
/*  Report ID (0x01)                                 */ 0x85, 0x01,
/*  Usage Minimum (224),                             */ 0x19, 0xE0,
/*  Usage Maximum (231),                             */ 0x29, 0xE7,
/*  Logical Minimum (0),                             */ 0x15, 0x00,
/*  Logical Maximum (1),                             */ 0x25, 0x01,
/*  Report Size (1),                                 */ 0x75, 0x01,
/*  Report Count (8),                                */ 0x95, 0x08,
/*  Input (Data, Variable, Absolute), ;Modifier byte */ 0x81, 0x02,
/*  Usage Page (Key Codes),                          */ 0x05, 0x07,
/*  Usage Minimum (0),                               */ 0x19, 0x00,
/*  Usage Maximum (101),                             */ 0x29, 0x65,
/*  Logical Minimum (0),                             */ 0x15, 0x00,
/*  Logical Maximum(101),                            */ 0x25, 0x65,
/*  Report Count (6),                                */ 0x95, 0x06,
/*  Report Size (8),                                 */ 0x75, 0x08,
/*  Input (Data, Array), ;Key arrays (6 bytes)       */ 0x81, 0x00,
/*End Collection                                     */ 0xC0,
};
static __code const unsigned char _USB_DeviceDescriptor_Data[] = {
/*bLength                  */ 0x12,             //(18 bytes)
/*bDescriptorType          */ 0x01,             //(Device Descriptor)
/*bcdUSB                   */ 0x00, 0x02,       //(USB Version 2.0) -> but device is Low-Speed only
/*bDeviceClass             */ 0x00,             //(defined by the interface descriptors)
/*bDeviceSubClass          */ 0x00,
/*bDeviceProtocol          */ 0x00,
/*bMaxPacketSize0          */ 0x40,              //(64 bytes)
/*idVendor                 */ 'M', 'S',
/*idProduct                */ 0, 'D',
/*bcdDevice                */ 0x01, 0x00,
/*iManufacturer            */ 0x01,             //(String Descriptor 1)
/*iProduct                 */ 0x02,             //(String Descriptor 2)
/*iSerialNumber            */ 0x00,             //(No String Descriptor)
/*bNumConfigurations       */ 0x01,             //(1 Configuration)
};
static __code const unsigned char _USB_ConfigurationDescription_Data[] = {
/*bLength                  */ 0x09,             //(9 bytes)
/*bDescriptorType          */ 0x02,             //(Configuration Descriptor)
/*wTotalLength             */ 9   + 9 + 9 + 7   + 9 + 9 + 7, 0x00,
/*bNumInterfaces           */ 0x02,             //(2 Interfaces)
/*bConfigurationValue      */ 0x01,             //(Configuration 1)
/*iConfiguration           */ 0x00,             //(No String Descriptor)
/*bmAttributes             */ 0x80,
/*MaxPower                 */ 0x32,             //(100 mA)
//-----------------------------------
//-----------------------------------
//-----------------------------------
/*bLength                  */ 0x09,             //(9 bytes)
/*bDescriptorType          */ 0x04,             //(Interface Descriptor)
/*bInterfaceNumber         */ 0x00,             //(Interface 0)
/*bAlternateSetting        */ 0x00,
/*bNumEndpoints            */ 0x01,             //(1 Endpoint)
/*bInterfaceClass          */ 0x03,             //(HID - Human Interface Device)
/*bInterfaceSubClass       */ 0x00,             //(None)
/*bInterfaceProtocol       */ 0x00,             //(None)
/*iInterface               */ 0x00,             //(No String Descriptor)
//-----------------------------------
/*bLength                  */ 0x09,             //(9 bytes)
/*bDescriptorType          */ 0x21,             //(HID Descriptor)
/*bcdHID                   */ 0x11, 0x01,       //(HID Version 1.11)
/*bCountryCode             */ 0x00,             //(00 = not localized)
/*bNumDescriptors          */ 0x01,
/*bDescriptorType          */ 0x22,             //(Class=Report)
/*wDescriptorLength        */ sizeof(_USB_HID_Custom_ReportDecriptor_Data), 0x00,
//-----------------------------------
/*bLength                  */ 0x07,             //(7 bytes)
/*bDescriptorType          */ 0x05,             //(Endpoint Descriptor)
/*bEndpointAddress         */ 0x01,             //(Direction=OUT EndpointID=1)
/*bmAttributes             */ 0x03,             //(TransferType=Interrupt)
/*wMaxPacketSize           */ 0x08, 0x00,
/*bInterval                */ 0x0A,             //(10 ms)
//-----------------------------------
//-----------------------------------
//-----------------------------------
/*bLength                  */ 0x09,             //(9 bytes)
/*bDescriptorType          */ 0x04,             //(Interface Descriptor)
/*bInterfaceNumber         */ 0x01,             //(Interface 1)
/*bAlternateSetting        */ 0x00,
/*bNumEndpoints            */ 0x01,             //(1 Endpoint)
/*bInterfaceClass          */ 0x03,             //(HID - Human Interface Device)
/*bInterfaceSubClass       */ 0x01,             //(Boot Interface)
/*bInterfaceProtocol       */ 0x01,             //(Keyboard)
/*iInterface               */ 0x00,             //(No String Descriptor)
//-----------------------------------
/*bLength                  */ 0x09,             //(9 bytes)
/*bDescriptorType          */ 0x21,             //(HID Descriptor)
/*bcdHID                   */ 0x11, 0x01,       //(HID Version 1.11)
/*bCountryCode             */ 0x00,             //(00 = not localized)
/*bNumDescriptors          */ 0x01,
/*bDescriptorType          */ 0x22,             //(Class=Report)
/*wDescriptorLength        */ sizeof(_USB_HID_Keyboard_ReportDecriptor_Data), 0x00,
//-----------------------------------
/*bLength                  */ 0x07,             //(7 bytes)
/*bDescriptorType          */ 0x05,             //(Endpoint Descriptor)
/*bEndpointAddress         */ 0x82,             //(Direction=IN EndpointID=2)
/*bmAttributes             */ 0x03,             //(TransferType=Interrupt)
/*wMaxPacketSize           */ 0x08, 0x00,
/*bInterval                */ 0x0A,             //(10 ms)
};
© www.soinside.com 2019 - 2024. All rights reserved.