1 /*
2  * Copyright (c) 2015 - 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 
9 #ifndef __USB_HOST_CDC_H__
10 #define __USB_HOST_CDC_H__
11 
12 /*!
13  * @addtogroup usb_host_cdc_drv
14  * @{
15  */
16 
17 /*******************************************************************************
18  * Definitions
19  ******************************************************************************/
20 
21 /* Class-specific request */
22 /* CDC 1.2 */
23 /*! @brief CDC class-specific request (SEND_ENCAPSULATED_COMMAND) */
24 #define USB_HOST_CDC_SEND_ENCAPSULATED_COMMAND 0x00U
25 /*! @brief CDC class-specific request (GET_ENCAPSULATED_RESPONSE) */
26 #define USB_HOST_CDC_GET_ENCAPSULATED_RESPONSE 0x01U
27 /* PSTN */
28 /*! @brief CDC class-specific request (SET_LINE_CODING) */
29 #define USB_HOST_CDC_SET_LINE_CODING 0x20U
30 /*! @brief CDC class-specific request (GET_LINE_CODING) */
31 #define USB_HOST_CDC_GET_LINE_CODING 0x21U
32 /*! @brief CDC class-specific request (SET_CONTROL_LINE_STATE) */
33 #define USB_HOST_CDC_SET_CONTROL_LINE_STATE 0x22U
34 
35 /*! @brief CDC class-specific notifications(SerialState) bitmap*/
36 #define USB_HOST_ACM_UART_STATE_BITMAP_BTXCARRITER 0x01U
37 /*! @brief CDC class-specific notifications(SerialState) bitmap*/
38 #define USB_HOST_ACM_UART_STATE_BITMAP_BRXCARRITER 0x02U
39 /*! @brief CDC class-specific notifications(SerialState) bitmap*/
40 #define USB_HOST_ACM_UART_STATE_BITMAP_BBREAK 0x04U
41 /*! @brief CDC class-specific notifications(SerialState) bitmap*/
42 #define USB_HOST_ACM_UART_STATE_BITMAP_BBRINGSIGNAL 0x10U
43 
44 /*! @brief CDC class-specific request (SET_CONTROL_LINE_STATE) bitmap*/
45 #define USB_HOST_CDC_CONTROL_LINE_STATE_DTR 0x01U
46 /*! @brief CDC class-specific request (SET_CONTROL_LINE_STATE) bitmap*/
47 #define USB_HOST_CDC_CONTROL_LINE_STATE_RTS 0x02U
48 
49 /*CDC SPEC*/
50 /*! @brief CDC class-specific bDescriptor SubType in functional descriptors*/
51 #define USB_HOST_DESC_SUBTYPE_HEADER 0x00U
52 /*! @brief CDC class-specific bDescriptor SubType in functional descriptors*/
53 #define USB_HOST_DESC_SUBTYPE_CM 0x01U
54 /*! @brief CDC class-specific bDescriptor SubType in functional descriptors*/
55 #define USB_HOST_DESC_SUBTYPE_ACM 0x02U
56 /*! @brief CDC class-specific bDescriptor SubType in functional descriptors*/
57 #define USB_HOST_DESC_SUBTYPE_DLM 0x03U
58 /*! @brief CDC class-specific bDescriptor SubType in functional descriptors*/
59 #define USB_HOST_DESC_SUBTYPE_TR 0x04U
60 /*! @brief CDC class-specific bDescriptor SubType in functional descriptors*/
61 #define USB_HOST_DESC_SUBTYPE_TC_LSR 0x05U
62 /*! @brief CDC class-specific bDescriptor SubType in functional descriptors*/
63 #define USB_HOST_DESC_SUBTYPE_UNION 0x06U
64 /*! @brief CDC class-specific bDescriptor SubType in functional descriptors*/
65 #define USB_HOST_DESC_SUBTYPE_CS 0x07U
66 /*! @brief CDC class-specific bDescriptor SubType in functional descriptors*/
67 #define USB_HOST_DESC_SUBTYPE_TOM 0x08U
68 
69 /*See the CDC specification page20*/
70 /*! @brief CDC class-specific code, Communications Interface Class Code*/
71 #define USB_HOST_CDC_COMMUNICATIONS_CLASS_CODE 0x02U
72 /*! @brief CDC class-specific code,Communications Class Subclass Codes*/
73 #define USB_HOST_CDC_SUBCLASS_ACM_CODE 0x02U
74 /*No class specific protocol required. See the CDC specification page22*/
75 #define USB_HOST_CDC_PROTOCOL_CODE 0x00U
76 /*! @brief CDC class-specific code,Data Class Interface Codes*/
77 #define USB_HOST_CDC_DATA_CLASS_CODE 0x0AU
78 /* This field is unused for Data Class interfaces and should have a value of 00h.*/
79 #define USB_HOST_CDC_DATA_SUBCLASS_CODE 0x00U
80 /*No class-specific protocol required. See the CDC specification page22*/
81 #define USB_HOST_CDC_DATA_PROTOCOL_CODE 0x00U
82 
83 /*! @brief CDC GetLineCoding structure according to the 6.3 in PSTN specification */
84 typedef struct _usb_host_cdc_line_coding_struct
85 {
86     uint32_t dwDTERate;  /*!< Data terminal rate, in bits per second*/
87     uint8_t bCharFormat; /*!< Stop bits*/
88     uint8_t bParityType; /*!< Parity*/
89     uint8_t bDataBits;   /*!< Data bits (5, 6, 7, 8 or 16).*/
90 } usb_host_cdc_line_coding_struct_t;
91 
92 /*! @brief CDC GetLineCoding structure according to the 6.3 in PSTN specification */
93 typedef struct _usb_host_cdc_control_line_state_struct
94 {
95     uint16_t line_state; /*!< D1, This signal corresponds to V.24 signal 105 and RS-232 signal RTS*/
96                          /*!< D0, This signal corresponds to V.24 signal 108/2 and RS-232 signal DTR*/
97 } usb_host_cdc_control_line_state_struct_t;
98 
99 /*! @brief CDC SerialState structure according to the 6.5.4 in PSTN specification */
100 typedef struct _usb_host_cdc_acm_state_struct
101 {
102     uint8_t reserved[8];  /*!< Notify response by the device, this is used as notification header which is return by the
103                              device */
104     uint8_t bmstate;      /*!< UART State Bitmap Values*/
105     uint8_t reserved1[1]; /*!< Fix 4B align issue*/
106     uint8_t reserved2[2]; /*!< Fix 4B align issue*/
107 } usb_host_cdc_acm_state_struct_t;
108 
109 /*! @brief CDC Header Functional Descriptor structure according to the 5.2.3 in CDC specification */
110 typedef struct _usb_host_cdc_head_function_desc_struct
111 {
112     uint8_t bFunctionLength;    /*!<Size of this descriptor in bytes.*/
113     uint8_t bDescriptorType;    /*!<CS_INTERFACE descriptor type.*/
114     uint8_t bDescriptorSubtype; /*!<Header functional descriptor subtype.*/
115     uint8_t bcdCDC[2]; /*!<USB Class Definitions for Communications Devices Specification release number in binary-coded
116                           decimal.*/
117 } usb_host_cdc_head_function_desc_struct_t;
118 
119 /*! @brief CDC Call Management Functional Descriptor structure according to the 5.3.1 in PSTN specification */
120 typedef struct _usb_host_cdc_call_manage_desc_struct
121 {
122     uint8_t bFunctionLength;    /*!<Size of this descriptor in bytes.*/
123     uint8_t bDescriptorType;    /*!<CS_INTERFACE.*/
124     uint8_t bDescriptorSubtype; /*!<Call Management functional descriptor subtype.*/
125     uint8_t bmCapabilities;     /*!<The capabilities that this configuration supports.*/
126     uint8_t bDataInterface;     /*!<Interface number of Data Class interface optionally used for call management.*/
127 } usb_host_cdc_call_manage_desc_struct_t;
128 
129 /*! @brief CDC Abstract Control Management Functional Descriptor structure according to the 5.3.2 in PSTN specification
130  */
131 typedef struct _usb_host_cdc_abstract_control_desc_struct
132 {
133     uint8_t bFunctionLength;    /*!<Size of this descriptor in bytes.*/
134     uint8_t bDescriptorType;    /*!<CS_INTERFACE.*/
135     uint8_t bDescriptorSubtype; /*!<Abstract Control Management functional descriptor subtype.*/
136     uint8_t bmCapabilities;     /*!<The capabilities that this configuration supports.*/
137 } usb_host_cdc_abstract_control_desc_struct_t;
138 
139 /*! @brief CDC Direct Line Management Functional Descriptor structure according to the 5.3.3 in PSTN specification */
140 typedef struct _usb_host_cdc_direct_line_desc_struct
141 {
142     uint8_t bFunctionLength;    /*!<Size of this descriptor in bytes.*/
143     uint8_t bDescriptorType;    /*!<CS_INTERFACE.*/
144     uint8_t bDescriptorSubtype; /*!<Direct Line Management functional descriptor subtype,.*/
145     uint8_t bmCapabilities;     /*!<The capabilities that this configuration supports.*/
146 } usb_host_cdc_direct_line_desc_struct_t;
147 
148 /*! @brief CDC Telephone Ringer Functional Descriptor structure according to the 5.3.4 in PSTN specification */
149 typedef struct _usb_host_cdc_telephone_ringer_desc_struct
150 {
151     uint8_t bFunctionLength;    /*!<Size of this descriptor in bytes.*/
152     uint8_t bDescriptorType;    /*!<CS_INTERFACE.*/
153     uint8_t bDescriptorSubtype; /*!<Telephone Ringer functional descriptor subtype*/
154     uint8_t bRingerVolSteps;    /*!<Number of discrete steps in volume supported by the ringer,.*/
155     uint8_t bNumRingerPatterns; /*!<Number of ringer patterns supported.*/
156 } usb_host_cdc_telephone_ringer_desc_struct_t;
157 
158 /*! @brief CDC Telephone Call and Line State Reporting Capabilities Descriptor structure according to the 5.3.6 in PSTN
159  * specification */
160 typedef struct _usb_host_cdc_tcLsr_desc_struct
161 {
162     uint8_t bFunctionLength;    /*!<Size of this descriptor in bytes.*/
163     uint8_t bDescriptorType;    /*!<CS_INTERFACE.*/
164     uint8_t bDescriptorSubtype; /*!<Telephone Call State Reporting Capabilities descriptor subtype.*/
165     uint8_t bmCapabilities[4];  /*!<Call and line state reporting capabilities of the device.*/
166 } usb_host_cdc_tcLsr_desc_struct_t;
167 
168 /*! @brief CDC Header Functional Descriptor structure according to the 5.2.3 in CDC specification */
169 typedef struct _usb_host_cdc_union_interface_desc_struct
170 {
171     uint8_t bFunctionLength;    /*!<Size of this descriptor in bytes.*/
172     uint8_t bDescriptorType;    /*!<CS_INTERFACE descriptor type.*/
173     uint8_t bDescriptorSubtype; /*!<Union Functional Descriptor SubType.*/
174     uint8_t bControlInterface;  /*!<USB Class Definitions for Communications Devices Specification release number in
175                                    binary-coded decimal.*/
176 } usb_host_cdc_union_interface_desc_struct_t;
177 
178 /*! @brief CDC Telephone Operational Modes Functional Descriptor structure according to the 5.3.5 in PSTN specification
179  */
180 typedef struct _usb_host_cdc_tom_desc_struct
181 {
182     uint8_t bFunctionLength;    /*!<Size of this descriptor in bytes.*/
183     uint8_t bDescriptorType;    /*!<CS_INTERFACE.*/
184     uint8_t bDescriptorSubtype; /*!<Telephone Operational Modes functional descriptor subtype.*/
185     uint8_t bmCapabilities;     /*!<Operational modes:.*/
186 } usb_host_cdc_tom_desc_struct_t;
187 
188 /*! @brief CDC common Functional Descriptor structure */
189 typedef struct _usb_host_cdc_common_desc_struct
190 {
191     uint8_t bFunctionLength;    /*!<Size of this descriptor in bytes.*/
192     uint8_t bDescriptorType;    /*!<CS_INTERFACE descriptor type.*/
193     uint8_t bDescriptorSubtype; /*!<Header functional descriptor subtype.*/
194 } usb_host_cdc_common_desc_struct_t;
195 
196 /*! @brief CDC union Functional Descriptor structure for analyze a class-specific descriptor */
197 typedef union _usb_cdc_func_desc_struct
198 {
199     usb_host_cdc_common_desc_struct_t common;
200     usb_host_cdc_head_function_desc_struct_t head;
201     usb_host_cdc_union_interface_desc_struct_t unionDesc;
202     usb_host_cdc_call_manage_desc_struct_t callManage;
203     usb_host_cdc_abstract_control_desc_struct_t acm;
204     usb_host_cdc_direct_line_desc_struct_t dl;
205     usb_host_cdc_telephone_ringer_desc_struct_t tr;
206     usb_host_cdc_tom_desc_struct_t tom;
207     usb_host_cdc_tcLsr_desc_struct_t tcLsr;
208 } usb_cdc_func_desc_struct_t;
209 
210 typedef struct _usb_host_cdc_instance_struct
211 {
212     usb_host_handle hostHandle;                             /*!< The handle of the USB host. */
213     usb_device_handle deviceHandle;                         /*!< The handle of the USB device structure. */
214     usb_host_interface_handle controlInterfaceHandle;       /*!< The handle of the CDC device control interface. */
215     usb_host_interface_handle dataInterfaceHandle;          /*!< The handle of the CDC device data interface. */
216     usb_host_pipe_handle interruptPipe;                     /*!< Interrupt pipe for the CDC device data interface. */
217     usb_host_pipe_handle controlPipe;                       /*!< Control pipe*/
218     usb_host_pipe_handle inPipe;                            /*!< CDC bulk in pipe*/
219     usb_host_pipe_handle outPipe;                           /*!< CDC bulk out pipe*/
220     usb_host_cdc_head_function_desc_struct_t *headDesc;     /*!< CDC class-specific head function descriptor*/
221     usb_host_cdc_call_manage_desc_struct_t *callManageDesc; /*!< cdCDCc class-specific call manage descriptor*/
222     usb_host_cdc_abstract_control_desc_struct_t
223         *abstractControlDesc; /*!< CDC class-specific abstract control descriptor*/
224     usb_host_cdc_union_interface_desc_struct_t *unionInterfaceDesc; /*!< CDC class-specific union function descriptor*/
225     void *interruptCallbackParam;                                   /*!< CDC interrupt in transfer callback parameter*/
226     void *controlCallbackParam;                                     /*!< CDC control transfer callback parameter*/
227     void *inCallbackParam;                                          /*!< CDC bulk in transfer callback parameter*/
228     void *outCallbackParam;                                         /*!< CDC bulk out transfer callback parameter*/
229     usb_host_transfer_t *controlTransfer;                           /*!< Ongoing control transfer*/
230     transfer_callback_t controlCallbackFn;   /*!< CDC control transfer callback function pointer*/
231     transfer_callback_t interruptCallbackFn; /*!< CDC interrupt transfer callback function pointer*/
232     transfer_callback_t outCallbackFn;       /*!< CDC bulk out transfer callback function pointer*/
233     transfer_callback_t inCallbackFn;        /*!< CDC bulk in transfer callback function pointer*/
234 #if ((defined USB_HOST_CONFIG_CLASS_AUTO_CLEAR_STALL) && USB_HOST_CONFIG_CLASS_AUTO_CLEAR_STALL)
235     uint8_t *stallDataBuffer; /*!< Keep the data buffer for stall transfer's data*/
236     uint32_t stallDataLength; /*!< Keep the data length for stall transfer's data*/
237 #endif
238     uint16_t packetSize;        /*!< CDC control pipe maximum packet size*/
239     uint16_t bulkOutPacketSize; /*!< CDC bulk out maximum packet size*/
240     uint16_t bulkInPacketSize;  /*!< CDC bulk in maximum packet size*/
241 } usb_host_cdc_instance_struct_t;
242 
243 #ifdef __cplusplus
244 extern "C" {
245 #endif
246 
247 /*******************************************************************************
248  * API
249  ******************************************************************************/
250 
251 /*!
252  * @name USB CDC host class driver
253  * @{
254  */
255 
256 /*!
257  * @brief Initializes the CDC instance.
258  *
259  * This function allocates the resource for the CDC instance.
260  *
261  * @param deviceHandle       The device handle.
262  * @param classHandle Returns class handle.
263  *
264  * @retval kStatus_USB_Success        The device is initialized successfully.
265  * @retval kStatus_USB_AllocFail      Allocate memory fail.
266  */
267 extern usb_status_t USB_HostCdcInit(usb_device_handle deviceHandle, usb_host_class_handle *classHandle);
268 
269 /*!
270  * @brief CDC set data interface callback and opens pipes.
271  *
272  * @param[in] classHandle      The class handle.
273  * @param[in] interfaceHandle  The interface handle.
274  * @param[in] alternateSetting The alternate setting value.
275  * @param[in] callbackFn       This callback is called after this function completes.
276  * @param[in] callbackParam    The first parameter in the callback function.
277  *
278  * @retval kStatus_USB_Success        The device is initialized successfully.
279  * @retval kStatus_USB_InvalidHandle  The classHandle is NULL pointer.
280  * @retval kStatus_USB_Busy           There is no idle transfer.
281  * @retval kStatus_USB_Error          Send transfer fail. See the USB_HostSendSetup.
282  * @retval kStatus_USB_Busy           Callback return status, there is no idle pipe.
283  * @retval kStatus_USB_TransferStall  Callback return status, the transfer is stalled by the device.
284  * @retval kStatus_USB_Error          Callback return status, open pipe fail. See the USB_HostOpenPipe.
285  */
286 
287 extern usb_status_t USB_HostCdcSetDataInterface(usb_host_class_handle classHandle,
288                                                 usb_host_interface_handle interfaceHandle,
289                                                 uint8_t alternateSetting,
290                                                 transfer_callback_t callbackFn,
291                                                 void *callbackParam);
292 
293 /*!
294  * @brief CDC set control interface callback and opens pipes.
295  *
296  * @param[in] classHandle      The class handle.
297  * @param[in] interfaceHandle  The interface handle.
298  * @param[in] alternateSetting The alternate setting value.
299  * @param[in] callbackFn       This callback is called after this function completes.
300  * @param[in] callbackParam    The first parameter in the callback function.
301  *
302  * @retval kStatus_USB_Success        The device is initialized successfully.
303  * @retval kStatus_USB_InvalidHandle  The classHandle is NULL pointer.
304  * @retval kStatus_USB_Busy           There is no idle transfer.
305  * @retval kStatus_USB_Error          Send transfer fail. See the USB_HostSendSetup.
306  * @retval kStatus_USB_Busy           Callback return status, there is no idle pipe.
307  * @retval kStatus_USB_TransferStall  Callback return status, the transfer is stalled by the device.
308  * @retval kStatus_USB_Error          Callback return status, open pipe fail. See the USB_HostOpenPipe.
309  */
310 
311 extern usb_status_t USB_HostCdcSetControlInterface(usb_host_class_handle classHandle,
312                                                    usb_host_interface_handle interfaceHandle,
313                                                    uint8_t alternateSetting,
314                                                    transfer_callback_t callbackFn,
315                                                    void *callbackParam);
316 
317 /*!
318  * @brief Deinitializes the CDC instance.
319  *
320  * This function frees the resource for the CDC instance.
321  *
322  * @param deviceHandle   The device handle.
323  * @param classHandle The class handle.
324  *
325  * @retval kStatus_USB_Success        The device is de-initialized successfully.
326  */
327 extern usb_status_t USB_HostCdcDeinit(usb_device_handle deviceHandle, usb_host_class_handle classHandle);
328 
329 /*!
330  * @brief Gets the pipe maximum packet size.
331  *
332  * @param[in] classHandle The class handle.
333  * @param[in] pipeType    Its value is USB_ENDPOINT_CONTROL, USB_ENDPOINT_ISOCHRONOUS, USB_ENDPOINT_BULK or
334  * USB_ENDPOINT_INTERRUPT.
335  *                        See the usb_spec.h
336  * @param[in] direction   Pipe direction.
337  *
338  * @retval 0        The classHandle is NULL.
339  * @retval max      Packet size.
340  */
341 extern uint16_t USB_HostCdcGetPacketsize(usb_host_class_handle classHandle, uint8_t pipeType, uint8_t direction);
342 
343 /*!
344  * @brief Receives data.
345  *
346  * This function implements the CDC receiving data.
347  *
348  * @param classHandle   The class handle.
349  * @param buffer         The buffer pointer.
350  * @param bufferLength   The buffer length.
351  * @param callbackFn    This callback is called after this function completes.
352  * @param callbackParam The first parameter in the callback function.
353  *
354  * @retval kStatus_USB_Success        Receive request successfully.
355  * @retval kStatus_USB_InvalidHandle  The classHandle is NULL pointer.
356  * @retval kStatus_USB_Busy           There is no idle transfer.
357  * @retval kStatus_USB_Error          Pipe is not initialized.
358  *                                    Or, send transfer fail. See the USB_HostRecv.
359  */
360 extern usb_status_t USB_HostCdcDataRecv(usb_host_class_handle classHandle,
361                                         uint8_t *buffer,
362                                         uint32_t bufferLength,
363                                         transfer_callback_t callbackFn,
364                                         void *callbackParam);
365 
366 /*!
367  * @brief Sends data.
368  *
369  * This function implements the CDC sending data.
370  *
371  * @param classHandle   The class handle.
372  * @param buffer         The buffer pointer.
373  * @param bufferLength     The buffer length.
374  * @param callbackFn    This callback is called after this function completes.
375  * @param callbackParam The first parameter in the callback function.
376  *
377  * @retval kStatus_USB_Success          Receive request successfully.
378  * @retval kStatus_USB_InvalidHandle    The classHandle is NULL pointer.
379  * @retval kStatus_USB_Busy             There is no idle transfer.
380  * @retval kStatus_USB_Error            Pipe is not initialized.
381  *                                    Or, send transfer fail. See the USB_HostSend.
382  */
383 extern usb_status_t USB_HostCdcDataSend(usb_host_class_handle classHandle,
384                                         uint8_t *buffer,
385                                         uint32_t bufferLength,
386                                         transfer_callback_t callbackFn,
387                                         void *callbackParam);
388 
389 /*!
390  * @brief Interrupts the receive data.
391  *
392  * This function implements the interrupt receiving data.
393  *
394  * @param classHandle    The class handle.
395  * @param buffer          The buffer pointer.
396  * @param bufferLength      The buffer length.
397  * @param callbackFn     This callback is called after this function completes.
398  * @param callbackParam The first parameter in the callback function.
399  *
400  * @retval kStatus_USB_Success         Receive request successfully.
401  * @retval kStatus_USB_InvalidHandle   The classHandle is NULL pointer.
402  * @retval kStatus_USB_Busy            There is no idle transfer.
403  * @retval kStatus_USB_Error           Pipe is not initialized.
404  *                                    Or, send transfer fail. See the USB_HostRecv.
405  */
406 extern usb_status_t USB_HostCdcInterruptRecv(usb_host_class_handle classHandle,
407                                              uint8_t *buffer,
408                                              uint32_t bufferLength,
409                                              transfer_callback_t callbackFn,
410                                              void *callbackParam);
411 
412 /*!
413  * @brief CDC get line coding.
414  *
415  * This function implements the CDC GetLineCoding request. See the PSTN specification.
416  *
417  * @param classHandle   The class handle.
418  * @param uartLineCoding   The line coding pointer.
419  * @param callbackFn    This callback is called after this function completes.
420  * @param callbackParam The first parameter in the callback function.
421  *
422  * @retval kStatus_USB_Success        Request successful.
423  * @retval kStatus_USB_InvalidHandle  The classHandle is NULL pointer.
424  * @retval kStatus_USB_Busy           There is no idle transfer.
425  * @retval kStatus_USB_Error          Send transfer fail. See the USB_HostSendSetup.
426  */
427 extern usb_status_t USB_HostCdcGetAcmLineCoding(usb_host_class_handle classHandle,
428                                                 usb_host_cdc_line_coding_struct_t *uartLineCoding,
429                                                 transfer_callback_t callbackFn,
430                                                 void *callbackParam);
431 
432 /*!
433  * @brief cdc set line coding.
434  *
435  * This function implements cdc SetLineCoding request.refer to pstn spec.
436  *
437  * @param classHandle    the class handle.
438  * @param buffer         the buffer pointer.
439  * @param bufferLength   the buffer length.
440  * @param callbackFn     this callback is called after this function completes.
441  * @param callbackParam  the first parameter in the callback function.
442  *
443  * @retval kStatus_USB_Success        request successfully.
444  * @retval kStatus_USB_InvalidHandle  The classHandle is NULL pointer.
445  * @retval kStatus_USB_Busy           There is no idle transfer.
446  * @retval kStatus_USB_Error          send transfer fail, please reference to USB_HostSendSetup.
447  */
448 extern usb_status_t USB_HostCdcSetAcmLineCoding(usb_host_class_handle classHandle,
449                                          usb_host_cdc_line_coding_struct_t *uartLineCoding,
450                                          transfer_callback_t callbackFn,
451                                          void *callbackParam);
452 
453 /*!
454  * @brief CDC setControlLineState.
455  *
456  * This function implements the CDC etControlLineState request. See PSTN specification.
457  *
458  * @param classHandle   The class handle.
459  * @param dtr           The DRS value.
460  * @param rts           The RTS value.
461  * @param callbackFn    This callback is called after this function completes.
462  * @param callbackParam The first parameter in the callback function.
463  *
464  * @retval kStatus_USB_Success        Request successful.
465  * @retval kStatus_USB_InvalidHandle  The classHandle is NULL pointer.
466  * @retval kStatus_USB_Busy           There is no idle transfer.
467  * @retval kStatus_USB_Error          Send transfer fail. See the USB_HostSendSetup.
468  */
469 extern usb_status_t USB_HostCdcSetAcmCtrlState(
470     usb_host_class_handle classHandle, uint8_t dtr, uint8_t rts, transfer_callback_t callbackFn, void *callbackParam);
471 
472 /*!
473  * @brief cdc send encapsulated command.
474  *
475  * This function implements cdc SEND_ENCAPSULATED_COMMAND request.refer to cdc 1.2 spec.
476  *
477  * @param classHandle    the class handle.
478  * @param buffer         the buffer pointer.
479  * @param bufferLength   the buffer length.
480  * @param callbackFn     this callback is called after this function completes.
481  * @param callbackParam  the first parameter in the callback function.
482  *
483  * @retval kStatus_USB_Success        request successfully.
484  * @retval kStatus_USB_InvalidHandle  The classHandle is NULL pointer.
485  * @retval kStatus_USB_Busy           There is no idle transfer.
486  * @retval kStatus_USB_Error          send transfer fail, please reference to USB_HostSendSetup.
487  */
488 usb_status_t USB_HostCdcSendEncapsulatedCommand(usb_host_class_handle classHandle,
489                                                 uint8_t *buffer,
490                                                 uint16_t bufferLength,
491                                                 transfer_callback_t callbackFn,
492                                                 void *callbackParam);
493 
494 /*!
495  * @brief cdc get encapsulated response.
496  *
497  * This function implements cdc GET_ENCAPSULATED_RESPONSE request.refer to cdc 1.2 spec.
498  *
499  * @param classHandle    the class handle.
500  * @param buffer         the buffer pointer.
501  * @param bufferLength   the buffer length.
502  * @param callbackFn     this callback is called after this function completes.
503  * @param callbackParam  the first parameter in the callback function.
504  *
505  * @retval kStatus_USB_Success        request successfully.
506  * @retval kStatus_USB_InvalidHandle  The classHandle is NULL pointer.
507  * @retval kStatus_USB_Busy           There is no idle transfer.
508  * @retval kStatus_USB_Error          send transfer fail, please reference to USB_HostSendSetup.
509  */
510 usb_status_t USB_HostCdcGetEncapsulatedResponse(usb_host_class_handle classHandle,
511                                                 uint8_t *buffer,
512                                                 uint16_t bufferLength,
513                                                 transfer_callback_t callbackFn,
514                                                 void *callbackParam);
515 
516 /*!
517  * @brief CDC gets the ACM descriptor.
518  *
519  * This function is hunting for the class-specific ACM descriptor in the configuration and gets the corresponding
520  * descriptor.
521  *
522  * @param classHandle          The class handle.
523  * @param headDesc             The head function descriptor pointer.
524  * @param callManageDesc       The call management functional descriptor pointer.
525  * @param abstractControlDesc  The abstract control management functional pointer.
526  * @param unionInterfaceDesc   The union functional descriptor pointer.
527  *
528  * @retval kStatus_USB_Error          Analyse descriptor error.
529  */
530 extern usb_status_t USB_HostCdcGetAcmDescriptor(usb_host_class_handle classHandle,
531                                                 usb_host_cdc_head_function_desc_struct_t **headDesc,
532                                                 usb_host_cdc_call_manage_desc_struct_t **callManageDesc,
533                                                 usb_host_cdc_abstract_control_desc_struct_t **abstractControlDesc,
534                                                 usb_host_cdc_union_interface_desc_struct_t **unionInterfaceDesc);
535 
536 /*!
537  * @brief CDC send control transfer common code.
538  *
539  * @param classHandle    The class handle.
540  * @param request_type   Set up the packet request type.
541  * @param request        Set up the packet request value.
542  * @param wvalue_l       Set up the packet wvalue low byte.
543  * @param wvalue_h       Set up the packet wvalue high byte.
544  * @param wlength        Set up the packet wlength value.
545  * @param data           Data buffer pointer
546  * @param callbackFn     This callback is called after this function completes.
547  * @param callbackParam  The first parameter in the callback function.
548  *
549  * @return An error code or kStatus_USB_Success.
550  */
551 extern usb_status_t USB_HostCdcControl(usb_host_class_handle classHandle,
552                                        uint8_t request_type,
553                                        uint8_t request,
554                                        uint8_t wvalue_l,
555                                        uint8_t wvalue_h,
556                                        uint16_t wlength,
557                                        uint8_t *data,
558                                        transfer_callback_t callbackFn,
559                                        void *callbackParam);
560 /*@}*/
561 
562 #ifdef __cplusplus
563 }
564 #endif
565 /*@}*/
566 
567 #endif /*__USB_HOST_CDC_H__*/
568