当前位置:网站首页>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 */
};
边栏推荐
- 50 lines of code to crawl TOP500 books and import TXT documents
- stm32和电机开发(直流有刷电机和步进电机)
- xlua获取ugui的button注册click事件
- Tiktok practice ~ sharing module ~ copy short video link
- mysql的充值问题
- (树) 树状数组
- 股票开户的具体步骤是什么?网上开户安全吗?
- 手机影像内卷几时休?
- Tiktok practice ~ sharing module ~ short video download (save to photo album)
- Basic and necessary common plug-ins of vscade
猜你喜欢
On the escape of inequality value
(几何) 凸包问题
Tiktok practice ~ sharing module ~ generate short video QR code
Tiktok practice ~ sharing module ~ copy short video link
郭明錤:苹果 AR / MR 头显是其有史以来设计最复杂的产品,将于 2023 年 1 月发布
Pinda general permission system (day 3~day 4)
(树) 树状数组
Uni app uses canvas to draw QR code
Tiktok practice ~ search page ~ video details
Arduino uno + DS1302 uses 31 byte static RAM to store data and print through serial port
随机推荐
Super VRT
Tiktok practice ~ sharing module ~ generate short video QR code
关于Qt数据库开发的一些冷知识
Microservice architecture
MySQL - table creation and management
Project practice 5: build elk log collection system
Boot指标监测
Chain game development finished product source code chain game system development details
Good thing recommendation: mobile terminal development security tool
自己创建一个时间拦截器
[recommended collection] these 8 common missing value filling skills must be mastered
JS mobile terminal touch screen event
Wechat applet uniapp left slide delete with Delete Icon
Installation and use of filebeat
Commodity seckill system
好物推薦:移動端開發安全工具
8VC Venture Cup 2017 - Final Round C. Nikita and stack
Installation and use of logstash
MySQL stored procedure
Successfully solved the problem of garbled microservice @value obtaining configuration file