Debian Codegraph @

ports/stm32/usbhost/Class/CDC/Inc/usbh_cdc.h

raw
1 /**
2 ******************************************************************************
3 * @file usbh_cdc.h
4 * @author MCD Application Team
5 * @version V3.0.0
6 * @date 18-February-2014
7 * @brief This file contains all the prototypes for the usbh_cdc.c
8 ******************************************************************************
9 * @attention
10 *
11 * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
12 *
13 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 * You may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at:
16 *
17 * http://www.st.com/software_license_agreement_liberty_v2
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 ******************************************************************************
26 */
27
28 /* Define to prevent recursive ----------------------------------------------*/
29 #ifndef __USBH_CDC_CORE_H
30 #define __USBH_CDC_CORE_H
31
32 /* Includes ------------------------------------------------------------------*/
33 #include "usbh_core.h"
34
35
36 /** @addtogroup USBH_LIB
37 * @{
38 */
39
40 /** @addtogroup USBH_CLASS
41 * @{
42 */
43
44 /** @addtogroup USBH_CDC_CLASS
45 * @{
46 */
47
48 /** @defgroup USBH_CDC_CORE
49 * @brief This file is the Header file for USBH_CDC_CORE.c
50 * @{
51 */
52
53
54
55
56 /*Communication Class codes*/
57 #define USB_CDC_CLASS 0x02
58 #define COMMUNICATION_INTERFACE_CLASS_CODE 0x02
59
60 /*Data Interface Class Codes*/
61 #define DATA_INTERFACE_CLASS_CODE 0x0A
62
63 /*Communcation sub class codes*/
64 #define RESERVED 0x00
65 #define DIRECT_LINE_CONTROL_MODEL 0x01
66 #define ABSTRACT_CONTROL_MODEL 0x02
67 #define TELEPHONE_CONTROL_MODEL 0x03
68 #define MULTICHANNEL_CONTROL_MODEL 0x04
69 #define CAPI_CONTROL_MODEL 0x05
70 #define ETHERNET_NETWORKING_CONTROL_MODEL 0x06
71 #define ATM_NETWORKING_CONTROL_MODEL 0x07
72
73
74 /*Communication Interface Class Control Protocol Codes*/
75 #define NO_CLASS_SPECIFIC_PROTOCOL_CODE 0x00
76 #define COMMON_AT_COMMAND 0x01
77 #define VENDOR_SPECIFIC 0xFF
78
79
80 #define CS_INTERFACE 0x24
81 #define CDC_PAGE_SIZE_64 0x40
82
83 /*Class-Specific Request Codes*/
84 #define CDC_SEND_ENCAPSULATED_COMMAND 0x00
85 #define CDC_GET_ENCAPSULATED_RESPONSE 0x01
86 #define CDC_SET_COMM_FEATURE 0x02
87 #define CDC_GET_COMM_FEATURE 0x03
88 #define CDC_CLEAR_COMM_FEATURE 0x04
89
90 #define CDC_SET_AUX_LINE_STATE 0x10
91 #define CDC_SET_HOOK_STATE 0x11
92 #define CDC_PULSE_SETUP 0x12
93 #define CDC_SEND_PULSE 0x13
94 #define CDC_SET_PULSE_TIME 0x14
95 #define CDC_RING_AUX_JACK 0x15
96
97 #define CDC_SET_LINE_CODING 0x20
98 #define CDC_GET_LINE_CODING 0x21
99 #define CDC_SET_CONTROL_LINE_STATE 0x22
100 #define CDC_SEND_BREAK 0x23
101
102 #define CDC_SET_RINGER_PARMS 0x30
103 #define CDC_GET_RINGER_PARMS 0x31
104 #define CDC_SET_OPERATION_PARMS 0x32
105 #define CDC_GET_OPERATION_PARMS 0x33
106 #define CDC_SET_LINE_PARMS 0x34
107 #define CDC_GET_LINE_PARMS 0x35
108 #define CDC_DIAL_DIGITS 0x36
109 #define CDC_SET_UNIT_PARAMETER 0x37
110 #define CDC_GET_UNIT_PARAMETER 0x38
111 #define CDC_CLEAR_UNIT_PARAMETER 0x39
112 #define CDC_GET_PROFILE 0x3A
113
114 #define CDC_SET_ETHERNET_MULTICAST_FILTERS 0x40
115 #define CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x41
116 #define CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERN FILTER 0x42
117 #define CDC_SET_ETHERNET_PACKET_FILTER 0x43
118 #define CDC_GET_ETHERNET_STATISTIC 0x44
119
120 #define CDC_SET_ATM_DATA_FORMAT 0x50
121 #define CDC_GET_ATM_DEVICE_STATISTICS 0x51
122 #define CDC_SET_ATM_DEFAULT_VC 0x52
123 #define CDC_GET_ATM_VC_STATISTICS 0x53
124
125
126 /* wValue for SetControlLineState*/
127 #define CDC_ACTIVATE_CARRIER_SIGNAL_RTS 0x0002
128 #define CDC_DEACTIVATE_CARRIER_SIGNAL_RTS 0x0000
129 #define CDC_ACTIVATE_SIGNAL_DTR 0x0001
130 #define CDC_DEACTIVATE_SIGNAL_DTR 0x0000
131
132 #define LINE_CODING_STRUCTURE_SIZE 0x07
133 /**
134 * @}
135 */
136
137 /** @defgroup USBH_CDC_CORE_Exported_Types
138 * @{
139 */
140
141 /* States for CDC State Machine */
142 typedef enum
143 {
144 CDC_IDLE= 0,
145 CDC_SEND_DATA,
146 CDC_SEND_DATA_WAIT,
147 CDC_RECEIVE_DATA,
148 CDC_RECEIVE_DATA_WAIT,
149 }
150 CDC_DataStateTypeDef;
151
152 typedef enum
153 {
154 CDC_IDLE_STATE= 0,
155 CDC_SET_LINE_CODING_STATE,
156 CDC_GET_LAST_LINE_CODING_STATE,
157 CDC_TRANSFER_DATA,
158 CDC_ERROR_STATE,
159 }
160 CDC_StateTypeDef;
161
162
163 /*Line coding structure*/
164 typedef union _CDC_LineCodingStructure
165 {
166 uint8_t Array[LINE_CODING_STRUCTURE_SIZE];
167
168 struct
169 {
170
171 uint32_t dwDTERate; /*Data terminal rate, in bits per second*/
172 uint8_t bCharFormat; /*Stop bits
173 0 - 1 Stop bit
174 1 - 1.5 Stop bits
175 2 - 2 Stop bits*/
176 uint8_t bParityType; /* Parity
177 0 - None
178 1 - Odd
179 2 - Even
180 3 - Mark
181 4 - Space*/
182 uint8_t bDataBits; /* Data bits (5, 6, 7, 8 or 16). */
183 }b;
184 }
185 CDC_LineCodingTypeDef;
186
187
188
189 /* Header Functional Descriptor
190 --------------------------------------------------------------------------------
191 Offset| field | Size | Value | Description
192 ------|---------------------|-------|------------|------------------------------
193 0 | bFunctionLength | 1 | number | Size of this descriptor.
194 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
195 2 | bDescriptorSubtype | 1 | Constant | Identifier (ID) of functional
196 | | | | descriptor.
197 3 | bcdCDC | 2 | |
198 | | | Number | USB Class Definitions for
199 | | | | Communication Devices Specification
200 | | | | release number in binary-coded
201 | | | | decimal
202 ------|---------------------|-------|------------|------------------------------
203 */
204 typedef struct _FunctionalDescriptorHeader
205 {
206 uint8_t bLength; /*Size of this descriptor.*/
207 uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
208 uint8_t bDescriptorSubType; /* Header functional descriptor subtype as*/
209 uint16_t bcdCDC; /* USB Class Definitions for Communication
210 Devices Specification release number in
211 binary-coded decimal. */
212 }
213 CDC_HeaderFuncDesc_TypeDef;
214 /* Call Management Functional Descriptor
215 --------------------------------------------------------------------------------
216 Offset| field | Size | Value | Description
217 ------|---------------------|-------|------------|------------------------------
218 0 | bFunctionLength | 1 | number | Size of this descriptor.
219 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
220 2 | bDescriptorSubtype | 1 | Constant | Call Management functional
221 | | | | descriptor subtype.
222 3 | bmCapabilities | 1 | Bitmap | The capabilities that this configuration
223 | | | | supports:
224 | | | | D7..D2: RESERVED (Reset to zero)
225 | | | | D1: 0 - Device sends/receives call
226 | | | | management information only over
227 | | | | the Communication Class
228 | | | | interface.
229 | | | | 1 - Device can send/receive call
230 | \ | | management information over a
231 | | | | Data Class interface.
232 | | | | D0: 0 - Device does not handle call
233 | | | | management itself.
234 | | | | 1 - Device handles call
235 | | | | management itself.
236 | | | | The previous bits, in combination, identify
237 | | | | which call management scenario is used. If bit
238 | | | | D0 is reset to 0, then the value of bit D1 is
239 | | | | ignored. In this case, bit D1 is reset to zero for
240 | | | | future compatibility.
241 4 | bDataInterface | 1 | Number | Interface number of Data Class interface
242 | | | | optionally used for call management.
243 ------|---------------------|-------|------------|------------------------------
244 */
245 typedef struct _CallMgmtFunctionalDescriptor
246 {
247 uint8_t bLength; /*Size of this functional descriptor, in bytes.*/
248 uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
249 uint8_t bDescriptorSubType; /* Call Management functional descriptor subtype*/
250 uint8_t bmCapabilities; /* bmCapabilities: D0+D1 */
251 uint8_t bDataInterface; /*bDataInterface: 1*/
252 }
253 CDC_CallMgmtFuncDesc_TypeDef;
254 /* Abstract Control Management Functional Descriptor
255 --------------------------------------------------------------------------------
256 Offset| field | Size | Value | Description
257 ------|---------------------|-------|------------|------------------------------
258 0 | bFunctionLength | 1 | number | Size of functional descriptor, in bytes.
259 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
260 2 | bDescriptorSubtype | 1 | Constant | Abstract Control Management
261 | | | | functional descriptor subtype.
262 3 | bmCapabilities | 1 | Bitmap | The capabilities that this configuration
263 | | | | supports ((A bit value of zero means that the
264 | | | | request is not supported.) )
265 D7..D4: RESERVED (Reset to zero)
266 | | | | D3: 1 - Device supports the notification
267 | | | | Network_Connection.
268 | | | | D2: 1 - Device supports the request
269 | | | | Send_Break
270 | | | | D1: 1 - Device supports the request
271 | \ | | combination of Set_Line_Coding,
272 | | | | Set_Control_Line_State, Get_Line_Coding, and the
273 notification Serial_State.
274 | | | | D0: 1 - Device supports the request
275 | | | | combination of Set_Comm_Feature,
276 | | | | Clear_Comm_Feature, and Get_Comm_Feature.
277 | | | | The previous bits, in combination, identify
278 | | | | which requests/notifications are supported by
279 | | | | a Communication Class interface with the
280 | | | | SubClass code of Abstract Control Model.
281 ------|---------------------|-------|------------|------------------------------
282 */
283 typedef struct _AbstractCntrlMgmtFunctionalDescriptor
284 {
285 uint8_t bLength; /*Size of this functional descriptor, in bytes.*/
286 uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
287 uint8_t bDescriptorSubType; /* Abstract Control Management functional
288 descriptor subtype*/
289 uint8_t bmCapabilities; /* The capabilities that this configuration supports */
290 }
291 CDC_AbstCntrlMgmtFuncDesc_TypeDef;
292 /* Union Functional Descriptor
293 --------------------------------------------------------------------------------
294 Offset| field | Size | Value | Description
295 ------|---------------------|-------|------------|------------------------------
296 0 | bFunctionLength | 1 | number | Size of this descriptor.
297 1 | bDescriptorType | 1 | Constant | CS_INTERFACE (0x24)
298 2 | bDescriptorSubtype | 1 | Constant | Union functional
299 | | | | descriptor subtype.
300 3 | bMasterInterface | 1 | Constant | The interface number of the
301 | | | | Communication or Data Class interface
302 4 | bSlaveInterface0 | 1 | Number | nterface number of first slave or associated
303 | | | | interface in the union.
304 ------|---------------------|-------|------------|------------------------------
305 */
306 typedef struct _UnionFunctionalDescriptor
307 {
308 uint8_t bLength; /*Size of this functional descriptor, in bytes*/
309 uint8_t bDescriptorType; /*CS_INTERFACE (0x24)*/
310 uint8_t bDescriptorSubType; /* Union functional descriptor SubType*/
311 uint8_t bMasterInterface; /* The interface number of the Communication or
312 Data Class interface,*/
313 uint8_t bSlaveInterface0; /*Interface number of first slave*/
314 }
315 CDC_UnionFuncDesc_TypeDef;
316
317 typedef struct _USBH_CDCInterfaceDesc
318 {
319 CDC_HeaderFuncDesc_TypeDef CDC_HeaderFuncDesc;
320 CDC_CallMgmtFuncDesc_TypeDef CDC_CallMgmtFuncDesc;
321 CDC_AbstCntrlMgmtFuncDesc_TypeDef CDC_AbstCntrlMgmtFuncDesc;
322 CDC_UnionFuncDesc_TypeDef CDC_UnionFuncDesc;
323 }
324 CDC_InterfaceDesc_Typedef;
325
326
327 /* Structure for CDC process */
328 typedef struct
329 {
330 uint8_t NotifPipe;
331 uint8_t NotifEp;
332 uint8_t buff[8];
333 uint16_t NotifEpSize;
334 }
335 CDC_CommItfTypedef ;
336
337 typedef struct
338 {
339 uint8_t InPipe;
340 uint8_t OutPipe;
341 uint8_t OutEp;
342 uint8_t InEp;
343 uint8_t buff[8];
344 uint16_t OutEpSize;
345 uint16_t InEpSize;
346 }
347 CDC_DataItfTypedef ;
348
349 /* Structure for CDC process */
350 typedef struct _CDC_Process
351 {
352 CDC_CommItfTypedef CommItf;
353 CDC_DataItfTypedef DataItf;
354 uint8_t *pTxData;
355 uint8_t *pRxData;
356 uint32_t TxDataLength;
357 uint32_t RxDataLength;
358 CDC_InterfaceDesc_Typedef CDC_Desc;
359 CDC_LineCodingTypeDef LineCoding;
360 CDC_LineCodingTypeDef *pUserLineCoding;
361 CDC_StateTypeDef state;
362 CDC_DataStateTypeDef data_tx_state;
363 CDC_DataStateTypeDef data_rx_state;
364 uint8_t Rx_Poll;
365 }
366 CDC_HandleTypeDef;
367
368 /**
369 * @}
370 */
371
372 /** @defgroup USBH_CDC_CORE_Exported_Defines
373 * @{
374 */
375
376 /**
377 * @}
378 */
379
380 /** @defgroup USBH_CDC_CORE_Exported_Macros
381 * @{
382 */
383 /**
384 * @}
385 */
386
387 /** @defgroup USBH_CDC_CORE_Exported_Variables
388 * @{
389 */
390 extern USBH_ClassTypeDef CDC_Class;
391 #define USBH_CDC_CLASS &CDC_Class
392
393 /**
394 * @}
395 */
396
397 /** @defgroup USBH_CDC_CORE_Exported_FunctionsPrototype
398 * @{
399 */
400
401 USBH_StatusTypeDef USBH_CDC_SetLineCoding(USBH_HandleTypeDef *phost,
402 CDC_LineCodingTypeDef *linecoding);
403
404 USBH_StatusTypeDef USBH_CDC_GetLineCoding(USBH_HandleTypeDef *phost,
405 CDC_LineCodingTypeDef *linecoding);
406
407 USBH_StatusTypeDef USBH_CDC_Transmit(USBH_HandleTypeDef *phost,
408 uint8_t *pbuff,
409 uint32_t length);
410
411 USBH_StatusTypeDef USBH_CDC_Receive(USBH_HandleTypeDef *phost,
412 uint8_t *pbuff,
413 uint32_t length);
414
415
416 uint16_t USBH_CDC_GetLastReceivedDataSize(USBH_HandleTypeDef *phost);
417
418 USBH_StatusTypeDef USBH_CDC_Stop(USBH_HandleTypeDef *phost);
419
420 void USBH_CDC_LineCodingChanged(USBH_HandleTypeDef *phost);
421
422 void USBH_CDC_TransmitCallback(USBH_HandleTypeDef *phost);
423
424 void USBH_CDC_ReceiveCallback(USBH_HandleTypeDef *phost);
425
426 /**
427 * @}
428 */
429
430
431 #endif /* __USBH_CDC_CORE_H */
432
433 /**
434 * @}
435 */
436
437 /**
438 * @}
439 */
440
441 /**
442 * @}
443 */
444
445 /**
446 * @}
447 */
448 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
449