18#ifndef __VSF_TEMPLATE_USB_H__
19#define __VSF_TEMPLATE_USB_H__
33#define USB_DC_SPEED_UNKNOWN 0
34#define USB_DC_SPEED_LOW 1
35#define USB_DC_SPEED_FULL 2
36#define USB_DC_SPEED_HIGH 3
37#define USB_DC_SPEED_SUPER 4
39#define __USB_HC_IP_FUNC_DEF(__N, __VALUE) \
40static vsf_err_t usb_hc##__N##_init(usb_hc_ip_cfg_t *cfg); \
41static void usb_hc##__N##_get_info(usb_hc_ip_info_t *info); \
42static void usb_hc##__N##_irq(void);
44#define __USB_HC_IP_INTERFACE_FUNC_DEF(__N, __VALUE) \
46 .Init = &usb_hc##__N##_init, \
47 .GetInfo = &usb_hc##__N##_get_info, \
48 .Irq = &usb_hc##__N##_irq, \
51#define __USB_HC_IP_BODY_EX(__N, __OBJ, __HEADER) \
52static vsf_err_t usb_hc##__N##_init(usb_hc_ip_cfg_t *cfg) \
53{ return __HEADER##_init(&(__OBJ), cfg); } \
54static void usb_hc##__N##_get_info(usb_hc_ip_info_t *info) \
55{ __HEADER##_get_info(&(__OBJ), info); } \
56static void usb_hc##__N##_irq(void) \
57{ __HEADER##_irq(&(__OBJ)); }
59#define __USB_HC_IP_BODY(__N, __HEADER) \
60 __USB_HC_IP_BODY_EX(__N, USB_HC##__N##_IP, __HEADER)
61#define __USB_OTG_HC_IP_BODY(__N, __HEADER) \
62 __USB_HC_IP_BODY_EX(__N, USB_OTG##__N##_IP, __HEADER)
66#define __USB_DC_IP_FUNC_DEF(__N, __VALUE) \
67static vsf_err_t usb_dc##__N##_init(usb_dc_ip_cfg_t *cfg); \
68static void usb_dc##__N##_fini(void); \
69static void usb_dc##__N##_get_info(usb_dc_ip_info_t *info); \
70static void usb_dc##__N##_connect(void); \
71static void usb_dc##__N##_disconnect(void); \
72static void usb_dc##__N##_irq(void);
74#define __USB_DC_IP_INTERFACE_FUNC_DEF(__N, __VALUE) \
76 .Init = &usb_dc##__N##_init, \
77 .Fini = &usb_dc##__N##_fini, \
78 .GetInfo = &usb_dc##__N##_get_info, \
79 .Connect = &usb_dc##__N##_connect, \
80 .Disconnect = &usb_dc##__N##_disconnect, \
81 .Irq = &usb_dc##__N##_irq, \
84#define __USB_DC_IP_BODY_EX(__N, __OBJ, __HEADER) \
85static vsf_err_t usb_dc##__N##_init(usb_dc_ip_cfg_t *cfg) \
86{ return __HEADER##_init(&(__OBJ), cfg); } \
87static void usb_dc##__N##_fini(void) \
88{ __HEADER##_fini(&(__OBJ)); } \
89static void usb_dc##__N##_get_info(usb_dc_ip_info_t *info) \
90{ __HEADER##_get_info(&(__OBJ), info); } \
91static void usb_dc##__N##_connect(void) \
92{ __HEADER##_connect(&(__OBJ)); } \
93static void usb_dc##__N##_disconnect(void) \
94{ __HEADER##_disconnect(&(__OBJ)); } \
95static void usb_dc##__N##_irq(void) \
96{ __HEADER##_irq(&(__OBJ)); }
98#define __USB_DC_IP_BODY(__N, __HEADER) \
99 __USB_DC_IP_BODY_EX(__N, USB_DC##__N##_IP, __HEADER)
100#define __USB_OTG_DC_IP_BODY(__N, __HEADER) \
101 __USB_DC_IP_BODY_EX(__N, USB_OTG##__N##_IP, __HEADER)
103#define __USB_DC_FROM_IP(__N, __OBJ, __DRV_NAME, __HEADER) \
104__USB_DC_FUNC_DEF(__N, NULL) \
105const i_usb_dc_t __DRV_NAME = __USB_DC_INTERFACE_FUNC_DEF(__N, NULL); \
106__USB_DC_BODY_EX(__N, __HEADER, __OBJ)
109#define __USB_DC_FUNC_DEF(__N, __VALUE) \
110static vsf_err_t usb_dc##__N##_init(usb_dc_cfg_t *cfg); \
111static void usb_dc##__N##_fini(void); \
112static void usb_dc##__N##_reset(usb_dc_cfg_t *cfg); \
114static void usb_dc##__N##_connect(void); \
115static void usb_dc##__N##_disconnect(void); \
116static void usb_dc##__N##_wakeup(void); \
118static void usb_dc##__N##_set_address(uint_fast8_t addr); \
119static uint_fast8_t usb_dc##__N##_get_address(void); \
121static uint_fast16_t usb_dc##__N##_get_frame_number(void); \
122static uint_fast8_t usb_dc##__N##_get_mframe_number(void); \
124static void usb_dc##__N##_get_setup(uint8_t *buffer); \
125static void usb_dc##__N##_status_stage(bool is_in); \
127static uint_fast8_t usb_dc##__N##_ep_get_feature( uint_fast8_t ep, \
128 uint_fast8_t feature); \
129static vsf_err_t usb_dc##__N##_ep_add( uint_fast8_t ep, \
130 usb_ep_type_t type, \
131 uint_fast16_t size); \
132static uint_fast16_t usb_dc##__N##_ep_get_size(uint_fast8_t ep); \
134static vsf_err_t usb_dc##__N##_ep_set_stall(uint_fast8_t ep); \
135static bool usb_dc##__N##_ep_is_stalled(uint_fast8_t ep); \
136static vsf_err_t usb_dc##__N##_ep_clear_stall(uint_fast8_t ep); \
138static uint_fast32_t usb_dc##__N##_ep_get_data_size(uint_fast8_t ep); \
139static vsf_err_t usb_dc##__N##_ep_transaction_read_buffer(uint_fast8_t ep, \
141 uint_fast16_t size);\
142static vsf_err_t usb_dc##__N##_ep_transaction_enable_out(uint_fast8_t ep); \
144static vsf_err_t usb_dc##__N##_ep_transaction_set_data_size( \
146 uint_fast16_t size);\
147static vsf_err_t usb_dc##__N##_ep_transaction_write_buffer( \
150 uint_fast16_t size);\
152static vsf_err_t usb_dc##__N##_ep_transfer_recv( uint_fast8_t ep, \
154 uint_fast32_t size); \
155static vsf_err_t usb_dc##__N##_ep_transfer_send( uint_fast8_t ep, \
157 uint_fast32_t size, \
160static void usb_dc##__N##_irq(void);
162#define __USB_DC_INTERFACE_FUNC_DEF(__N, __VALUE) \
164 .Init = &usb_dc##__N##_init, \
165 .Fini = &usb_dc##__N##_fini, \
166 .Reset = &usb_dc##__N##_reset, \
167 .Connect = &usb_dc##__N##_connect, \
168 .Disconnect = &usb_dc##__N##_disconnect, \
169 .Wakeup = &usb_dc##__N##_wakeup, \
170 .SetAddress = &usb_dc##__N##_set_address, \
171 .GetAddress = &usb_dc##__N##_get_address, \
172 .GetFrameNo = &usb_dc##__N##_get_frame_number, \
173 .GetMicroFrameNo= &usb_dc##__N##_get_mframe_number, \
174 .GetSetup = &usb_dc##__N##_get_setup, \
175 .StatusStage = &usb_dc##__N##_status_stage, \
177 .Ep.GetFeature = &usb_dc##__N##_ep_get_feature, \
178 .Ep.Add = &usb_dc##__N##_ep_add, \
179 .Ep.GetSize = &usb_dc##__N##_ep_get_size, \
180 .Ep.SetStall = &usb_dc##__N##_ep_set_stall, \
181 .Ep.IsStalled = &usb_dc##__N##_ep_is_stalled, \
182 .Ep.ClearStall = &usb_dc##__N##_ep_clear_stall, \
183 .Ep.GetDataSize = &usb_dc##__N##_ep_get_data_size, \
184 .Ep.Transaction.ReadBuffer = \
185 &usb_dc##__N##_ep_transaction_read_buffer, \
186 .Ep.Transaction.EnableOut = \
187 &usb_dc##__N##_ep_transaction_enable_out, \
188 .Ep.Transaction.SetDataSize = \
189 &usb_dc##__N##_ep_transaction_set_data_size, \
190 .Ep.Transaction.WriteBuffer = \
191 &usb_dc##__N##_ep_transaction_write_buffer, \
192 .Ep.Transfer.Recv = \
193 &usb_dc##__N##_ep_transfer_recv, \
194 .Ep.Transfer.Send = \
195 &usb_dc##__N##_ep_transfer_send, \
197 .Irq = &usb_dc##__N##_irq, \
200#define __USB_DC_BODY_EX(__N, __HEADER, __OBJ) \
201static vsf_err_t usb_dc##__N##_init(usb_dc_cfg_t *cfg) \
202{ return __HEADER##_init(&(__OBJ), cfg); } \
203static void usb_dc##__N##_fini(void) \
204{ __HEADER##_fini(&(__OBJ)); } \
205static void usb_dc##__N##_reset(usb_dc_cfg_t *cfg) \
206{ __HEADER##_reset(&(__OBJ), cfg); } \
207static void usb_dc##__N##_connect(void) \
208{ __HEADER##_connect(&(__OBJ)); } \
209static void usb_dc##__N##_disconnect(void) \
210{ __HEADER##_disconnect(&(__OBJ)); } \
211static void usb_dc##__N##_wakeup(void) \
212{ __HEADER##_wakeup(&(__OBJ)); } \
213static void usb_dc##__N##_set_address(uint_fast8_t addr) \
214{ __HEADER##_set_address(&(__OBJ), addr); } \
215static uint_fast8_t usb_dc##__N##_get_address(void) \
216{ return __HEADER##_get_address(&(__OBJ)); } \
217static uint_fast16_t usb_dc##__N##_get_frame_number(void) \
218{ return __HEADER##_get_frame_number(&(__OBJ)); } \
219static uint_fast8_t usb_dc##__N##_get_mframe_number(void) \
220{ return __HEADER##_get_mframe_number(&(__OBJ)); } \
221static void usb_dc##__N##_get_setup(uint8_t *buffer) \
222{ __HEADER##_get_setup(&(__OBJ), buffer); } \
223static void usb_dc##__N##_status_stage(bool is_in) \
224{ __HEADER##_status_stage(&(__OBJ), is_in); } \
225static uint_fast8_t usb_dc##__N##_ep_get_feature( uint_fast8_t ep, \
226 uint_fast8_t feature) \
227{ return __HEADER##_ep_get_feature(&(__OBJ), ep, feature); } \
228static vsf_err_t usb_dc##__N##_ep_add( uint_fast8_t ep, \
229 usb_ep_type_t type, \
230 uint_fast16_t size) \
231{ return __HEADER##_ep_add(&(__OBJ), ep, type, size); } \
232static uint_fast16_t usb_dc##__N##_ep_get_size(uint_fast8_t ep) \
233{ return __HEADER##_ep_get_size(&(__OBJ), ep); } \
234static vsf_err_t usb_dc##__N##_ep_set_stall(uint_fast8_t ep) \
235{ return __HEADER##_ep_set_stall(&(__OBJ), ep); } \
236static bool usb_dc##__N##_ep_is_stalled(uint_fast8_t ep) \
237{ return __HEADER##_ep_is_stalled(&(__OBJ), ep); } \
238static vsf_err_t usb_dc##__N##_ep_clear_stall(uint_fast8_t ep) \
239{ return __HEADER##_ep_clear_stall(&(__OBJ), ep); } \
240static uint_fast32_t usb_dc##__N##_ep_get_data_size(uint_fast8_t ep) \
241{ return __HEADER##_ep_get_data_size(&(__OBJ), ep); } \
242static vsf_err_t usb_dc##__N##_ep_transaction_read_buffer( \
245 uint_fast16_t size) \
246{ return __HEADER##_ep_transaction_read_buffer(&(__OBJ), ep, buffer, size); } \
247static vsf_err_t usb_dc##__N##_ep_transaction_enable_out(uint_fast8_t ep) \
248{ return __HEADER##_ep_transaction_enable_out(&(__OBJ), ep); } \
249static vsf_err_t usb_dc##__N##_ep_transaction_set_data_size(uint_fast8_t ep, \
250 uint_fast16_t size) \
251{ return __HEADER##_ep_transaction_set_data_size(&(__OBJ), ep, size); } \
252static vsf_err_t usb_dc##__N##_ep_transaction_write_buffer( uint_fast8_t ep, \
254 uint_fast16_t size) \
255{ return __HEADER##_ep_transaction_write_buffer(&(__OBJ), ep, buffer, size); } \
256static vsf_err_t usb_dc##__N##_ep_transfer_recv(uint_fast8_t ep, \
258 uint_fast32_t size) \
259{ return __HEADER##_ep_transfer_recv(&(__OBJ), ep, buffer, size); } \
260static vsf_err_t usb_dc##__N##_ep_transfer_send(uint_fast8_t ep, \
262 uint_fast32_t size, \
264{ return __HEADER##_ep_transfer_send(&(__OBJ), ep, buffer, size, zlp); } \
265static void usb_dc##__N##_irq(void) \
266{ __HEADER##_irq(&(__OBJ)); }
268#define __USB_DC_BODY(__N, __HEADER) \
269 __USB_DC_BODY_EX(__N, __HEADER, USB_DC##__N)
vsf_err_t
Definition __type.h:42
vsf_err_t(* Init)(vsf_adc_cfg_t *pCfg)
Definition adc_interface.h:38
vsf_arch_prio_t
Definition cortex_a_generic.h:88
end_def_interface(i_pm_wakeup_t) struct vsf_pm_pclk_cfg_t
Definition device.h:249
unsigned char uint8_t
Definition lvgl.h:40
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 vsf_template_usb.h:316
vsf_arch_prio_t priority
interrupt priority
Definition vsf_template_usb.h:317
usb_dc_evthandler_t evthandler
evthandler function
Definition vsf_template_usb.h:318
void * param
dcd related parameters
Definition vsf_template_usb.h:319
usb_dc_speed_t speed
speed
Definition vsf_template_usb.h:321
Definition vsf_template_usb.h:408
void * regbase
Definition vsf_template_usb.h:409
bool is_dma
Definition vsf_template_usb.h:411
uint8_t ep_num
Definition vsf_template_usb.h:410
Definition vsf_template_usb.h:446
uint8_t ep_num
Definition vsf_template_usb.h:448
void * regbase
Definition vsf_template_usb.h:447
bool is_dma
Definition vsf_template_usb.h:449
vk_av_control_value_t value
Definition vsf_audio.h:171
vk_av_control_type_t type
Definition vsf_audio.h:170
uint32_t size
Definition vsf_memfs.h:50
void(* Fini)(void)
Definition vsf_template_usb.h:331
void(* Connect)(void)
Definition vsf_template_usb.h:334
void(* Irq)(void)
irq handler
Definition vsf_template_usb.h:388
vsf_err_t(* SetDataSize)(uint_fast8_t ep, uint_fast16_t size)
Definition vsf_template_usb.h:369
struct @574::@579 Transfer
uint_fast8_t(* GetFeature)(uint_fast8_t ep, uint_fast8_t feature)
Definition vsf_template_usb.h:348
usb_ep_type_t
Definition vsf_template_usb.h:277
@ USB_EP_TYPE_CONTROL
Definition vsf_template_usb.h:278
@ USB_EP_TYPE_BULK
Definition vsf_template_usb.h:280
@ USB_EP_TYPE_INTERRUPT
Definition vsf_template_usb.h:279
@ USB_EP_TYPE_ISO
Definition vsf_template_usb.h:281
usb_dc_err_t
Definition vsf_template_usb.h:302
@ USB_DC_ERR_ERROR
Definition vsf_template_usb.h:303
@ USB_DC_ERR_SOF_TO
Definition vsf_template_usb.h:305
@ USB_DC_ERR_INVALID_CRC
Definition vsf_template_usb.h:304
vsf_err_t(* SetStall)(uint_fast8_t ep)
Definition vsf_template_usb.h:356
usb_evt_t
Definition vsf_template_usb.h:284
@ USB_ON_SOF
Definition vsf_template_usb.h:292
@ USB_ON_ERROR
Definition vsf_template_usb.h:289
@ USB_ON_SETUP
Definition vsf_template_usb.h:288
@ USB_ON_SUSPEND
Definition vsf_template_usb.h:290
@ USB_ON_ATTACH
Definition vsf_template_usb.h:285
@ USB_ON_RESUME
Definition vsf_template_usb.h:291
@ USB_ON_STATUS
Definition vsf_template_usb.h:296
@ USB_ON_RESET
Definition vsf_template_usb.h:287
@ USB_ON_NAK
Definition vsf_template_usb.h:294
@ USB_ON_IN
Definition vsf_template_usb.h:293
@ USB_ON_OVERFLOW
Definition vsf_template_usb.h:298
@ USB_ON_OUT
Definition vsf_template_usb.h:295
@ USB_USR_EVT
Definition vsf_template_usb.h:299
@ USB_ON_UNDERFLOW
Definition vsf_template_usb.h:297
@ USB_ON_DETACH
Definition vsf_template_usb.h:286
void(* Reset)(usb_dc_cfg_t *cfg)
Definition vsf_template_usb.h:332
uint8_t usb_dc_speed_t
Definition vsf_template_usb.h:313
void(* Wakeup)(void)
Definition vsf_template_usb.h:336
uint_fast16_t(* GetFrameNo)(void)
Definition vsf_template_usb.h:341
void(* usb_ip_irqhandler_t)(void *param)
Definition vsf_template_usb.h:308
usb_hc_ip_cfg_t
Definition vsf_template_usb.h:441
vsf_err_t(* ReadBuffer)(uint_fast8_t ep, uint8_t *buffer, uint_fast16_t size)
Definition vsf_template_usb.h:365
usb_dc_ip_cfg_t
Definition vsf_template_usb.h:403
uint_fast32_t(* GetDataSize)(uint_fast8_t ep)
Definition vsf_template_usb.h:362
void(* StatusStage)(bool is_in)
Definition vsf_template_usb.h:345
struct @574::@578 Transaction
uint_fast8_t(* GetAddress)(void)
Definition vsf_template_usb.h:339
vsf_err_t(* Recv)(uint_fast8_t ep, uint8_t *buffer, uint_fast32_t size)
Definition vsf_template_usb.h:377
vsf_err_t(* ClearStall)(uint_fast8_t ep)
Definition vsf_template_usb.h:358
void(* GetSetup)(uint8_t *buffer)
Definition vsf_template_usb.h:344
void(* SetAddress)(uint_fast8_t addr)
Definition vsf_template_usb.h:338
bool(* IsStalled)(uint_fast8_t ep)
Definition vsf_template_usb.h:357
usb_dc_feature_t
Definition vsf_template_usb.h:273
@ USB_DC_FEATURE_TRANSFER
Definition vsf_template_usb.h:274
uint_fast8_t(* GetMicroFrameNo)(void)
Definition vsf_template_usb.h:342
void(* GetInfo)(usb_dc_ip_info_t *info)
get register base
Definition vsf_template_usb.h:423
vsf_err_t(* EnableOut)(uint_fast8_t ep)
Definition vsf_template_usb.h:368
vsf_err_t(* Add)(uint_fast8_t ep, usb_ep_type_t type, uint_fast16_t size)
Definition vsf_template_usb.h:351
void(* usb_dc_evthandler_t)(void *param, usb_evt_t evt, uint_fast8_t value)
Definition vsf_template_usb.h:309
vsf_err_t(* Send)(uint_fast8_t ep, uint8_t *buffer, uint_fast32_t size, bool zlp)
Definition vsf_template_usb.h:380
void(* Disconnect)(void)
Definition vsf_template_usb.h:335
uint_fast16_t(* GetSize)(uint_fast8_t ep)
Definition vsf_template_usb.h:354
vsf_err_t(* WriteBuffer)(uint_fast8_t ep, uint8_t *buffer, uint_fast16_t size)
Definition vsf_template_usb.h:371
def_interface(i_usb_dc_t) vsf_err_t(*Init)(usb_dc_cfg_t *cfg)