VSF Documented
vsf_usbd_winusb.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __VSF_USBD_WINUSB_H__
19#define __VSF_USBD_WINUSB_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#if VSF_USE_USB_DEVICE == ENABLED
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/*============================ MACROS ========================================*/
32
33#define USB_BOS_CAP_WINUSB_LEN \
34 USB_DESC_BOS_CAPABILITY_LEN(8)
35
36#define MSOS20_FEATURE_WINUSB_SIZE \
37 ( USB_DT_MSOS20_SUBSET_HEADER_CONFIGURATION_SIZE + \
38 USB_DT_MSOS20_FEATURE_COMPATIBLE_ID_SIZE + \
39 USB_DESC_MSOS20_FEATURE_REG_PROPERTY_LEN( \
40 MSOS20_REG_PROPERTY_NAME_LEN___DEVICE_INTERFACE_GUIDS___, \
41 MSOS20_REG_PROPERTY_DATA_LEN___DEVICE_INTERFACE_GUIDS___ \
42 ) \
43 )
44
45#define MSOS20_REQ_DISCRIPTOR_INDEX 7
46#define MSOS20_REQ_SET_ALT_ENUMERATION 8
47
48#define USB_DT_MSOS20_SET_HEADER_SIZE 10
49#define USB_DT_MSOS20_SUBSET_HEADER_CONFIGURATION_SIZE 8
50#define USB_DT_MSOS20_FEATURE_COMPATIBLE_ID_SIZE 20
51
52#define MSOS20_REG_PROPERTY_NAME_LEN___DEVICE_INTERFACE_GUIDS___ 42
53#define MSOS20_REG_PROPERTY_DATA_LEN___DEVICE_INTERFACE_GUIDS___ 80
54#define MSOS20_REG_PROPERTY_NAME___DEVICE_INTERFACE_GUIDS___ \
55 'D',0,'e',0,'v',0,'i',0,'c',0,'e',0, \
56 'I',0,'n',0,'t',0,'e',0,'r',0,'f',0,'a',0,'c',0,'e',0, \
57 'G',0,'U',0,'I',0,'D',0,'s',0,0,0,
58
59#define MSOS20_REG_PROPERTY_TYPE_REG_MULTI_SZ 7
60
61#define USB_DT_MSOS20_SET_HEADER 0x00
62#define USB_DT_MSOS20_SUBSET_HEADER_CONFIGURATION 0x01
63#define USB_DT_MSOS20_SUBSET_HEADER_FUNCTION 0x02
64#define USB_DT_MSOS20_FEATURE_COMPATIBLE_ID 0x03
65#define USB_DT_MSOS20_FEATURE_REG_PROPERTY 0x04
66#define USB_DT_MSOS20_FEATURE_MIN_RESUME_TIME 0x05
67#define USB_DT_MSOS20_FEATURE_MODEL_ID 0x06
68#define USB_DT_MSOS20_FEATURE_CCGP_DEVICE 0x07
69#define USB_DT_MSOS20_FEATURE_VENDOR_REVISION 0x08
70
71/*============================ MACROFIED FUNCTIONS ===========================*/
72
73#define USB_DESC_MSOS20_SET_HEADER(__TOTAL_LEN) \
74 USB_DESC_WORD(USB_DT_MSOS20_SET_HEADER_SIZE), \
75 USB_DESC_WORD(USB_DT_MSOS20_SET_HEADER), \
76 0x00, 0x00, 0x03, 0x06, /* dwWindowsVersion: Win8.1+ */ \
77 USB_DESC_WORD(__TOTAL_LEN),
78
79#define USB_DESC_MSOS20_SUBSET_FUNCTION(__FIRST_IFS, __LEN, ...) \
80 USB_DESC_WORD(USB_DT_MSOS20_SUBSET_HEADER_CONFIGURATION_SIZE), \
81 USB_DESC_WORD(USB_DT_MSOS20_SUBSET_HEADER_FUNCTION), \
82 (__FIRST_IFS), \
83 0, \
84 USB_DESC_WORD(USB_DT_MSOS20_SUBSET_HEADER_CONFIGURATION_SIZE + (__LEN)),\
85 __VA_ARGS__
86
87#define USB_DESC_MSOS20_FEATURE_COMPATIBLE_ID(...) \
88 USB_DESC_WORD(USB_DT_MSOS20_FEATURE_COMPATIBLE_ID_SIZE), \
89 USB_DESC_WORD(USB_DT_MSOS20_FEATURE_COMPATIBLE_ID), \
90 __VA_ARGS__
91
92#define USB_DESC_MSOS20_FEATURE_REG_PROPERTY_LEN(__NAME_LEN, __DATA_LEN) \
93 (10 + (__NAME_LEN) + (__DATA_LEN))
94#define USB_DESC_MSOS20_FEATURE_REG_PROPERTY(__NAME_LEN, __NAME, __DATA_LEN, ...)\
95 USB_DESC_WORD(USB_DESC_MSOS20_FEATURE_REG_PROPERTY_LEN((__NAME_LEN), (__DATA_LEN))),\
96 USB_DESC_WORD(USB_DT_MSOS20_FEATURE_REG_PROPERTY), \
97 USB_DESC_WORD(MSOS20_REG_PROPERTY_TYPE_REG_MULTI_SZ), \
98 USB_DESC_WORD(__NAME_LEN), \
99 __NAME \
100 USB_DESC_WORD(__DATA_LEN), \
101 __VA_ARGS__
102
103#define USB_DESC_BOS_CAPABILITY_MSOS20(__len) \
104 USB_DESC_BOS_CAPABILITY_HEADER(4 + (__len), 5, \
105 0xDF, 0x60, 0xDD, 0xD8, /* uuid */ \
106 0x89, 0x45, 0xC7, 0x4C, \
107 0x9C, 0xD2, 0x65, 0x9D, \
108 0x9E, 0x64, 0x8A, 0x9F, \
109 ) \
110 0x00, 0x00, 0x03, 0x06, /* dwWindowsVersion: Win8.1+ */
111
112#define __usbd_msos20_desc(__name, __desc_size, ...) \
113 enum { \
114 __##__name##_msos20_desc_len = USB_DT_MSOS20_SET_HEADER_SIZE + (__desc_size),\
115 }; \
116 const uint8_t __##__name##_msos20_desc[__##__name##_msos20_desc_len] = {\
117 USB_DESC_MSOS20_SET_HEADER(__##__name##_msos20_desc_len) \
118 __VA_ARGS__ \
119 };
120
121#define usbd_msos20_desc(__name, __desc_size, ...) \
122 __usbd_msos20_desc(__name, __desc_size, __VA_ARGS__)
123
124#define __usbd_msos20_desc_buffer(__name) __##__name##_msos20_desc
125#define __usbd_msos20_desc_len(__name) __##__name##_msos20_desc_len
126#define usbd_msos20_desc_buffer(__name) __usbd_msos20_desc_buffer(__name)
127#define usbd_msos20_desc_len(__name) __usbd_msos20_desc_len(__name)
128
129#define __msos20_feature_winusb(__first_ifs, ...) \
130 USB_DESC_MSOS20_SUBSET_FUNCTION(__first_ifs, \
131 USB_DT_MSOS20_FEATURE_COMPATIBLE_ID_SIZE + \
132 USB_DESC_MSOS20_FEATURE_REG_PROPERTY_LEN( \
133 MSOS20_REG_PROPERTY_NAME_LEN___DEVICE_INTERFACE_GUIDS___,\
134 MSOS20_REG_PROPERTY_DATA_LEN___DEVICE_INTERFACE_GUIDS___\
135 ), \
136 USB_DESC_MSOS20_FEATURE_COMPATIBLE_ID( \
137 'W', 'I', 'N', 'U', 'S', 'B', 0, 0, \
138 0, 0, 0, 0, 0, 0, 0, 0, \
139 ) \
140 USB_DESC_MSOS20_FEATURE_REG_PROPERTY( \
141 MSOS20_REG_PROPERTY_NAME_LEN___DEVICE_INTERFACE_GUIDS___, \
142 MSOS20_REG_PROPERTY_NAME___DEVICE_INTERFACE_GUIDS___, \
143 MSOS20_REG_PROPERTY_DATA_LEN___DEVICE_INTERFACE_GUIDS___, \
144 __VA_ARGS__ \
145 ) \
146 0,0,0,0, \
147 )
148
149// msos20_feature_winusb(__fisrst_ifs, __guid)
150#define msos20_feature_winusb(__first_ifs, ...) \
151 __msos20_feature_winusb((__first_ifs), __VA_ARGS__)
152
153#define __bos_desc_winusb(__vendor_code, __alt_enum_code, __desc_len) \
154 USB_DESC_BOS_CAPABILITY_MSOS20(4) \
155 USB_DESC_WORD(__desc_len), /* wMSOSDescriptorSetTotalLength */ \
156 (__vendor_code), /* bMS_VendorCode */ \
157 (__alt_enum_code), /* bAltEnumCode */
158
159#define bos_desc_winusb(__vendor_code, __alt_enum_code, __desc_len) \
160 __bos_desc_winusb((__vendor_code), (__alt_enum_code), (__desc_len))
161
162/*============================ TYPES =========================================*/
163/*============================ GLOBAL VARIABLES ==============================*/
164/*============================ PROTOTYPES ====================================*/
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif // VSF_USE_USB_DEVICE
171#endif // __VSF_USBD_WINUSB_H__