1beacf11bSopenharmony_ci/****************************************************************************
2beacf11bSopenharmony_ci * drivers/usbdev/cdcacm.h
3beacf11bSopenharmony_ci *
4beacf11bSopenharmony_ci *   Copyright (C) 2011-2012, 2015, 2017 Gregory Nutt. All rights reserved.
5beacf11bSopenharmony_ci *   Copyright (c) Huawei Technologies Co., Ltd. 2017-2019. All rights reserved.
6beacf11bSopenharmony_ci *   Author: Gregory Nutt <gnutt@nuttx.org>
7beacf11bSopenharmony_ci *
8beacf11bSopenharmony_ci * Redistribution and use in source and binary forms, with or without
9beacf11bSopenharmony_ci * modification, are permitted provided that the following conditions
10beacf11bSopenharmony_ci * are met:
11beacf11bSopenharmony_ci *
12beacf11bSopenharmony_ci * 1. Redistributions of source code must retain the above copyright
13beacf11bSopenharmony_ci *    notice, this list of conditions and the following disclaimer.
14beacf11bSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
15beacf11bSopenharmony_ci *    notice, this list of conditions and the following disclaimer in
16beacf11bSopenharmony_ci *    the documentation and/or other materials provided with the
17beacf11bSopenharmony_ci *    distribution.
18beacf11bSopenharmony_ci * 3. Neither the name NuttX nor the names of its contributors may be
19beacf11bSopenharmony_ci *    used to endorse or promote products derived from this software
20beacf11bSopenharmony_ci *    without specific prior written permission.
21beacf11bSopenharmony_ci *
22beacf11bSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23beacf11bSopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24beacf11bSopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25beacf11bSopenharmony_ci * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26beacf11bSopenharmony_ci * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27beacf11bSopenharmony_ci * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28beacf11bSopenharmony_ci * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29beacf11bSopenharmony_ci * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30beacf11bSopenharmony_ci * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31beacf11bSopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32beacf11bSopenharmony_ci * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33beacf11bSopenharmony_ci * POSSIBILITY OF SUCH DAMAGE.
34beacf11bSopenharmony_ci *
35beacf11bSopenharmony_ci ****************************************************************************/
36beacf11bSopenharmony_ci/****************************************************************************
37beacf11bSopenharmony_ci * Notice of Export Control Law
38beacf11bSopenharmony_ci * ===============================================
39beacf11bSopenharmony_ci * Huawei LiteOS may be subject to applicable export control laws and regulations,
40beacf11bSopenharmony_ci * which might include those applicable to Huawei LiteOS of U.S. and the country in
41beacf11bSopenharmony_ci * which you are located.
42beacf11bSopenharmony_ci * Import, export and usage of Huawei LiteOS in any manner by you shall be in
43beacf11bSopenharmony_ci * compliance with such applicable export control laws and regulations.
44beacf11bSopenharmony_ci ****************************************************************************/
45beacf11bSopenharmony_ci
46beacf11bSopenharmony_ci#ifndef __DRIVERS_USBDEV_CDCACM_H
47beacf11bSopenharmony_ci#define __DRIVERS_USBDEV_CDCACM_H
48beacf11bSopenharmony_ci
49beacf11bSopenharmony_ci/****************************************************************************
50beacf11bSopenharmony_ci * Included Files
51beacf11bSopenharmony_ci ****************************************************************************/
52beacf11bSopenharmony_ci
53beacf11bSopenharmony_ci#include "gadget/composite.h"
54beacf11bSopenharmony_ci
55beacf11bSopenharmony_ci/* Interface IDs:
56beacf11bSopenharmony_ci *
57beacf11bSopenharmony_ci * CDCACM_NINTERFACES              Two interfaces
58beacf11bSopenharmony_ci * CDCACM_NOTIFID                  ID of the notifier interface
59beacf11bSopenharmony_ci * CDCACM_NOTALTIFID               No alternate for the notifier interface
60beacf11bSopenharmony_ci * CDCACM_DATAIFID                 ID of the data interface
61beacf11bSopenharmony_ci * CDCACM_DATAALTIFID              No alternate for the data interface
62beacf11bSopenharmony_ci */
63beacf11bSopenharmony_ci
64beacf11bSopenharmony_ci#define CDCACM_NOTALTIFID          (0)
65beacf11bSopenharmony_ci#define CDCACM_DATAALTIFID         (0)
66beacf11bSopenharmony_ci
67beacf11bSopenharmony_ci/* Buffer big enough for any of our descriptors (the config descriptor is the
68beacf11bSopenharmony_ci * biggest).
69beacf11bSopenharmony_ci */
70beacf11bSopenharmony_ci
71beacf11bSopenharmony_ci#define CDCACM_MXDESCLEN           (64)
72beacf11bSopenharmony_ci#define CDCACM_MAXSTRLEN           (CDCACM_MXDESCLEN-2)
73beacf11bSopenharmony_ci
74beacf11bSopenharmony_ci/* Device descriptor values */
75beacf11bSopenharmony_ci
76beacf11bSopenharmony_ci#define CDCACM_VERSIONNO           (0x0101) /* Device version number 1.1 (BCD) */
77beacf11bSopenharmony_ci
78beacf11bSopenharmony_ci/* String language */
79beacf11bSopenharmony_ci
80beacf11bSopenharmony_ci#define CDCACM_STR_LANGUAGE        (0x0409) /* en-us */
81beacf11bSopenharmony_ci
82beacf11bSopenharmony_ci/* Descriptor strings.  If there serial device is part of a composite device
83beacf11bSopenharmony_ci * then the manufacturer, product, and serial number strings will be provided
84beacf11bSopenharmony_ci * by the composite logic.
85beacf11bSopenharmony_ci */
86beacf11bSopenharmony_ci
87beacf11bSopenharmony_ci#ifndef CONFIG_CDCACM_COMPOSITE
88beacf11bSopenharmony_ci#define CDCACM_LASTBASESTRID     (4)
89beacf11bSopenharmony_ci#define CDCACM_STRBASE           (0)
90beacf11bSopenharmony_ci#else
91beacf11bSopenharmony_ci#define CDCACM_STRBASE           CONFIG_CDCACM_STRBASE
92beacf11bSopenharmony_ci#define CDCACM_LASTBASESTRID     CONFIG_CDCACM_STRBASE
93beacf11bSopenharmony_ci#endif
94beacf11bSopenharmony_ci
95beacf11bSopenharmony_ci/* These string IDs only exist if a user-defined string is provided */
96beacf11bSopenharmony_ci
97beacf11bSopenharmony_ci#ifdef CONFIG_CDCACM_NOTIFSTR
98beacf11bSopenharmony_ci#define CDCACM_NOTIFSTRID        (CDCACM_LASTBASESTRID+1)
99beacf11bSopenharmony_ci#else
100beacf11bSopenharmony_ci#define CDCACM_NOTIFSTRID        CDCACM_LASTBASESTRID
101beacf11bSopenharmony_ci#endif
102beacf11bSopenharmony_ci
103beacf11bSopenharmony_ci#ifdef CONFIG_CDCACM_DATAIFSTR
104beacf11bSopenharmony_ci#define CDCACM_DATAIFSTRID       (CDCACM_NOTIFSTRID+1)
105beacf11bSopenharmony_ci#else
106beacf11bSopenharmony_ci#define CDCACM_DATAIFSTRID       CDCACM_NOTIFSTRID
107beacf11bSopenharmony_ci#endif
108beacf11bSopenharmony_ci
109beacf11bSopenharmony_ci#define CDCACM_LASTSTRID           CDCACM_DATAIFSTRID
110beacf11bSopenharmony_ci#define CDCACM_NSTRIDS             (CDCACM_LASTSTRID - CDCACM_STRBASE)
111beacf11bSopenharmony_ci
112beacf11bSopenharmony_ci#define CDCACM_EP_INTIN_IDX        (0)
113beacf11bSopenharmony_ci#define CDCACM_EP_BULKIN_IDX       (1)
114beacf11bSopenharmony_ci#define CDCACM_EP_BULKOUT_IDX      (2)
115beacf11bSopenharmony_ci
116beacf11bSopenharmony_ci/* Endpoint configuration ****************************************************/
117beacf11bSopenharmony_ci
118beacf11bSopenharmony_ci#define CDCACM_MKEPINTIN(desc)     ((desc)->epno[CDCACM_EP_INTIN_IDX])
119beacf11bSopenharmony_ci
120beacf11bSopenharmony_ci#define CDCACM_MKEPBULKIN(desc)    ((desc)->epno[CDCACM_EP_BULKIN_IDX])
121beacf11bSopenharmony_ci
122beacf11bSopenharmony_ci#define CDCACM_MKEPBULKOUT(desc)   ((desc)->epno[CDCACM_EP_BULKOUT_IDX])
123beacf11bSopenharmony_ci
124beacf11bSopenharmony_ci/* Device driver definitions ************************************************/
125beacf11bSopenharmony_ci/* A CDC/ACM device is specific by a minor number in the range of 0-255.
126beacf11bSopenharmony_ci * This maps to a character device at /dev/ttyACMx, x=0..255.
127beacf11bSopenharmony_ci */
128beacf11bSopenharmony_ci
129beacf11bSopenharmony_ci#define CDCACM_DEVNAME_FORMAT      "/dev/ttyGS0"
130beacf11bSopenharmony_ci#define CDCACM_DEVNAME_SIZE        16
131beacf11bSopenharmony_ci
132beacf11bSopenharmony_ci/* Misc Macros **************************************************************/
133beacf11bSopenharmony_ci/* MIN/MAX macros */
134beacf11bSopenharmony_ci
135beacf11bSopenharmony_ci#ifndef MIN
136beacf11bSopenharmony_ci#define MIN(a,b) ((a)<(b)?(a):(b))
137beacf11bSopenharmony_ci#endif
138beacf11bSopenharmony_ci
139beacf11bSopenharmony_ci#ifndef MAX
140beacf11bSopenharmony_ci#define MAX(a,b) ((a)>(b)?(a):(b))
141beacf11bSopenharmony_ci#endif
142beacf11bSopenharmony_ci
143beacf11bSopenharmony_ci#define CDCACM_NUM_EPS             (3)
144beacf11bSopenharmony_ci
145beacf11bSopenharmony_ci#define CDCACM_NCONFIGS            (1)      /* Number of configurations supported */
146beacf11bSopenharmony_ci
147beacf11bSopenharmony_ci/* Configuration descriptor values */
148beacf11bSopenharmony_ci
149beacf11bSopenharmony_ci#define CDCACM_CONFIGID            (1)      /* The only supported configuration ID */
150beacf11bSopenharmony_ci#define CDCACM_NINTERFACES         (2)      /* Number of interfaces in the configuration */
151beacf11bSopenharmony_ci
152beacf11bSopenharmony_ci/* Table 69: UART State Bitmap Values */
153beacf11bSopenharmony_ci
154beacf11bSopenharmony_ci#define CDC_UART_RXCARRIER      (1 << 0) /* bRxCarrier State of receiver carrier detection
155beacf11bSopenharmony_ci                                          * mechanism of device. This signal corresponds to
156beacf11bSopenharmony_ci                                          * V.24 signal 109 and RS-232 signal DCD.
157beacf11bSopenharmony_ci                                          */
158beacf11bSopenharmony_ci#define CDC_UART_TXCARRIER      (1 << 1) /* bTxCarrier State of transmission carrier. This
159beacf11bSopenharmony_ci                                          * signal corresponds to V.24 signal 106 and RS-232
160beacf11bSopenharmony_ci                                          * signal DSR.
161beacf11bSopenharmony_ci                                          */
162beacf11bSopenharmony_ci
163beacf11bSopenharmony_ci/* CDC/ACM friendly naming */
164beacf11bSopenharmony_ci
165beacf11bSopenharmony_ci#define CDCACM_UART_DCD          CDC_UART_RXCARRIER
166beacf11bSopenharmony_ci#define CDCACM_UART_DSR          CDC_UART_TXCARRIER
167beacf11bSopenharmony_ci
168beacf11bSopenharmony_ci/* "SerialState is used like a real interrupt status register. Once a notification has been
169beacf11bSopenharmony_ci *  sent, the device will reset and reevaluate the different signals.  For the consistent
170beacf11bSopenharmony_ci *  signals like carrier detect or transmission carrier, this will mean another notification
171beacf11bSopenharmony_ci *  will not be generated until there is a state change.  For the irregular signals like
172beacf11bSopenharmony_ci *  break, the incoming ring signal, or the overrun error state, this will reset their values
173beacf11bSopenharmony_ci *  to zero and again will not send another notification until their state changes."
174beacf11bSopenharmony_ci */
175beacf11bSopenharmony_ci
176beacf11bSopenharmony_ci#define CDC_UART_CONSISTENT     (CDC_UART_RXCARRIER | CDC_UART_TXCARRIER)
177beacf11bSopenharmony_ci
178beacf11bSopenharmony_ci#ifndef CONFIG_CDCACM_EPBULKOUT_FSSIZE
179beacf11bSopenharmony_ci#define CONFIG_CDCACM_EPBULKOUT_FSSIZE 0x200
180beacf11bSopenharmony_ci#endif
181beacf11bSopenharmony_ci
182beacf11bSopenharmony_ci#ifndef CONFIG_CDCACM_EPBULKOUT_HSSIZE
183beacf11bSopenharmony_ci#define CONFIG_CDCACM_EPBULKOUT_HSSIZE 0x400
184beacf11bSopenharmony_ci#endif
185beacf11bSopenharmony_ci
186beacf11bSopenharmony_ci#ifndef CONFIG_CDCACM_EPBULKIN_FSSIZE
187beacf11bSopenharmony_ci#define CONFIG_CDCACM_EPBULKIN_FSSIZE 0x200
188beacf11bSopenharmony_ci#endif
189beacf11bSopenharmony_ci
190beacf11bSopenharmony_ci#ifndef CONFIG_CDCACM_EPBULKIN_HSSIZE
191beacf11bSopenharmony_ci#define CONFIG_CDCACM_EPBULKIN_HSSIZE 0x400
192beacf11bSopenharmony_ci#endif
193beacf11bSopenharmony_ci
194beacf11bSopenharmony_ci#ifdef LOSCFG_DRIVERS_USB3_DEVICE_CONTROLLER
195beacf11bSopenharmony_ci#define DWC3_USB_SERIAL
196beacf11bSopenharmony_ci#endif
197beacf11bSopenharmony_ci
198beacf11bSopenharmony_ci#ifdef DWC3_USB_SERIAL
199beacf11bSopenharmony_ci#define MAX_PACKET_SIZE 0x400
200beacf11bSopenharmony_ci#else
201beacf11bSopenharmony_ci#define MAX_PACKET_SIZE 0x200
202beacf11bSopenharmony_ci#endif
203beacf11bSopenharmony_ci
204beacf11bSopenharmony_ci#define ACM_NOTIFY_SERIAL_STATE 0x20
205beacf11bSopenharmony_ci#define ACM_GET_LINE_CODING     0x21 /* Requests current DTE rate, stop-bits, parity, and
206beacf11bSopenharmony_ci                                      * number-of-character bits. (Optional)
207beacf11bSopenharmony_ci                                      */
208beacf11bSopenharmony_ci#define ACM_SET_LINE_CODING     0x20 /* Configures DTE rate, stop-bits, parity, and
209beacf11bSopenharmony_ci                                      * number-of-character bits. (Optional)
210beacf11bSopenharmony_ci                                      */
211beacf11bSopenharmony_ci#define ACM_SET_CTRL_LINE_STATE 0x22 /* RS-232 signal used to tell the DCE device the
212beacf11bSopenharmony_ci                                      * DTE device is now present. (Optional)
213beacf11bSopenharmony_ci                                      */
214beacf11bSopenharmony_ci#define SIZEOF_CDC_LINECODING 7
215beacf11bSopenharmony_ci
216beacf11bSopenharmony_ci#define USB_SERIAL_READ_EVENT   0x11
217beacf11bSopenharmony_ci
218beacf11bSopenharmony_ci/* define descriptor */
219beacf11bSopenharmony_ci
220beacf11bSopenharmony_ci#define DEVICE_VENDOR_ID        0x0525
221beacf11bSopenharmony_ci#define DEVICE_PRODUCT_ID       0xa4a7
222beacf11bSopenharmony_ci#define DEVICE_VERSION          0x0100
223beacf11bSopenharmony_ci
224beacf11bSopenharmony_ci#define RING_BUFFER_SIZE 6144U
225beacf11bSopenharmony_ci
226beacf11bSopenharmony_ci#define STAE_BUFFER_OFFSET 1
227beacf11bSopenharmony_ci
228beacf11bSopenharmony_cistruct cdcacm_hs_function_descriptor
229beacf11bSopenharmony_ci{
230beacf11bSopenharmony_ci  struct usb_interface_assoc_descriptor ifcad;
231beacf11bSopenharmony_ci  struct usb_interface_descriptor ifcd; /* acm control interface descriptor */
232beacf11bSopenharmony_ci  struct usb_cdc_header_descriptor cdc_desc;
233beacf11bSopenharmony_ci  struct usb_cdc_cm_descriptor cdc_call_desc;
234beacf11bSopenharmony_ci  struct usb_cdc_acm_descriptor cdc_acm_desc;
235beacf11bSopenharmony_ci  struct usb_cdc_union_desc cdc_union_desc;
236beacf11bSopenharmony_ci  struct usb_endpoint_descriptor nepd;
237beacf11bSopenharmony_ci#ifdef DWC3_USB_SERIAL
238beacf11bSopenharmony_ci  struct usb_endpoint_ss_comp_descriptor ncompd;
239beacf11bSopenharmony_ci#endif
240beacf11bSopenharmony_ci  struct usb_interface_descriptor ifdd;
241beacf11bSopenharmony_ci  struct usb_endpoint_descriptor iepd;
242beacf11bSopenharmony_ci#ifdef DWC3_USB_SERIAL
243beacf11bSopenharmony_ci  struct usb_endpoint_ss_comp_descriptor icompd;
244beacf11bSopenharmony_ci#endif
245beacf11bSopenharmony_ci  struct usb_endpoint_descriptor oepd;
246beacf11bSopenharmony_ci#ifdef DWC3_USB_SERIAL
247beacf11bSopenharmony_ci  struct usb_endpoint_ss_comp_descriptor ocompd;
248beacf11bSopenharmony_ci#endif
249beacf11bSopenharmony_ci} __packed;
250beacf11bSopenharmony_ci
251beacf11bSopenharmony_ci/****************************************************************************
252beacf11bSopenharmony_ci * Public Types
253beacf11bSopenharmony_ci ****************************************************************************/
254beacf11bSopenharmony_ci
255beacf11bSopenharmony_cienum cdcacm_epdesc_e
256beacf11bSopenharmony_ci{
257beacf11bSopenharmony_ci  CDCACM_EPINTIN = 0,  /* Interrupt IN endpoint descriptor */
258beacf11bSopenharmony_ci  CDCACM_EPBULKOUT,    /* Bulk OUT endpoint descriptor */
259beacf11bSopenharmony_ci  CDCACM_EPBULKIN      /* Bulk IN endpoint descriptor */
260beacf11bSopenharmony_ci};
261beacf11bSopenharmony_ci
262beacf11bSopenharmony_ci/****************************************************************************
263beacf11bSopenharmony_ci * Public Data
264beacf11bSopenharmony_ci ****************************************************************************/
265beacf11bSopenharmony_ci
266beacf11bSopenharmony_ciextern struct cdcacm_hs_function_descriptor g_cdcacm_hs_func_desc;
267beacf11bSopenharmony_ci
268beacf11bSopenharmony_ci/****************************************************************************
269beacf11bSopenharmony_ci * Public Function Prototypes
270beacf11bSopenharmony_ci ****************************************************************************/
271beacf11bSopenharmony_ci
272beacf11bSopenharmony_civoid cdcacm_mkdevdesc(uint8_t *buf);
273beacf11bSopenharmony_ci
274beacf11bSopenharmony_ci/****************************************************************************
275beacf11bSopenharmony_ci * Name: cdcacm_mkstrdesc
276beacf11bSopenharmony_ci *
277beacf11bSopenharmony_ci * Description:
278beacf11bSopenharmony_ci *   Construct a string descriptor
279beacf11bSopenharmony_ci *
280beacf11bSopenharmony_ci ****************************************************************************/
281beacf11bSopenharmony_ci
282beacf11bSopenharmony_ciint cdcacm_mkstrdesc(uint8_t id, uint8_t *buf);
283beacf11bSopenharmony_ci
284beacf11bSopenharmony_ci/****************************************************************************
285beacf11bSopenharmony_ci * Name: cdcacm_mkcfgdesc
286beacf11bSopenharmony_ci *
287beacf11bSopenharmony_ci * Description:
288beacf11bSopenharmony_ci *   Construct the configuration descriptor
289beacf11bSopenharmony_ci *
290beacf11bSopenharmony_ci ****************************************************************************/
291beacf11bSopenharmony_ci
292beacf11bSopenharmony_ciint16_t cdcacm_mkcfgdesc(uint8_t *buf, struct usbdev_devinfo_s *devinfo);
293beacf11bSopenharmony_ci
294beacf11bSopenharmony_civoid usbdev_cdcacm_initialize_sub(FAR struct composite_devdesc_s *dev, int ifnobase, int minor);
295beacf11bSopenharmony_ci#endif /* __DRIVERS_USBDEV_CDCACM_H */
296