1 /***********************************************************************
2 * $Id:: mw_usbd_cdcuser.h 331 2012-08-09 18:54:34Z usb10131                   $
3 *
4 * Project: USB device ROM Stack
5 *
6 * Description:
7 *     USB Communication Device Class User module Definitions.
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 __CDCUSER_H__
25 #define __CDCUSER_H__
26 
27 #include "error.h"
28 #include "usbd.h"
29 #include "usbd_cdc.h"
30 
31 /** \file
32  *  \brief Communication Device Class (CDC) API structures and function prototypes.
33  *
34  *  Definition of functions exported by ROM based CDC function driver.
35  *
36  */
37 
38 /** \ingroup Group_USBD
39  *  @defgroup USBD_CDC Communication Device Class (CDC) Function Driver
40  *  \section Sec_CDCModDescription Module Description
41  *  CDC Class Function Driver module. This module contains an internal implementation of the USB CDC Class.
42  *
43  *  User applications can use this class driver instead of implementing the CDC-ACM class manually
44  *  via the low-level USBD_HW and USBD_Core APIs.
45  *
46  *  This module is designed to simplify the user code by exposing only the required interface needed to interface with
47  *  Devices using the USB CDC-ACM Class.
48  */
49 
50 /*----------------------------------------------------------------------------
51   We need a buffer for incoming data on USB port because USB receives
52   much faster than  UART transmits
53  *---------------------------------------------------------------------------*/
54 /* Buffer masks */
55 #define CDC_BUF_SIZE               (128)               /* Output buffer in bytes (power 2) */
56                                                        /* large enough for file transfer */
57 #define CDC_BUF_MASK               (CDC_BUF_SIZE-1ul)
58 
59 /** \brief Communication Device Class function driver initialization parameter data structure.
60  *  \ingroup USBD_CDC
61  *
62  *  \details  This data structure is used to pass initialization parameters to the
63  *  Communication Device Class function driver's init function.
64  *
65  */
66 typedef struct USBD_CDC_INIT_PARAM
67 {
68   /* memory allocation params */
69   uint32_t mem_base;  /**< Base memory location from where the stack can allocate
70                       data and buffers. \note The memory address set in this field
71                       should be accessible by USB DMA controller. Also this value
72                       should be aligned on 4 byte boundary.
73                       */
74   uint32_t mem_size;  /**< The size of memory buffer which stack can use.
75                       \note The \em mem_size should be greater than the size
76                       returned by USBD_CDC_API::GetMemSize() routine.*/
77   /** Pointer to the control interface descriptor within the descriptor
78   * array (\em high_speed_desc) passed to Init() through \ref USB_CORE_DESCS_T
79   * structure. The stack assumes both HS and FS use same BULK endpoints.
80   */
81   uint8_t* cif_intf_desc;
82   /** Pointer to the data interface descriptor within the descriptor
83   * array (\em high_speed_desc) passed to Init() through \ref USB_CORE_DESCS_T
84   * structure. The stack assumes both HS and FS use same BULK endpoints.
85   */
86   uint8_t* dif_intf_desc;
87 
88   /* user defined functions */
89 
90   /* required functions */
91   /**
92   *  Communication Interface Class specific get request call-back function.
93   *
94   *  This function is provided by the application software. This function gets called
95   *  when host sends CIC management element get requests.
96   *  \note Applications implementing Abstract Control Model subclass can set this
97   *  param to NULL. As the default driver parses ACM requests and calls the
98   *  individual ACM call-back routines defined in this structure. For all other subclasses
99   *  this routine should be provided by the application.
100   *  \n
101   *  The setup packet data (\em pSetup) is passed to the call-back so that application
102   *  can extract the CIC request type and other associated data. By default the stack
103   *  will assign \em pBuffer pointer to \em EP0Buff allocated at init. The application
104   *  code can directly write data into this buffer as long as data is less than 64 byte.
105   *  If more data has to be sent then application code should update \em pBuffer pointer
106   *  and length accordingly.
107   *
108   *
109   *  \param[in] hCdc Handle to CDC function driver.
110   *  \param[in] pSetup Pointer to setup packet received from host.
111   *  \param[in, out] pBuffer  Pointer to a pointer of data buffer containing request data.
112   *                       Pointer-to-pointer is used to implement zero-copy buffers.
113   *                       See \ref USBD_ZeroCopy for more details on zero-copy concept.
114   *  \param[in, out] length  Amount of data to be sent back to host.
115   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
116   *          \retval LPC_OK On success.
117   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
118   *          \retval ERR_USBD_xxx  For other error conditions.
119   *
120   */
121   ErrorCode_t (*CIC_GetRequest)( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* length);
122 
123   /**
124   *  Communication Interface Class specific set request call-back function.
125   *
126   *  This function is provided by the application software. This function gets called
127   *  when host sends a CIC management element requests.
128   *  \note Applications implementing Abstract Control Model subclass can set this
129   *  param to NULL. As the default driver parses ACM requests and calls the
130   *  individual ACM call-back routines defined in this structure. For all other subclasses
131   *  this routine should be provided by the application.
132   *  \n
133   *  The setup packet data (\em pSetup) is passed to the call-back so that application can
134   *  extract the CIC request type and other associated data. If a set request has data associated,
135   *  then this call-back is called twice.
136   *  -# First when setup request is received, at this time application code could update
137   *  \em pBuffer pointer to point to the intended destination. The length param is set to 0
138   *  so that application code knows this is first time. By default the stack will
139   *  assign \em pBuffer pointer to \em EP0Buff allocated at init. Note, if data length is
140   *  greater than 64 bytes and application code doesn't update \em pBuffer pointer the
141   *  stack will send STALL condition to host.
142   *  -# Second when the data is received from the host. This time the length param is set
143   *  with number of data bytes received.
144   *
145   *  \param[in] hCdc Handle to CDC function driver.
146   *  \param[in] pSetup Pointer to setup packet received from host.
147   *  \param[in, out] pBuffer  Pointer to a pointer of data buffer containing request data.
148   *                       Pointer-to-pointer is used to implement zero-copy buffers.
149   *                       See \ref USBD_ZeroCopy for more details on zero-copy concept.
150   *  \param[in] length  Amount of data copied to destination buffer.
151   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
152   *          \retval LPC_OK On success.
153   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
154   *          \retval ERR_USBD_xxx  For other error conditions.
155   *
156   */
157   ErrorCode_t (*CIC_SetRequest)( USBD_HANDLE_T hCdc, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length);
158 
159   /**
160   *  Communication Device Class specific BULK IN endpoint handler.
161   *
162   *  The application software should provide the BULK IN endpoint handler.
163   *  Applications should transfer data depending on the communication protocol type set in descriptors.
164   *  \n
165   *  \note
166   *
167   *  \param[in] hUsb Handle to the USB device stack.
168   *  \param[in] data Pointer to the data which will be passed when callback function is called by the stack.
169   *  \param[in] event  Type of endpoint event. See \ref USBD_EVENT_T for more details.
170   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
171   *          \retval LPC_OK On success.
172   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
173   *          \retval ERR_USBD_xxx  For other error conditions.
174   *
175   */
176   ErrorCode_t (*CDC_BulkIN_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
177 
178   /**
179   *  Communication Device Class specific BULK OUT endpoint handler.
180   *
181   *  The application software should provide the BULK OUT endpoint handler.
182   *  Applications should transfer data depending on the communication protocol type set in descriptors.
183   *  \n
184   *  \note
185   *
186   *  \param[in] hUsb Handle to the USB device stack.
187   *  \param[in] data Pointer to the data which will be passed when callback function is called by the stack.
188   *  \param[in] event  Type of endpoint event. See \ref USBD_EVENT_T for more details.
189   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
190   *          \retval LPC_OK On success.
191   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
192   *          \retval ERR_USBD_xxx  For other error conditions.
193   *
194   */
195   ErrorCode_t (*CDC_BulkOUT_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
196 
197   /**
198   *  Abstract control model(ACM) subclass specific SEND_ENCAPSULATED_COMMAND request call-back function.
199   *
200   *  This function is provided by the application software. This function gets called
201   *  when host sends a SEND_ENCAPSULATED_COMMAND set request.
202   *
203   *  \param[in] hCdc Handle to CDC function driver.
204   *  \param[in] buffer Pointer to the command buffer.
205   *  \param[in] len  Length of the command buffer.
206   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
207   *          \retval LPC_OK On success.
208   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
209   *          \retval ERR_USBD_xxx  For other error conditions.
210   *
211   */
212   ErrorCode_t (*SendEncpsCmd) (USBD_HANDLE_T hCDC, uint8_t* buffer, uint16_t len);
213 
214   /**
215   *  Abstract control model(ACM) subclass specific GET_ENCAPSULATED_RESPONSE request call-back function.
216   *
217   *  This function is provided by the application software. This function gets called
218   *  when host sends a GET_ENCAPSULATED_RESPONSE request.
219   *
220   *  \param[in] hCdc Handle to CDC function driver.
221   *  \param[in, out] buffer Pointer to a pointer of data buffer containing response data.
222   *                       Pointer-to-pointer is used to implement zero-copy buffers.
223   *                       See \ref USBD_ZeroCopy for more details on zero-copy concept.
224   *  \param[in, out] len  Amount of data to be sent back to host.
225   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
226   *          \retval LPC_OK On success.
227   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
228   *          \retval ERR_USBD_xxx  For other error conditions.
229   *
230   */
231   ErrorCode_t (*GetEncpsResp) (USBD_HANDLE_T hCDC, uint8_t** buffer, uint16_t* len);
232 
233   /**
234   *  Abstract control model(ACM) subclass specific SET_COMM_FEATURE request call-back function.
235   *
236   *  This function is provided by the application software. This function gets called
237   *  when host sends a SET_COMM_FEATURE set request.
238   *
239   *  \param[in] hCdc Handle to CDC function driver.
240   *  \param[in] feature Communication feature type. See usbcdc11.pdf, section 6.2.4, Table 47.
241   *  \param[in] buffer Pointer to the settings buffer for the specified communication feature.
242   *  \param[in] len  Length of the request buffer.
243   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
244   *          \retval LPC_OK On success.
245   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
246   *          \retval ERR_USBD_xxx  For other error conditions.
247   *
248   */
249   ErrorCode_t (*SetCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature, uint8_t* buffer, uint16_t len);
250 
251   /**
252   *  Abstract control model(ACM) subclass specific GET_COMM_FEATURE request call-back function.
253   *
254   *  This function is provided by the application software. This function gets called
255   *  when host sends a GET_ENCAPSULATED_RESPONSE request.
256   *
257   *  \param[in] hCdc Handle to CDC function driver.
258   *  \param[in] feature Communication feature type. See usbcdc11.pdf, section 6.2.4, Table 47.
259   *  \param[in, out] buffer Pointer to a pointer of data buffer containing current settings
260   *                         for the communication feature.
261   *                       Pointer-to-pointer is used to implement zero-copy buffers.
262   *  \param[in, out] len  Amount of data to be sent back to host.
263   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
264   *          \retval LPC_OK On success.
265   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
266   *          \retval ERR_USBD_xxx  For other error conditions.
267   *
268   */
269   ErrorCode_t (*GetCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature, uint8_t** pBuffer, uint16_t* len);
270 
271   /**
272   *  Abstract control model(ACM) subclass specific CLEAR_COMM_FEATURE request call-back function.
273   *
274   *  This function is provided by the application software. This function gets called
275   *  when host sends a CLEAR_COMM_FEATURE request. In the call-back the application
276   *  should Clears the settings for a particular communication feature.
277   *
278   *  \param[in] hCdc Handle to CDC function driver.
279   *  \param[in] feature Communication feature type. See usbcdc11.pdf, section 6.2.4, Table 47.
280   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
281   *          \retval LPC_OK On success.
282   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
283   *          \retval ERR_USBD_xxx  For other error conditions.
284   *
285   */
286   ErrorCode_t (*ClrCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature);
287 
288   /**
289   *  Abstract control model(ACM) subclass specific SET_CONTROL_LINE_STATE request call-back function.
290   *
291   *  This function is provided by the application software. This function gets called
292   *  when host sends a SET_CONTROL_LINE_STATE request. RS-232 signal used to tell the DCE
293   *  device the DTE device is now present
294   *
295   *  \param[in] hCdc Handle to CDC function driver.
296   *  \param[in] state The state value uses bitmap values defined in usbcdc11.pdf,
297   *        section 6.2.14, Table 51.
298   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
299   *          \retval LPC_OK On success.
300   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
301   *          \retval ERR_USBD_xxx  For other error conditions.
302   *
303   */
304   ErrorCode_t (*SetCtrlLineState) (USBD_HANDLE_T hCDC, uint16_t state);
305 
306   /**
307   *  Abstract control model(ACM) subclass specific SEND_BREAK request call-back function.
308   *
309   *  This function is provided by the application software. This function gets called
310   *  when host sends a SEND_BREAK request.
311   *
312   *  \param[in] hCdc Handle to CDC function driver.
313   *  \param[in] mstime Duration of Break signal in milliseconds. If mstime is FFFFh, then
314   *        the application should send break until another SendBreak request is received
315   *        with the wValue of 0000h.
316   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
317   *          \retval LPC_OK On success.
318   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
319   *          \retval ERR_USBD_xxx  For other error conditions.
320   *
321   */
322   ErrorCode_t (*SendBreak) (USBD_HANDLE_T hCDC, uint16_t mstime);
323 
324   /**
325   *  Abstract control model(ACM) subclass specific SET_LINE_CODING request call-back function.
326   *
327   *  This function is provided by the application software. This function gets called
328   *  when host sends a SET_LINE_CODING request. The application should configure the device
329   *  per DTE rate, stop-bits, parity, and number-of-character bits settings provided in
330   *  command buffer. See usbcdc11.pdf, section 6.2.13, table 50 for detail of the command buffer.
331   *
332   *  \param[in] hCdc Handle to CDC function driver.
333   *  \param[in] line_coding Pointer to the CDC_LINE_CODING command buffer.
334   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
335   *          \retval LPC_OK On success.
336   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
337   *          \retval ERR_USBD_xxx  For other error conditions.
338   *
339   */
340   ErrorCode_t (*SetLineCode) (USBD_HANDLE_T hCDC, CDC_LINE_CODING* line_coding);
341 
342   /**
343   *  Optional Communication Device Class specific INTERRUPT IN endpoint handler.
344   *
345   *  The application software should provide the INT IN endpoint handler.
346   *  Applications should transfer data depending on the communication protocol type set in descriptors.
347   *  \n
348   *  \note
349   *
350   *  \param[in] hUsb Handle to the USB device stack.
351   *  \param[in] data Pointer to the data which will be passed when callback function is called by the stack.
352   *  \param[in] event  Type of endpoint event. See \ref USBD_EVENT_T for more details.
353   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
354   *          \retval LPC_OK On success.
355   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
356   *          \retval ERR_USBD_xxx  For other error conditions.
357   *
358   */
359   ErrorCode_t (*CDC_InterruptEP_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
360 
361   /**
362   *  Optional user override-able function to replace the default CDC class handler.
363   *
364   *  The application software could override the default EP0 class handler with their
365   *  own by providing the handler function address as this data member of the parameter
366   *  structure. Application which like the default handler should set this data member
367   *  to zero before calling the USBD_CDC_API::Init().
368   *  \n
369   *  \note
370   *
371   *  \param[in] hUsb Handle to the USB device stack.
372   *  \param[in] data Pointer to the data which will be passed when callback function is called by the stack.
373   *  \param[in] event  Type of endpoint event. See \ref USBD_EVENT_T for more details.
374   *  \return The call back should returns \ref ErrorCode_t type to indicate success or error condition.
375   *          \retval LPC_OK On success.
376   *          \retval ERR_USBD_UNHANDLED  Event is not handled hence pass the event to next in line.
377   *          \retval ERR_USBD_xxx  For other error conditions.
378   *
379   */
380   ErrorCode_t (*CDC_Ep0_Hdlr) (USBD_HANDLE_T hUsb, void* data, uint32_t event);
381 
382 } USBD_CDC_INIT_PARAM_T;
383 
384 /** \brief CDC class API functions structure.
385  *  \ingroup USBD_CDC
386  *
387  *  This module exposes functions which interact directly with USB device controller hardware.
388  *
389  */
390 typedef struct USBD_CDC_API
391 {
392   /** \fn uint32_t GetMemSize(USBD_CDC_INIT_PARAM_T* param)
393    *  Function to determine the memory required by the CDC function driver module.
394    *
395    *  This function is called by application layer before calling pUsbApi->CDC->Init(), to allocate memory used
396    *  by CDC function driver module. The application should allocate the memory which is accessible by USB
397    *  controller/DMA controller.
398    *  \note Some memory areas are not accessible by all bus masters.
399    *
400    *  \param[in] param Structure containing CDC function driver module initialization parameters.
401    *  \return Returns the required memory size in bytes.
402    */
403   uint32_t (*GetMemSize)(USBD_CDC_INIT_PARAM_T* param);
404 
405   /** \fn ErrorCode_t init(USBD_HANDLE_T hUsb, USBD_CDC_INIT_PARAM_T* param)
406    *  Function to initialize CDC function driver module.
407    *
408    *  This function is called by application layer to initialize CDC function driver module.
409    *
410    *  \param[in] hUsb Handle to the USB device stack.
411    *  \param[in, out] param Structure containing CDC function driver module initialization parameters.
412    *  \return Returns \ref ErrorCode_t type to indicate success or error condition.
413    *          \retval LPC_OK On success
414    *          \retval ERR_USBD_BAD_MEM_BUF  Memory buffer passed is not 4-byte
415    *              aligned or smaller than required.
416    *          \retval ERR_API_INVALID_PARAM2 Either CDC_Write() or CDC_Read() or
417    *              CDC_Verify() callbacks are not defined.
418    *          \retval ERR_USBD_BAD_INTF_DESC  Wrong interface descriptor is passed.
419    *          \retval ERR_USBD_BAD_EP_DESC  Wrong endpoint descriptor is passed.
420    */
421   ErrorCode_t (*init)(USBD_HANDLE_T hUsb, USBD_CDC_INIT_PARAM_T* param, USBD_HANDLE_T* phCDC);
422 
423   /** \fn ErrorCode_t SendNotification(USBD_HANDLE_T hCdc, uint8_t bNotification, uint16_t data)
424    *  Function to send CDC class notifications to host.
425    *
426    *  This function is called by application layer to send CDC class notifications to host.
427    *  See usbcdc11.pdf, section 6.3, Table 67 for various notification types the CDC device can send.
428    *  \note The current version of the driver only supports following notifications allowed by ACM subclass:
429    *  CDC_NOTIFICATION_NETWORK_CONNECTION, CDC_RESPONSE_AVAILABLE, CDC_NOTIFICATION_SERIAL_STATE.
430    *  \n
431    *  For all other notifications application should construct the notification buffer appropriately
432    *  and call hw->USB_WriteEP() for interrupt endpoint associated with the interface.
433    *
434    *  \param[in] hCdc Handle to CDC function driver.
435    *  \param[in] bNotification Notification type allowed by ACM subclass. Should be CDC_NOTIFICATION_NETWORK_CONNECTION,
436    *        CDC_RESPONSE_AVAILABLE or CDC_NOTIFICATION_SERIAL_STATE. For all other types ERR_API_INVALID_PARAM2
437    *        is returned. See usbcdc11.pdf, section 3.6.2.1, table 5.
438    *  \param[in] data Data associated with notification.
439    *        \n For CDC_NOTIFICATION_NETWORK_CONNECTION a non-zero data value is interpreted as connected state.
440    *        \n For CDC_RESPONSE_AVAILABLE this parameter is ignored.
441    *        \n For CDC_NOTIFICATION_SERIAL_STATE the data should use bitmap values defined in usbcdc11.pdf,
442    *        section 6.3.5, Table 69.
443    *  \return Returns \ref ErrorCode_t type to indicate success or error condition.
444    *          \retval LPC_OK On success
445    *          \retval ERR_API_INVALID_PARAM2  If unsupported notification type is passed.
446    *
447    */
448   ErrorCode_t (*SendNotification)(USBD_HANDLE_T hCdc, uint8_t bNotification, uint16_t data);
449 
450 } USBD_CDC_API_T;
451 
452 /*-----------------------------------------------------------------------------
453  *  Private functions & structures prototypes
454  *-----------------------------------------------------------------------------*/
455 /** @cond  ADVANCED_API */
456 
457 typedef struct _CDC_CTRL_T
458 {
459   USB_CORE_CTRL_T*  pUsbCtrl;
460   /* notification buffer */
461   uint8_t notice_buf[12];
462   CDC_LINE_CODING line_coding;
463   uint8_t pad0;
464 
465   uint8_t cif_num;                 /* control interface number */
466   uint8_t dif_num;                 /* data interface number */
467   uint8_t epin_num;                /* BULK IN endpoint number */
468   uint8_t epout_num;               /* BULK OUT endpoint number */
469   uint8_t epint_num;               /* Interrupt IN endpoint number */
470   uint8_t pad[3];
471   /* user defined functions */
472   ErrorCode_t (*SendEncpsCmd) (USBD_HANDLE_T hCDC, uint8_t* buffer, uint16_t len);
473   ErrorCode_t (*GetEncpsResp) (USBD_HANDLE_T hCDC, uint8_t** buffer, uint16_t* len);
474   ErrorCode_t (*SetCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature, uint8_t* buffer, uint16_t len);
475   ErrorCode_t (*GetCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature, uint8_t** pBuffer, uint16_t* len);
476   ErrorCode_t (*ClrCommFeature) (USBD_HANDLE_T hCDC, uint16_t feature);
477   ErrorCode_t (*SetCtrlLineState) (USBD_HANDLE_T hCDC, uint16_t state);
478   ErrorCode_t (*SendBreak) (USBD_HANDLE_T hCDC, uint16_t state);
479   ErrorCode_t (*SetLineCode) (USBD_HANDLE_T hCDC, CDC_LINE_CODING* line_coding);
480 
481   /* virtual functions */
482   ErrorCode_t (*CIC_GetRequest)( USBD_HANDLE_T hHid, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t* length);
483   ErrorCode_t (*CIC_SetRequest)( USBD_HANDLE_T hCdc, USB_SETUP_PACKET* pSetup, uint8_t** pBuffer, uint16_t length);
484 
485 } USB_CDC_CTRL_T;
486 
487 /* structure used by old ROM drivers, needed for workaround */
488 typedef struct _CDC0_CTRL_T {
489 	USB_CORE_CTRL_T *pUsbCtrl;
490 	/* notification buffer */
491 	uint8_t notice_buf[12];
492 	CDC_LINE_CODING line_coding;
493 
494 	uint8_t cif_num;				/* control interface number */
495 	uint8_t dif_num;				/* data interface number */
496 	uint8_t epin_num;				/* BULK IN endpoint number */
497 	uint8_t epout_num;				/* BULK OUT endpoint number */
498 	uint8_t epint_num;				/* Interrupt IN endpoint number */
499 	/* user defined functions */
500 	ErrorCode_t (*SendEncpsCmd)(USBD_HANDLE_T hCDC, uint8_t *buffer, uint16_t len);
501 	ErrorCode_t (*GetEncpsResp)(USBD_HANDLE_T hCDC, uint8_t * *buffer, uint16_t *len);
502 	ErrorCode_t (*SetCommFeature)(USBD_HANDLE_T hCDC, uint16_t feature, uint8_t *buffer, uint16_t len);
503 	ErrorCode_t (*GetCommFeature)(USBD_HANDLE_T hCDC, uint16_t feature, uint8_t * *pBuffer, uint16_t *len);
504 	ErrorCode_t (*ClrCommFeature)(USBD_HANDLE_T hCDC, uint16_t feature);
505 	ErrorCode_t (*SetCtrlLineState)(USBD_HANDLE_T hCDC, uint16_t state);
506 	ErrorCode_t (*SendBreak)(USBD_HANDLE_T hCDC, uint16_t state);
507 	ErrorCode_t (*SetLineCode)(USBD_HANDLE_T hCDC, CDC_LINE_CODING *line_coding);
508 
509 	/* virtual functions */
510 	ErrorCode_t (*CIC_GetRequest)(USBD_HANDLE_T hHid, USB_SETUP_PACKET *pSetup, uint8_t * *pBuffer, uint16_t *length);
511 	ErrorCode_t (*CIC_SetRequest)(USBD_HANDLE_T hCdc, USB_SETUP_PACKET *pSetup, uint8_t * *pBuffer, uint16_t length);
512 
513 } USB_CDC0_CTRL_T;
514 
515 typedef ErrorCode_t (*CIC_SetRequest_t)(USBD_HANDLE_T hCdc, USB_SETUP_PACKET *pSetup, uint8_t * *pBuffer, uint16_t length);
516 
517 /** @cond  DIRECT_API */
518 extern uint32_t mwCDC_GetMemSize(USBD_CDC_INIT_PARAM_T* param);
519 extern ErrorCode_t mwCDC_init(USBD_HANDLE_T hUsb, USBD_CDC_INIT_PARAM_T* param, USBD_HANDLE_T* phCDC);
520 extern ErrorCode_t mwCDC_SendNotification (USBD_HANDLE_T hCdc, uint8_t bNotification, uint16_t data);
521 /** @endcond */
522 
523 /** @endcond */
524 
525 
526 
527 
528 
529 #endif  /* __CDCUSER_H__ */
530