forked from jimmo/numato-mimasv2-pic-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usb_descriptors.c
250 lines (222 loc) · 9.89 KB
/
usb_descriptors.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include "usb.h"
#include "usb_device_cdc.h"
// TODO(jim): Verify that this is ending up in romdata.
const USB_DEVICE_DESCRIPTOR device_dsc = {
0x12, // Size of this descriptor in bytes
USB_DESCRIPTOR_DEVICE, // DEVICE descriptor type
0x0200, // USB Spec Release Number in BCD format
CDC_DEVICE, // Class Code
0x00, // Subclass code
0x00, // Protocol code
USB_EP0_BUFF_SIZE, // Max packet size for EP0, see usb_config.h
0x2a19, // Vendor ID (Numato)
0x1002, // Product ID (Numato Lab Mimas V2 Spartan 3A Development Board)
0x0100, // Device release number in BCD format
0x01, // Manufacturer string index
0x02, // Product string index
0x00, // Device serial number string index
0x01 // Number of possible configurations
};
const uint8_t configDescriptor1[] = {
// ----- Configuration descriptor ------------------------------------------
0x09, // Size of this descriptor in bytes
USB_DESCRIPTOR_CONFIGURATION, // CONFIGURATION descriptor type
9+58*2,0, // Total length of data for this cfg
USB_MAX_NUM_INT, // Number of interfaces in this cfg
1, // Index value of this configuration
0, // Configuration string index
_DEFAULT | _SELF, // Attributes, see usb_device.h
50, // Max power consumption (2X mA)
// ---- CDC1 - comm interface ----------------------------------------------
9, // Size of this descriptor in bytes
USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type
0, // Interface Number ***
0, // Alternate Setting Number
1, // Number of endpoints in this intf
COMM_INTF, // Class code
ABSTRACT_CONTROL_MODEL, // Subclass code
V25TER, // Protocol code
0x03, // Interface string index ***
// ----- CDC1 - class-specific descriptors ---------------------------------
sizeof(USB_CDC_HEADER_FN_DSC),
CS_INTERFACE,
DSC_FN_HEADER,
0x10,0x01,
sizeof(USB_CDC_ACM_FN_DSC),
CS_INTERFACE,
DSC_FN_ACM,
USB_CDC_ACM_FN_DSC_VAL,
sizeof(USB_CDC_UNION_FN_DSC),
CS_INTERFACE,
DSC_FN_UNION,
0, // Interface ID of the comm interface. ***
1, // Interface ID of the data interface. ***
sizeof(USB_CDC_CALL_MGT_FN_DSC),
CS_INTERFACE,
DSC_FN_CALL_MGT,
0x00,
1, // Interface ID of the data interface. ***
// ----- CDC1 - comm endpoint ----------------------------------------------
0x07, // Size of this descriptor in bytes
USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
_EP01_IN, // EndpointAddress ***
_INTERRUPT, // Attributes
0x08,0x00, // Max tx/rx size
0x02, // Interval
// ----- CDC1 - data interface ---------------------------------------------
0x09, // Size of this descriptor in bytes
USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type
1, // Interface Number ***
0, // Alternate Setting Number
2, // Number of endpoints in this intf
DATA_INTF, // Class code
0, // Subclass code
NO_PROTOCOL, // Protocol code
0x03, // Interface string index ***
// ----- CDC1 - data out endpoint ------------------------------------------
0x07, // Size of this descriptor in bytes
USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
_EP02_OUT, // EndpointAddress ***
_BULK, // Attributes
CDC_DATA_OUT_EP_SIZE,0x00, // Max tx/rx size
0x00, // Interval
// ----- CDC1 - data in endpoint ---0---------------------------------------
0x07, // Size of this descriptor in bytes
USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
_EP02_IN, // EndpointAddress ***
_BULK, // Attributes
CDC_DATA_IN_EP_SIZE,0x00, // Max tx/rx size
0x00, // Interval
// ---- CDC2 - comm interface ----------------------------------------------
9, // Size of this descriptor in bytes
USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type
2, // Interface Number ***
0, // Alternate Setting Number
1, // Number of endpoints in this intf
COMM_INTF, // Class code
ABSTRACT_CONTROL_MODEL, // Subclass code
V25TER, // Protocol code
0x04, // Interface string index ***
// ----- CDC2 - class-specific descriptors ---------------------------------
sizeof(USB_CDC_HEADER_FN_DSC),
CS_INTERFACE,
DSC_FN_HEADER,
0x10,0x01,
sizeof(USB_CDC_ACM_FN_DSC),
CS_INTERFACE,
DSC_FN_ACM,
USB_CDC_ACM_FN_DSC_VAL,
sizeof(USB_CDC_UNION_FN_DSC),
CS_INTERFACE,
DSC_FN_UNION,
2, // Interface ID of the comm interface. ***
3, // Interface ID of the data interface. ***
sizeof(USB_CDC_CALL_MGT_FN_DSC),
CS_INTERFACE,
DSC_FN_CALL_MGT,
0x00,
3, // Interface ID of the data interface.
// ----- CDC2 - comm endpoint ----------------------------------------------
0x07, // Size of this descriptor in bytes
USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
_EP03_IN, // EndpointAddress ***
_INTERRUPT, // Attributes
0x08,0x00, // Max tx/rx size
0x02, // Interval
// ----- CDC2 - data interface ---------------------------------------------
0x09, // Size of this descriptor in bytes
USB_DESCRIPTOR_INTERFACE, // INTERFACE descriptor type
3, // Interface Number ***
0, // Alternate Setting Number
2, // Number of endpoints in this intf
DATA_INTF, // Class code
0, // Subclass code
NO_PROTOCOL, // Protocol code
0x04, // Interface string index ***
// ----- CDC2 - data out endpoint ------------------------------------------
0x07, // Size of this descriptor in bytes
USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
_EP04_OUT, // EndpointAddress ***
_BULK, // Attributes
CDC_DATA_OUT_EP_SIZE,0x00, // Max tx/rx size
0x00, // Interval
// ----- CDC2 - data in endpoint ---0---------------------------------------
0x07, // Size of this descriptor in bytes
USB_DESCRIPTOR_ENDPOINT, // Endpoint Descriptor
_EP04_IN, // EndpointAddress ***
_BULK, // Attributes
CDC_DATA_IN_EP_SIZE,0x00, // Max tx/rx size
0x00, // Interval
};
// Language code string descriptor
const struct {
uint8_t bLength;
uint8_t bDscType;
uint16_t string[1];
} sd000 = {
sizeof(sd000),
USB_DESCRIPTOR_STRING,
{
0x0409
}
};
// Manufacturer string descriptor
const struct {
uint8_t bLength;
uint8_t bDscType;
uint16_t string[24];
} sd001 = {
sizeof(sd001),
USB_DESCRIPTOR_STRING,
{
'N','u','m','a','t','o',' ','S','y','s','t','e','m','s',' ','P','v','t','.',' ','L','t','d','.'
}
};
// Product string descriptor
const struct {
uint8_t bLength;
uint8_t bDscType;
uint16_t string[60];
} sd002 = {
sizeof(sd002),
USB_DESCRIPTOR_STRING,
{
'N','u','m','a','t','o',' ','L','a','b',' ','M','i','m','a','s',' ','V','2',' ','S','p','a','r','t','a','n','6',' ','F','P','G','A',' ','D','e','v','e','l','o','p','m','e','n','t',' ','B','o','a','r','d'
}
};
// CDC1 descriptor
const struct {
uint8_t bLength;
uint8_t bDscType;
uint16_t string[9];
} sd003 = {
sizeof(sd003),
USB_DESCRIPTOR_STRING,
{
'S','P','I',' ','F','l','a','s','h'
}
};
// CDC2 descriptor
const struct {
uint8_t bLength;
uint8_t bDscType;
uint16_t string[9];
} sd004 = {
sizeof(sd004),
USB_DESCRIPTOR_STRING,
{
'F','P','G','A',' ','U','A','R','T'
}
};
// Array of configuration descriptors
const uint8_t *const USB_CD_Ptr[] = {
(const uint8_t *const)configDescriptor1
};
// Array of string descriptors
const uint8_t *const USB_SD_Ptr[USB_NUM_STRING_DESCRIPTORS] = {
(const uint8_t *const)&sd000,
(const uint8_t *const)&sd001,
(const uint8_t *const)&sd002,
(const uint8_t *const)&sd003,
(const uint8_t *const)&sd004,
};