⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_descriptor.cpp

📁 STM32 USB HID
💻 CPP
字号:
#include"usb_descriptor.hpp"
//-----------------------------------------------------------------------------
const unsigned char Device_Descriptor[]=
{
  18,                       /*bLength */
  0x01, /*bDescriptorType*/

  0x10,                       /*bcdUSB */
  0x01,
  0x00,                       /*bDeviceClass*/
  0x00,                       /*bDeviceSubClass*/
  0x00,                       /*bDeviceProtocol*/
  0x40,                       /*bMaxPacketSize40*/

  0xc4,                       /*idVendor (0x0483)*/
  0x10,
  0xcd,                       /*idProduct = 0x5750*/
  0x82,

  0x00,                       /*bcdDevice rel. 0.00*/
  0x00,	

  1,    /*Index of string descriptor describing manufacturer */
  2,    /*Index of string descriptor describing product*/
  0,		/*Index of string descriptor describing the device serial number */

  0x01                        /*bNumConfigurations*/
};
//-----------------------------------------------------------------------------
const unsigned char Config_Descriptor[CONFIG_DESC_SIZE]=
{
  0x09, /* bLength: Configuation Descriptor size */
  2, /* bDescriptorType: Configuration */
  CONFIG_DESC_SIZE,
  /* wTotalLength: Bytes returned */
  0x00,
  0x01,         /* bNumInterfaces: 1 interface */
  0x01,         /* bConfigurationValue: Configuration value */
  0x00,         /* iConfiguration: Index of string descriptor describing
                               the configuration*/
  0x80,         /* bmAttributes: Bus powered */
  0x64,         /* MaxPower 100 mA: this current is used for detecting Vbus */

  /************** Descriptor of Custom HID interface ****************/
  /* 09 */
  0x09,         /* bLength: Interface Descriptor size */
  4,/* bDescriptorType: Interface descriptor type */
  0x00,         /* 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 */
  0,            /* iInterface: Index of string descriptor */
  /******************** Descriptor of Custom HID HID ********************/
  /* 18 */
  0x09,         /* bLength: HID Descriptor size */
  0x21, /* bDescriptorType: HID */

  0x00,         /* bcdHID: HID Class Spec release number */
  0x02,

  0x00,         /* bCountryCode: Hardware target country */
  0x01,         /* bNumDescriptors: Number of HID class descriptors to follow */
  0x22,         /* bDescriptorType */
  REPORT_DESC_SIZE,/* wItemLength: Total length of Report descriptor */
  0x00,
  /******************** Descriptor of Custom HID endpoints ******************/
  /* 27 */
  0x07,          /* bLength: Endpoint Descriptor size */
  5, /* bDescriptorType: */

  0x81,          /* bEndpointAddress: Endpoint Address (IN) */
  0x03,          /* bmAttributes: Interrupt endpoint */
  0x40,          /* wMaxPacketSize: 2 Bytes max */
  0x00,
  1,          /* bInterval: Polling Interval (32 ms) */
  /* 34 */
  	
  0x07,	/* bLength: Endpoint Descriptor size */
  5,	/* bDescriptorType: */
		/*	Endpoint descriptor type */
  0x01,	/* bEndpointAddress: */
		/*	Endpoint Address (OUT) */
  0x03,	/* bmAttributes: Interrupt endpoint */
  0x40,	/* wMaxPacketSize: 2 Bytes max  */
  0x00,
  1,	/* bInterval: Polling Interval (20 ms) */
  /* 41 */
}; /* CustomHID_ConfigDescriptor */
//-----------------------------------------------------------------------------
const unsigned char StringLangID[]=
{
  0x04,
  0x03,
  0x09,
  0x04 /* LangID = 0x0409: U.S. English */
};
//-----------------------------------------------------------------------------
const unsigned char StringVendor[]=
{
	38,     /* Size of Vendor string */
	0x03,             /* bDescriptorType*/
	/* Manufacturer: "STMicroelectronics" */
	'S', 0, 
	'T', 0, 
	'M', 0, 
	'i', 0, 
	'c', 0, 
	'r', 0, 
	'o', 0, 
	'e', 0,
	'l', 0, 
	'e', 0, 
	'c', 0, 
	't', 0, 
	'r', 0, 
	'o', 0, 
	'n', 0, 
	'i', 0,
	'c', 0, 
	's', 0
};
//-----------------------------------------------------------------------------
const unsigned char StringProduct[]=
{
	30,          /* bLength */
	0x03,        /* bDescriptorType */
	/* Product name: "STM32 Virtual COM Port" */
	'S', 0, 
	'T', 0, 
	'M', 0, 
	'3', 0, 
	'2', 0, 
	' ', 0, 
	'J', 0,
	'o', 0, 
	'y', 0, 
	's', 0, 
	't', 0, 
	'i', 0, 
	'c', 0, 
	'k', 0
};
//-----------------------------------------------------------------------------
const unsigned char StringSerial[STRING_SERIAL_SIZE]=
{
  STRING_SERIAL_SIZE,           /* bLength */
  3,        /* bDescriptorType */
  'S', 0, 
	'T', 0, 
	'M', 0,
	'3', 0,
	'2', 0, 
	'1', 0, 
	'0', 0
};
//-----------------------------------------------------------------------------
const unsigned char Report_Descriptor[]=
{    
  0x06, 0x00, 0xff,              // USAGE_PAGE (Vendor Defined Page 1)
	0x09, 0x01,                    // USAGE (Vendor Usage 1)
	0xa1, 0x01,                    // COLLECTION (Application)

	
	0x85, 1,    //   Report ID = 1
  0x95, 0x03,                    //   REPORT_COUNT (16)
  0x75, 0x08,                    //   REPORT_SIZE (8)
  0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
  0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
  0x09, 0x01,                    //   USAGE (Vendor Usage 1)
  0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)

  0x85, 2, 		 //   Report ID = 2
  0x95, 0x03,                    //   REPORT_COUNT (16)
  0x75, 0x08,                    //   REPORT_SIZE (8)
  0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
  0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
  0x09, 0x01,                    //   USAGE (Vendor Usage 1)
  0x81, 0x02,                    //   INPUT (Data,Var,Abs)
																													
	0x85, 3, 		//   Report ID = 3
  0x95, 0x01,                    //   REPORT_COUNT (1)
  0x75, 0x08,                    //   REPORT_SIZE (8)
  0x26, 0xff, 0x00,              //   LOGICAL_MAXIMUM (255)
  0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
  0x09, 0x01,                    //   USAGE (Vendor Usage 1)
  0x81, 0x02,                    //   INPUT (Data,Var,Abs)
	
	0xC0                                                   //   end Application Collection
}; /* CustomHID_ReportDescriptor */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -