当前位置:网站首页>Gd32 USB composite device file descriptor

Gd32 USB composite device file descriptor

2022-06-26 19:49:00 NoName51C_ T_ O

Use GD32 Two interfaces , Respectively used for mouse and upper computer communication .

Mouse use endpoint 1 communicate ( Only for EP1_IN)

Upper computer communication uses endpoint 2  (EP2_IN、EP2_OUT)


The configuration descriptor is as follows :

/* USB HID device configuration descriptor set */
const uint8_t USBD_HID_CfgDesc[USB_HID_CONFIG_DESC_SIZE] =
{
    0x09,         /* bLength: configuration descriptor size */
    USB_DESCTYPE_CONFIGURATION, /* bDescriptorType: configuration descriptor type */
    USB_HID_CONFIG_DESC_SIZE,   /* wTotalLength: configuration descriptor set total length */
    0x00,
    0x02,         /* bNumInterfaces: 2 interface */
    0x01,         /* bConfigurationValue: configuration value */
    0x00,         /* iConfiguration: index of string descriptor describing the configuration */
    0xA0,         /* bmAttributes: device attributes (bus powered and support remote wakeup) */
    0x32,         /* bMaxPower 100 mA: this current is used for detecting Vbus */




   /*
    interface 0 for mouse.
    huohongpeng 2017-02-10
    */
    /************** interface descriptor  0****************/
    0x09,         /* bLength: interface descriptor size */
    USB_DESCTYPE_INTERFACE,/* bDescriptorType: interface descriptor type */
    0x00,         /* bInterfaceNumber: number of interface */
    0x00,         /* bAlternateSetting: alternate setting */
    0x01,         /* bNumEndpoints: just use 1 endpoint for Tx */
    0x03,         /* bInterfaceClass: HID class */
    0x01,         /* bInterfaceSubClass: 1 = BIOS boot, 0 = no boot */
    0x02,         /* nInterfaceProtocol: 0 = none, 1 = keyboard, 2 = mouse */
    0x00,         /* iInterface: index of interface string descriptor */


    /******************** HID descriptor  0********************/
    0x09,         /* bLength: HID descriptor size */
    HID_DESC_TYPE,/* bDescriptorType: HID */
    0x11,         /* bcdHID: HID class protocol(HID1.11) */
    0x01,
    0x00,         /* bCountryCode: device country code */
    0x01,         /* bNumDescriptors: number of HID class descriptors to follow */
    0x22,         /* bDescriptorType: followed class descriptor type(report descriptor) */
    USB_HID_REPORT_DESC0_SIZE, /* wDescriptorLength: total length of report descriptor */
    0x00,


    /******************** Mouse endpoint descriptor ********************/
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
    HID1_IN_EP,     /* bEndpointAddress: endpoint address (EP1_IN) */
    0x03,          /* bmAttributes: endpoint attribute(interrupt endpoint) */
    HID1_IN_PACKET, /* wMaxPacketSize: 4 bytes max */
    0x00,
    0x0A,          /* bInterval: polling interval (10 ms) */






    /*
    interface 1 for host communication to mcu.
    huohongpeng 2017-02-10
    */
    /************** interface descriptor  1****************/
    0x09,         /* bLength: interface descriptor size */
    USB_DESCTYPE_INTERFACE,/* bDescriptorType: interface descriptor type */
    0x01,         /* bInterfaceNumber: number of interface */
    0x00,         /* bAlternateSetting: alternate setting */
    0x02,         /* bNumEndpoints: use 2 endpoint for Tx and Rx*/
    0x03,         /* bInterfaceClass: HID class */
    0x00,         /* bInterfaceSubClass: 1 = BIOS boot, 0 = no boot */
    0x00,         /* nInterfaceProtocol: 0 = none, 1 = keyboard, 2 = mouse */
    0x00,         /* iInterface: index of interface string descriptor */


    /******************** HID descriptor  1********************/
    0x09,         /* bLength: HID descriptor size */
    HID_DESC_TYPE,/* bDescriptorType: HID */
    0x11,         /* bcdHID: HID class protocol(HID1.11) */
    0x01,
    0x00,         /* bCountryCode: device country code */
    0x01,         /* bNumDescriptors: number of HID class descriptors to follow */
    0x22,         /* bDescriptorType: followed class descriptor type(report descriptor) */
    USB_HID_REPORT_DESC1_SIZE, /* wDescriptorLength: total length of report descriptor */
    0x00,


    /****************host communication mcu Tx endpoint descriptor ***********/
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
    HID2_IN_EP,     /* bEndpointAddress: endpoint address (EP2_IN) */
    0x03,          /* bmAttributes: endpoint attribute(interrupt endpoint) */
    HID2_IN_PACKET, /* wMaxPacketSize: 64 bytes max */
    0x00,
    0x0A,          /* bInterval: polling interval (10 ms) */


    /************** host communication mcu Tx endpoint descriptor ************/
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_DESCTYPE_ENDPOINT, /* bDescriptorType: endpoint descriptor type */
    HID2_OUT_EP,     /* bEndpointAddress: endpoint address (EP2_OUT) */
    0x03,          /* bmAttributes: endpoint attribute(interrupt endpoint) */
    HID2_OUT_PACKET, /* wMaxPacketSize: 64 bytes max */
    0x00,
    0x0A,          /* bInterval: polling interval (10 ms) */
};


The mouse report descriptor is as follows :

/*
for mouse HID report descriptor 
huohongpeng 2017-02-10
create tools: HID Description Tool
*/


const uint8_t HID_ReportDesc0[USB_HID_REPORT_DESC0_SIZE] =
{
    0x05,   0x01,   /* USAGE_PAGE (Generic Desktop) */ 
    0x09,   0x02,   /* USAGE (Mouse)                */
    0xa1,   0x01,   /* COLLECTION (Application)     */
    
    0x09,   0x01,   /* USAGE (Pointer)              */
    0xa1,   0x01,   /* COLLECTION (PHYSICAL)        */


    0x05,   0x09,   /* USAGE_PAGE (Button)          */
    0x19,   0x01,   /* USAGE_MINIMUM (Button 1)     */
                    /* 1-left, 2-right, 3-middle    */
    0x29,   0x03,   /* USAGE_MAXIMUM (Button 3)     */
    0x15,   0x00,   /* LOGICAL_MINIMUM (0)          */
    0x25,   0x01,   /* LOGICAL_MAXIMUM (1)          */
    0x75,   0x01,   /* REPORT_SIZE (1)              */
    0x95,   0x03,   /* REPORT_COUNT (3)             */
    0x81,   0x02,   /* INPUT (Data, Var, Abs)       */  
                    /*add 5bit align 1byte          */
    0x75,   0x05,   /* REPORT_SIZE (5)              */
    0x95,   0x01,   /* REPORT_COUNT (1)             */
    0x81,   0x03,   /* INPUT (Cnst, Var, Abs)       */


    0x05,   0x01,   /* USAGE_PAGE (Generic Desktop) */
    0x09,   0x30,   /* USAGE (X)                    */
    0x09,   0x31,   /* USAGE (Y)                    */
    0x09,   0x38,   /* USAGE (WHEEL)                */
    0x15,   0x81,   /* LOGICAL_MINIMUM (-127)       */
    0x25,   0x7f,   /* LOGICAL_MAXIMUM (+127)       */
    0x75,   0x08,   /* REPORT_SIZE (8)              */
    0x95,   0x03,   /* REPORT_COUNT (3)             */
    0x81,   0x06,   /* INPUT (Data, Var, Rel)       */
    
    0xc0,           /* END_COLLECTION               */
    0xc0,           /* END_COLLECTION               */
};


The upper computer communication report descriptor is as follows :

/*
for mcu and host communication HID report descriptor 
huohongpeng 2017-02-10
create tools: HID Description Tool
*/
const uint8_t HID_ReportDesc1[USB_HID_REPORT_DESC1_SIZE] =
{
    0x05,   0x40,   /* USAGE_PAGE (HDWB Page)    */ 
    0x09,   0x01,   /* USAGE (host commnication) */
    0xa1,   0x01,   /* COLLECTION (Application)  */


    /* The Input Report */
    0x09,   0x03,   /* USAGE (Vendor defined)    */
    0x15,   0x00,   /* LOGICAL_MINIMUM (0)       */
    0x25,   0xff,   /* LOGICAL_MAXIMUM (255)     */
    0x75,   0x08,   /* REPORT_SIZE (8)           */
    0x95,   0x40,   /* REPORT_COUNT (64)         */
    0x81,   0x02,   /* INPUT (Data, Var, Abs)    */


    /* The Output Report */
    0x09,   0x04,   /* USAGE (Vendor defined)    */
    0x15,   0x00,   /* LOGICAL_MINIMUM (0)       */
    0x25,   0xff,   /* LOGICAL_MAXIMUM (1)       */
    0x75,   0x08,   /* REPORT_SIZE (8)           */
    0x95,   0x40,   /* REPORT_COUNT (64)         */
    0x91,   0x02,   /* OUTPUT (Data, Var, Abs)   */
    0xc0            /* END_COLLECT               */
};

原网站

版权声明
本文为[NoName51C_ T_ O]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202161727578926.html