VSF Documented
vsf_usbd.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_H__
19#define __VSF_USBD_H__
20
21/*============================ INCLUDES ======================================*/
22
24
25#if VSF_USE_USB_DEVICE == ENABLED
26
27#include "../common/usb_common.h"
28#include "../common/usb_desc.h"
29#include "kernel/vsf_kernel.h"
30
35
36// dcd driver layer
37#include "hal/vsf_hal.h"
38#if VSF_USBD_USE_DCD_MUSB_FDRC == ENABLED
39# include "../driver/otg/musb/fdrc/vsf_musb_fdrc_dcd.h"
40#endif
41#if VSF_USBD_USE_DCD_DWCOTG == ENABLED
42# include "../driver/otg/dwcotg/vsf_dwcotg_dcd.h"
43#endif
44#if VSF_USBD_USE_DCD_USBIP == ENABLED
45# include "../driver/dcd/usbip_dcd/vsf_usbip_dcd.h"
46#endif
47
48#if VSF_USBD_CFG_RAW_MODE == ENABLED
49// user want to do everything, expose driver interface
50# include "./vsf_usbd_drv_ifs.h"
51#endif
52
53#if defined(__VSF_USBD_CLASS_IMPLEMENT)
54# define __VSF_CLASS_IMPLEMENT__
55#elif defined(__VSF_USBD_CLASS_INHERIT__)
56# define __VSF_CLASS_INHERIT__
57#endif
58
59#include "utilities/ooc_class.h"
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65/*============================ MACROS ========================================*/
66
67#ifndef VSF_USBD_CFG_AUTOSETUP
68# define VSF_USBD_CFG_AUTOSETUP ENABLED
69#endif
70
71#ifndef VSF_USBD_CFG_USE_EDA
72# define VSF_USBD_CFG_USE_EDA VSF_USE_KERNEL
73#endif
74
75#if (VSF_USBD_CFG_USE_EDA == ENABLED) && (VSF_USE_KERNEL != ENABLED)
76# error "VSF_USBD_CFG_USE_EDA depend on VSF_USE_KERNEL"
77#endif
78
79#if (VSF_USBD_CFG_USE_EDA == ENABLED) && !defined(VSF_USBD_CFG_EDA_PRIORITY)
80# define VSF_USBD_CFG_EDA_PRIORITY vsf_prio_0
81#endif
82
83#if !defined(VSF_USBD_CFG_HW_PRIORITY)
84# define VSF_USBD_CFG_HW_PRIORITY vsf_arch_prio_0
85#endif
86
87#define VSF_USBD_DESC_DEVICE(__DESC, __SIZE) \
88 {USB_DT_DEVICE, 0, 0, (__SIZE), (uint8_t*)(__DESC)}
89#define VSF_USBD_DESC_CONFIG(__INDEX, __DESC, __SIZE) \
90 {USB_DT_CONFIG, (__INDEX), 0, (__SIZE), (uint8_t*)(__DESC)}
91#define VSF_USBD_DESC_STRING(__LANGID, __INDEX, __DESC, __SIZE) \
92 {USB_DT_STRING, (__INDEX), (__LANGID), (__SIZE), (uint8_t*)(__DESC)}
93#define VSF_USBD_DESC_QUALIFIER(__DESC) \
94 {USB_DT_DEVICE_QUALIFIER, 0, 0, USB_DT_DEVICE_QUALIFIER_SIZE, (uint8_t*)(__DESC)}
95
96
97
98// __USB_IFS is used for class drivers
99#define __USB_IFS(__DRV, __PARAM) \
100 { \
101 .class_op = (__DRV), \
102 .class_param = (__PARAM), \
103 },
104#define USB_IFS(__DRV, __PARAM) \
105 __USB_IFS((__DRV), (__PARAM))
106
107
108
109#if __STDC_VERSION__ >= 201112L || defined(__cplusplus)
110# define usb_unicode_t char16_t
111#else
112# define usb_unicode_t wchar_t
113#endif
114
115#define __describe_usbd_version_langid_bcd_ver( \
116 __name, /* name of the usbd, eg: user_usbd */\
117 __vid, /* vendor id, 0x0000 - 0xFFFF */ \
118 __pid, /* product id, 0x0000 - 0xFFFF */ \
119 __speed, /* usb speed, USB_DC_SPEED_[LOW/FULL/HIGH/SUPER]*/\
120 __version, /* usb version, eg: 0x210/0x200 */ \
121 __lang_id, /* language id, eg: 0x0409 */ \
122 __bcd_ver /* bcdVersion */ \
123 ) \
124 enum { \
125 __##__name##_version = (__version), \
126 __##__name##_pid = (__pid), \
127 __##__name##_vid = (__vid), \
128 __##__name##_langid = (__lang_id), \
129 __##__name##_speed = (__speed), \
130 __##__name##_bcd_version = (__bcd_ver), \
131 };
132#define __describe_usbd_version_langid( \
133 __name, /* name of the usbd, eg: user_usbd */\
134 __vid, /* vendor id, 0x0000 - 0xFFFF */ \
135 __pid, /* product id, 0x0000 - 0xFFFF */ \
136 __speed, /* usb speed, USB_DC_SPEED_[LOW/FULL/HIGH/SUPER]*/\
137 __version, /* usb version, eg: 0x210/0x200 */ \
138 __lang_id /* language id, eg: 0x0409 */ \
139 ) \
140 __describe_usbd_version_langid_bcd_ver(__name, __vid, __pid, __speed, __version, __lang_id, 0x0100)
141#define __describe_usbd_version(__name, /* name of the usbd, eg: user_usbd */\
142 __vid, /* vendor id, 0x0000 - 0xFFFF */ \
143 __pid, /* product id, 0x0000 - 0xFFFF */ \
144 __speed, /* usb speed, USB_DC_SPEED_[LOW/FULL/HIGH/SUPER]*/\
145 __version /* usb version, eg: 0x210/0x200 */ \
146 ) \
147 __describe_usbd_version_langid(__name, __vid, __pid, __speed, __version, 0x0409)
148#define __describe_usbd( __name, /* name of the usbd, eg: user_usbd */\
149 __vid, /* vendor id, 0x0000 - 0xFFFF */ \
150 __pid, /* product id, 0x0000 - 0xFFFF */ \
151 __speed /* usb speed, USB_DC_SPEED_[LOW/FULL/HIGH/SUPER]*/\
152 ) \
153 __describe_usbd_version(__name, __vid, __pid, __speed, 0x0200)
154#define __describe_usbd4 __describe_usbd
155#define __describe_usbd5 __describe_usbd_version
156#define __describe_usbd6 __describe_usbd_version_langid
157#define __describe_usbd7 __describe_usbd_version_langid_bcd_ver
158
159// __str in UTF16 format, eg u"string"
160#define __usbd_str_desc(__name, __type, __str) \
161 struct { \
162 uint8_t bLength; \
163 uint8_t bDescriptorType; \
164 usb_unicode_t str[dimof(__str) - 1]; \
165 } VSF_CAL_PACKED const __##__name##_str_##__type = { \
166 .bLength = sizeof(__##__name##_str_##__type), \
167 .bDescriptorType = USB_DT_STRING, \
168 .str = __str, \
169 };
170
171#define usbd_str_desc(__name, __type, __str) \
172 __usbd_str_desc(__name, __type, __str)
173
174#define __usbd_str_product_desc(__name, __str_product) \
175 __usbd_str_desc(__name, product, __str_product)
176#define usbd_str_product_desc(__name, __str_product) \
177 __usbd_str_product_desc(__name, __str_product)
178
179#define __usbd_str_vendor_desc(__name, __str_vendor) \
180 __usbd_str_desc(__name, vendor, __str_vendor)
181#define usbd_str_vendor_desc(__name, __str_vendor) \
182 __usbd_str_vendor_desc(__name, __str_vendor)
183
184#define __usbd_str_serial_desc(__name, __str_serial) \
185 __usbd_str_desc(__name, serial, __str_serial)
186#define usbd_str_serial_desc(__name, __str_serial) \
187 __usbd_str_serial_desc(__name, __str_serial)
188
189#define __usbd_str_langid_desc(__name) \
190 struct { \
191 uint8_t bLength; \
192 uint8_t bDescriptorType; \
193 usb_unicode_t str[1]; \
194 } VSF_CAL_PACKED const __##__name##_str_langid = { \
195 .bLength = 4, \
196 .bDescriptorType = USB_DT_STRING, \
197 .str = (__##__name##_langid), \
198 };
199#define usbd_str_langid_desc(__name) \
200 __usbd_str_langid_desc(__name)
201
202#define __usbd_device_iad_desc(__name) \
203 const uint8_t __##__name##_device_desc[USB_DT_DEVICE_SIZE] = { \
204 USB_DESC_DEV_IAD((__##__name##_version), (__##__name##_ep0size), \
205 (__##__name##_vid), (__##__name##_pid), \
206 (__##__name##_bcd_version), 1, 2, 3, (__##__name##_config_num)) \
207 };
208#define usbd_device_iad_desc(__name) \
209 __usbd_device_iad_desc(__name)
210
211#define __usbd_device_desc(__name, __class, __subclass, __protocol) \
212 const uint8_t __##__name##_device_desc[USB_DT_DEVICE_SIZE] = { \
213 USB_DESC_DEV((__##__name##_version), (__class), (__subclass), \
214 (__protocol), (__##__name##_ep0size), (__##__name##_vid), \
215 (__##__name##_pid), (__##__name##_bcd_version), 1, 2, 3, \
216 (__##__name##_config_num)) \
217 };
218#define usbd_device_desc(__name, __class, __subclass, __protocol) \
219 __usbd_device_desc(__name, (__class), (__subclass), (__protocol))
220
221#define __usbd_config_desc(__name, __func_desc_size, __func_ifs_num, __attribute, __max_power_ma)\
222 const uint8_t __##__name##_config_desc[USB_DT_CONFIG_SIZE + (__func_desc_size)] = {\
223 USB_DESC_CFG(USB_DT_CONFIG_SIZE + (__func_desc_size), (__func_ifs_num),\
224 1, 0, USB_CONFIG_ATT_ONE | (__attribute), (__max_power_ma) >> 1)
225#define usbd_config_desc(__name, __func_desc_size, __func_ifs_num, __attribute, __max_power_ma)\
226 __usbd_config_desc(__name, (__func_desc_size), (__func_ifs_num), (__attribute), (__max_power_ma))
227
228#define __usbd_basic_desc(__name, __func_ifs_num, __ep0_size) \
229 enum { \
230 __##__name##_ifsnum = (__func_ifs_num), \
231 __##__name##_ep0size = (__ep0_size), \
232 __##__name##_config_num = 1, \
233 };
234#define usbd_basic_desc(__name, __func_ifs_num, __ep0_size) \
235 __usbd_basic_desc(__name, (__func_ifs_num), (__ep0_size))
236
237// known limitations:
238// __str_product/__str_vendor/__str_serial MUST be strings in UTF16
239// multiple configuration is not supported
240// does not support big endian
241// to add
242#define __usbd_common_desc( __name, /* name of the usbd, eg: user_usbd */\
243 __str_product, /* product string in UTF16, eg: u"VSF_Board" */\
244 __str_vendor, /* vendor string in UTF16, eg: u"VSF" */\
245 __str_serial, /* serial string in UTF16, eg: u"1.0.0" */\
246 __class, /* device class */\
247 __subclass, /* device subclass */\
248 __protocol, /* device protocol */\
249 __ep0_size, /* size of endpoint 0, 0 - 64 */\
250 __func_desc_size, /* size of all func descriptors, eg: USB_DESC_CDC_ACM_IAD_LEN + USB_DESC_MSCBOT_IAD_LEN */\
251 __func_ifs_num, /* number of all func interfaces, eg: USB_CDC_ACM_IFS_NUM + USB_MSC_IFS_NUM */\
252 __attribute, /* mask attributes, eg: USB_CONFIG_ATT_[SELFPOWER/WAKEUP/BATTERY] */\
253 __max_power_ma /* power consumption from USB host in mA, eg: 500 */\
254 ) \
255 usbd_basic_desc(__name, __func_ifs_num, __ep0_size) \
256 usbd_str_langid_desc(__name) \
257 usbd_str_product_desc(__name, __str_product) \
258 usbd_str_vendor_desc(__name, __str_vendor) \
259 usbd_str_serial_desc(__name, __str_serial) \
260 usbd_device_desc(__name, (__class), (__subclass), (__protocol)) \
261 usbd_config_desc(__name, (__func_desc_size), (__func_ifs_num), (__attribute), (__max_power_ma))
262
263#define __usbd_common_desc_iad( __name, /* name of the usbd, eg: user_usbd */\
264 __str_product, /* product string in UTF16, eg: u"VSF_Board" */\
265 __str_vendor, /* vendor string in UTF16, eg: u"VSF" */\
266 __str_serial, /* serial string in UTF16, eg: u"1.0.0" */\
267 __ep0_size, /* size of endpoint 0, 0 - 64 */\
268 __func_desc_size, /* size of all func descriptors, eg: USB_DESC_CDC_ACM_IAD_LEN + USB_DESC_MSCBOT_IAD_LEN */\
269 __func_ifs_num, /* number of all func interfaces, eg: USB_CDC_ACM_IFS_NUM + USB_MSC_IFS_NUM */\
270 __attribute, /* mask attributes, eg: USB_CONFIG_ATT_[SELFPOWER/WAKEUP/BATTERY] */\
271 __max_power_ma /* power consumption from USB host in mA, eg: 500 */\
272 ) \
273 __usbd_common_desc(__name, (__str_product), (__str_vendor), (__str_serial), USB_CLASS_MISC, 0x02, 0x01, (__ep0_size), (__func_desc_size), (__func_ifs_num), (__attribute), (__max_power_ma))
274
275#define __usbd_func_str_desc(__name, __func_id, __str_func) \
276 __usbd_str_desc(__name, func##__func_id, __str_func)
277
278#define __usbd_qualifier_desc(__name) \
279 const uint8_t __##__name##_qualifier_desc[USB_DT_DEVICE_QUALIFIER_SIZE] = {\
280 USB_DESC_QUALIFIER((__##__name##_version), 0, 0, 0, (__##__name##_ep0size), (__##__name##_config_num))\
281 };
282
283#define __usbd_std_desc_table(__name) \
284 const vk_usbd_desc_t __##__name##_std_descs[] = { \
285 VSF_USBD_DESC_DEVICE(__##__name##_device_desc, sizeof(__##__name##_device_desc)),\
286 VSF_USBD_DESC_CONFIG(0, __##__name##_config_desc, sizeof(__##__name##_config_desc)),\
287 VSF_USBD_DESC_STRING(0, 0, &__##__name##_str_langid, sizeof(__##__name##_str_langid)),\
288 VSF_USBD_DESC_STRING(__##__name##_langid, 1, &__##__name##_str_vendor, sizeof(__##__name##_str_vendor)),\
289 VSF_USBD_DESC_STRING(__##__name##_langid, 2, &__##__name##_str_product, sizeof(__##__name##_str_product)),\
290 VSF_USBD_DESC_STRING(__##__name##_langid, 3, &__##__name##_str_serial, sizeof(__##__name##_str_serial)),
291
292#define __usbd_str_desc_table4(__name, __index, __type, __langid) \
293 VSF_USBD_DESC_STRING((__langid), (__index), &__##__name##_str_##__type, sizeof(__##__name##_str_##__type)),
294#define __usbd_str_desc_table3(__name, __index, __type) \
295 VSF_USBD_DESC_STRING(__##__name##_langid, (__index), &__##__name##_str_##__type, sizeof(__##__name##_str_##__type)),
296// usbd_str_desc_table(name, index, type, langid=default)
297// __type is the same in usbd_str_desc
298#define usbd_str_desc_table(__name, __index, __type, ...) \
299 __PLOOC_EVAL(__usbd_str_desc_table, __name, __index, __type, ##__VA_ARGS__)(__name, (__index), __type, ##__VA_ARGS__)
300
301#define __usbd_func_str_desc_table_langid(__name, __func_id, __lang_id) \
302 VSF_USBD_DESC_STRING((__lang_id), 4 + __func_id, &__##__name##_str_func##__func_id, sizeof(__##__name##_str_func##__func_id)),
303#define __usbd_func_str_desc_table(__name, __func_id) \
304 __usbd_func_str_desc_table_langid(__name, __func_id, __##__name##_langid)
305#define __usbd_func_str_desc_table2 __usbd_func_str_desc_table
306#define __usbd_func_str_desc_table3 __usbd_func_str_desc_table_langid
307
308#define __usbd_qualifier_desc_table(__name) \
309 VSF_USBD_DESC_QUALIFIER(&__##__name##_qualifier_desc),
310
311#define __usbd_ifs(__name) \
312 vk_usbd_ifs_t __##__name##_ifs[__##__name##_ifsnum] = {
313
314#ifdef __VSF_USBD_CFG_DRV_INTERFACE
315# define __end_describe_usbd_drv(__drv) .drv = &(__drv),
316#else
317# define __end_describe_usbd_drv(__drv)
318#endif
319
320#define __end_describe_usbd(__name, __drv, ...) \
321 vk_usbd_cfg_t __##__name##_cfg[1] = { \
322 { \
323 .num_of_ifs = dimof(__##__name##_ifs), \
324 .ifs = __##__name##_ifs, \
325 }, \
326 }; \
327 vk_usbd_dev_t __name = { \
328 .num_of_config = dimof(__##__name##_cfg), \
329 .config = __##__name##_cfg, \
330 .num_of_desc = dimof(__##__name##_std_descs), \
331 .desc = (vk_usbd_desc_t *)__##__name##_std_descs, \
332 .speed = (usb_dc_speed_t)__##__name##_speed, \
333 __end_describe_usbd_drv(__drv) \
334 __VA_ARGS__ \
335 };
336
337
338// prototype:
339// describe_usbd(__name, __vid, __pid, __speed, __version = 0x0200, __lang_id = 0x0409, __bcd_ver = 0x0100)
340#define describe_usbd(__name, __vid, __pid, __speed, ...) \
341 extern vk_usbd_dev_t __name; \
342 __PLOOC_EVAL(__describe_usbd, __name, __vid, __pid, __speed, ##__VA_ARGS__)(__name, __vid, __pid, __speed, ##__VA_ARGS__)
343#define usbd_common_desc_iad(__name, __str_product, __str_vendor, __str_serial, __ep0_size, __func_desc_size, __func_ifs_num, __attribute, __max_power_ma, ...)\
344 __usbd_common_desc_iad(__name, __str_product, __str_vendor, __str_serial, (__ep0_size), (__func_desc_size), (__func_ifs_num), (__attribute), (__max_power_ma))\
345 __VA_ARGS__};
346#define usbd_common_desc(__name, __str_product, __str_vendor, __str_serial, __class, __subclass, __protocol, __ep0_size, __func_desc_size, __func_ifs_num, __attribute, __max_power_ma, ...)\
347 __usbd_common_desc(__name, __str_product, __str_vendor, __str_serial, (__class), (__subclass), (__protocol), (__ep0_size), (__func_desc_size), (__func_ifs_num), (__attribute), (__max_power_ma))\
348 __VA_ARGS__};
349#define usbd_func_str_desc(__name, __func_id, __str_func) \
350 __usbd_func_str_desc(__name, __func_id, __str_func)
351#define usbd_qualifier_desc(__name) \
352 __usbd_qualifier_desc(__name)
353#define usbd_std_desc_table(__name, ...) \
354 __usbd_std_desc_table(__name) \
355 __VA_ARGS__};
356// prototype:
357// usbd_func_str_desc_table(__name, __func_id, __lang_id = __LANG_ID_FROM_DESCRIBE_USBD)
358#define usbd_func_str_desc_table(__name, __func_id, ...) \
359 __PLOOC_EVAL(__usbd_func_str_desc_table, __name, __func_id, ##__VA_ARGS__)(__name, __func_id, ##__VA_ARGS__)
360#define usbd_qualifier_desc_table(__name) \
361 __usbd_qualifier_desc_table(__name)
362#define usbd_func(__name, ...) __VA_ARGS__
363#define usbd_ifs(__name, ...) \
364 __usbd_ifs(__name) \
365 __VA_ARGS__};
366#define end_describe_usbd(__name, __drv, ...) \
367 __end_describe_usbd(__name, (__drv), ##__VA_ARGS__)
368
369/*============================ MACROFIED FUNCTIONS ===========================*/
370/*============================ TYPES =========================================*/
371
372vsf_dcl_class(vk_usbd_dev_t)
373vsf_dcl_class(vk_usbd_cfg_t)
374vsf_dcl_class(vk_usbd_ifs_t)
376vsf_dcl_class(vk_usbd_class_op_t)
377
378typedef enum vk_usbd_evt_t {
384
385typedef struct vk_usbd_desc_t {
392
393#if VSF_USBD_CFG_RAW_MODE != ENABLED
394vsf_class(vk_usbd_class_op_t) {
395 protected_member(
396 vk_usbd_desc_t * (*get_desc)(vk_usbd_dev_t *dev, uint_fast8_t type,
397 uint_fast8_t index, uint_fast16_t langid);
398
399 vsf_err_t (*request_prepare)(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs);
400 vsf_err_t (*request_process)(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs);
401
402 vsf_err_t (*init)(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs);
403 vsf_err_t (*fini)(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs);
404 )
405};
406#endif
407
409 public_member(
410 uint8_t ep;
411 uint8_t feature;
412 bool zlp;
413 bool notify_eda;
414 implement(vsf_mem_t)
415 union {
416 struct {
417 void (*on_finish)(void *param);
418 void *param;
419 };
420#if VSF_USE_KERNEL == ENABLED
421 struct {
422 vsf_eda_t *eda;
423 };
424#endif
425 };
427
428 private_member(
429 vsf_slist_node_t node;
430 uint8_t *cur;
431 )
432};
433
439
440#if VSF_USBD_CFG_RAW_MODE != ENABLED
441vsf_class(vk_usbd_ifs_t) {
442
443 public_member(
444 const vk_usbd_class_op_t *class_op;
445 void *class_param;
446 )
447
448 private_member(
449 uint8_t alternate_setting;
450 bool is_inited;
451 )
452};
453
454vsf_class(vk_usbd_cfg_t) {
455
456 public_member(
457 vsf_err_t (*init)(vk_usbd_dev_t *dev);
458 vsf_err_t (*fini)(vk_usbd_dev_t *dev);
459
460 uint8_t num_of_ifs;
461 vk_usbd_ifs_t *ifs;
462 )
463
464 private_member(
465 uint8_t configuration_value;
466 int8_t ep_ifs_map[32];
467 )
468};
469#endif
470
471vsf_class(vk_usbd_dev_t) {
472 public_member(
473 usb_dc_speed_t speed;
474
475#if VSF_USBD_CFG_RAW_MODE != ENABLED
476 uint8_t num_of_config;
477 uint8_t num_of_desc;
478 vk_usbd_desc_t *desc;
479#endif
480
481#if VSF_USBD_CFG_RAW_MODE != ENABLED
482 vk_usbd_cfg_t *config;
483#endif
484
485#ifdef __VSF_USBD_CFG_DRV_INTERFACE
486 const i_usb_dc_t *drv;
487#endif
488
489 struct {
490 vsf_err_t (*prepare)(vk_usbd_dev_t *dev);
491 void (*process)(vk_usbd_dev_t *dev);
492 } vendor;
493 )
494
495#if VSF_USBD_CFG_RAW_MODE == ENABLED
496 public_member(
497#else
498 protected_member(
499#endif
500 vk_usbd_ctrl_handler_t ctrl_handler;
501 )
502
503 private_member(
504#if VSF_USBD_CFG_RAW_MODE != ENABLED
505 uint8_t address;
506 uint8_t configuration;
507 uint8_t feature;
508 bool configured;
509#endif
510 vsf_slist_t trans_list;
511#if VSF_USBD_CFG_USE_EDA == ENABLED
512# if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
513 vsf_teda_t eda;
514 bool wakeup_pending;
515# else
516 vsf_eda_t eda;
517# endif
518#endif
519 )
520};
521
522#if VSF_USBD_CFG_STREAM_EN == ENABLED
523#if VSF_USE_SIMPLE_STREAM == ENABLED
524vsf_class(vk_usbd_ep_stream_t) {
525
526 public_member(
527 vsf_stream_t *stream;
528 struct {
529 void (*on_finish)(void *param);
530 void *param;
531 } callback;
532 )
533
534 protected_member(
535 implement(vk_usbd_trans_t)
536 vk_usbd_dev_t *dev;
537 uint32_t total_size;
538 uint32_t transferred_size;
539 uint32_t cur_size : 31;
540 uint32_t zlp_save : 1;
541 )
542};
543
544#elif VSF_USE_STREAM == ENABLED
545
546declare_class(vk_usbd_ep_stream_t)
547
548
549typedef struct vk_usbd_ep_stream_cfg_t {
550 uint8_t rx_ep;
551 uint8_t tx_ep;
552 //vk_usbd_dev_t *dev;
553} vk_usbd_ep_stream_cfg_t;
554
555def_class(vk_usbd_ep_stream_t,
556 public_member(
557 implement(vsf_stream_src_t)
558 implement(vsf_stream_usr_t)
559 )
560 private_member(
561 vk_usbd_trans_t tx_trans;
562 vk_usbd_trans_t rx_trans;
563 vsf_pbuf_t *tx_current;
564 vsf_pbuf_t *rx_current;
565 vk_usbd_dev_t *dev;
566 )
567)
568end_def_class(vk_usbd_ep_stream_src_t)
569
570#endif
571#endif
572
573/*============================ GLOBAL VARIABLES ==============================*/
574/*============================ PROTOTYPES ====================================*/
575
576extern void vk_usbd_init(vk_usbd_dev_t *dev);
577extern void vk_usbd_fini(vk_usbd_dev_t *dev);
578extern void vk_usbd_connect(vk_usbd_dev_t *dev);
579extern void vk_usbd_disconnect(vk_usbd_dev_t *dev);
580extern void vk_usbd_wakeup(vk_usbd_dev_t *dev);
581
582#if defined(__VSF_USBD_CLASS_IMPLEMENT) || defined(__VSF_USBD_CLASS_INHERIT__)
583
584#if VSF_USBD_CFG_RAW_MODE != ENABLED
587 uint_fast8_t index, uint_fast16_t langid);
588
589extern vk_usbd_cfg_t * vk_usbd_get_cur_cfg(vk_usbd_dev_t *dev);
590extern vk_usbd_ifs_t * vk_usbd_get_ifs(vk_usbd_dev_t *dev, uint_fast8_t ifs_no);
591extern uint_fast8_t vk_usbd_get_ifs_no(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs);
592extern vsf_err_t vk_usbd_ifs_add_ep(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs, uint_fast8_t ep,
594#endif
595
596extern vsf_err_t vk_usbd_ep_stall(vk_usbd_dev_t *dev, uint_fast8_t ep);
597extern vsf_err_t vk_usbd_ep_recv(vk_usbd_dev_t *dev, vk_usbd_trans_t *trans);
598extern vsf_err_t vk_usbd_ep_send(vk_usbd_dev_t *dev, vk_usbd_trans_t *trans);
599
600extern void vk_usbd_stdreq_data_stage(vk_usbd_dev_t *dev);
601extern void vk_usbd_stdreq_status_stage(vk_usbd_dev_t *dev);
602
603# if VSF_USBD_CFG_STREAM_EN == ENABLED
604extern vsf_err_t vk_usbd_ep_recv_stream(vk_usbd_ep_stream_t *stream, uint_fast32_t size);
605extern vsf_err_t vk_usbd_ep_send_stream(vk_usbd_ep_stream_t *stream, uint_fast32_t size);
606
607# if VSF_USE_STREAM == ENABLED
608
609extern
610void vk_usbd_ep_stream_init( vk_usbd_ep_stream_t *obj,
611 vk_usbd_ep_stream_cfg_t *cfg);
612
613extern
614void vk_usbd_ep_stream_connect_dev(vk_usbd_ep_stream_t *obj,
615 vk_usbd_dev_t *dev);
616# endif // VSF_USE_STREAM
617# endif // VSF_USBD_CFG_STREAM_EN
618
619#endif // __VSF_USBD_CLASS_IMPLEMENT || __VSF_USBD_CLASS_INHERIT__
620
621#ifdef __cplusplus
622}
623#endif
624
625/*============================ INCLUDES ======================================*/
626
627#if VSF_USBD_USE_CDC == ENABLED
629# if VSF_USBD_USE_CDCACM == ENABLED
631# endif
632# if VSF_USBD_USE_CDCNCM == ENABLED
634# endif
635#endif
636#if VSF_USBD_USE_HID == ENABLED
638#endif
639#if VSF_USBD_USE_UVC == ENABLED
641#endif
642#if VSF_USBD_USE_UAC == ENABLED
644#endif
645#if VSF_USBD_USE_MSC == ENABLED
647#endif
648#if VSF_USBD_USE_DFU == ENABLED
650#endif
651
652#if defined(VSF_USBD_CFG_DRV_LV0_OO) && defined(VSF_USBD_CFG_DRV_LV0_OO_OBJ_HEADER)
653# include VSF_USBD_CFG_DRV_LV0_OO_OBJ_HEADER
654#endif
655
656#undef __VSF_USBD_CLASS_IMPLEMENT
657#undef __VSF_USBD_CLASS_INHERIT__
658
659#endif // VSF_USE_USB_DEVICE
660#endif // __VSF_USBD_H__
#define ENABLED
Definition __type.h:28
vsf_err_t
Definition __type.h:42
declare_class(vsf_tgui_t)
Definition __vk_tgui_slider.c:41
Definition vsf_usbd.h:408
Definition vsf_eda.h:769
Definition vsf_simple_stream.h:254
Definition vsf_eda.h:837
#define vsf_dcl_class
Definition ooc_class.h:50
#define vsf_class(__name)
Definition ooc_class.h:52
unsigned short uint16_t
Definition stdint.h:7
unsigned char uint_fast8_t
Definition stdint.h:23
unsigned uint32_t
Definition stdint.h:9
unsigned int uint_fast32_t
Definition stdint.h:27
unsigned short uint_fast16_t
Definition stdint.h:25
unsigned char uint8_t
Definition stdint.h:5
signed char int8_t
Definition stdint.h:4
Definition usb_common.h:89
Definition vsf_usbd.h:434
vk_usbd_trans_t trans
Definition vsf_usbd.h:436
uint8_t reply_buffer[4]
Definition vsf_usbd.h:437
struct usb_ctrlrequest_t request
Definition vsf_usbd.h:435
Definition vsf_usbd.h:385
uint8_t * buffer
Definition vsf_usbd.h:390
uint16_t langid
Definition vsf_usbd.h:388
uint8_t index
Definition vsf_usbd.h:387
uint16_t size
Definition vsf_usbd.h:389
uint8_t type
Definition vsf_usbd.h:386
Definition vsf_utilities.h:51
Definition vsf_list.h:876
Definition vsf_list.h:872
vk_av_control_type_t type
Definition vsf_audio.h:170
uint32_t size
Definition vsf_memfs.h:50
def_class(vsf_stream_fifo_t, public:vsf_stream_tx_t TX;vsf_stream_rx_t RX;private:vsf_slist_queue_t union { vsf_stream_fifo_cfg_t cfg;struct { vsf_stream_dat_rdy_evt_t tDataReadyEventHandling;vsf_stream_dat_drn_evt_t tDataDrainEventHandling;vsf_stream_status_t Status;#if !defined(VSF_PBUF_QUEUE_CFG_ATOM_ACCESS) vsf_protect_region_t *pregion;#endif };};) end_def_class(vsf_stream_fifo_t) extern vsf_err_t vsf_stream_fifo_init(vsf_stream_fifo_t *obj_ptr
usb_ep_type_t
Definition vsf_template_usb.h:293
@ USB_USR_EVT
Definition vsf_template_usb.h:315
uint8_t usb_dc_speed_t
Definition vsf_template_usb.h:329
void vk_usbd_connect(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:980
void vk_usbd_init(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:1042
void vk_usbd_disconnect(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:987
vsf_err_t vk_usbd_ep_recv(vk_usbd_dev_t *dev, vk_usbd_trans_t *trans)
Definition vsf_usbd.c:235
void vk_usbd_stdreq_data_stage(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:752
void vk_usbd_fini(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:1110
vsf_err_t vk_usbd_ep_send(vk_usbd_dev_t *dev, vk_usbd_trans_t *trans)
Definition vsf_usbd.c:280
void vk_usbd_stdreq_status_stage(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:729
void vk_usbd_wakeup(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:998
vsf_err_t vk_usbd_ep_send_stream(vk_usbd_ep_stream_t *stream_ep, uint_fast32_t size)
Definition vsf_usbd.c:1272
vsf_err_t vk_usbd_ep_stall(vk_usbd_dev_t *dev, uint_fast8_t ep)
Definition vsf_usbd.c:227
vk_usbd_desc_t * vk_usbd_get_descriptor(vk_usbd_desc_t *desc, uint_fast8_t desc_num, uint_fast8_t type, uint_fast8_t index, uint_fast16_t langid)
Definition vsf_usbd.c:137
vsf_err_t vk_usbd_ep_recv_stream(vk_usbd_ep_stream_t *stream_ep, uint_fast32_t size)
Definition vsf_usbd.c:1207
vk_usbd_evt_t
Definition vsf_usbd.h:378
@ VSF_USBD_MAX_EVT
Definition vsf_usbd.h:382
@ USB_ON_FINI
Definition vsf_usbd.h:380
@ USB_ON_STATUS_QUERY
Definition vsf_usbd.h:381
@ USB_ON_INIT
Definition vsf_usbd.h:379
Generated from commit: vsfteam/vsf@7f3e4ff