一、概论:

在STM32_USB-FS-Device_Lib_V4.1.0的Custom_HID工程基础上进行修改;

开发一款设备,有三个HID接口,mouse+pen+自定义HID

其中:0_HID 是mouse(端点1 IN);1_HID 是pen(端点2 IN);2_HID 是自定义(端点3 IN-OUT)。

在设备管理器和bus hound可以看到如下:

3--STM32 USB-三个HID-interface 复合(组合)设备的代码实现-基于固件库(原创)3--STM32 USB-三个HID-interface 复合(组合)设备的代码实现-基于固件库(原创)

 

 二、修改步骤:

 1、修改设备$$配置描述符


/* USB Standard Device Descriptor */
const uint8_t CustomHID_DeviceDescriptor[CUSTOMHID_SIZ_DEVICE_DESC] =
  {
    0x12,                       /*bLength */
    USB_DEVICE_DESCRIPTOR_TYPE, /*bDescriptorType*/
    0x10,                       /*bcdUSB */
    0x01,
    0x00,                       /*bDeviceClass*/
    0x00,                       /*bDeviceSubClass*/
    0x00,                       /*bDeviceProtocol*/
    0x40,                       /*bMaxPacketSize:64 bytes*/
    LOBYTE(USBD_VID),           /*idVendor*/
    HIBYTE(USBD_VID),           /*idVendor*/
    LOBYTE(USBD_PID),           /*idVendor*/
    HIBYTE(USBD_PID),           /*idVendor*/
    0x00,                       /*bcdDevice rel. 00.00*/
    0x00,
    USBD_IDX_MFC_STR,           /*Index of manufacturer  string*/
    USBD_IDX_PRODUCT_STR,       /*Index of product string*/
    USBD_IDX_SERIAL_STR,        /*Index of serial number string*/
    USBD_CFG_MAX_NUM            /*bNumConfigurations*/
  }; /* CustomHID_DeviceDescriptor */

/* USB Configuration Descriptor */
/*   All Descriptors (Configuration, Interface, Endpoint, Class, Vendor */
const uint8_t CustomHID_ConfigDescriptor[CUSTOMHID_SIZ_CONFIG_DESC] =
  {
    /************** Configuration Descriptor  Bus Powered, 100 mA ****************/
    0x09, /* bLength: Configuration Descriptor size */
    USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
    0x5b,         /* wTotalLength: Bytes returned */
    0x00,
    0x03,         /* bNumInterfaces: 1 interface *///3个HID接口  
    0x01,         /* bConfigurationValue: Configuration value */
    0x00,         /* iConfiguration: Index of string descriptor describing the configuration*/
    0xA0,         /* bmAttributes: Self powered:C0 Bus Powered, Remote Wakeup:A0 */
    0x32,         /* MaxPower 100 mA: this current is used for detecting Vbus */

// 0/0 HID 1 Endpoint IN of 端点1
    /************** Descriptor of 0/0 HID interface ****************/
    /* 09 */
    0x09,         /* bLength: Interface Descriptor size */
    USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
    0x00,         /* bInterfaceNumber: Number of Interface */
    0x00,         /* bAlternateSetting: Alternate setting */
    0x01,         /* bNumEndpoints */
    0x03,         /* bInterfaceClass: HID */
    0x01,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */
    0x02,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
    0x00,         /* iInterface: Index of string descriptor */
    /******************** Descriptor of 0/0 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 */
    sizeof(mouse_ReportDescriptor)&0xFF,         /* wItemLength: Total length of Report descriptor :177 bytes*/
    (sizeof(mouse_ReportDescriptor)>>8)&0xFF,
    /******************** Descriptor of 0/0 HID endpoints :1IN ******************/
    /* 27 */
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
    0x81,          /* bEndpointAddress: Endpoint Address (IN) */
    0x03,          /* bmAttributes: Interrupt endpoint */
    0x08,          /* wMaxPacketSize: 8 Bytes max */
    0x00,
    0x04,          /* bInterval: Polling Interval (4 ms) */
    
// 1/0 HID 1 Endpoint IN of 端点2
    /************** Descriptor of 1/0 HID interface ****************/
    /* 34 */
    0x09,         /* bLength: Interface Descriptor size */
    USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
    0x01,         /* bInterfaceNumber: Number of Interface */
    0x00,         /* bAlternateSetting: Alternate setting */
    0x01,         /* bNumEndpoints */
    0x03,         /* bInterfaceClass: HID */
    0x01,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */
    0x02,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
    0x00,         /* iInterface: Index of string descriptor */
    /******************** Descriptor of 1/0 HID ********************/
    /* 43 */
    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 */
    sizeof(pen_ReportDescriptor)&0xFF,         /* wItemLength: Total length of Report descriptor :237 bytes*/
    (sizeof(pen_ReportDescriptor)>>8)&0xFF,
    /******************** Descriptor of 1/0 HID endpoints :2 IN ******************/
    /* 52 */
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
    0x82,          /* bEndpointAddress: Endpoint Address (IN) */
    0x03,          /* bmAttributes: Interrupt endpoint */
    0x40,          /* wMaxPacketSize: 64 Bytes max */
    0x00,
    0x03,          /* bInterval: Polling Interval (3 ms) */  
    
// 2/0 HID 1 Endpoint IN /1 Endpoint OUT of 端点3
    /************** Descriptor of 2/0 HID interface ****************/
    /* 59 */
    0x09,         /* bLength: Interface Descriptor size */
    USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
    0x02,         /* bInterfaceNumber: Number of Interface */
    0x00,         /* bAlternateSetting: Alternate setting */
    0x02,         /* bNumEndpoints */
    0x03,         /* bInterfaceClass: HID */
    0x00,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */
    0x00,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
    0x00,         /* iInterface: Index of string descriptor */
    /******************** Descriptor of 2/0 HID ********************/
    /* 68 */
    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 */
    sizeof(HID_driver_ReportDescriptor)&0xFF,         /* wItemLength: Total length of Report descriptor :36 bytes*/
    (sizeof(HID_driver_ReportDescriptor)>>8)&0xFF,
    /******************** Descriptor of 2/0 HID endpoints :3 In, Interrupt, 3 ms******************/
    /* 77 */
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
    0x83,          /* bEndpointAddress: Endpoint Address (IN) */
    0x03,          /* bmAttributes: Interrupt endpoint */
    0x0A,          /* wMaxPacketSize: 10 Bytes max */
    0x00,
    0x03,          /* bInterval: Polling Interval (3 ms) */  
    /******************** Descriptor of 2/0 HID endpoints :3 Out, Interrupt, 3 ms******************/
    /* 84 */
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */
    0x03,          /* bEndpointAddress: Endpoint Address (out) */
    0x03,          /* bmAttributes: Interrupt endpoint */
    0x0A,          /* wMaxPacketSize: 10 Bytes max */
    0x00,
    0x0A,          /* bInterval: Polling Interval (10 ms) */ 
  }; /* CustomHID_ConfigDescriptor */
View Code

相关文章:

  • 2022-12-23
  • 2021-11-22
  • 2022-01-21
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
  • 2022-02-15
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2021-11-20
  • 2021-07-12
  • 2022-12-23
相关资源
相似解决方案