Lightweight USB stack  1.0
usb_std.h
1 /* This file is the part of the Lightweight USB device Stack for STM32 microcontrollers
2  *
3  * Copyright ©2016 Dmitry Filimonchuk <dmitrystu[at]gmail[dot]com>
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef _USB_STD_H_
17 #define _USB_STD_H_
18 #if defined(__cplusplus)
19 extern "C" {
20 #endif
21 
22 #define __CAT(x,y) x ## y
23 #define CAT(x,y) __CAT(x,y)
24 
40 #define VERSION_BCD(maj, min, rev) (((maj & 0xFF) << 8) | ((min & 0x0F) << 4) | (rev & 0x0F))
41 
43 #define USB_ARRAY_DESC(...) {.bLength = 2 + sizeof((uint16_t[]){__VA_ARGS__}),\
44  .bDescriptorType = USB_DTYPE_STRING,\
45  .wString = {__VA_ARGS__}}
46 
47 #define USB_STRING_DESC(s) {.bLength = sizeof(CAT(u,s)),\
48  .bDescriptorType = USB_DTYPE_STRING,\
49  .wString = {CAT(u,s)}}
50 
52 #define USB_CFG_POWER_MA(mA) ((mA) >> 1)
53 
57 #define USB_CFG_ATTR_RESERVED 0x80
58 #define USB_CFG_ATTR_SELFPOWERED 0x40
59 
64 #define USB_EPDIR_IN 0x00
65 #define USB_EPDIR_OUT 0x80
66 #define USB_EPTYPE_CONTROL 0x00
67 #define USB_EPTYPE_ISOCHRONUS 0x01
68 #define USB_EPTYPE_BULK 0x02
69 #define USB_EPTYPE_INTERRUPT 0x03
70 #define USB_EPATTR_NO_SYNC 0x00
71 #define USB_EPATTR_ASYNC 0x04
72 #define USB_EPATTR_ADAPTIVE 0x08
73 #define USB_EPATTR_SYNC 0x0C
74 #define USB_EPUSAGE_DATA 0x00
75 #define USB_EPUSAGE_FEEDBACK 0x10
76 #define USB_EPUSAGE_IMP_FEEDBACK 0x20
81 #define NO_DESCRIPTOR 0x00
82 #define INTSERIALNO_DESCRIPTOR 0xFE
88 #define USB_CLASS_PER_INTERFACE 0x00
89 #define USB_SUBCLASS_NONE 0x00
90 #define USB_PROTO_NONE 0x00
91 #define USB_CLASS_AUDIO 0x01
92 #define USB_CLASS_PHYSICAL 0x05
93 #define USB_CLASS_STILL_IMAGE 0x06
94 #define USB_CLASS_PRINTER 0x07
95 #define USB_CLASS_MASS_STORAGE 0x08
96 #define USB_CLASS_HUB 0x09
97 #define USB_CLASS_CSCID 0x0B
98 #define USB_CLASS_CONTENT_SEC 0x0D
99 #define USB_CLASS_VIDEO 0x0E
100 #define USB_CLASS_HEALTHCARE 0x0F
101 #define USB_CLASS_AV 0x10
102 #define USB_CLASS_BILLBOARD 0x11
103 #define USB_CLASS_CBRIDGE 0x12
104 #define USB_CLASS_DIAGNOSTIC 0xDC
105 #define USB_CLASS_WIRELESS 0xE0
106 #define USB_CLASS_MISC 0xEF
107 #define USB_CLASS_APP_SPEC 0xFE
108 #define USB_CLASS_VENDOR 0xFF
109 #define USB_SUBCLASS_VENDOR 0xFF
110 #define USB_PROTO_VENDOR 0xFF
111 #define USB_CLASS_IAD 0xEF
112 #define USB_SUBCLASS_IAD 0x02
113 #define USB_PROTO_IAD 0x01
118 #define USB_DTYPE_DEVICE 0x01
119 #define USB_DTYPE_CONFIGURATION 0x02
120 #define USB_DTYPE_STRING 0x03
121 #define USB_DTYPE_INTERFACE 0x04
122 #define USB_DTYPE_ENDPOINT 0x05
123 #define USB_DTYPE_QUALIFIER 0x06
124 #define USB_DTYPE_OTHER 0x07
125 #define USB_DTYPE_INTERFACEPOWER 0x08
126 #define USB_DTYPE_OTG 0x09
127 #define USB_DTYPE_DEBUG 0x0A
128 #define USB_DTYPE_INTERFASEASSOC 0x0B
129 #define USB_DTYPE_CS_INTERFACE 0x24
130 #define USB_DTYPE_CS_ENDPOINT 0x25
135 #define USB_STD_GET_STATUS 0x00
136 #define USB_STD_CLEAR_FEATURE 0x01
137 #define USB_STD_SET_FEATURE 0x03
138 #define USB_STD_SET_ADDRESS 0x05
140 #define USB_STD_GET_DESCRIPTOR 0x06
142 #define USB_STD_SET_DESCRIPTOR 0x07
145 #define USB_STD_GET_CONFIG 0x08
146 #define USB_STD_SET_CONFIG 0x09
147 #define USB_STD_GET_INTERFACE 0x0A
149 #define USB_STD_SET_INTERFACE 0x0B
151 #define USB_STD_SYNCH_FRAME 0x0C
157 #define USB_FEAT_ENDPOINT_HALT 0x00
158 #define USB_FEAT_REMOTE_WKUP 0x01
159 #define USB_FEAT_TEST_MODE 0x02
160 #define USB_FEAT_DEBUG_MODE 0x06
161 
165 #define USB_TEST_J 0x01
166 #define USB_TEST_K 0x02
167 #define USB_TEST_SE0_NAK 0x03
168 #define USB_TEST_PACKET 0x04
169 #define USB_TEST_FORCE_ENABLE 0x05
174 #define USB_LANGID_AFR 0x0436
175 #define USB_LANGID_SQI 0x041c
176 #define USB_LANGID_ARA_SA 0x0401
177 #define USB_LANGID_ARA_IQ 0x0801
178 #define USB_LANGID_ARA_EG 0x0c01
179 #define USB_LANGID_ARA_LY 0x1001
180 #define USB_LANGID_ARA_DZ 0x1401
181 #define USB_LANGID_ARA_MA 0x1801
182 #define USB_LANGID_ARA_TN 0x1c01
183 #define USB_LANGID_ARA_OM 0x2001
184 #define USB_LANGID_ARA_YE 0x2401
185 #define USB_LANGID_ARA_SY 0x2801
186 #define USB_LANGID_ARA_JO 0x2c01
187 #define USB_LANGID_ARA_LB 0x3001
188 #define USB_LANGID_ARA_KW 0x3401
189 #define USB_LANGID_ARA_AE 0x3801
190 #define USB_LANGID_ARA_BH 0x3c01
191 #define USB_LANGID_ARA_QA 0x4001
192 #define USB_LANGID_HYE 0x042b
193 #define USB_LANGID_ASM 0x044d
194 #define USB_LANGID_AZE_LAT 0x042c
195 #define USB_LANGID_AZE_CYR 0x082c
196 #define USB_LANGID_EUS 0x042d
197 #define USB_LANGID_BEL 0x0423
198 #define USB_LANGID_BEN 0x0445
199 #define USB_LANGID_BUL 0x0402
200 #define USB_LANGID_MYA 0x0455
201 #define USB_LANGID_CAT 0x0403
202 #define USB_LANGID_ZHO_TW 0x0404
203 #define USB_LANGID_ZHO_CN 0x0804
204 #define USB_LANGID_ZHO_HK 0x0c04
205 #define USB_LANGID_ZHO_SG 0x1004
206 #define USB_LANGID_ZHO_MO 0x1404
207 #define USB_LANGID_HRV 0x041a
208 #define USB_LANGID_CZE 0x0405
209 #define USB_LANGID_DAN 0x0406
210 #define USB_LANGID_NLD_NL 0x0413
211 #define USB_LANGID_NLD_BE 0x0813
212 #define USB_LANGID_ENG_US 0x0409
213 #define USB_LANGID_ENG_UK 0x0809
214 #define USB_LANGID_ENG_AU 0x0c09
215 #define USB_LANGID_ENG_CA 0x1009
216 #define USB_LANGID_ENG_NZ 0x1409
217 #define USB_LANGID_ENG_IE 0x1809
218 #define USB_LANGID_ENG_ZA 0x1c09
219 #define USB_LANGID_ENG_JM 0x2009
220 #define USB_LANGID_ENG_CAR 0x2409
221 #define USB_LANGID_ENG_BZ 0x2809
222 #define USB_LANGID_ENG_TH 0x2c09
223 #define USB_LANGID_ENG_ZW 0x3009
224 #define USB_LANGID_ENG_PH 0x3409
225 #define USB_LANGID_EST 0x0425
226 #define USB_LANGID_FAO 0x0438
227 #define USB_LANGID_FAS 0x0429
228 #define USB_LANGID_FIN 0x040b
229 #define USB_LANGID_FRA 0x040c
230 #define USB_LANGID_FRA_BE 0x080c
231 #define USB_LANGID_FRA_CA 0x0c0c
232 #define USB_LANGID_FRA_SZ 0x100c
233 #define USB_LANGID_FRA_LU 0x140c
234 #define USB_LANGID_FRA_MC 0x180c
235 #define USB_LANGID_KAT 0x0437
236 #define USB_LANGID_DEU 0x0407
237 #define USB_LANGID_DEU_SZ 0x0807
238 #define USB_LANGID_DEU_AT 0x0c07
239 #define USB_LANGID_DEU_LU 0x1007
240 #define USB_LANGID_DEU_LI 0x1407
241 #define USB_LANGID_ELL 0x0408
242 #define USB_LANGID_GUJ 0x0447
243 #define USB_LANGID_HEB 0x040d
244 #define USB_LANGID_HIN 0x0439
245 #define USB_LANGID_HUN 0x040e
246 #define USB_LANGID_ISL 0x040f
247 #define USB_LANGID_IND 0x0421
248 #define USB_LANGID_ITA 0x0410
249 #define USB_LANGID_ITA_SZ 0x0810
250 #define USB_LANGID_JPN 0x0411
251 #define USB_LANGID_KAN 0x044b
252 #define USB_LANGID_KAS 0x0860
253 #define USB_LANGID_KAZ 0x043f
254 #define USB_LANGID_KOK 0x0457
255 #define USB_LANGID_KOR 0x0412
256 #define USB_LANGID_KOR_JOH 0x0812
257 #define USB_LANGID_LAV 0x0426
258 #define USB_LANGID_LIT 0x0427
259 #define USB_LANGID_LIT_CLS 0x0827
260 #define USB_LANGID_MKD 0x042f
261 #define USB_LANGID_MSA 0x043e
262 #define USB_LANGID_MSA_BN 0x083e
263 #define USB_LANGID_MAL 0x044c
264 #define USB_LANGID_MNI 0x0458
265 #define USB_LANGID_MAR 0x044e
266 #define USB_LANGID_NEP 0x0861
267 #define USB_LANGID_NOB 0x0414
268 #define USB_LANGID_NNO 0x0814
269 #define USB_LANGID_ORI 0x0448
270 #define USB_LANGID_POL 0x0415
271 #define USB_LANGID_POR_BR 0x0416
272 #define USB_LANGID_POR 0x0816
273 #define USB_LANGID_PAN 0x0446
274 #define USB_LANGID_RON 0x0418
275 #define USB_LANGID_RUS 0x0419
276 #define USB_LANGID_SAN 0x044f
277 #define USB_LANGID_SRB_CYR 0x0c1a
278 #define USB_LANGID_SRB_LAT 0x081a
279 #define USB_LANGID_SND 0x0459
280 #define USB_LANGID_SLK 0x041b
281 #define USB_LANGID_SLV 0x0424
282 #define USB_LANGID_SPA 0x040a
283 #define USB_LANGID_SPA_MX 0x080a
284 #define USB_LANGID_SPA_MDN 0x0c0a
285 #define USB_LANGID_SPA_GT 0x100a
286 #define USB_LANGID_SPA_CR 0x140a
287 #define USB_LANGID_SPA_PA 0x180a
288 #define USB_LANGID_SPA_DO 0x1c0a
289 #define USB_LANGID_SPA_VE 0x200a
290 #define USB_LANGID_SPA_CO 0x240a
291 #define USB_LANGID_SPA_PE 0x280a
292 #define USB_LANGID_SPA_AR 0x2c0a
293 #define USB_LANGID_SPA_EC 0x300a
294 #define USB_LANGID_SPA_CL 0x340a
295 #define USB_LANGID_SPA_UY 0x380a
296 #define USB_LANGID_SPA_PY 0x3c0a
297 #define USB_LANGID_SPA_BO 0x400a
298 #define USB_LANGID_SPA_SV 0x440a
299 #define USB_LANGID_SPA_HN 0x480a
300 #define USB_LANGID_SPA_NI 0x4c0a
301 #define USB_LANGID_SPA_PR 0x500a
302 #define USB_LANGID_NSO 0x0430
303 #define USB_LANGID_SWA 0x0441
304 #define USB_LANGID_SWE 0x041d
305 #define USB_LANGID_SWE_FI 0x081d
306 #define USB_LANGID_TAM 0x0449
307 #define USB_LANGID_TAT 0x0444
308 #define USB_LANGID_TEL 0x044a
309 #define USB_LANGID_THA 0x041e
310 #define USB_LANGID_TUR 0x041f
311 #define USB_LANGIG_UKR 0x0422
312 #define USB_LANGID_URD_PK 0x0420
313 #define USB_LANGID_URD_IN 0x0820
314 #define USB_LANGID_UZB_LAT 0x0443
315 #define USB_LANGID_UZB_CYR 0x0843
316 #define USB_LANGID_VIE 0x042a
320 struct usb_header_descriptor {
321  uint8_t bLength;
322  uint8_t bDescriptorType;
323 } __attribute__((packed));
331  uint8_t bLength;
332  uint8_t bDescriptorType;
333  uint16_t bcdUSB;
334  uint8_t bDeviceClass;
335  uint8_t bDeviceSubClass;
336  uint8_t bDeviceProtocol;
337  uint8_t bMaxPacketSize0;
338  uint16_t idVendor;
339  uint16_t idProduct;
340  uint16_t bcdDevice;
341  uint8_t iManufacturer;
342  uint8_t iProduct;
343  uint8_t iSerialNumber;
345 } __attribute__((packed));
353  uint8_t bLength;
354  uint8_t bDescriptorType;
355  uint16_t bcdUSB;
356  uint8_t bDeviceClass;
357  uint8_t bDeviceSubClass;
358  uint8_t bDeviceProtocol;
359  uint8_t bMaxPacketSize0;
361  uint8_t bReserved;
362 } __attribute__((packed));
369  uint8_t bLength;
370  uint8_t bDescriptorType;
371  uint16_t wTotalLength;
373  uint8_t bNumInterfaces;
374  uint8_t bConfigurationValue;
375  uint8_t iConfiguration;
376  uint8_t bmAttributes;
380  uint8_t bMaxPower;
382 } __attribute__((packed));
389  uint8_t bLength;
390  uint8_t bDescriptorType;
391  uint8_t bInterfaceNumber;
392  uint8_t bAlternateSetting;
393  uint8_t bNumEndpoints;
394  uint8_t bInterfaceClass;
395  uint8_t bInterfaceSubClass;
396  uint8_t bInterfaceProtocol;
397  uint8_t iInterface;
398 } __attribute__((packed));
404  uint8_t bLength;
405  uint8_t bDescriptorType;
406  uint8_t bFirstInterface;
407  uint8_t bInterfaceCount;
408  uint8_t bFunctionClass;
409  uint8_t bFunctionSubClass;
410  uint8_t bFunctionProtocol;
411  uint8_t iFunction;
413 } __attribute__((packed));
419  uint8_t bLength;
420  uint8_t bDescriptorType;
421  uint8_t bEndpointAddress;
423  uint8_t bmAttributes;
424  uint16_t wMaxPacketSize;
426  uint8_t bInterval;
428 } __attribute__((packed));
436 struct usb_string_descriptor {
437  uint8_t bLength;
438  uint8_t bDescriptorType;
439  uint16_t wString[];
441 } __attribute__((packed, aligned(2)));
442 
448 struct usb_debug_descriptor {
449  uint8_t bLength;
450  uint8_t bDescriptorType;
451  uint8_t bDebugInEndpoint;
452  uint8_t bDebugOutEndpoint;
453 } __attribute__((packed));
454 
457 #if defined (__cplusplus)
458 }
459 #endif
460 #endif //_USB_STD_H_
uint8_t bDeviceProtocol
USB device protocol.
Definition: usb_std.h:344
uint8_t bDeviceSubClass
USB device subclass.
Definition: usb_std.h:343
USB debug descriptor.
Definition: usb_std.h:456
USB interface association descriptor.
Definition: usb_std.h:411
uint8_t bDescriptorType
USB_DTYPE_DEVICE Device descriptor.
Definition: usb_std.h:340
uint8_t iSerialNumber
String index for the product serial number.
Definition: usb_std.h:351
uint16_t bcdUSB
BCD of the supported USB specification.
Definition: usb_std.h:341
uint8_t bDeviceClass
USB device class.
Definition: usb_std.h:342
uint8_t bMaxPacketSize0
Size of the control endpoint&#39;s bank in bytes.
Definition: usb_std.h:345
uint8_t iManufacturer
String index for the manufacturer&#39;s name.
Definition: usb_std.h:349
USB device qualifier descriptor.
Definition: usb_std.h:360
uint16_t bcdDevice
Product release (version) number.
Definition: usb_std.h:348
uint8_t bNumConfigurations
Total number of configurations supported by the device.
Definition: usb_std.h:352
USB string descriptor.
Definition: usb_std.h:444
uint16_t idProduct
Unique product ID for the USB product.
Definition: usb_std.h:347
USB interface descriptor.
Definition: usb_std.h:396
uint16_t idVendor
Vendor ID for the USB product.
Definition: usb_std.h:346
Represents a USB device descriptor.
Definition: usb_std.h:338
uint8_t iProduct
String index for the product name/details.
Definition: usb_std.h:350
USB endpoint descriptor.
Definition: usb_std.h:426
uint8_t bLength
Size of the descriptor, in bytes.
Definition: usb_std.h:339
USB device configuration descriptor.
Definition: usb_std.h:376