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
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#define __end_describe_usbd(__name, __drv, ...) \
315 vk_usbd_cfg_t __##__name##_cfg[1] = { \
316 { \
317 .num_of_ifs = dimof(__##__name##_ifs), \
318 .ifs = __##__name##_ifs, \
319 }, \
320 }; \
321 vk_usbd_dev_t __name = { \
322 .num_of_config = dimof(__##__name##_cfg), \
323 .config = __##__name##_cfg, \
324 .num_of_desc = dimof(__##__name##_std_descs), \
325 .desc = (vk_usbd_desc_t *)__##__name##_std_descs, \
326 .speed = (usb_dc_speed_t)__##__name##_speed, \
327 .drv = &(__drv), \
328 __VA_ARGS__ \
329 };
330
331
332// prototype:
333// describe_usbd(__name, __vid, __pid, __speed, __version = 0x0200, __lang_id = 0x0409, __bcd_ver = 0x0100)
334#define describe_usbd(__name, __vid, __pid, __speed, ...) \
335 extern vk_usbd_dev_t __name; \
336 __PLOOC_EVAL(__describe_usbd, __name, __vid, __pid, __speed, ##__VA_ARGS__)(__name, __vid, __pid, __speed, ##__VA_ARGS__)
337#define usbd_common_desc_iad(__name, __str_product, __str_vendor, __str_serial, __ep0_size, __func_desc_size, __func_ifs_num, __attribute, __max_power_ma, ...)\
338 __usbd_common_desc_iad(__name, __str_product, __str_vendor, __str_serial, (__ep0_size), (__func_desc_size), (__func_ifs_num), (__attribute), (__max_power_ma))\
339 __VA_ARGS__};
340#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, ...)\
341 __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))\
342 __VA_ARGS__};
343#define usbd_func_str_desc(__name, __func_id, __str_func) \
344 __usbd_func_str_desc(__name, __func_id, __str_func)
345#define usbd_qualifier_desc(__name) \
346 __usbd_qualifier_desc(__name)
347#define usbd_std_desc_table(__name, ...) \
348 __usbd_std_desc_table(__name) \
349 __VA_ARGS__};
350// prototype:
351// usbd_func_str_desc_table(__name, __func_id, __lang_id = __LANG_ID_FROM_DESCRIBE_USBD)
352#define usbd_func_str_desc_table(__name, __func_id, ...) \
353 __PLOOC_EVAL(__usbd_func_str_desc_table, __name, __func_id, ##__VA_ARGS__)(__name, __func_id, ##__VA_ARGS__)
354#define usbd_qualifier_desc_table(__name) \
355 __usbd_qualifier_desc_table(__name)
356#define usbd_func(__name, ...) __VA_ARGS__
357#define usbd_ifs(__name, ...) \
358 __usbd_ifs(__name) \
359 __VA_ARGS__};
360#define end_describe_usbd(__name, __drv, ...) \
361 __end_describe_usbd(__name, (__drv), ##__VA_ARGS__)
362
363/*============================ MACROFIED FUNCTIONS ===========================*/
364/*============================ TYPES =========================================*/
365
366vsf_dcl_class(vk_usbd_dev_t)
367vsf_dcl_class(vk_usbd_cfg_t)
368vsf_dcl_class(vk_usbd_ifs_t)
370vsf_dcl_class(vk_usbd_class_op_t)
371
372typedef enum vk_usbd_evt_t {
378
379typedef struct vk_usbd_desc_t {
386
387#if VSF_USBD_CFG_RAW_MODE != ENABLED
388vsf_class(vk_usbd_class_op_t) {
389 protected_member(
390 vk_usbd_desc_t * (*get_desc)(vk_usbd_dev_t *dev, uint_fast8_t type,
391 uint_fast8_t index, uint_fast16_t langid);
392
393 vsf_err_t (*request_prepare)(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs);
394 vsf_err_t (*request_process)(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs);
395
396 vsf_err_t (*init)(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs);
397 vsf_err_t (*fini)(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs);
398 )
399};
400#endif
401
403 public_member(
404 uint8_t ep;
405 uint8_t feature;
406 bool zlp;
407 bool notify_eda;
408 implement(vsf_mem_t)
409 union {
410 struct {
411 void (*on_finish)(void *param);
412 void *param;
413 };
414#if VSF_USE_KERNEL == ENABLED
415 struct {
416 vsf_eda_t *eda;
417 };
418#endif
419 };
421
422 private_member(
423 vsf_slist_node_t node;
424 uint8_t *cur;
425 )
426};
427
433
434#if VSF_USBD_CFG_RAW_MODE != ENABLED
435vsf_class(vk_usbd_ifs_t) {
436
437 public_member(
438 const vk_usbd_class_op_t *class_op;
439 void *class_param;
440 )
441
442 private_member(
443 uint8_t alternate_setting;
444 bool is_inited;
445 )
446};
447
448vsf_class(vk_usbd_cfg_t) {
449
450 public_member(
451 vsf_err_t (*init)(vk_usbd_dev_t *dev);
452 vsf_err_t (*fini)(vk_usbd_dev_t *dev);
453
454 uint8_t num_of_ifs;
455 vk_usbd_ifs_t *ifs;
456 )
457
458 private_member(
459 uint8_t configuration_value;
460 int8_t ep_ifs_map[32];
461 )
462};
463#endif
464
465vsf_class(vk_usbd_dev_t) {
466 public_member(
467 usb_dc_speed_t speed;
468
469#if VSF_USBD_CFG_RAW_MODE != ENABLED
470 uint8_t num_of_config;
471 uint8_t num_of_desc;
472 vk_usbd_desc_t *desc;
473#endif
474
475#if VSF_USBD_CFG_RAW_MODE != ENABLED
476 vk_usbd_cfg_t *config;
477#endif
478
479#ifdef __VSF_USBD_CFG_DRV_INTERFACE
480 const i_usb_dc_t *drv;
481#endif
482
483 struct {
484 vsf_err_t (*prepare)(vk_usbd_dev_t *dev);
485 void (*process)(vk_usbd_dev_t *dev);
486 } vendor;
487 )
488
489#if VSF_USBD_CFG_RAW_MODE == ENABLED
490 public_member(
491#else
492 protected_member(
493#endif
494 vk_usbd_ctrl_handler_t ctrl_handler;
495 )
496
497 private_member(
498#if VSF_USBD_CFG_RAW_MODE != ENABLED
499 uint8_t address;
500 uint8_t configuration;
501 uint8_t feature;
502 bool configured;
503#endif
504 vsf_slist_t trans_list;
505#if VSF_USBD_CFG_USE_EDA == ENABLED
506 vsf_eda_t eda;
507#endif
508 )
509};
510
511#if VSF_USBD_CFG_STREAM_EN == ENABLED
512#if VSF_USE_SIMPLE_STREAM == ENABLED
513vsf_class(vk_usbd_ep_stream_t) {
514
515 public_member(
516 vsf_stream_t *stream;
517 struct {
518 void (*on_finish)(void *param);
519 void *param;
520 } callback;
521 )
522
523 protected_member(
524 implement(vk_usbd_trans_t)
525 vk_usbd_dev_t *dev;
526 uint32_t total_size;
527 uint32_t transferred_size;
528 uint32_t cur_size : 31;
529 uint32_t zlp_save : 1;
530 )
531};
532
533#elif VSF_USE_STREAM == ENABLED
534
535declare_class(vk_usbd_ep_stream_t)
536
537
538typedef struct vk_usbd_ep_stream_cfg_t {
539 uint8_t rx_ep;
540 uint8_t tx_ep;
541 //vk_usbd_dev_t *dev;
542} vk_usbd_ep_stream_cfg_t;
543
544def_class(vk_usbd_ep_stream_t,
545 which(
546 implement(vsf_stream_src_t)
547 implement(vsf_stream_usr_t)
548 )
549 private_member(
550 vk_usbd_trans_t tx_trans;
551 vk_usbd_trans_t rx_trans;
552 vsf_pbuf_t *tx_current;
553 vsf_pbuf_t *rx_current;
554 vk_usbd_dev_t *dev;
555 )
556)
557end_def_class(vk_usbd_ep_stream_src_t)
558
559#endif
560#endif
561
562/*============================ GLOBAL VARIABLES ==============================*/
563/*============================ PROTOTYPES ====================================*/
564
565extern void vk_usbd_init(vk_usbd_dev_t *dev);
566extern void vk_usbd_fini(vk_usbd_dev_t *dev);
567extern void vk_usbd_connect(vk_usbd_dev_t *dev);
568extern void vk_usbd_disconnect(vk_usbd_dev_t *dev);
569extern void vk_usbd_wakeup(vk_usbd_dev_t *dev);
570
571#if defined(__VSF_USBD_CLASS_IMPLEMENT) || defined(__VSF_USBD_CLASS_INHERIT__)
572
573#if VSF_USBD_CFG_RAW_MODE != ENABLED
576 uint_fast8_t index, uint_fast16_t langid);
577
578extern vk_usbd_cfg_t * vk_usbd_get_cur_cfg(vk_usbd_dev_t *dev);
579extern vk_usbd_ifs_t * vk_usbd_get_ifs(vk_usbd_dev_t *dev, uint_fast8_t ifs_no);
580extern uint_fast8_t vk_usbd_get_ifs_no(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs);
581extern vsf_err_t vk_usbd_ifs_add_ep(vk_usbd_dev_t *dev, vk_usbd_ifs_t *ifs, uint_fast8_t ep,
583#endif
584
585extern vsf_err_t vk_usbd_ep_stall(vk_usbd_dev_t *dev, uint_fast8_t ep);
586extern vsf_err_t vk_usbd_ep_recv(vk_usbd_dev_t *dev, vk_usbd_trans_t *trans);
587extern vsf_err_t vk_usbd_ep_send(vk_usbd_dev_t *dev, vk_usbd_trans_t *trans);
588
589extern void vk_usbd_stdreq_data_stage(vk_usbd_dev_t *dev);
590extern void vk_usbd_stdreq_status_stage(vk_usbd_dev_t *dev);
591
592# if VSF_USBD_CFG_STREAM_EN == ENABLED
593extern vsf_err_t vk_usbd_ep_recv_stream(vk_usbd_ep_stream_t *stream, uint_fast32_t size);
594extern vsf_err_t vk_usbd_ep_send_stream(vk_usbd_ep_stream_t *stream, uint_fast32_t size);
595
596# if VSF_USE_STREAM == ENABLED
597
598extern
599void vk_usbd_ep_stream_init( vk_usbd_ep_stream_t *obj,
600 vk_usbd_ep_stream_cfg_t *cfg);
601
602extern
603void vk_usbd_ep_stream_connect_dev(vk_usbd_ep_stream_t *obj,
604 vk_usbd_dev_t *dev);
605# endif // VSF_USE_STREAM
606# endif // VSF_USBD_CFG_STREAM_EN
607
608#endif // __VSF_USBD_CLASS_IMPLEMENT || __VSF_USBD_CLASS_INHERIT__
609
610#ifdef __cplusplus
611}
612#endif
613
614/*============================ INCLUDES ======================================*/
615
616#if VSF_USBD_USE_CDC == ENABLED
618# if VSF_USBD_USE_CDCACM == ENABLED
620# endif
621#endif
622#if VSF_USBD_USE_HID == ENABLED
624#endif
625#if VSF_USBD_USE_UVC == ENABLED
627#endif
628#if VSF_USBD_USE_UAC == ENABLED
630#endif
631#if VSF_USBD_USE_MSC == ENABLED
633#endif
634#if VSF_USBD_USE_DFU == ENABLED
636#endif
637
638#if defined(VSF_USBD_CFG_DRV_LV0_OO) && defined(VSF_USBD_CFG_DRV_LV0_OO_OBJ_HEADER)
639# include VSF_USBD_CFG_DRV_LV0_OO_OBJ_HEADER
640#endif
641
642#undef __VSF_USBD_CLASS_IMPLEMENT
643#undef __VSF_USBD_CLASS_INHERIT__
644
645#endif // VSF_USE_USB_DEVICE
646#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:402
Definition vsf_eda.h:766
Definition vsf_simple_stream.h:254
#define vsf_dcl_class
Definition ooc_class.h:46
#define vsf_class(__name)
Definition ooc_class.h:48
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:85
Definition vsf_usbd.h:428
vk_usbd_trans_t trans
Definition vsf_usbd.h:430
uint8_t reply_buffer[4]
Definition vsf_usbd.h:431
struct usb_ctrlrequest_t request
Definition vsf_usbd.h:429
Definition vsf_usbd.h:379
uint8_t * buffer
Definition vsf_usbd.h:384
uint16_t langid
Definition vsf_usbd.h:382
uint8_t index
Definition vsf_usbd.h:381
uint16_t size
Definition vsf_usbd.h:383
uint8_t type
Definition vsf_usbd.h:380
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, which(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:277
@ USB_USR_EVT
Definition vsf_template_usb.h:299
uint8_t usb_dc_speed_t
Definition vsf_template_usb.h:313
which(union { inherit(vsf_msgt_container_t) vsf_tgui_control_t };vsf_tgui_v_container_t) implement_ex(struct
Definition vsf_tgui_control.h:540
void vk_usbd_connect(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:966
void vk_usbd_init(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:1011
void vk_usbd_disconnect(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:973
vsf_err_t vk_usbd_ep_recv(vk_usbd_dev_t *dev, vk_usbd_trans_t *trans)
Definition vsf_usbd.c:230
void vk_usbd_stdreq_data_stage(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:748
void vk_usbd_fini(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:1069
vsf_err_t vk_usbd_ep_send(vk_usbd_dev_t *dev, vk_usbd_trans_t *trans)
Definition vsf_usbd.c:275
void vk_usbd_stdreq_status_stage(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:725
void vk_usbd_wakeup(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:980
vsf_err_t vk_usbd_ep_send_stream(vk_usbd_ep_stream_t *stream_ep, uint_fast32_t size)
Definition vsf_usbd.c:1231
vsf_err_t vk_usbd_ep_stall(vk_usbd_dev_t *dev, uint_fast8_t ep)
Definition vsf_usbd.c:222
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:132
vsf_err_t vk_usbd_ep_recv_stream(vk_usbd_ep_stream_t *stream_ep, uint_fast32_t size)
Definition vsf_usbd.c:1166
vk_usbd_evt_t
Definition vsf_usbd.h:372
@ VSF_USBD_MAX_EVT
Definition vsf_usbd.h:376
@ USB_ON_FINI
Definition vsf_usbd.h:374
@ USB_ON_STATUS_QUERY
Definition vsf_usbd.h:375
@ USB_ON_INIT
Definition vsf_usbd.h:373