STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
usbh_cdc.h
Go to the documentation of this file.
1 
28 /* Define to prevent recursive ----------------------------------------------*/
29 #ifndef __USBH_CDC_H
30 #define __USBH_CDC_H
31 
32 #ifdef __cplusplus
33  extern "C" {
34 #endif
35 
36 /* Includes ------------------------------------------------------------------*/
37 #include "usbh_core.h"
38 
39 
60 /*Communication Class codes*/
61 #define USB_CDC_CLASS 0x02
62 #define COMMUNICATION_INTERFACE_CLASS_CODE 0x02
63 
64 /*Data Interface Class Codes*/
65 #define DATA_INTERFACE_CLASS_CODE 0x0A
66 
67 /*Communication sub class codes*/
68 #define RESERVED 0x00
69 #define DIRECT_LINE_CONTROL_MODEL 0x01
70 #define ABSTRACT_CONTROL_MODEL 0x02
71 #define TELEPHONE_CONTROL_MODEL 0x03
72 #define MULTICHANNEL_CONTROL_MODEL 0x04
73 #define CAPI_CONTROL_MODEL 0x05
74 #define ETHERNET_NETWORKING_CONTROL_MODEL 0x06
75 #define ATM_NETWORKING_CONTROL_MODEL 0x07
76 
77 
78 /*Communication Interface Class Control Protocol Codes*/
79 #define NO_CLASS_SPECIFIC_PROTOCOL_CODE 0x00
80 #define COMMON_AT_COMMAND 0x01
81 #define VENDOR_SPECIFIC 0xFF
82 
83 
84 #define CS_INTERFACE 0x24
85 #define CDC_PAGE_SIZE_64 0x40
86 
87 /*Class-Specific Request Codes*/
88 #define CDC_SEND_ENCAPSULATED_COMMAND 0x00
89 #define CDC_GET_ENCAPSULATED_RESPONSE 0x01
90 #define CDC_SET_COMM_FEATURE 0x02
91 #define CDC_GET_COMM_FEATURE 0x03
92 #define CDC_CLEAR_COMM_FEATURE 0x04
93 
94 #define CDC_SET_AUX_LINE_STATE 0x10
95 #define CDC_SET_HOOK_STATE 0x11
96 #define CDC_PULSE_SETUP 0x12
97 #define CDC_SEND_PULSE 0x13
98 #define CDC_SET_PULSE_TIME 0x14
99 #define CDC_RING_AUX_JACK 0x15
100 
101 #define CDC_SET_LINE_CODING 0x20
102 #define CDC_GET_LINE_CODING 0x21
103 #define CDC_SET_CONTROL_LINE_STATE 0x22
104 #define CDC_SEND_BREAK 0x23
105 
106 #define CDC_SET_RINGER_PARMS 0x30
107 #define CDC_GET_RINGER_PARMS 0x31
108 #define CDC_SET_OPERATION_PARMS 0x32
109 #define CDC_GET_OPERATION_PARMS 0x33
110 #define CDC_SET_LINE_PARMS 0x34
111 #define CDC_GET_LINE_PARMS 0x35
112 #define CDC_DIAL_DIGITS 0x36
113 #define CDC_SET_UNIT_PARAMETER 0x37
114 #define CDC_GET_UNIT_PARAMETER 0x38
115 #define CDC_CLEAR_UNIT_PARAMETER 0x39
116 #define CDC_GET_PROFILE 0x3A
117 
118 #define CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
119 #define CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x41
120 #define CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x42
121 #define CDC_SET_ETHERNET_PACKET_FILTER 0x43
122 #define CDC_GET_ETHERNET_STATISTIC 0x44
123 
124 #define CDC_SET_ATM_DATA_FORMAT 0x50
125 #define CDC_GET_ATM_DEVICE_STATISTICS 0x51
126 #define CDC_SET_ATM_DEFAULT_VC 0x52
127 #define CDC_GET_ATM_VC_STATISTICS 0x53
128 
129 
130 /* wValue for SetControlLineState*/
131 #define CDC_ACTIVATE_CARRIER_SIGNAL_RTS 0x0002
132 #define CDC_DEACTIVATE_CARRIER_SIGNAL_RTS 0x0000
133 #define CDC_ACTIVATE_SIGNAL_DTR 0x0001
134 #define CDC_DEACTIVATE_SIGNAL_DTR 0x0000
135 
136 #define LINE_CODING_STRUCTURE_SIZE 0x07
137 
145 /* States for CDC State Machine */
146 typedef enum
147 {
153 }
155 
156 typedef enum
157 {
163 }
165 
166 
167 /*Line coding structure*/
169 {
171 
172  struct
173  {
174 
175  uint32_t dwDTERate; /*Data terminal rate, in bits per second*/
176  uint8_t bCharFormat; /*Stop bits
177  0 - 1 Stop bit
178  1 - 1.5 Stop bits
179  2 - 2 Stop bits*/
180  uint8_t bParityType; /* Parity
181  0 - None
182  1 - Odd
183  2 - Even
184  3 - Mark
185  4 - Space*/
186  uint8_t bDataBits; /* Data bits (5, 6, 7, 8 or 16). */
187  }b;
188 }
190 
191 
192 
193 /* Header Functional Descriptor
194 --------------------------------------------------------------------------------
195 Offset| field | Size | Value | Description
196 ------|---------------------|-------|------------|------------------------------
197 0 | bFunctionLength | 1 | number | Size of this descriptor.
198 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
199 2 | bDescriptorSubtype | 1 | Constant | Identifier (ID) of functional
200  | | | | descriptor.
201 3 | bcdCDC | 2 | |
202  | | | Number | USB Class Definitions for
203  | | | | Communication Devices Specification
204  | | | | release number in binary-coded
205  | | | | decimal
206 ------|---------------------|-------|------------|------------------------------
207 */
209 {
210  uint8_t bLength; /*Size of this descriptor.*/
211  uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
212  uint8_t bDescriptorSubType; /* Header functional descriptor subtype as*/
213  uint16_t bcdCDC; /* USB Class Definitions for Communication
214  Devices Specification release number in
215  binary-coded decimal. */
216 }
218 /* Call Management Functional Descriptor
219 --------------------------------------------------------------------------------
220 Offset| field | Size | Value | Description
221 ------|---------------------|-------|------------|------------------------------
222 0 | bFunctionLength | 1 | number | Size of this descriptor.
223 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
224 2 | bDescriptorSubtype | 1 | Constant | Call Management functional
225  | | | | descriptor subtype.
226 3 | bmCapabilities | 1 | Bitmap | The capabilities that this configuration
227  | | | | supports:
228  | | | | D7..D2: RESERVED (Reset to zero)
229  | | | | D1: 0 - Device sends/receives call
230  | | | | management information only over
231  | | | | the Communication Class
232  | | | | interface.
233  | | | | 1 - Device can send/receive call
234  | \ | | management information over a
235  | | | | Data Class interface.
236  | | | | D0: 0 - Device does not handle call
237  | | | | management itself.
238  | | | | 1 - Device handles call
239  | | | | management itself.
240  | | | | The previous bits, in combination, identify
241  | | | | which call management scenario is used. If bit
242  | | | | D0 is reset to 0, then the value of bit D1 is
243  | | | | ignored. In this case, bit D1 is reset to zero for
244  | | | | future compatibility.
245 4 | bDataInterface | 1 | Number | Interface number of Data Class interface
246  | | | | optionally used for call management.
247 ------|---------------------|-------|------------|------------------------------
248 */
250 {
251  uint8_t bLength; /*Size of this functional descriptor, in bytes.*/
252  uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
253  uint8_t bDescriptorSubType; /* Call Management functional descriptor subtype*/
254  uint8_t bmCapabilities; /* bmCapabilities: D0+D1 */
255  uint8_t bDataInterface; /*bDataInterface: 1*/
256 }
258 /* Abstract Control Management Functional Descriptor
259 --------------------------------------------------------------------------------
260 Offset| field | Size | Value | Description
261 ------|---------------------|-------|------------|------------------------------
262 0 | bFunctionLength | 1 | number | Size of functional descriptor, in bytes.
263 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
264 2 | bDescriptorSubtype | 1 | Constant | Abstract Control Management
265  | | | | functional descriptor subtype.
266 3 | bmCapabilities | 1 | Bitmap | The capabilities that this configuration
267  | | | | supports ((A bit value of zero means that the
268  | | | | request is not supported.) )
269  D7..D4: RESERVED (Reset to zero)
270  | | | | D3: 1 - Device supports the notification
271  | | | | Network_Connection.
272  | | | | D2: 1 - Device supports the request
273  | | | | Send_Break
274  | | | | D1: 1 - Device supports the request
275  | \ | | combination of Set_Line_Coding,
276  | | | | Set_Control_Line_State, Get_Line_Coding, and the
277  notification Serial_State.
278  | | | | D0: 1 - Device supports the request
279  | | | | combination of Set_Comm_Feature,
280  | | | | Clear_Comm_Feature, and Get_Comm_Feature.
281  | | | | The previous bits, in combination, identify
282  | | | | which requests/notifications are supported by
283  | | | | a Communication Class interface with the
284  | | | | SubClass code of Abstract Control Model.
285 ------|---------------------|-------|------------|------------------------------
286 */
288 {
289  uint8_t bLength; /*Size of this functional descriptor, in bytes.*/
290  uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
291  uint8_t bDescriptorSubType; /* Abstract Control Management functional
292  descriptor subtype*/
293  uint8_t bmCapabilities; /* The capabilities that this configuration supports */
294 }
296 /* Union Functional Descriptor
297 --------------------------------------------------------------------------------
298 Offset| field | Size | Value | Description
299 ------|---------------------|-------|------------|------------------------------
300 0 | bFunctionLength | 1 | number | Size of this descriptor.
301 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
302 2 | bDescriptorSubtype | 1 | Constant | Union functional
303  | | | | descriptor subtype.
304 3 | bMasterInterface | 1 | Constant | The interface number of the
305  | | | | Communication or Data Class interface
306 4 | bSlaveInterface0 | 1 | Number | nterface number of first slave or associated
307  | | | | interface in the union.
308 ------|---------------------|-------|------------|------------------------------
309 */
311 {
312  uint8_t bLength; /*Size of this functional descriptor, in bytes*/
313  uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
314  uint8_t bDescriptorSubType; /* Union functional descriptor SubType*/
315  uint8_t bMasterInterface; /* The interface number of the Communication or
316  Data Class interface,*/
317  uint8_t bSlaveInterface0; /*Interface number of first slave*/
318 }
320 
322 {
327 }
329 
330 
331 /* Structure for CDC process */
332 typedef struct
333 {
334  uint8_t NotifPipe;
335  uint8_t NotifEp;
336  uint8_t buff[8];
337  uint16_t NotifEpSize;
338 }
340 
341 typedef struct
342 {
343  uint8_t InPipe;
344  uint8_t OutPipe;
345  uint8_t OutEp;
346  uint8_t InEp;
347  uint8_t buff[8];
348  uint16_t OutEpSize;
349  uint16_t InEpSize;
350 }
352 
353 /* Structure for CDC process */
354 typedef struct _CDC_Process
355 {
358  uint8_t *pTxData;
359  uint8_t *pRxData;
360  uint32_t TxDataLength;
361  uint32_t RxDataLength;
365  CDC_StateTypeDef state;
366  CDC_DataStateTypeDef data_tx_state;
367  CDC_DataStateTypeDef data_rx_state;
368  uint8_t Rx_Poll;
369 }
371 
395 #define USBH_CDC_CLASS &CDC_Class
396 
407 
410 
412  uint8_t *pbuff,
413  uint32_t length);
414 
416  uint8_t *pbuff,
417  uint32_t length);
418 
419 
421 
423 
425 
427 
429 
434 #ifdef __cplusplus
435 }
436 #endif
437 
438 #endif /* __USBH_CDC_H */
439 
455 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
456 
USBH_ClassTypeDef CDC_Class
Definition: usbh_cdc.c:125
Header file for usbh_core.c.
CDC_HeaderFuncDesc_TypeDef CDC_HeaderFuncDesc
Definition: usbh_cdc.h:323
CDC_DataStateTypeDef
Definition: usbh_cdc.h:146
USBD_CDC_LineCodingTypeDef linecoding
CDC_CallMgmtFuncDesc_TypeDef CDC_CallMgmtFuncDesc
Definition: usbh_cdc.h:324
struct _USBH_CDCInterfaceDesc CDC_InterfaceDesc_Typedef
struct _CallMgmtFunctionalDescriptor CDC_CallMgmtFuncDesc_TypeDef
USBH_StatusTypeDef USBH_CDC_Transmit(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length)
This function prepares the state before issuing the class specific commands.
Definition: usbh_cdc.c:545
uint16_t USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost)
This function return last received data size.
Definition: usbh_cdc.c:526
uint16_t InEpSize
Definition: usbh_cdc.h:349
uint8_t NotifPipe
Definition: usbh_cdc.h:334
uint8_t * pRxData
Definition: usbh_cdc.h:359
void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost)
The function informs user that data have been received.
Definition: usbh_cdc.c:728
void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost)
The function informs user that Settings have been changed.
Definition: usbh_cdc.c:748
CDC_StateTypeDef
Definition: usbh_cdc.h:156
CDC_AbstCntrlMgmtFuncDesc_TypeDef CDC_AbstCntrlMgmtFuncDesc
Definition: usbh_cdc.h:325
CDC_CommItfTypedef CommItf
Definition: usbh_cdc.h:356
USBH_StatusTypeDef USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecoding)
This function prepares the state before issuing the class specific commands.
Definition: usbh_cdc.c:506
CDC_InterfaceDesc_Typedef CDC_Desc
Definition: usbh_cdc.h:362
#define LINE_CODING_STRUCTURE_SIZE
Definition: usbh_cdc.h:136
struct _FunctionalDescriptorHeader CDC_HeaderFuncDesc_TypeDef
CDC_DataItfTypedef DataItf
Definition: usbh_cdc.h:357
USBH_StatusTypeDef USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost, CDC_LineCodingTypeDef *linecoding)
This function prepares the state before issuing the class specific commands.
Definition: usbh_cdc.c:486
uint32_t TxDataLength
Definition: usbh_cdc.h:360
CDC_StateTypeDef state
Definition: usbh_cdc.h:365
USBH_StatusTypeDef
Definition: usbh_def.h:302
void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost)
The function informs user that data have been sent.
Definition: usbh_cdc.c:738
uint8_t * pTxData
Definition: usbh_cdc.h:358
USBH_StatusTypeDef USBH_CDC_Receive(USBH_HandleTypeDef *phost, uint8_t *pbuff, uint32_t length)
This function prepares the state before issuing the class specific commands.
Definition: usbh_cdc.c:570
CDC_UnionFuncDesc_TypeDef CDC_UnionFuncDesc
Definition: usbh_cdc.h:326
uint16_t NotifEpSize
Definition: usbh_cdc.h:337
USBH_StatusTypeDef USBH_CDC_Stop(USBH_HandleTypeDef *phost)
USBH_CDC_Stop Stop current CDC Transmission.
Definition: usbh_cdc.c:423
struct _CDC_LineCodingStructure::@36 b
CDC_DataStateTypeDef data_tx_state
Definition: usbh_cdc.h:366
struct _AbstractCntrlMgmtFunctionalDescriptor CDC_AbstCntrlMgmtFuncDesc_TypeDef
struct _UnionFunctionalDescriptor CDC_UnionFuncDesc_TypeDef
CDC_LineCodingTypeDef LineCoding
Definition: usbh_cdc.h:363
uint8_t Rx_Poll
Definition: usbh_cdc.h:368
union _CDC_LineCodingStructure CDC_LineCodingTypeDef
struct _CDC_Process CDC_HandleTypeDef
uint16_t OutEpSize
Definition: usbh_cdc.h:348
uint8_t Array[LINE_CODING_STRUCTURE_SIZE]
Definition: usbh_cdc.h:170
CDC_DataStateTypeDef data_rx_state
Definition: usbh_cdc.h:367
CDC_LineCodingTypeDef * pUserLineCoding
Definition: usbh_cdc.h:364
uint32_t RxDataLength
Definition: usbh_cdc.h:361