-
Notifications
You must be signed in to change notification settings - Fork 28
/
usb_desc.c
154 lines (136 loc) · 6.17 KB
/
usb_desc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include "usb_desc.h"
#include "ch554_platform.h"
// Device Descriptor
code const uint8_t DevDesc[] = {
USB_DESCSIZE_DEVICE, // Total length
0x01, // Type: Device Descriptor
0x10, 0x01, // USB Spec., 0x0110 -> USB 1.1
0x00, // Class code, 00 - each interface defines its own class
0x00, // Device Subclass
0x00, // Device Protocol
8, // Max packet size
0x3d, 0x41, // VID 0x413d
0x07, 0x21, // PID 0x2107
0x00, 0x00, // Device release number in BCD
0x04, // Manufactor, index of string descriptor
0x03, // Product string descriptor ID
0x00, // Serial number (String descriptor ID)
0x01 // Number of available configurations
};
// Configuration Descriptor and Interface Descriptor
code const uint8_t CfgDesc[] =
{
// Configuration Descriptor
9, // Length of the descriptor
0x02, // Type: Configuration Descriptor
// Total length of this and following descriptors
USB_DESCSIZE_CONFIG_L, USB_DESCSIZE_CONFIG_H,
USB_INTERFACES, // Number of interfaces
0x01, // Value used to select this configuration
0x00, // Index of corresponding string descriptor
0x80, // Attributes, D7 must be 1, D6 Self-powered, D5 Remote Wakeup, D4-D0=0
0x32, // Max current drawn by device, in units of 2mA
// Interface descriptor (Vendor-defined)
9, // Length of the descriptor
0x04, // Type: Interface Descriptor
0x00, // Interface ID
0x00, // Alternate setting
0x02, // Number of Endpoints
0x03, // Interface class code
0x01, // Subclass code 0=No subclass, 1=Boot Interface subclass
0x00, // Protocol code 0=None, 1=Keyboard, 2=Mouse
0x01, // Index of corresponding string descriptor (On Windows, it is called "Bus reported device description")
// HID descriptor (Vendor-defined)
9, // Length of the descriptor
0x21, // Type: HID Descriptor
0x10, 0x01, // bcdHID: HID Class Spec release number
0x00, // bCountryCode: Hardware target country
0x01, // bNumDescriptors: Number of HID class descriptors to follow
0x22, // bDescriptorType
// wItemLength: Total length of Report descriptor
USB_HIDREPSIZE_VENDORDEF, 0,
// Endpoint descriptor (Vendor-defined) // EP2, IN
7, // Length of the descriptor
0x05, // Type: Endpoint Descriptor
0x82, // Endpoint: D7: 0-Out 1-In, D6-D4=0, D3-D0 Endpoint number
0x03, // Attributes:
// D1:0 Transfer type: 00 = Control 01 = Isochronous 10 = Bulk 11 = Interrupt
// The following only apply to isochronous endpoints. Else set to 0.
// D3:2 Synchronisation Type: 00 = No Synchronisation 01 = Asynchronous 10 = Adaptive 11 = Synchronous
// D5:4 Usage Type: 00 = Data endpoint 01 = Feedback endpoint 10 = Implicit feedback Data endpoint 11 = Reserved
// D7:6 = 0
0x40,0x00, // Maximum packet size can be handled
0x18, // Interval for polling, in units of 1 ms for low/full speed
// Endpoint descriptor (Vendor-defined) // EP2, OUT
7, // Length of the descriptor
0x05, // Type: Endpoint Descriptor
0x02, // Endpoint: D7: 0-Out 1-In, D6-D4=0, D3-D0 Endpoint number
0x03, // Attributes:
// D1:0 Transfer type: 00 = Control 01 = Isochronous 10 = Bulk 11 = Interrupt
// The following only apply to isochronous endpoints. Else set to 0.
// D3:2 Synchronisation Type: 00 = No Synchronisation 01 = Asynchronous 10 = Adaptive 11 = Synchronous
// D5:4 Usage Type: 00 = Data endpoint 01 = Feedback endpoint 10 = Implicit feedback Data endpoint 11 = Reserved
// D7:6 = 0
0x40,0x00, // Maximum packet size can be handled
0x18, // Interval for polling, in units of 1 ms for low/full speed
// Interface descriptor (Keyboard)
9, // Length of the descriptor
0x04, // Type: Interface Descriptor
0x01, // Interface ID
0x00, // Alternate setting
0x01, // Number of Endpoints
0x03, // Interface class code
0x01, // Subclass code 0=No subclass, 1=Boot Interface subclass
0x01, // Protocol code 0=None, 1=Keyboard, 2=Mouse
0x02, // Index of corresponding string descriptor
// HID descriptor (Keyboard)
9, // Length of the descriptor
0x21, // Type: HID Descriptor
0x11, 0x01, // bcdHID: HID Class Spec release number
0x00, // bCountryCode: Hardware target country
0x01, // bNumDescriptors: Number of HID class descriptors to follow
0x22, // bDescriptorType
// wItemLength: Total length of Report descriptor
USB_HIDREPSIZE_KEYBOARD, 0,
// Endpoint descriptor (Keyboard) // EP1, IN
7, // Length of the descriptor
0x05, // Type: Endpoint Descriptor
0x81, // Endpoint: D7: 0-Out 1-In, D6-D4=0, D3-D0 Endpoint number
0x03, // Attributes:
// D1:0 Transfer type: 00 = Control 01 = Isochronous 10 = Bulk 11 = Interrupt
// The following only apply to isochronous endpoints. Else set to 0.
// D3:2 Synchronisation Type: 00 = No Synchronisation 01 = Asynchronous 10 = Adaptive 11 = Synchronous
// D5:4 Usage Type: 00 = Data endpoint 01 = Feedback endpoint 10 = Implicit feedback Data endpoint 11 = Reserved
// D7:6 = 0
0x08, 0x00, // Maximum packet size can be handled
0x0a, // Interval for polling, in units of 1 ms for low/full speed
/******************** Descriptor of Mass Storage interface ********************/
/* 09 */
9, /* bLength: Interface Descriptor size */
0x04, /* bDescriptorType: */
/* Interface descriptor type */
0x02, /* bInterfaceNumber: Number of Interface */
0x00, /* bAlternateSetting: Alternate setting */
0x02, /* bNumEndpoints*/
0x08, /* bInterfaceClass: MASS STORAGE Class */
0x06, /* bInterfaceSubClass : SCSI transparent*/
0x50, /* nInterfaceProtocol */
0, /* iInterface: */
/* 18 */
7, /*Endpoint descriptor length = 7*/
0x05, /*Endpoint descriptor type */
0x83, /*Endpoint address (IN, address 1) */
0x02, /*Bulk endpoint type */
0x40, /*Maximum packet size (64 bytes) */
0x00,
0x00, /*Polling interval in milliseconds */
/* 25 */
0x07, /*Endpoint descriptor length = 7 */
0x05, /*Endpoint descriptor type */
0x03, /*Endpoint address (OUT, address 2) */
0x02, /*Bulk endpoint type */
0x40, /*Maximum packet size (64 bytes) */
0x00,
0x00 /*Polling interval in milliseconds*/
/*32*/
};