1 /*!
2     \file    usb_cdc.h
3     \brief   the header file of communication device class standard
4 
5     \version 2020-08-04, V1.1.0, firmware for GD32VF103
6 */
7 
8 /*
9     Copyright (c) 2020, GigaDevice Semiconductor Inc.
10 
11     Redistribution and use in source and binary forms, with or without modification,
12 are permitted provided that the following conditions are met:
13 
14     1. Redistributions of source code must retain the above copyright notice, this
15        list of conditions and the following disclaimer.
16     2. Redistributions in binary form must reproduce the above copyright notice,
17        this list of conditions and the following disclaimer in the documentation
18        and/or other materials provided with the distribution.
19     3. Neither the name of the copyright holder nor the names of its contributors
20        may be used to endorse or promote products derived from this software without
21        specific prior written permission.
22 
23     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 OF SUCH DAMAGE.
33 */
34 
35 #ifndef __USB_CDC_H
36 #define __USB_CDC_H
37 
38 #include "usb_ch9_std.h"
39 
40 /* communications device class code */
41 #define USB_CLASS_CDC                                       0x02U
42 
43 /* communications interface class control protocol codes */
44 #define USB_CDC_PROTOCOL_NONE                               0x00U
45 #define USB_CDC_PROTOCOL_AT                                 0x01U
46 #define USB_CDC_PROTOCOL_VENDOR                             0xFFU
47 
48 /* data interface class code */
49 #define USB_CLASS_DATA                                      0x0AU
50 
51 #define USB_DESCTYPE_CDC_ACM                                0x21U
52 #define USB_DESCTYPE_CS_INTERFACE                           0x24U
53 
54 #define USB_CDC_ACM_CONFIG_DESC_SIZE                        0x43U
55 
56 /* class-specific notification codes for pstn subclasses */
57 #define USB_CDC_NOTIFY_SERIAL_STATE                         0x20U
58 
59 /* class-specific request codes */
60 #define SEND_ENCAPSULATED_COMMAND                           0x00U
61 #define GET_ENCAPSULATED_RESPONSE                           0x01U
62 #define SET_COMM_FEATURE                                    0x02U
63 #define GET_COMM_FEATURE                                    0x03U
64 #define CLEAR_COMM_FEATURE                                  0x04U
65 
66 #define SET_AUX_LINE_STATE                                  0x10U
67 #define SET_HOOK_STATE                                      0x11U
68 #define PULSE_SETUP                                         0x12U
69 #define SEND_PULSE                                          0x13U
70 #define SET_PULSE_TIME                                      0x14U
71 #define RING_AUX_JACK                                       0x15U
72 
73 #define SET_LINE_CODING                                     0x20U
74 #define GET_LINE_CODING                                     0x21U
75 #define SET_CONTROL_LINE_STATE                              0x22U
76 #define SEND_BREAK                                          0x23U
77 #define NO_CMD                                              0xFFU
78 
79 #define SET_RINGER_PARMS                                    0x30U
80 #define GET_RINGER_PARMS                                    0x31U
81 #define SET_OPERATION_PARMS                                 0x32U
82 #define GET_OPERATION_PARMS                                 0x33U
83 #define SET_LINE_PARMS                                      0x34U
84 #define GET_LINE_PARMS                                      0x35U
85 #define DIAL_DIGITS                                         0x36U
86 #define SET_UNIT_PARAMETER                                  0x37U
87 #define GET_UNIT_PARAMETER                                  0x38U
88 #define CLEAR_UNIT_PARAMETER                                0x39U
89 #define GET_PROFILE                                         0x3AU
90 
91 #define SET_ETHERNET_MULTICAST_FILTERS                      0x40U
92 #define SET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER        0x41U
93 #define GET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER        0x42U
94 #define SET_ETHERNET_PACKET_FILTER                          0x43U
95 #define GET_ETHERNET_STATISTIC                              0x44U
96 
97 #define SET_ATM_DATA_FORMAT                                 0x50U
98 #define GET_ATM_DEVICE_STATISTICS                           0x51U
99 #define SET_ATM_DEFAULT_VC                                  0x52U
100 #define GET_ATM_VC_STATISTICS                               0x53U
101 
102 /* wValue for set control line state */
103 #define CDC_ACTIVATE_CARRIER_SIGNAL_RTS                     0x0002U
104 #define CDC_DEACTIVATE_CARRIER_SIGNAL_RTS                   0x0000U
105 #define CDC_ACTIVATE_SIGNAL_DTR                             0x0001U
106 #define CDC_DEACTIVATE_SIGNAL_DTR                           0x0000U
107 
108 /* CDC subclass code */
109 enum usb_cdc_subclass {
110     USB_CDC_SUBCLASS_RESERVED = 0U,  /*!< reserved */
111     USB_CDC_SUBCLASS_DLCM,           /*!< direct line control mode */
112     USB_CDC_SUBCLASS_ACM,            /*!< abstract control mode */
113     USB_CDC_SUBCLASS_TCM,            /*!< telephone control mode */
114     USB_CDC_SUBCLASS_MCM,            /*!< multichannel control model */
115     USB_CDC_SUBCLASS_CCM,            /*!< CAPI control model */
116     USB_CDC_SUBCLASS_ENCM,           /*!< ethernet networking control model */
117     USB_CDC_SUBCLASS_ANCM            /*!< ATM networking control model */
118 };
119 
120 #pragma pack(1)
121 
122 /* cdc acm line coding structure */
123 typedef struct {
124     uint32_t dwDTERate;                   /*!< data terminal rate */
125     uint8_t  bCharFormat;                 /*!< stop bits */
126     uint8_t  bParityType;                 /*!< parity */
127     uint8_t  bDataBits;                   /*!< data bits */
128 } acm_line;
129 
130 /* notification structure */
131 typedef struct {
132     uint8_t bmRequestType;                /*!< type of request */
133     uint8_t bNotification;                /*!< communication interface class notifications */
134     uint16_t wValue;                      /*!< value of notification */
135     uint16_t wIndex;                      /*!< index of interface */
136     uint16_t wLength;                     /*!< length of notification data */
137 } acm_notification;
138 
139 typedef struct {
140     usb_desc_header header;               /*!< descriptor header, including type and size. */
141     uint8_t   bDescriptorSubtype;         /*!< bDescriptorSubtype: header function descriptor */
142     uint16_t  bcdCDC;                     /*!< bcdCDC: low byte of spec release number (CDC1.10) */
143 } usb_desc_header_func;
144 
145 typedef struct {
146     usb_desc_header header;               /*!< descriptor header, including type and size. */
147     uint8_t  bDescriptorSubtype;          /*!< bDescriptorSubtype:  call management function descriptor */
148     uint8_t  bmCapabilities;              /*!< bmCapabilities: D0 is reset, D1 is ignored */
149     uint8_t  bDataInterface;              /*!< bDataInterface: 1 interface used for call management */
150 } usb_desc_call_managment_func;
151 
152 typedef struct {
153     usb_desc_header header;               /*!< descriptor header, including type and size. */
154     uint8_t  bDescriptorSubtype;          /*!< bDescriptorSubtype: abstract control management descriptor */
155     uint8_t  bmCapabilities;              /*!< bmCapabilities: D1 */
156 } usb_desc_acm_func;
157 
158 typedef struct {
159     usb_desc_header header;               /*!< descriptor header, including type and size. */
160     uint8_t  bDescriptorSubtype;          /*!< bDescriptorSubtype: union function descriptor */
161     uint8_t  bMasterInterface;            /*!< bMasterInterface: communication class interface */
162     uint8_t  bSlaveInterface0;            /*!< bSlaveInterface0: data class interface */
163 } usb_desc_union_func;
164 
165 #pragma pack()
166 
167 typedef struct {
168     usb_desc_config                  config;
169     usb_desc_itf                     cmd_itf;
170     usb_desc_header_func             cdc_header;
171     usb_desc_call_managment_func     cdc_call_managment;
172     usb_desc_acm_func                cdc_acm;
173     usb_desc_union_func              cdc_union;
174     usb_desc_ep                      cdc_cmd_endpoint;
175     usb_desc_itf                     cdc_data_interface;
176     usb_desc_ep                      cdc_out_endpoint;
177     usb_desc_ep                      cdc_in_endpoint;
178 } usb_cdc_desc_config_set;
179 
180 #endif /* __USB_CDC_H */
181