VSF Documented
usb_desc.h
Go to the documentation of this file.
1#ifndef __USB_DESC_H__
2#define __USB_DESC_H__
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#define USB_DESC_WORD(__VALUE) \
9 ((uint16_t)(__VALUE) >> 0) & 0xFF, ((uint16_t)(__VALUE) >> 8) & 0xFF
10
11#define USB_DESC_DWORD(__VALUE) \
12 ((__VALUE) >> 0) & 0xFF, ((__VALUE) >> 8) & 0xFF, \
13 ((__VALUE) >> 16) & 0xFF, ((__VALUE) >> 24) & 0xFF
14
15#define USB_DESC_DEV_LEN USB_DT_DEVICE_SIZE
16#define USB_DESC_DEV(__VERSION, __CLASS, __SUBCLASS, __PROTOCOL, __EP0_SIZE, __VID, __PID, __BCD_VER, __I_MANUFACTURER, __I_PRODUCT, __I_SERIAL_NUM, __CONFIG_NUM)\
17 USB_DESC_DEV_LEN, \
18 USB_DT_DEVICE, \
19 USB_DESC_WORD(__VERSION), /* bcdUSB */ \
20 (__CLASS), /* device class: IAD */ \
21 (__SUBCLASS), /* device sub class */ \
22 (__PROTOCOL), /* device protocol */ \
23 (__EP0_SIZE), /* max packet size */ \
24 USB_DESC_WORD(__VID), /* vendor */ \
25 USB_DESC_WORD(__PID), /* product */ \
26 USB_DESC_WORD(__BCD_VER), /* bcdDevice */ \
27 (__I_MANUFACTURER), /* manufacturer */ \
28 (__I_PRODUCT), /* product */ \
29 (__I_SERIAL_NUM), /* serial number */ \
30 (__CONFIG_NUM), /* number of configuration */
31
32#define USB_DESC_DEV_IAD_LEN (USB_DESC_IAD_LEN + USB_DESC_DEV_LEN)
33#define USB_DESC_DEV_IAD(__VERSION, __EP0_SIZE, __VID, __PID, __BCD_VER, __I_MANUFACTURER, __I_PRODUCT, __I_SERIAL_NUM, __CONFIG_NUM)\
34 USB_DESC_DEV((__VERSION), 0xEF, 0x02, 0x01, (__EP0_SIZE), (__VID), (__PID), (__BCD_VER), (__I_MANUFACTURER), (__I_PRODUCT), (__I_SERIAL_NUM), (__CONFIG_NUM))
35
36#define USB_DESC_CFG_LEN USB_DT_CONFIG_SIZE
37#define USB_DESC_CFG(__CFG_SIZE, __IFS_NUM, __CONFIG_VALUE, __I_CONFIG, __ATTR, __MAX_POWER)\
38 USB_DESC_CFG_LEN, \
39 USB_DT_CONFIG, \
40 USB_DESC_WORD(__CFG_SIZE), /* wTotalLength */ \
41 (__IFS_NUM), /* bNumInterfaces: */ \
42 (__CONFIG_VALUE), /* bConfigurationValue: Configuration value */\
43 (__I_CONFIG), /* iConfiguration: Index of string descriptor describing the configuration */\
44 (__ATTR), /* bmAttributes: bus powered */ \
45 (__MAX_POWER), /* MaxPower */
46
47#define USB_DESC_IFS_LEN USB_DT_INTERFACE_SIZE
48#define USB_DESC_IFS(__IFS_NUM, __ALT_SETTING, __EP_NUM, __CLASS, __SUBCLASS, __PROTOCOL, __I_IFS)\
49 USB_DESC_IFS_LEN, \
50 USB_DT_INTERFACE, \
51 (__IFS_NUM), /* bInterfaceNumber: Number of Interface */\
52 (__ALT_SETTING), /* bAlternateSetting: Alternate setting */\
53 (__EP_NUM), /* bNumEndpoints */ \
54 (__CLASS), /* bInterfaceClass */ \
55 (__SUBCLASS), /* bInterfaceSubClass */ \
56 (__PROTOCOL), /* nInterfaceProtocol */ \
57 (__I_IFS), /* iInterface: */
58
59#define USB_DESC_EP_LEN USB_DT_ENDPOINT_SIZE
60#define USB_DESC_EP(__EP_NUM, __EP_ATTR, __EP_SIZE, __EP_INTERVAL) \
61 USB_DESC_EP_LEN, \
62 USB_DT_ENDPOINT, \
63 (__EP_NUM), /* bEndpointAddress: */ \
64 (__EP_ATTR), /* bmAttributes: */ \
65 USB_DESC_WORD(__EP_SIZE), /* wMaxPacketSize: */ \
66 (__EP_INTERVAL), /* bInterval: */
67
68#define USB_DESC_QUALIFIER_LEN USB_DT_DEVICE_QUALIFIER_SIZE
69#define USB_DESC_QUALIFIER(__VERSION, __CLASS, __SUB_CLASS, __PROTOCOL, __EP0_SIZE, __CONFIG_NUM)\
70 USB_DESC_QUALIFIER_LEN, \
71 USB_DT_DEVICE_QUALIFIER, \
72 USB_DESC_WORD(__VERSION), /* bcdUSB */ \
73 (__CLASS), /* bDeviceClass */ \
74 (__SUB_CLASS), /* bDeviceSubClass */ \
75 (__PROTOCOL), /* bDeviceProtocol */ \
76 (__EP0_SIZE), /* bMaxPacketSize0 */ \
77 (__CONFIG_NUM), /* bNumConfigurations */ \
78 0, /* bReserved */
79
80#define USB_DESC_IAD_LEN USB_DT_INTERFACE_ASSOCIATION_SIZE
81#define USB_DESC_IAD(__IFS_START, __IFS_NUM, __CLASS, __SUBCLASS, __PROTOCOL, __I_FUNC)\
82 USB_DESC_IAD_LEN, /* IDA */ \
83 USB_DT_INTERFACE_ASSOCIATION, \
84 (__IFS_START), /* bFirstInterface */ \
85 (__IFS_NUM), /* bInterfaceCount */ \
86 (__CLASS), /* bFunctionClass */ \
87 (__SUBCLASS), /* bFunctionSubClass */ \
88 (__PROTOCOL), /* bFunctionProtocol */ \
89 (__I_FUNC), /* iFunction */
90
91#define USB_DESC_STRING_LEN(__STR_LEN) ((__STR_LEN) + 2)
92#define USB_DESC_STRING(__STR_LEN, ...) \
93 USB_DESC_STRING_LEN(__STR_LEN), \
94 USB_DT_STRING, \
95 __VA_ARGS__,
96
97#ifdef __cplusplus
98}
99#endif
100
101#endif // __USB_DESC_H__