📄 usb_descriptor.c
字号:
//-----------------------------------------------------------------------------
// USB_DESCRIPTOR.c
//-----------------------------------------------------------------------------
// Copyright (C) 2005 Silicon Laboratories, Inc.
//
// AUTH: DM
// DATE: 22 NOV 02
//
// Description: Source file for USB firmware. Includes descriptor data.
//
// Target: C8051F32x
// Tool chain: KEIL C51 6.03 / KEIL EVAL C51
//
//
#include "USB_REGISTER.h"
#include "USB_MAIN.h"
#include "USB_DESCRIPTOR.h"
//---------------------------
// Descriptor Declarations
//---------------------------
const device_descriptor DeviceDesc =
{ 18, // bLength 0x01, // bDescriptorType 0x1001, // bcdUSB 0x00, // bDeviceClass 0x00, // bDeviceSubClass 0x00, // bDeviceProtocol EP0_PACKET_SIZE, // bMaxPacketSize0 0xC410, // idVendor 0x0100, // idProduct (=1 for HID, to avoid loading of SiInt.sys driver) 0x0000, // bcdDevice 0x01, // iManufacturer 0x02, // iProduct 0x00, // iSerialNumber 0x01 // bNumConfigurations
}; //end of DeviceDesc
// From "USB Device Class Definition for Human Interface Devices (HID)".
// Section 7.1:
// "When a Get_Descriptor(Configuration) request is issued,
// it returns the Configuration descriptor, all Interface descriptors,
// all Endpoint descriptors, and the HID descriptor for each interface."
const hid_configuration_descriptor HidConfigDesc =
{
{ // configuration_descriptor hid_configuration_descriptor
0x09, // Length
0x02, // Type
0x2900, // Totallength (= 9+9+9+7+7)
0x01, // NumInterfaces
0x01, // bConfigurationValue
0x00, // iConfiguration
0x80, // bmAttributes
0x20 // MaxPower (in 2mA units)
},
{ // interface_descriptor hid_interface_descriptor
0x09, // bLength
0x04, // bDescriptorType
0x00, // bInterfaceNumber
0x00, // bAlternateSetting
0x02, // bNumEndpoints
0x03, // bInterfaceClass (3 = HID)
0x00, // bInterfaceSubClass
0x00, // bInterfaceProcotol
0x00 // iInterface
},
{ // class_descriptor hid_descriptor
0x09, // bLength
0x21, // bDescriptorType
0x0101, // bcdHID
0x00, // bCountryCode
0x01, // bNumDescriptors
0x22, // bDescriptorType
HID_REPORT_DESCRIPTOR_SIZE_LE // wItemLength (total length of report descriptor)
},
// IN endpoint (mandatory for HID)
{ // endpoint_descriptor hid_endpoint_in_descriptor
0x07, // bLength
0x05, // bDescriptorType
0x81, // bEndpointAddress
0x03, // bmAttributes
EP1_PACKET_SIZE_LE, // MaxPacketSize (LITTLE ENDIAN)
0x01 // bInterval
},
// OUT endpoint (optional for HID)
{ // endpoint_descriptor hid_endpoint_out_descriptor
0x07, // bLength
0x05, // bDescriptorType
0x02, // bEndpointAddress
0x03, // bmAttributes
EP2_PACKET_SIZE_LE, // MaxPacketSize (LITTLE ENDIAN)
0x01 // bInterval
}
};
const hid_report_descriptor HidReportDesc =
{
0x06, 0x00, 0xff, // USAGE_PAGE (Vendor Defined Page 1)
0x09, 0x01, // USAGE (Vendor Usage 1)
0xa1, 0x01, // COLLECTION (Application)
0x09, 0x01, // USAGE (Vendor Usage 1)
0x95, 0x08, // REPORT_COUNT (8)
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)
0x09, 0x01, // USAGE (Vendor Usage 1)
0x91, 0x02, // OUTPUT (Data,Var,Abs)
0xc0 // END_COLLECTION
};
#define STR0LEN 4
code const BYTE String0Desc[STR0LEN] =
{
STR0LEN, 0x03, 0x09, 0x04
}; //end of String0Desc
#define STR1LEN sizeof("SILICON LABORATORIES")*2
code const BYTE String1Desc[STR1LEN] =
{
STR1LEN, 0x03,
'S', 0,
'I', 0,
'L', 0,
'I', 0,
'C', 0,
'O', 0,
'N', 0,
' ', 0,
'L', 0,
'A', 0,
'B', 0,
'O', 0,
'R', 0,
'A', 0,
'T', 0,
'O', 0,
'R', 0,
'I', 0,
'E', 0,
'S', 0
}; //end of String1Desc
#define STR2LEN sizeof("C8051F320 Development Board")*2
code const BYTE String2Desc[STR2LEN] =
{
STR2LEN, 0x03,
'C', 0,
'8', 0,
'0', 0,
'5', 0,
'1', 0,
'F', 0,
'3', 0,
'2', 0,
'0', 0,
' ', 0,
'D', 0,
'e', 0,
'v', 0,
'e', 0,
'l', 0,
'o', 0,
'p', 0,
'm', 0,
'e', 0,
'n', 0,
't', 0,
' ', 0,
'B', 0,
'o', 0,
'a', 0,
'r', 0,
'd', 0
}; //end of String2Desc
BYTE* const StringDescTable[] =
{
String0Desc,
String1Desc,
String2Desc
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -