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