M480 BSP  V3.05.001
The Board Support Package for M480 Series
usbh_cdc.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef _USBH_CDC_H_
10 #define _USBH_CDC_H_
11 
12 #include "NuMicro.h"
13 #include "usb.h"
14 
15 #ifdef __cplusplus
16 extern "C"
17 {
18 #endif
19 
21 
22 #define CDC_DEBUG
23 
24 #define CDC_ERRMSG printf
25 #ifdef CDC_DEBUG
26 #define CDC_DBGMSG printf
27 #else
28 #define CDC_DBGMSG(...)
29 #endif
30 
31 #define CDC_STATUS_BUFF_SIZE 64
32 #define CDC_RX_BUFF_SIZE 64
33 
34 /* Interface Class Codes (defined in usbh.h) */
35 //#define USB_CLASS_COMM 0x02
36 //#define USB_CLASS_DATA 0x0A
37 
38 /* Communication Interface Class SubClass Codes */
39 #define CDC_SC_RESERVED 0x00 /* RESERVED */
40 #define CDC_SC_LINE_CTRL 0x01 /* Direct Line Control Model */
41 #define CDC_SC_ABS_CTRL 0x02 /* Abstract Control Model */
42 #define CDC_SC_TEL_CTRL 0x03 /* Telephone Control Model */
43 #define CDC_SC_MULTI_CHN 0x04 /* Multi-Channel Control Model */
44 #define CDC_SC_CAPI 0x05 /* CAPI Control Model */
45 #define CDC_SC_ETHER 0x06 /* Ethernet Networking Control Model */
46 #define CDC_SC_ATM 0x07 /* ATM Networking Control Model */
47 
48 /* Communication Interface Class Control Protocol Codes */
49 #define CDC_PC_NONE 0x00 /* No class specific protocol required */
50 #define CDC_PC_V25_TER 0x01 /* Common AT commands */
51 #define CDC_PC_VENDOR 0xFF /* Vendor-specific */
52 
53 /* CDC Class-specific descritpor types */
54 #define CDC_CS_INTERFACE 0x24
55 #define CDC_CS_ENDPOINT 0x25
56 
57 /*
58  * CDC class specific descritpor types
59  */
60 #define CDC_DT_HDR_FUNC 0x00 /* Header Functional Descriptor */
61 #define CDC_DT_CALL_MANAGE 0x01 /* Call Management Functional Descriptor */
62 #define CDC_DT_ABS_CTRL 0x02 /* Abstract Control Management Functional Descriptor */
63 #define CDC_DT_LINE_MANAGE 0x03 /* Direct Line Management Functional Descriptor */
64 #define CDC_DT_TEL_RINGER 0x04 /* Telephone Ringer Functional Descriptor */
65 #define CDC_DT_CALL_LINE_CAP 0x05 /* Telephone Call and Line State Reporting Capabilities Descriptor */
66 #define CDC_DT_UNION 0x06 /* Union Functional Descriptor */
67 #define CDC_DT_COUNTRY_SEL 0x07 /* Country Selection Functional Descriptor */
68 #define CDC_DT_TEL_OPER_MODES 0x08 /* Telephone Operational Modes Functional Descriptor */
69 #define CDC_DT_USB_TERMINAL 0x09 /* USB Terminal Functional Descriptor */
70 #define CDC_DT_NET_CHANNEL 0x0A /* Network Channel Terminal Functional Descriptor */
71 #define CDC_DT_PROTO_UNIT 0x0B /* Protocol Unit Functional Descriptor */
72 #define CDC_DT_EXTENT_UNIT 0x0C /* Extension Unit Functional Descriptor */
73 #define CDC_DT_MULTI_CHANNEL 0x0D /* Multi-Channel Management Functional Descriptor */
74 #define CDC_DT_CAPI_CTRL 0x0E /* CAPI Control Management Functional Descriptor */
75 #define CDC_DT_ETHERNET_FUNC 0x0F /* Ethernet Networking Functional Descriptor */
76 #define CDC_DT_ATM_FUNC 0x10 /* ATM Networking Functional Descriptor */
77 
78 
79 /*
80  * CDC class requests
81  */
82 #define CDC_SEND_ENCAPSULATED_COMMAND 0x00
83 #define CDC_GET_ENCAPSULATED_RESPONSE 0x01
84 #define CDC_SET_COMM_FEATURE 0x02
85 #define CDC_GET_COMM_FEATURE 0x03
86 #define CDC_CLEAR_COMM_FEATURE 0x04
87 #define CDC_SET_AUX_LINE_STATE 0x10
88 #define CDC_SET_HOOK_STATE 0x11
89 #define CDC_PULSE_SETUP 0x12
90 #define CDC_SEND_PULSE 0x13
91 #define CDC_SET_PULSE_TIME 0x14
92 #define CDC_RING_AUX_JACK 0x15
93 #define CDC_SET_LINE_CODING 0x20
94 #define CDC_GET_LINE_CODING 0x21
95 #define CDC_SET_CONTROL_LINE_STATE 0x22
96 #define CDC_SEND_BREAK 0x23
97 #define CDC_SET_RINGER_PARMS 0x30
98 #define CDC_GET_RINGER_PARMS 0x31
99 #define CDC_SET_OPERATION_PARMS 0x32
100 #define CDC_GET_OPERATION_PARMS 0x33
101 #define CDC_SET_LINE_PARMS 0x34
102 #define CDC_GET_LINE_PARMS 0x35
103 #define CDC_DIAL_DIGITS 0x36
104 #define CDC_SET_UNIT_PARAMETER 0x37
105 #define CDC_GET_UNIT_PARAMETER 0x38
106 #define CDC_CLEAR_UNIT_PARAMETER 0x39
107 #define CDC_GET_PROFILE 0x3A
108 #define CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
109 #define CDC_SET_ETHERNET_PM_PATTERN_FILTER 0x41
110 #define CDC_GET_ETHERNET_PM_PATTERN_FILTER 0x42
111 #define CDC_SET_ETHERNET_PACKET_FILTER 0x43
112 #define CDC_GET_ETHERNET_STATISTIC 0x44
113 #define CDC_SET_ATM_DATA_FORMAT 0x50
114 #define CDC_GET_ATM_DEVICE_STATISTICS 0x51
115 #define CDC_SET_ATM_DEFAULT_VC 0x52
116 #define CDC_GET_ATM_VC_STATISTICS 0x53
117 
118 #define CDC_CMD_TIMEOUT 100
119 
120 
121 /*-----------------------------------------------------------------------------------
122  * CDC Class-specific interface descriptor header
123  */
124 #ifdef __ICCARM__
125 typedef struct cdc_if_header
126 {
127  __packed uint8_t bLength;
128  __packed uint8_t bDescriptorType;
129  __packed uint8_t bDescriptorSubtype;
130  __packed uint8_t payload[16];
131 } CDC_IF_HDR_T;
132 #else
133 typedef struct __attribute__((__packed__)) cdc_if_header
134 {
135  uint8_t bLength;
136  uint8_t bDescriptorType;
137  uint8_t bDescriptorSubtype;
138  uint8_t payload[16];
139 } CDC_IF_HDR_T;
140 #endif
141 
142 struct cdc_dev_t;
143 
145 
146 
151 /*
152  * Line Coding
153  */
154 #ifdef __ICCARM__
155 typedef struct line_coding_t
156 {
157  __packed uint32_t baud; /* Baud Rate */
158  __packed uint8_t stop_bits; /* 0 - 1 Stop bit; 1 - 1.5 Stop bits; 2 - 2 Stop bits */
159  __packed uint8_t parity; /* 0 - None; 1 - Odd; 2 - Even; 3 - Mark; 4 - Space */
160  __packed uint8_t data_bits; /* Data bits (5, 6, 7, 8 or 16) */
161 } LINE_CODING_T;
162 #else
163 typedef struct __attribute__((__packed__)) line_coding_t
164 {
165  uint32_t baud; /* Baud Rate */
166  uint8_t stop_bits; /* 0 - 1 Stop bit; 1 - 1.5 Stop bits; 2 - 2 Stop bits */
167  uint8_t parity; /* 0 - None; 1 - Odd; 2 - Even; 3 - Mark; 4 - Space */
168  uint8_t data_bits; /* Data bits (5, 6, 7, 8 or 16) */
170 #endif
171 
172 /*
173  * USB-specific CDC device struct
174  */
175 typedef struct cdc_dev_t
176 {
177  UDEV_T *udev;
178  IFACE_T *iface_cdc; /* CDC interface number */
179  IFACE_T *iface_data; /* CDC data interface number (can be NULL) */
181  EP_INFO_T *ep_sts;
182  EP_INFO_T *ep_rx;
183  EP_INFO_T *ep_tx;
184  UTR_T *utr_sts; /* Interrupt in URB */
185  UTR_T *utr_rx; /* Bulk in URB */
186  uint32_t sts_buff[CDC_STATUS_BUFF_SIZE/4];
187  uint32_t rx_buff[CDC_RX_BUFF_SIZE/4];
188  CDC_CB_FUNC *sts_func; /* Interrupt in data received callback */
189  CDC_CB_FUNC *rx_func; /* Bulk in data received callabck */
190  uint8_t rx_busy; /* Bulk in transfer is on going */
191  struct cdc_dev_t *next;
192 } CDC_DEV_T;
193  /* end of group USBH_EXPORTED_STRUCTURES */
195  /* end of group USBH_Library */
197  /* end of group Library */
199 
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 #endif /* _USBH_CDC_H_ */
205 
206 /*** (C) COPYRIGHT 2018 Nuvoton Technology Corp. ***/
uint8_t rx_busy
Definition: usbh_cdc.h:190
LINE_CODING_T
Definition: usbh_cdc.h:169
NuMicro peripheral access layer header file.
CDC_CB_FUNC * sts_func
Definition: usbh_cdc.h:188
UTR_T * utr_rx
Definition: usbh_cdc.h:185
int ifnum_data
Definition: usbh_cdc.h:180
EP_INFO_T * ep_sts
Definition: usbh_cdc.h:181
CDC_CB_FUNC * rx_func
Definition: usbh_cdc.h:189
UTR_T * utr_sts
Definition: usbh_cdc.h:184
struct __attribute__((__packed__)) line_coding_t
Definition: usbh_cdc.h:163
UDEV_T * udev
Definition: usbh_cdc.h:177
IFACE_T * iface_data
Definition: usbh_cdc.h:179
EP_INFO_T * ep_tx
Definition: usbh_cdc.h:183
struct cdc_dev_t * next
Definition: usbh_cdc.h:191
USB Host library header file.
void() CDC_CB_FUNC(struct cdc_dev_t *cdev, uint8_t *rdata, int data_len)
Definition: usbh_lib.h:120
EP_INFO_T * ep_rx
Definition: usbh_cdc.h:182
uint32_t rx_buff[CDC_RX_BUFF_SIZE/4]
Definition: usbh_cdc.h:187
IFACE_T * iface_cdc
Definition: usbh_cdc.h:178
struct cdc_dev_t CDC_DEV_T
uint32_t sts_buff[CDC_STATUS_BUFF_SIZE/4]
Definition: usbh_cdc.h:186