25#if VSF_USE_USB_DEVICE == ENABLED
27#include "../common/usb_common.h"
28#include "../common/usb_desc.h"
38#if VSF_USBD_USE_DCD_MUSB_FDRC == ENABLED
39# include "../driver/otg/musb/fdrc/vsf_musb_fdrc_dcd.h"
41#if VSF_USBD_USE_DCD_DWCOTG == ENABLED
42# include "../driver/otg/dwcotg/vsf_dwcotg_dcd.h"
44#if VSF_USBD_USE_DCD_USBIP == ENABLED
45# include "../driver/dcd/usbip_dcd/vsf_usbip_dcd.h"
48#if VSF_USBD_CFG_RAW_MODE == ENABLED
53#if defined(__VSF_USBD_CLASS_IMPLEMENT)
54# define __VSF_CLASS_IMPLEMENT__
55#elif defined(__VSF_USBD_CLASS_INHERIT__)
56# define __VSF_CLASS_INHERIT__
67#ifndef VSF_USBD_CFG_AUTOSETUP
68# define VSF_USBD_CFG_AUTOSETUP ENABLED
71#ifndef VSF_USBD_CFG_USE_EDA
72# define VSF_USBD_CFG_USE_EDA VSF_USE_KERNEL
75#if (VSF_USBD_CFG_USE_EDA == ENABLED) && (VSF_USE_KERNEL != ENABLED)
76# error "VSF_USBD_CFG_USE_EDA depend on VSF_USE_KERNEL"
79#if (VSF_USBD_CFG_USE_EDA == ENABLED) && !defined(VSF_USBD_CFG_EDA_PRIORITY)
80# define VSF_USBD_CFG_EDA_PRIORITY vsf_prio_0
83#if !defined(VSF_USBD_CFG_HW_PRIORITY)
84# define VSF_USBD_CFG_HW_PRIORITY vsf_arch_prio_0
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)}
99#define __USB_IFS(__DRV, __PARAM) \
101 .class_op = (__DRV), \
102 .class_param = (__PARAM), \
104#define USB_IFS(__DRV, __PARAM) \
105 __USB_IFS((__DRV), (__PARAM))
109#if __STDC_VERSION__ >= 201112L
110# define usb_unicode_t char16_t
112# define usb_unicode_t wchar_t
115#define __describe_usbd_version_langid_bcd_ver( \
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), \
132#define __describe_usbd_version_langid( \
140 __describe_usbd_version_langid_bcd_ver(__name, __vid, __pid, __speed, __version, __lang_id, 0x0100)
141#define __describe_usbd_version(__name, \
147 __describe_usbd_version_langid(__name, __vid, __pid, __speed, __version, 0x0409)
148#define __describe_usbd( __name, \
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
160#define __usbd_str_desc(__name, __type, __str) \
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, \
171#define usbd_str_desc(__name, __type, __str) \
172 __usbd_str_desc(__name, __type, __str)
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)
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)
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)
189#define __usbd_str_langid_desc(__name) \
192 uint8_t bDescriptorType; \
193 usb_unicode_t str[1]; \
194 } VSF_CAL_PACKED const __##__name##_str_langid = { \
196 .bDescriptorType = USB_DT_STRING, \
197 .str = (__##__name##_langid), \
199#define usbd_str_langid_desc(__name) \
200 __usbd_str_langid_desc(__name)
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)) \
208#define usbd_device_iad_desc(__name) \
209 __usbd_device_iad_desc(__name)
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)) \
218#define usbd_device_desc(__name, __class, __subclass, __protocol) \
219 __usbd_device_desc(__name, (__class), (__subclass), (__protocol))
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))
228#define __usbd_basic_desc(__name, __func_ifs_num, __ep0_size) \
230 __##__name##_ifsnum = (__func_ifs_num), \
231 __##__name##_ep0size = (__ep0_size), \
232 __##__name##_config_num = 1, \
234#define usbd_basic_desc(__name, __func_ifs_num, __ep0_size) \
235 __usbd_basic_desc(__name, (__func_ifs_num), (__ep0_size))
242#define __usbd_common_desc( __name, \
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))
263#define __usbd_common_desc_iad( __name, \
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))
275#define __usbd_func_str_desc(__name, __func_id, __str_func) \
276 __usbd_str_desc(__name, func##__func_id, __str_func)
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))\
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)),
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)),
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__)
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
308#define __usbd_qualifier_desc_table(__name) \
309 VSF_USBD_DESC_QUALIFIER(&__##__name##_qualifier_desc),
311#define __usbd_ifs(__name) \
312 vk_usbd_ifs_t __##__name##_ifs[__##__name##_ifsnum] = {
314#define __end_describe_usbd(__name, __drv, ...) \
315 vk_usbd_cfg_t __##__name##_cfg[1] = { \
317 .num_of_ifs = dimof(__##__name##_ifs), \
318 .ifs = __##__name##_ifs, \
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, \
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))\
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))\
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) \
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, ...) \
360#define end_describe_usbd(__name, __drv, ...) \
361 __end_describe_usbd(__name, (__drv), ##__VA_ARGS__)
387#if VSF_USBD_CFG_RAW_MODE != ENABLED
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);
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);
411 void (*on_finish)(
void *param);
414#if VSF_USE_KERNEL == ENABLED
434#if VSF_USBD_CFG_RAW_MODE != ENABLED
438 const vk_usbd_class_op_t *class_op;
469#if VSF_USBD_CFG_RAW_MODE != ENABLED
475#if VSF_USBD_CFG_RAW_MODE != ENABLED
476 vk_usbd_cfg_t *config;
479#ifdef __VSF_USBD_CFG_DRV_INTERFACE
480 const i_usb_dc_t *drv;
484 vsf_err_t (*prepare)(vk_usbd_dev_t *dev);
485 void (*process)(vk_usbd_dev_t *dev);
489#
if VSF_USBD_CFG_RAW_MODE ==
ENABLED
498#
if VSF_USBD_CFG_RAW_MODE !=
ENABLED
505#if VSF_USBD_CFG_USE_EDA == ENABLED
511#if VSF_USBD_CFG_STREAM_EN == ENABLED
512#if VSF_USE_SIMPLE_STREAM == ENABLED
518 void (*on_finish)(
void *param);
533#elif VSF_USE_STREAM == ENABLED
538typedef struct vk_usbd_ep_stream_cfg_t {
542} vk_usbd_ep_stream_cfg_t;
546 implement(vsf_stream_src_t)
547 implement(vsf_stream_usr_t)
552 vsf_pbuf_t *tx_current;
553 vsf_pbuf_t *rx_current;
557end_def_class(vk_usbd_ep_stream_src_t)
571#if defined(__VSF_USBD_CLASS_IMPLEMENT) || defined(__VSF_USBD_CLASS_INHERIT__)
573#if VSF_USBD_CFG_RAW_MODE != ENABLED
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);
592# if VSF_USBD_CFG_STREAM_EN == ENABLED
596# if VSF_USE_STREAM == ENABLED
599void vk_usbd_ep_stream_init( vk_usbd_ep_stream_t *obj,
600 vk_usbd_ep_stream_cfg_t *cfg);
603void vk_usbd_ep_stream_connect_dev(vk_usbd_ep_stream_t *obj,
616#if VSF_USBD_USE_CDC == ENABLED
618# if VSF_USBD_USE_CDCACM == ENABLED
621# if VSF_USBD_USE_CDCNCM == ENABLED
625#if VSF_USBD_USE_HID == ENABLED
628#if VSF_USBD_USE_UVC == ENABLED
631#if VSF_USBD_USE_UAC == ENABLED
634#if VSF_USBD_USE_MSC == ENABLED
637#if VSF_USBD_USE_DFU == ENABLED
641#if defined(VSF_USBD_CFG_DRV_LV0_OO) && defined(VSF_USBD_CFG_DRV_LV0_OO_OBJ_HEADER)
642# include VSF_USBD_CFG_DRV_LV0_OO_OBJ_HEADER
645#undef __VSF_USBD_CLASS_IMPLEMENT
646#undef __VSF_USBD_CLASS_INHERIT__
#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_simple_stream.h:254
unsigned short uint16_t
Definition lvgl.h:41
unsigned int uint32_t
Definition lvgl.h:43
unsigned char uint8_t
Definition lvgl.h:40
signed char int8_t
Definition lvgl.h:38
#define vsf_dcl_class
Definition ooc_class.h:46
#define vsf_class(__name)
Definition ooc_class.h:48
unsigned char uint_fast8_t
Definition stdint.h:23
unsigned int uint_fast32_t
Definition stdint.h:27
unsigned short uint_fast16_t
Definition stdint.h:25
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:562
void vk_usbd_connect(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:967
void vk_usbd_init(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:1012
void vk_usbd_disconnect(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:974
vsf_err_t vk_usbd_ep_recv(vk_usbd_dev_t *dev, vk_usbd_trans_t *trans)
Definition vsf_usbd.c:231
void vk_usbd_stdreq_data_stage(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:749
void vk_usbd_fini(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:1070
vsf_err_t vk_usbd_ep_send(vk_usbd_dev_t *dev, vk_usbd_trans_t *trans)
Definition vsf_usbd.c:276
void vk_usbd_stdreq_status_stage(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:726
void vk_usbd_wakeup(vk_usbd_dev_t *dev)
Definition vsf_usbd.c:981
vsf_err_t vk_usbd_ep_send_stream(vk_usbd_ep_stream_t *stream_ep, uint_fast32_t size)
Definition vsf_usbd.c:1232
vsf_err_t vk_usbd_ep_stall(vk_usbd_dev_t *dev, uint_fast8_t ep)
Definition vsf_usbd.c:223
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:133
vsf_err_t vk_usbd_ep_recv_stream(vk_usbd_ep_stream_t *stream_ep, uint_fast32_t size)
Definition vsf_usbd.c:1167
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