当前位置:网站首页>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 */
};
边栏推荐
- 抖音实战~首页视频~下拉刷新
- The goal you specified requires a project to execute but there is no POM
- Reading notes: process consulting III
- 关于Qt数据库开发的一些冷知识
- [kubernetes] kubernetes principle analysis and practical application (under update)
- 刷新三观的HP-UX系统中的强指针赋值出core问题
- 论数据库的传统与未来之争之溯源溯本----AWS系列专栏
- find_ path、find_ Library memo
- JSONUtils工具类(基于alibaba fastjson)
- 物联网协议的王者:MQTT
猜你喜欢
随机推荐
On the escape of inequality value
物联网协议的王者:MQTT
[MySQL series] collection of common working SQL (continuous update)
抖音实战~首页视频~下拉刷新
JS mobile terminal touch screen event
案例描述:比赛分数管理系统,需要统计历届冠军所得比赛得分,并记录到文件中,其中系统有如下需求:- 打开系统有欢迎界面,并显示可选择的选项- 选项1:记录比赛得分- 选项2:查看往届
MySQL - table creation and management
50 lines of code to crawl TOP500 books and import TXT documents
xlua获取ugui的button注册click事件
Some cold knowledge about QT database development
关于不等式取值转义的思路
[kubernetes] kubernetes principle analysis and practical application (under update)
Pinda general permission system (day 1~day 2)
8VC Venture Cup 2017 - Final Round C. Nikita and stack
项目实战六:分布式事务-Seata
To: Apple CEO Cook: great ideas come from constantly rejecting the status quo
Deep learning: numpy
Kubernetes resource topology aware scheduling optimization
On the origin of the dispute between the tradition and the future of database -- AWS series column
Super VRT









