1 /***********************************************************************
2 * $Id:: mw_usbd_core.h 331 2012-08-09 18:54:34Z usb10131 $
3 *
4 * Project: USB device ROM Stack
5 *
6 * Description:
7 * USB core controller structure definitions and function prototypes.
8 *
9 ***********************************************************************
10 * Copyright(C) 2011, NXP Semiconductor
11 * All rights reserved.
12 *
13 * Software that is described herein is for illustrative purposes only
14 * which provides customers with programming information regarding the
15 * products. This software is supplied "AS IS" without any warranties.
16 * NXP Semiconductors assumes no responsibility or liability for the
17 * use of the software, conveys no license or title under any patent,
18 * copyright, or mask work right to the product. NXP Semiconductors
19 * reserves the right to make changes in the software without
20 * notification. NXP Semiconductors also make no representation or
21 * warranty that such application will be suitable for the specified
22 * use without further testing or modification.
23 **********************************************************************/
24 #ifndef __MW_USBD_CORE_H__
25 #define __MW_USBD_CORE_H__
26
27 #include "error.h"
28 #include "usbd.h"
29 #include "app_usbd_cfg.h"
30
31 /** \file
32 * \brief ROM API for USB device stack.
33 *
34 * Definition of functions exported by core layer of ROM based USB device stack.
35 *
36 */
37
38 /** \ingroup Group_USBD
39 * @defgroup USBD_Core USB Core Layer
40 * \section Sec_CoreModDescription Module Description
41 * The USB Core Layer implements the device abstraction defined in the <em> Universal Serial Bus Specification, </em>
42 * for applications to interact with the USB device interface on the device. The software in this layer responds to
43 * standard requests and returns standard descriptors. In current stack the Init() routine part of
44 * \ref USBD_HW_API_T structure initializes both hardware layer and core layer.
45 */
46
47
48 /* function pointer types */
49
50 /** \ingroup USBD_Core
51 * \typedef USB_CB_T
52 * \brief USB device stack's event callback function type.
53 *
54 * The USB device stack exposes several event triggers through callback to application layer. The
55 * application layer can register methods to be called when such USB event happens.
56 *
57 * \param[in] hUsb Handle to the USB device stack.
58 * \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
59 * \retval LPC_OK On success
60 * \retval ERR_USBD_UNHANDLED Event is not handled hence pass the event to next in line.
61 * \retval ERR_USBD_xxx Other error conditions.
62 *
63 */
64 typedef ErrorCode_t (*USB_CB_T) (USBD_HANDLE_T hUsb);
65
66 /** \ingroup USBD_Core
67 * \typedef USB_PARAM_CB_T
68 * \brief USB device stack's event callback function type.
69 *
70 * The USB device stack exposes several event triggers through callback to application layer. The
71 * application layer can register methods to be called when such USB event happens.
72 *
73 * \param[in] hUsb Handle to the USB device stack.
74 * \param[in] param1 Extra information related to the event.
75 * \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
76 * \retval LPC_OK On success
77 * \retval ERR_USBD_UNHANDLED Event is not handled hence pass the event to next in line.
78 * \retval ERR_USBD_xxx For other error conditions.
79 *
80 */
81 typedef ErrorCode_t (*USB_PARAM_CB_T) (USBD_HANDLE_T hUsb, uint32_t param1);
82
83 /** \ingroup USBD_Core
84 * \typedef USB_EP_HANDLER_T
85 * \brief USBD setup request and endpoint event handler type.
86 *
87 * The application layer should define the custom class's EP0 handler with function signature.
88 * The stack calls all the registered class handlers on any EP0 event before going through default
89 * handling of the event. This gives the class handlers to implement class specific request handlers
90 * and also to override the default stack handling for a particular event targeted to the interface.
91 * If an event is not handled by the callback the function should return ERR_USBD_UNHANDLED. For all
92 * other return codes the stack assumes that callback has taken care of the event and hence will not
93 * process the event any further and issues a STALL condition on EP0 indicating error to the host.
94 * \n
95 * For endpoint interrupt handler the return value is ignored by the stack.
96 * \n
97 * \param[in] hUsb Handle to the USB device stack.
98 * \param[in] data Pointer to the data which will be passed when callback function is called by the stack.
99 * \param[in] event Type of endpoint event. See \ref USBD_EVENT_T for more details.
100 * \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
101 * \retval LPC_OK On success.
102 * \retval ERR_USBD_UNHANDLED Event is not handled hence pass the event to next in line.
103 * \retval ERR_USBD_xxx For other error conditions.
104 *
105 */
106 typedef ErrorCode_t (*USB_EP_HANDLER_T)(USBD_HANDLE_T hUsb, void* data, uint32_t event);
107
108
109 /** \ingroup USBD_Core
110 * \brief USB descriptors data structure.
111 * \ingroup USBD_Core
112 *
113 * \details This structure is used as part of USB device stack initialization
114 * parameter structure \ref USBD_API_INIT_PARAM_T. This structure contains
115 * pointers to various descriptor arrays needed by the stack. These descriptors
116 * are reported to USB host as part of enumerations process.
117 *
118 * \note All descriptor pointers assigned in this structure should be on 4 byte
119 * aligned address boundary.
120 */
121 typedef struct _USB_CORE_DESCS_T
122 {
123 uint8_t *device_desc; /**< Pointer to USB device descriptor */
124 uint8_t *string_desc; /**< Pointer to array of USB string descriptors */
125 uint8_t *full_speed_desc; /**< Pointer to USB device configuration descriptor
126 * when device is operating in full speed mode.
127 */
128 uint8_t *high_speed_desc; /**< Pointer to USB device configuration descriptor
129 * when device is operating in high speed mode. For
130 * full-speed only implementation this pointer should
131 * be same as full_speed_desc.
132 */
133 uint8_t *device_qualifier; /**< Pointer to USB device qualifier descriptor. For
134 * full-speed only implementation this pointer should
135 * be set to null (0).
136 */
137 } USB_CORE_DESCS_T;
138
139 /** \brief USB device stack initialization parameter data structure.
140 * \ingroup USBD_Core
141 *
142 * \details This data structure is used to pass initialization parameters to the
143 * USB device stack's init function.
144 *
145 */
146 typedef struct USBD_API_INIT_PARAM
147 {
148 uint32_t usb_reg_base; /**< USB device controller's base register address. */
149 uint32_t mem_base; /**< Base memory location from where the stack can allocate
150 data and buffers. \note The memory address set in this field
151 should be accessible by USB DMA controller. Also this value
152 should be aligned on 2048 byte boundary.
153 */
154 uint32_t mem_size; /**< The size of memory buffer which stack can use.
155 \note The \em mem_size should be greater than the size
156 returned by USBD_HW_API::GetMemSize() routine.*/
157 uint8_t max_num_ep; /**< max number of endpoints supported by the USB device
158 controller instance (specified by \em usb_reg_base field)
159 to which this instance of stack is attached.
160 */
161 uint8_t pad0[3];
162 /* USB Device Events Callback Functions */
163 /** Event for USB interface reset. This event fires when the USB host requests that the device
164 * reset its interface. This event fires after the control endpoint has been automatically
165 * configured by the library.
166 * \n
167 * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this
168 * callback will prevent the device from enumerating correctly or operate properly.
169 *
170 */
171 USB_CB_T USB_Reset_Event;
172
173 /** Event for USB suspend. This event fires when the USB host suspends the device by halting its
174 * transmission of Start Of Frame pulses to the device. This is generally hooked in order to move
175 * the device over to a low power state until the host wakes up the device.
176 * \n
177 * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this
178 * callback will cause other system issues.
179 */
180 USB_CB_T USB_Suspend_Event;
181
182 /** Event for USB wake up or resume. This event fires when a the USB device interface is suspended
183 * and the host wakes up the device by supplying Start Of Frame pulses. This is generally
184 * hooked to pull the user application out of a low power state and back into normal operating
185 * mode.
186 * \n
187 * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this
188 * callback will cause other system issues.
189 *
190 */
191 USB_CB_T USB_Resume_Event;
192
193 /** Reserved parameter should be set to zero. */
194 USB_CB_T reserved_sbz;
195
196 /** Event for USB Start Of Frame detection, when enabled. This event fires at the start of each USB
197 * frame, once per millisecond in full-speed mode or once per 125 microseconds in high-speed mode,
198 * and is synchronized to the USB bus.
199 *
200 * This event is time-critical; it is run once per millisecond (full-speed mode) and thus long handlers
201 * will significantly degrade device performance. This event should only be enabled when needed to
202 * reduce device wake-ups.
203 *
204 * \note This event is not normally active - it must be manually enabled and disabled via the USB interrupt
205 * register.
206 * \n\n
207 */
208 USB_CB_T USB_SOF_Event;
209
210 /** Event for remote wake-up configuration, when enabled. This event fires when the USB host
211 * request the device to configure itself for remote wake-up capability. The USB host sends
212 * this request to device which report remote wake-up capable in their device descriptors,
213 * before going to low-power state. The application layer should implement this callback if
214 * they have any special on board circuit to trigger remote wake up event. Also application
215 * can use this callback to differentiate the following SUSPEND event is caused by cable plug-out
216 * or host SUSPEND request. The device can wake-up host only after receiving this callback and
217 * remote wake-up feature is enabled by host. To signal remote wake-up the device has to generate
218 * resume signaling on bus by calling usapi.hw->WakeUp() routine.
219 *
220 * \n\n
221 * \param[in] hUsb Handle to the USB device stack.
222 * \param[in] param1 When 0 - Clear the wake-up configuration, 1 - Enable the wake-up configuration.
223 * \return The call back should return \ref ErrorCode_t type to indicate success or error condition.
224 */
225 USB_PARAM_CB_T USB_WakeUpCfg;
226
227 /** Reserved parameter should be set to zero. */
228 USB_PARAM_CB_T USB_Power_Event;
229
230 /** Event for error condition. This event fires when USB device controller detect
231 * an error condition in the system.
232 *
233 * \n\n
234 * \param[in] hUsb Handle to the USB device stack.
235 * \param[in] param1 USB device interrupt status register.
236 * \return The call back should return \ref ErrorCode_t type to indicate success or error condition.
237 */
238 USB_PARAM_CB_T USB_Error_Event;
239
240 /* USB Core Events Callback Functions */
241 /** Event for USB configuration number changed. This event fires when a the USB host changes the
242 * selected configuration number. On receiving configuration change request from host, the stack
243 * enables/configures the endpoints needed by the new configuration before calling this callback
244 * function.
245 * \n
246 * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this
247 * callback will prevent the device from enumerating correctly or operate properly.
248 *
249 */
250 USB_CB_T USB_Configure_Event;
251
252 /** Event for USB interface setting changed. This event fires when a the USB host changes the
253 * interface setting to one of alternate interface settings. On receiving interface change
254 * request from host, the stack enables/configures the endpoints needed by the new alternate
255 * interface setting before calling this callback function.
256 * \n
257 * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this
258 * callback will prevent the device from enumerating correctly or operate properly.
259 *
260 */
261 USB_CB_T USB_Interface_Event;
262
263 /** Event for USB feature changed. This event fires when a the USB host send set/clear feature
264 * request. The stack handles this request for USB_FEATURE_REMOTE_WAKEUP, USB_FEATURE_TEST_MODE
265 * and USB_FEATURE_ENDPOINT_STALL features only. On receiving feature request from host, the
266 * stack handle the request appropriately and then calls this callback function.
267 * \n
268 * \note This event is called from USB_ISR context and hence is time-critical. Having delays in this
269 * callback will prevent the device from enumerating correctly or operate properly.
270 *
271 */
272 USB_CB_T USB_Feature_Event;
273
274 /* cache and MMU translation functions */
275 /** Reserved parameter for future use. should be set to zero. */
276 uint32_t (* virt_to_phys)(void* vaddr);
277 /** Reserved parameter for future use. should be set to zero. */
278 void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);
279
280 } USBD_API_INIT_PARAM_T;
281
282
283 /** \brief USBD stack Core API functions structure.
284 * \ingroup USBD_Core
285 *
286 * \details This module exposes functions which interact directly with USB device stack's core layer.
287 * The application layer uses this component when it has to implement custom class function driver or
288 * standard class function driver which is not part of the current USB device stack.
289 * The functions exposed by this interface are to register class specific EP0 handlers and corresponding
290 * utility functions to manipulate EP0 state machine of the stack. This interface also exposes
291 * function to register custom endpoint interrupt handler.
292 *
293 */
294 typedef struct USBD_CORE_API
295 {
296 /** \fn ErrorCode_t RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data)
297 * Function to register class specific EP0 event handler with USB device stack.
298 *
299 * The application layer uses this function when it has to register the custom class's EP0 handler.
300 * The stack calls all the registered class handlers on any EP0 event before going through default
301 * handling of the event. This gives the class handlers to implement class specific request handlers
302 * and also to override the default stack handling for a particular event targeted to the interface.
303 * Check \ref USB_EP_HANDLER_T for more details on how the callback function should be implemented. Also
304 * application layer could use this function to register EP0 handler which responds to vendor specific
305 * requests.
306 *
307 * \param[in] hUsb Handle to the USB device stack.
308 * \param[in] pfn Class specific EP0 handler function.
309 * \param[in] data Pointer to the data which will be passed when callback function is called by the stack.
310 * \return Returns \ref ErrorCode_t type to indicate success or error condition.
311 * \retval LPC_OK On success
312 * \retval ERR_USBD_TOO_MANY_CLASS_HDLR(0x0004000c) The number of class handlers registered is
313 greater than the number of handlers allowed by the stack.
314 *
315 */
316 ErrorCode_t (*RegisterClassHandler)(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);
317
318 /** \fn ErrorCode_t RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data)
319 * Function to register interrupt/event handler for the requested endpoint with USB device stack.
320 *
321 * The application layer uses this function to register the endpoint event handler.
322 * The stack calls all the registered endpoint handlers when
323 * - USB_EVT_OUT or USB_EVT_OUT_NAK events happen for OUT endpoint.
324 * - USB_EVT_IN or USB_EVT_IN_NAK events happen for IN endpoint.
325 * Check USB_EP_HANDLER_T for more details on how the callback function should be implemented.
326 * \note By default endpoint _NAK events are not enabled. Application should call \ref USBD_HW_API_T::EnableEvent
327 * for the corresponding endpoint.
328 *
329 * \param[in] hUsb Handle to the USB device stack.
330 * \param[in] ep_index Endpoint index. Computed as
331 * - For OUT endpoints = 2 * endpoint number eg. for EP2_OUT it is 4.
332 * - For IN endopoints = (2 * endpoint number) + 1 eg. for EP2_IN it is 5.
333 * \param[in] pfn Endpoint event handler function.
334 * \param[in] data Pointer to the data which will be passed when callback function is called by the stack.
335 * \return Returns \ref ErrorCode_t type to indicate success or error condition.
336 * \retval LPC_OK On success
337 * \retval ERR_API_INVALID_PARAM2 ep_index is outside the boundary ( < 2 * USBD_API_INIT_PARAM_T::max_num_ep).
338 *
339 */
340 ErrorCode_t (*RegisterEpHandler)(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);
341
342 /** \fn void SetupStage(USBD_HANDLE_T hUsb)
343 * Function to set EP0 state machine in setup state.
344 *
345 * This function is called by USB stack and the application layer to
346 * set the EP0 state machine in setup state. This function will read
347 * the setup packet received from USB host into stack's buffer.
348 * \n
349 * \note This interface is provided to users to invoke this function in other
350 * scenarios which are not handle by current stack. In most user applications
351 * this function is not called directly.Also this function can be used by
352 * users who are selectively modifying the USB device stack's standard handlers
353 * through callback interface exposed by the stack.
354 *
355 * \param[in] hUsb Handle to the USB device stack.
356 * \return Nothing.
357 */
358 void (*SetupStage )(USBD_HANDLE_T hUsb);
359
360 /** \fn void DataInStage(USBD_HANDLE_T hUsb)
361 * Function to set EP0 state machine in data_in state.
362 *
363 * This function is called by USB stack and the application layer to
364 * set the EP0 state machine in data_in state. This function will write
365 * the data present in EP0Data buffer to EP0 FIFO for transmission to host.
366 * \n
367 * \note This interface is provided to users to invoke this function in other
368 * scenarios which are not handle by current stack. In most user applications
369 * this function is not called directly.Also this function can be used by
370 * users who are selectively modifying the USB device stack's standard handlers
371 * through callback interface exposed by the stack.
372 *
373 * \param[in] hUsb Handle to the USB device stack.
374 * \return Nothing.
375 */
376 void (*DataInStage)(USBD_HANDLE_T hUsb);
377
378 /** \fn void DataOutStage(USBD_HANDLE_T hUsb)
379 * Function to set EP0 state machine in data_out state.
380 *
381 * This function is called by USB stack and the application layer to
382 * set the EP0 state machine in data_out state. This function will read
383 * the control data (EP0 out packets) received from USB host into EP0Data buffer.
384 * \n
385 * \note This interface is provided to users to invoke this function in other
386 * scenarios which are not handle by current stack. In most user applications
387 * this function is not called directly.Also this function can be used by
388 * users who are selectively modifying the USB device stack's standard handlers
389 * through callback interface exposed by the stack.
390 *
391 * \param[in] hUsb Handle to the USB device stack.
392 * \return Nothing.
393 */
394 void (*DataOutStage)(USBD_HANDLE_T hUsb);
395
396 /** \fn void StatusInStage(USBD_HANDLE_T hUsb)
397 * Function to set EP0 state machine in status_in state.
398 *
399 * This function is called by USB stack and the application layer to
400 * set the EP0 state machine in status_in state. This function will send
401 * zero length IN packet on EP0 to host, indicating positive status.
402 * \n
403 * \note This interface is provided to users to invoke this function in other
404 * scenarios which are not handle by current stack. In most user applications
405 * this function is not called directly.Also this function can be used by
406 * users who are selectively modifying the USB device stack's standard handlers
407 * through callback interface exposed by the stack.
408 *
409 * \param[in] hUsb Handle to the USB device stack.
410 * \return Nothing.
411 */
412 void (*StatusInStage)(USBD_HANDLE_T hUsb);
413 /** \fn void StatusOutStage(USBD_HANDLE_T hUsb)
414 * Function to set EP0 state machine in status_out state.
415 *
416 * This function is called by USB stack and the application layer to
417 * set the EP0 state machine in status_out state. This function will read
418 * the zero length OUT packet received from USB host on EP0.
419 * \n
420 * \note This interface is provided to users to invoke this function in other
421 * scenarios which are not handle by current stack. In most user applications
422 * this function is not called directly.Also this function can be used by
423 * users who are selectively modifying the USB device stack's standard handlers
424 * through callback interface exposed by the stack.
425 *
426 * \param[in] hUsb Handle to the USB device stack.
427 * \return Nothing.
428 */
429 void (*StatusOutStage)(USBD_HANDLE_T hUsb);
430
431 /** \fn void StallEp0(USBD_HANDLE_T hUsb)
432 * Function to set EP0 state machine in stall state.
433 *
434 * This function is called by USB stack and the application layer to
435 * generate STALL signaling on EP0 endpoint. This function will also
436 * reset the EP0Data buffer.
437 * \n
438 * \note This interface is provided to users to invoke this function in other
439 * scenarios which are not handle by current stack. In most user applications
440 * this function is not called directly.Also this function can be used by
441 * users who are selectively modifying the USB device stack's standard handlers
442 * through callback interface exposed by the stack.
443 *
444 * \param[in] hUsb Handle to the USB device stack.
445 * \return Nothing.
446 */
447 void (*StallEp0)(USBD_HANDLE_T hUsb);
448
449 } USBD_CORE_API_T;
450
451 /*-----------------------------------------------------------------------------
452 * Private functions & structures prototypes
453 *-----------------------------------------------------------------------------*/
454
455 /** @cond ADVANCED_API */
456
457 /* forward declaration */
458 struct _USB_CORE_CTRL_T;
459 typedef struct _USB_CORE_CTRL_T USB_CORE_CTRL_T;
460
461 /* USB device Speed status defines */
462 #define USB_FULL_SPEED 0
463 #define USB_HIGH_SPEED 1
464
465 /* USB Endpoint Data Structure */
466 typedef struct _USB_EP_DATA
467 {
468 uint8_t *pData;
469 uint16_t Count;
470 uint16_t pad0;
471 } USB_EP_DATA;
472
473
474 /* USB core controller data structure */
475 struct _USB_CORE_CTRL_T
476 {
477 /* override-able function pointers ~ c++ style virtual functions*/
478 USB_CB_T USB_EvtSetupHandler;
479 USB_CB_T USB_EvtOutHandler;
480 USB_PARAM_CB_T USB_ReqVendor;
481 USB_CB_T USB_ReqGetStatus;
482 USB_CB_T USB_ReqGetDescriptor;
483 USB_CB_T USB_ReqGetConfiguration;
484 USB_CB_T USB_ReqSetConfiguration;
485 USB_CB_T USB_ReqGetInterface;
486 USB_CB_T USB_ReqSetInterface;
487 USB_PARAM_CB_T USB_ReqSetClrFeature;
488
489 /* USB Device Events Callback Functions */
490 USB_CB_T USB_Reset_Event;
491 USB_CB_T USB_Suspend_Event;
492 USB_CB_T USB_Resume_Event;
493 USB_CB_T USB_SOF_Event;
494 USB_PARAM_CB_T USB_Power_Event;
495 USB_PARAM_CB_T USB_Error_Event;
496 USB_PARAM_CB_T USB_WakeUpCfg;
497
498 /* USB Core Events Callback Functions */
499 USB_CB_T USB_Configure_Event;
500 USB_CB_T USB_Interface_Event;
501 USB_CB_T USB_Feature_Event;
502
503 /* cache and MMU translation functions */
504 uint32_t (* virt_to_phys)(void* vaddr);
505 void (* cache_flush)(uint32_t* start_adr, uint32_t* end_adr);
506
507 /* event handlers for endpoints. */
508 USB_EP_HANDLER_T ep_event_hdlr[2 * USB_MAX_EP_NUM];
509 void* ep_hdlr_data[2 * USB_MAX_EP_NUM];
510
511 /* USB class handlers */
512 USB_EP_HANDLER_T ep0_hdlr_cb[USB_MAX_IF_NUM];
513 void* ep0_cb_data[USB_MAX_IF_NUM];
514 uint8_t num_ep0_hdlrs;
515 /* USB Core data Variables */
516 uint8_t max_num_ep; /* max number of endpoints supported by the HW */
517 uint8_t device_speed;
518 uint8_t num_interfaces;
519 uint8_t device_addr;
520 uint8_t config_value;
521 uint16_t device_status;
522 uint8_t *device_desc;
523 uint8_t *string_desc;
524 uint8_t *full_speed_desc;
525 uint8_t *high_speed_desc;
526 uint8_t *device_qualifier;
527 uint32_t ep_mask;
528 uint32_t ep_halt;
529 uint32_t ep_stall;
530 uint8_t alt_setting[USB_MAX_IF_NUM];
531 /* HW driver data pointer */
532 void* hw_data;
533
534 /* USB Endpoint 0 Data Info */
535 USB_EP_DATA EP0Data;
536
537 /* USB Endpoint 0 Buffer */
538 //ALIGNED(4)
539 uint8_t EP0Buf[64];
540
541 /* USB Setup Packet */
542 //ALIGNED(4)
543 USB_SETUP_PACKET SetupPacket;
544
545 };
546
547 /* USB Core Functions */
548 extern void mwUSB_InitCore(USB_CORE_CTRL_T* pCtrl, USB_CORE_DESCS_T* pdescr, USBD_API_INIT_PARAM_T* param);
549 extern void mwUSB_ResetCore(USBD_HANDLE_T hUsb);
550
551 /* inline functions */
USB_SetSpeedMode(USB_CORE_CTRL_T * pCtrl,uint8_t mode)552 static INLINE void USB_SetSpeedMode(USB_CORE_CTRL_T* pCtrl, uint8_t mode)
553 {
554 pCtrl->device_speed = mode;
555 }
556
USB_IsConfigured(USBD_HANDLE_T hUsb)557 static INLINE bool USB_IsConfigured(USBD_HANDLE_T hUsb)
558 {
559 USB_CORE_CTRL_T* pCtrl = (USB_CORE_CTRL_T*) hUsb;
560 return (bool) (pCtrl->config_value != 0);
561 }
562
563 /** @cond DIRECT_API */
564 /* midleware API */
565 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);
566 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);
567 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb);
568 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);
569 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb);
570 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb);
571 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);
572 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);
573 extern ErrorCode_t mwUSB_RegisterClassHandler(USBD_HANDLE_T hUsb, USB_EP_HANDLER_T pfn, void* data);
574 extern ErrorCode_t mwUSB_RegisterEpHandler(USBD_HANDLE_T hUsb, uint32_t ep_index, USB_EP_HANDLER_T pfn, void* data);
575 extern void mwUSB_SetupStage (USBD_HANDLE_T hUsb);
576 extern void mwUSB_DataInStage(USBD_HANDLE_T hUsb);
577 extern void mwUSB_DataOutStage(USBD_HANDLE_T hUsb);
578 extern void mwUSB_StatusInStage(USBD_HANDLE_T hUsb);
579 extern void mwUSB_StatusOutStage(USBD_HANDLE_T hUsb);
580 extern void mwUSB_StallEp0(USBD_HANDLE_T hUsb);
581 /** @endcond */
582
583 /** @endcond */
584
585 #endif /* __MW_USBD_CORE_H__ */
586