当前位置:网站首页>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 */
};
边栏推荐
- Kubernetes 资源拓扑感知调度优化
- vue中缓存组件keep-alive
- Database SQL statement writing
- 开发者调查:Rust/PostgreSQL 最受喜爱,PHP 薪水偏低
- Good thing recommendation: mobile terminal development security tool
- 微服务架构
- Preliminary analysis of serial port printing and stack for arm bare board debugging
- Solidity - 合约继承子合约包含构造函数时报错 及 一个合约调用另一合约view函数收取gas费用
- Some basic mistakes
- Kubernetes resource topology aware scheduling optimization
猜你喜欢
随机推荐
好物推荐:移动端开发安全工具
Selection of database paradigm and main code
Solve com mysql. jdbc. exceptions. jdbc4.MySQLNonTransientConnectionException: Could not create connection
MySQL - database creation and management
Kubernetes 资源拓扑感知调度优化
Summary of knowledge points
Current limiting design and Implementation
Wechat applet uniapp left slide delete with Delete Icon
The goal you specified requires a project to execute but there is no POM
Pinda general permission system (day 3~day 4)
Boot指标监测
转:苹果CEO库克:伟大的想法来自不断拒绝接受现状
抖音实战~搜索页面~视频详情
Arduino UNO + DS1302利用31字节静态RAM存储数据并串口打印
50 lines of code to crawl TOP500 books and import TXT documents
Deep learning: numpy
Request method 'POST' not supported
(几何) 凸包问题
Filebeat安装及使用
Is it safe to open an account for CICC Wealth Online?









