1 //*****************************************************************************
2 //
3 // usbhid.h - Definitions used by Communication Device Class devices.
4 //
5 // Copyright (c) 2007-2010 Texas Instruments Incorporated.  All rights reserved.
6 // Software License Agreement
7 //
8 // Texas Instruments (TI) is supplying this software for use solely and
9 // exclusively on TI's microcontroller products. The software is owned by
10 // TI and/or its suppliers, and is protected under applicable copyright
11 // laws. You may not combine this software with "viral" open-source
12 // software in order to form a larger program.
13 //
14 // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
15 // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
16 // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
18 // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
19 // DAMAGES, FOR ANY REASON WHATSOEVER.
20 //
21 //
22 //*****************************************************************************
23 
24 //*****************************************************************************
25 //
26 // Note: This header contains definitions related to the USB Communication
27 //       Device Class specification.  The header is complete for ACM model
28 //       devices but request and notification definitions specific to other
29 //       modem types, ISDN, ATM and Ethernet are currently incomplete or
30 //       omitted.
31 //
32 //*****************************************************************************
33 
34 #ifndef __USBCDC_H__
35 #define __USBCDC_H__
36 
37 //*****************************************************************************
38 //
39 // If building with a C++ compiler, make all of the definitions in this header
40 // have a C binding.
41 //
42 //*****************************************************************************
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47 
48 //*****************************************************************************
49 //
50 //! \addtogroup cdc_device_class_api
51 //! @{
52 //
53 //*****************************************************************************
54 
55 //*****************************************************************************
56 //
57 // Generic macros to read a byte, word or long from a character pointer.
58 //
59 //*****************************************************************************
60 #define BYTE(pucData)           (*(uint8 *)(pucData))
61 #define SHORT(pucData)          (*(uint16 *)(pucData))
62 #define LONG(pucData)           (*(uint32 *)(pucData))
63 
64 //*****************************************************************************
65 //
66 // USB CDC subclass codes.  Used in interface descriptor, bInterfaceClass
67 //
68 //*****************************************************************************
69 #define USB_CDC_SUBCLASS_DIRECT_LINE_MODEL          0x01
70 #define USB_CDC_SUBCLASS_ABSTRACT_MODEL             0x02
71 #define USB_CDC_SUBCLASS_TELEPHONE_MODEL            0x03
72 #define USB_CDC_SUBCLASS_MULTI_CHANNEL_MODEL        0x04
73 #define USB_CDC_SUBCLASS_CAPI_MODEL                 0x05
74 #define USB_CDC_SUBCLASS_ETHERNET_MODEL             0x06
75 #define USB_CDC_SUBCLASS_ATM_MODEL                  0x07
76 
77 //*****************************************************************************
78 //
79 // USB CDC control interface protocols.  Used in control interface descriptor,
80 // bInterfaceProtocol
81 //
82 //*****************************************************************************
83 #define USB_CDC_PROTOCOL_NONE                       0x00
84 #define USB_CDC_PROTOCOL_V25TER                     0x01
85 #define USB_CDC_PROTOCOL_VENDOR                     0xFF
86 
87 //*****************************************************************************
88 //
89 // USB CDC data interface protocols.  Used in data interface descriptor,
90 // bInterfaceProtocol
91 //
92 //*****************************************************************************
93 //      USB_CDC_PROTOCOL_NONE                       0x00
94 #define USB_CDC_PROTOCOL_I420                       0x30
95 #define USB_CDC_PROTOCOL_TRANSPARENT                0x32
96 #define USB_CDC_PROTOCOL_Q921M                      0x50
97 #define USB_CDC_PROTOCOL_Q921                       0x51
98 #define USB_CDC_PROTOCOL_Q921TM                     0x52
99 #define USB_CDC_PROTOCOL_V42BIS                     0x90
100 #define USB_CDC_PROTOCOL_Q921EURO                   0x91
101 #define USB_CDC_PROTOCOL_V120                       0x92
102 #define USB_CDC_PROTOCOL_CAPI20                     0x93
103 #define USB_CDC_PROTOCOL_HOST_DRIVER                0xFD
104 #define USB_CDC_PROTOCOL_CDC_SPEC                   0xFE
105 //      USB_CDC_PROTOCOL_VENDOR                     0xFF
106 
107 //*****************************************************************************
108 //
109 // Functional descriptor definitions
110 //
111 //*****************************************************************************
112 
113 //*****************************************************************************
114 //
115 // Functional descriptor types
116 //
117 //*****************************************************************************
118 #define USB_CDC_CS_INTERFACE                    0x24
119 #define USB_CDC_CS_ENDPOINT                     0x25
120 
121 //*****************************************************************************
122 //
123 // Functional descriptor subtypes
124 //
125 //*****************************************************************************
126 #define USB_CDC_FD_SUBTYPE_HEADER               0x00
127 #define USB_CDC_FD_SUBTYPE_CALL_MGMT            0x01
128 #define USB_CDC_FD_SUBTYPE_ABSTRACT_CTL_MGMT    0x02
129 #define USB_CDC_FD_SUBTYPE_DIRECT_LINE_MGMT     0x03
130 #define USB_CDC_FD_SUBTYPE_TELEPHONE_RINGER     0x04
131 #define USB_CDC_FD_SUBTYPE_LINE_STATE_CAPS      0x05
132 #define USB_CDC_FD_SUBTYPE_UNION                0x06
133 #define USB_CDC_FD_SUBTYPE_COUNTRY              0x07
134 #define USB_CDC_FD_SUBTYPE_TELEPHONE_MODES      0x08
135 #define USB_CDC_FD_SUBTYPE_USB_TERMINAL         0x09
136 #define USB_CDC_FD_SUBTYPE_NETWORK_TERMINAL     0x0A
137 #define USB_CDC_FD_SUBTYPE_PROTOCOL_UNIT        0x0B
138 #define USB_CDC_FD_SUBTYPE_EXTENSION_UNIT       0x0C
139 #define USB_CDC_FD_SUBTYPE_MULTI_CHANNEL_MGMT   0x0D
140 #define USB_CDC_FD_SUBTYPE_CAPI_MGMT            0x0E
141 #define USB_CDC_FD_SUBTYPE_ETHERNET             0x0F
142 #define USB_CDC_FD_SUBTYPE_ATM                  0x10
143 
144 //*****************************************************************************
145 //
146 // USB_CDC_FD_SUBTYPE_CALL_MGMT, Header functional descriptor, bmCapabilities
147 //
148 //*****************************************************************************
149 #define USB_CDC_CALL_MGMT_VIA_DATA              0x02
150 #define USB_CDC_CALL_MGMT_HANDLED               0x01
151 
152 //*****************************************************************************
153 //
154 // USB_CDC_FD_SUBTYPE_ABSTRACT_CTL_MGMT, Abstract Control Management functional
155 // descriptor, bmCapabilities
156 //
157 //*****************************************************************************
158 #define USB_CDC_ACM_SUPPORTS_NETWORK_CONNECTION 0x08
159 #define USB_CDC_ACM_SUPPORTS_SEND_BREAK         0x04
160 #define USB_CDC_ACM_SUPPORTS_LINE_PARAMS        0x02
161 #define USB_CDC_ACM_SUPPORTS_COMM_FEATURE       0x01
162 
163 //*****************************************************************************
164 //
165 // USB_CDC_FD_SUBTYPE_DIRECT_LINE_MGMT, Direct Line Management functional
166 // descriptor, bmCapabilities
167 //
168 //*****************************************************************************
169 #define USB_CDC_DLM_NEEDS_EXTRA_PULSE_SETUP     0x04
170 #define USB_CDC_DLM_SUPPORTS_AUX                0x02
171 #define USB_CDC_DLM_SUPPORTS_PULSE              0x01
172 
173 //*****************************************************************************
174 //
175 // USB_CDC_FD_SUBTYPE_TELEPHONE_MODES, Telephone Operational Modes functional
176 // descriptor, bmCapabilities
177 //
178 //*****************************************************************************
179 #define USB_CDC_TELEPHONE_SUPPORTS_COMPUTER     0x04
180 #define USB_CDC_TELEPHONE_SUPPORTS_STANDALONE   0x02
181 #define USB_CDC_TELEPHONE_SUPPORTS_SIMPLE       0x01
182 
183 //*****************************************************************************
184 //
185 // USB_CDC_FD_SUBTYPE_LINE_STATE_CAPS, Telephone Call and Line State Reporting
186 // Capabilities descriptor
187 //
188 //*****************************************************************************
189 #define USB_CDC_LINE_STATE_CHANGES_NOTIFIED     0x20
190 #define USB_CDC_LINE_STATE_REPORTS_DTMF         0x10
191 #define USB_CDC_LINE_STATE_REPORTS_DIST_RING    0x08
192 #define USB_CDC_LINE_STATE_REPORTS_CALLERID     0x04
193 #define USB_CDC_LINE_STATE_REPORTS_BUSY         0x02
194 #define USB_CDC_LINE_STATE_REPORTS_INT_DIALTONE 0x01
195 
196 //*****************************************************************************
197 //
198 // USB_CDC_FD_SUBTYPE_USB_TERMINAL, USB Terminal functional descriptor,
199 // bmOptions
200 //
201 //*****************************************************************************
202 #define USB_CDC_TERMINAL_NO_WRAPPER_USED        0x00
203 #define USB_CDC_TERMINAL_WRAPPER_USED           0x01
204 
205 //*****************************************************************************
206 //
207 // USB_CDC_FD_SUBTYPE_MULTI_CHANNEL_MGMT, Multi-Channel Management functional
208 // descriptor, bmCapabilities
209 //
210 //*****************************************************************************
211 #define USB_CDC_MCM_SUPPORTS_SET_UNIT_PARAM     0x04
212 #define USB_CDC_MCM_SUPPORTS_CLEAR_UNIT_PARAM   0x02
213 #define USB_CDC_MCM_UNIT_PARAMS_NON_VOLATILE    0x01
214 
215 //*****************************************************************************
216 //
217 // USB_CDC_FD_SUBTYPE_CAPI_MGMT, CAPI Control Management functional descriptor,
218 // bmCapabilities
219 //
220 //*****************************************************************************
221 #define USB_CDC_CAPI_INTELLIGENT                0x01
222 #define USB_CDC_CAPI_SIMPLE                     0x00
223 
224 //*****************************************************************************
225 //
226 // USB_CDC_FD_SUBTYPE_ETHERNET, Ethernet Networking functional descriptor,
227 // bmEthernetStatistics
228 //
229 //*****************************************************************************
230 #define USB_CDC_ETHERNET_XMIT_OK                0x01000000
231 #define USB_CDC_ETHERNET_RCV_OK                 0x02000000
232 #define USB_CDC_ETHERNET_XMIT_ERROR             0x04000000
233 #define USB_CDC_ETHERNET_RCV_ERROR              0x08000000
234 #define USB_CDC_ETHERNET_RCV_NO_BUFFER          0x10000000
235 #define USB_CDC_ETHERNET_DIRECTED_BYTES_XMIT    0x20000000
236 #define USB_CDC_ETHERNET_DIRECTED_FRAMES_XMIT   0x40000000
237 #define USB_CDC_ETHERNET_MULTICAST_BYTES_XMIT   0x80000000
238 #define USB_CDC_ETHERNET_MULTICAST_FRAMES_XMIT  0x00010000
239 #define USB_CDC_ETHERNET_BROADCAST_BYTES_XMIT   0x00020000
240 #define USB_CDC_ETHERNET_BROADCAST_FRAMES_XMIT  0x00040000
241 #define USB_CDC_ETHERNET_DIRECTED_BYTES_RCV     0x00080000
242 #define USB_CDC_ETHERNET_DIRECTED_FRAMES_RCV    0x00100000
243 #define USB_CDC_ETHERNET_MULTICAST_BYTES_RCV    0x00200000
244 #define USB_CDC_ETHERNET_MULTICAST_FRAMES_RCV   0x00400000
245 #define USB_CDC_ETHERNET_BROADCAST_BYTES_RCV    0x00800000
246 #define USB_CDC_ETHERNET_BROADCAST_FRAMES_RCV   0x00000100
247 #define USB_CDC_ETHERNET_RCV_CRC_ERROR          0x00000200
248 #define USB_CDC_ETHERNET_TRANSMIT_QUEUE_LENGTH  0x00000400
249 #define USB_CDC_ETHERNET_RCV_ERROR_ALIGNMENT    0x00000800
250 #define USB_CDC_ETHERNET_XMIT_ONE_COLLISION     0x00001000
251 #define USB_CDC_ETHERNET_XMIT_MORE_COLLISIONS   0x00002000
252 #define USB_CDC_ETHERNET_XMIT_DEFERRED          0x00004000
253 #define USB_CDC_ETHERNET_XMIT_MAX_COLLISIONS    0x00008000
254 #define USB_CDC_ETHERNET_RCV_OVERRUN            0x00000001
255 #define USB_CDC_ETHERNET_XMIT_UNDERRUN          0x00000002
256 #define USB_CDC_ETHERNET_XMIT_HEARTBEAT_FAILURE 0x00000004
257 #define USB_CDC_ETHERNET_XMIT_TIMES_CRS_LOST    0x00000008
258 #define USB_CDC_ETHERNET_XMIT_LATE_COLLISIONS   0x00000010
259 
260 //*****************************************************************************
261 //
262 // USB_CDC_FD_SUBTYPE_ATM, ATM Networking functional descriptor,
263 // bmDataCapabilities
264 //
265 //*****************************************************************************
266 #define USB_CDC_ATM_TYPE_3                      0x08
267 #define USB_CDC_ATM_TYPE_2                      0x04
268 #define USB_CDC_ATM_TYPE_1                      0x02
269 
270 //*****************************************************************************
271 //
272 // bmATMDeviceStatistics
273 //
274 //*****************************************************************************
275 #define USB_CDC_ATM_VC_US_CELLS_SENT            0x10
276 #define USB_CDC_ATM_VC_US_CELLS_RECEIVED        0x08
277 #define USB_CDC_ATM_DS_CELLS_HEC_ERR_CORRECTED  0x04
278 #define USB_CDC_ATM_US_CELLS_SENT               0x02
279 #define USB_CDC_ATM_US_CELLS_RECEIVED           0x01
280 
281 //*****************************************************************************
282 //
283 // Management Element Requests (provided in tUSBRequest.ucRequest)
284 //
285 //*****************************************************************************
286 #define USB_CDC_SEND_ENCAPSULATED_COMMAND                       0x00
287 #define USB_CDC_GET_ENCAPSULATED_RESPONSE                       0x01
288 #define USB_CDC_SET_COMM_FEATURE                                0x02
289 #define USB_CDC_GET_COMM_FEATURE                                0x03
290 #define USB_CDC_CLEAR_COMM_FEATURE                              0x04
291 #define USB_CDC_SET_AUX_LINE_STATE                              0x10
292 #define USB_CDC_SET_HOOK_STATE                                  0x11
293 #define USB_CDC_PULSE_SETUP                                     0x12
294 #define USB_CDC_SEND_PULSE                                      0x13
295 #define USB_CDC_SET_PULSE_TIME                                  0x14
296 #define USB_CDC_RING_AUX_JACK                                   0x15
297 #define USB_CDC_SET_LINE_CODING                                 0x20
298 #define USB_CDC_GET_LINE_CODING                                 0x21
299 #define USB_CDC_SET_CONTROL_LINE_STATE                          0x22
300 #define USB_CDC_SEND_BREAK                                      0x23
301 #define USB_CDC_SET_RINGER_PARMS                                0x30
302 #define USB_CDC_GET_RINGER_PARMS                                0x31
303 #define USB_CDC_SET_OPERATION_PARMS                             0x32
304 #define USB_CDC_GET_OPERATION_PARMS                             0x33
305 #define USB_CDC_SET_LINE_PARMS                                  0x34
306 #define USB_CDC_GET_LINE_PARMS                                  0x35
307 #define USB_CDC_DIAL_DIGITS                                     0x36
308 #define USB_CDC_SET_UNIT_PARAMETER                              0x37
309 #define USB_CDC_GET_UNIT_PARAMETER                              0x38
310 #define USB_CDC_CLEAR_UNIT_PARAMETER                            0x39
311 #define USB_CDC_GET_PROFILE                                     0x3A
312 #define USB_CDC_SET_ETHERNET_MULTICAST_FILTERS                  0x40
313 #define USB_CDC_SET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER    0x41
314 #define USB_CDC_GET_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER    0x42
315 #define USB_CDC_SET_ETHERNET_PACKET_FILTER                      0x43
316 #define USB_CDC_GET_ETHERNET_STATISTIC                          0x44
317 #define USB_CDC_SET_ATM_DATA_FORMAT                             0x50
318 #define USB_CDC_GET_ATM_DEVICE_STATISTICS                       0x51
319 #define USB_CDC_SET_ATM_DEFAULT_VC                              0x52
320 #define USB_CDC_GET_ATM_VC_STATISTICS                           0x53
321 
322 //*****************************************************************************
323 //
324 // In cases where a request defined above results in the return of a fixed size
325 // data block, the following group of labels define the size of that block.  In
326 // each of these cases, an access macro is also provided to write the response
327 // data into an appropriately-sized array of uint8acters.
328 //
329 //*****************************************************************************
330 #define USB_CDC_SIZE_COMM_FEATURE                                2
331 #define USB_CDC_SIZE_LINE_CODING                                 7
332 #define USB_CDC_SIZE_RINGER_PARMS                                4
333 #define USB_CDC_SIZE_OPERATION_PARMS                             2
334 #define USB_CDC_SIZE_UNIT_PARAMETER                              2
335 #define USB_CDC_SIZE_PROFILE                                     64
336 #define USB_CDC_SIZE_ETHERNET_POWER_MANAGEMENT_PATTERN_FILTER    2
337 #define USB_CDC_SIZE_ETHERNET_STATISTIC                          4
338 #define USB_CDC_SIZE_ATM_DEVICE_STATISTICS                       4
339 #define USB_CDC_SIZE_ATM_VC_STATISTICS                           4
340 #define USB_CDC_SIZE_LINE_PARMS                                  10
341 
342 //*****************************************************************************
343 //
344 // NB: USB_CDC_SIZE_LINE_PARAMS assumes only a single call.  For multiple
345 // calls, add 4 bytes per additional call.
346 //
347 //*****************************************************************************
348 
349 //*****************************************************************************
350 //
351 // USB_CDC_GET_COMM_FEATURE & USB_CDC_SET_COMM_FEATURE
352 //
353 //*****************************************************************************
354 
355 //*****************************************************************************
356 //
357 // wValue (Feature Selector)
358 //
359 //*****************************************************************************
360 #define USB_CDC_ABSTRACT_STATE                  0x0001
361 #define USB_CDC_COUNTRY_SETTING                 0x0002
362 
363 //*****************************************************************************
364 //
365 // Data when feature selector is USB_DCD_ABSTRACT_STATE
366 //
367 //*****************************************************************************
368 #define USB_CDC_ABSTRACT_CALL_DATA_MULTIPLEXED  0x0002
369 #define USB_CDC_ABSTRACT_ENDPOINTS_IDLE         0x0001
370 
371 //*****************************************************************************
372 //
373 // Macros to populate the response data buffer (whose size in bytes is defined
374 // by USB_CDC_SIZE_COMM_FEATURE).
375 //
376 //*****************************************************************************
377 #define SetResponseCommFeature(pcBuf, usData)        \
378         do                                           \
379         {                                            \
380             (*(uint16 *)(pcBuf)) = (usData); \
381         }                                            \
382         while(0)
383 
384 //*****************************************************************************
385 //
386 // USB_CDC_SET_AUX_LINE_STATE, wValue
387 //
388 //*****************************************************************************
389 #define USB_CDC_AUX_DISCONNECT                  0x0000
390 #define USB_CDC_AUX_CONNECT                     0x0001
391 
392 //*****************************************************************************
393 //
394 // USB_CDC_SET_HOOK_STATE, wValue
395 //
396 //*****************************************************************************
397 #define USB_CDC_ON_HOOK                         0x0000
398 #define USB_CDC_OFF_HOOK                        0x0001
399 #define USB_CDC_SNOOPING                        0x0002
400 
401 //*****************************************************************************
402 //
403 // USB_CDC_GET_LINE_CODING
404 //
405 //*****************************************************************************
406 #define USB_CDC_STOP_BITS_1                     0x00
407 #define USB_CDC_STOP_BITS_1_5                   0x01
408 #define USB_CDC_STOP_BITS_2                     0x02
409 
410 #define USB_CDC_PARITY_NONE                     0x00
411 #define USB_CDC_PARITY_ODD                      0x01
412 #define USB_CDC_PARITY_EVEN                     0x02
413 #define USB_CDC_PARITY_MARK                     0x03
414 #define USB_CDC_PARITY_SPACE                    0x04
415 
416 //*****************************************************************************
417 //
418 // Macro to populate the response data buffer (whose size in bytes is defined
419 // by USB_CDC_SIZE_LINE_CODING).
420 //
421 //*****************************************************************************
422 #define SetResponseLineCoding(pcBuf, ucRate, ucStop, ucParity, ucDatabits) \
423         do                                                                 \
424         {                                                                  \
425             (*(uint32 *)(pcBuf)) = (ucRate);                        \
426             (*((uint8 *)(pcBuf) + 4)) = (ucStop);                  \
427             (*((uint8 *)(pcBuf) + 5)) = (ucParity);                \
428             (*((uint8 *)(pcBuf) + 6)) = (ucDatabits);              \
429         }                                                                  \
430         while(0)
431 
432 //*****************************************************************************
433 //
434 // USB_CDC_SET_CONTROL_LINE_STATE, wValue
435 //
436 //*****************************************************************************
437 #define USB_CDC_DEACTIVATE_CARRIER              0x00
438 #define USB_CDC_ACTIVATE_CARRIER                0x02
439 #define USB_CDC_DTE_NOT_PRESENT                 0x00
440 #define USB_CDC_DTE_PRESENT                     0x01
441 
442 //*****************************************************************************
443 //
444 // USB_CDC_SET_RINGER_PARMS, USB_CDC_GET_RINGER_PARMS and
445 // USB_CDC_GET_LINE_PARMS (ulRingerBmp)
446 //
447 //*****************************************************************************
448 #define USB_CDC_RINGER_EXISTS                   0x80000000
449 #define USB_CDC_RINGER_DOES_NOT_EXIST           0x00000000
450 
451 //*****************************************************************************
452 //
453 // Macro to populate the response data buffer to USB_CDC_GET_RINGER_PARMS.
454 // Parameter buf points to a buffer of size USB_CDC_SIZE_RINGER_PARMS bytes.
455 //
456 //*****************************************************************************
457 #define SetResponseRingerParms(pcBuf, ucPattern, ucVolume, ulExists)          \
458         do                                                                    \
459         {                                                                     \
460             *(uint32 *)(pcBuf) = ((ucPattern) +                        \
461                                          ((ucVolume & 0xFF) << 8) +           \
462                                          (ulExists & USB_CDC_RINGER_EXISTS)); \
463         }                                                                     \
464         while(0)
465 
466 //*****************************************************************************
467 //
468 // Macros to extract fields from the USB_CDC_SET_RINGER_PARMS data
469 //
470 //*****************************************************************************
471 #define GetRingerVolume(pcData)  (BYTE((pcData)+1))
472 #define GetRingerPattern(pcData) (BYTE(pcData))
473 #define GetRingerExists(pcData)  ((LONG(pcData)) & USB_CDC_RINGER_EXISTS)
474 
475 //*****************************************************************************
476 //
477 // USB_CDC_SET_OPERATION_PARMS, wValue
478 //
479 //*****************************************************************************
480 #define USB_CDC_SIMPLE_MODE                     0x0000
481 #define USB_CDC_STANDALONE_MODE                 0x0001
482 #define USB_CDC_HOST_CENTRIC_MODE               0x0002
483 
484 //*****************************************************************************
485 //
486 // Macro to populate the response data buffer to USB_CDC_GET_OPERATION_PARMS.
487 // Parameter buf points to a buffer of size USB_CDC_SIZE_OPERATION_PARMS
488 // bytes.
489 //
490 //*****************************************************************************
491 #define SetResponseOperationParms(pBbuf, usData) \
492         do                                       \
493         {                                        \
494             WORD(pcBuf) = (usData);              \
495         }                                        \
496         while(0)
497 
498 //*****************************************************************************
499 //
500 // USB_CDC_SET_LINE_PARMS, wParam - Line State Change
501 //
502 //*****************************************************************************
503 #define USB_CDC_DROP_ACTIVE_CALL                0x0000
504 #define USB_CDC_START_NEW_CALL                  0x0001
505 #define USB_CDC_APPLY_RINGING                   0x0002
506 #define USB_CDC_REMOVE_RINGING                  0x0003
507 #define USB_CDC_SWITCH_CALL                     0x0004
508 
509 //*****************************************************************************
510 //
511 // Line state bitmap in USB_CDC_GET_LINE_PARMS response
512 //
513 //*****************************************************************************
514 #define USB_CDC_LINE_IS_ACTIVE                  0x80000000
515 #define USB_CDC_LINE_IS_IDLE                    0x00000000
516 #define USB_CDC_LINE_NO_ACTIVE_CALL             0x000000FF
517 
518 #define USB_CDC_CALL_ACTIVE                     0x80000000
519 
520 //*****************************************************************************
521 //
522 // Call state value definitions
523 //
524 //*****************************************************************************
525 #define USB_CDC_CALL_IDLE                       0x00000000
526 #define USB_CDC_CALL_TYPICAL_DIALTONE           0x00000001
527 #define USB_CDC_CALL_INTERRUPTED_DIALTONE       0x00000002
528 #define USB_CDC_CALL_DIALING                    0x00000003
529 #define USB_CDC_CALL_RINGBACK                   0x00000004
530 #define USB_CDC_CALL_CONNECTED                  0x00000005
531 #define USB_CDC_CALL_INCOMING                   0x00000006
532 
533 //*****************************************************************************
534 //
535 // Call state change value definitions
536 //
537 //*****************************************************************************
538 #define USB_CDC_CALL_STATE_IDLE                 0x01
539 #define USB_CDC_CALL_STATE_DIALING              0x02
540 #define USB_CDC_CALL_STATE_RINGBACK             0x03
541 #define USB_CDC_CALL_STATE_CONNECTED            0x04
542 #define USB_CDC_CALL_STATE_INCOMING             0x05
543 
544 //*****************************************************************************
545 //
546 // Extra byte of data describing the connection type for
547 // USB_CDC_CALL_STATE_CONNECTED.
548 //
549 //*****************************************************************************
550 #define USB_CDC_VOICE                           0x00
551 #define USB_CDC_ANSWERING_MACHINE               0x01
552 #define USB_CDC_FAX                             0x02
553 #define USB_CDC_MODEM                           0x03
554 #define USB_CDC_UNKNOWN                         0xFF
555 
556 //*****************************************************************************
557 //
558 // Macro to extract call index from request in cases where wParam is
559 // USB_CDC_SWITCH_CALL.
560 //
561 //*****************************************************************************
562 #define GetCallIndex(pcData) (BYTE(pcData))
563 
564 //*****************************************************************************
565 //
566 // Macro to populate the CallState entries in response to request
567 // USB_CDC_GET_LINE_PARMS.  The ucIndex parameter is a zero based index
568 // indicating which call entry in the pcBuf response buffer to fill in.  Note
569 // that pcBuf points to the first byte of the buffer (the wLength field).
570 //
571 //*****************************************************************************
572 #define SetResponseCallState(pcBuf, ucIndex, ulActive, ucStateChange,   \
573                              ucState)                                   \
574         do                                                              \
575         {                                                               \
576             (LONG((uint8 *)(pcBuf) + (10 + (4 * (ucIndex))))) = \
577                 (((ulActive) & USB_CDC_CALL_IS_ACTIVE) +                \
578                  (((ucStateChange) & 0xFF) << 8) +                      \
579                  ((ucState) & 0xFF));                                   \
580         }                                                               \
581         while(0)
582 
583 //*****************************************************************************
584 //
585 // Macro to populate the response data buffer (whose size in bytes is defined
586 // by USB_CDC_SIZE_LINE_PARMS).  Note that this macro only populates fields for
587 // a single call.  If multiple calls are being managed, additional 4 byte
588 // fields must be appended to provide call state for each call after the first.
589 // This may be done using the SetResponseCallState macro with the appropriate
590 // call index supplied.
591 //
592 //*****************************************************************************
593 #define SetResponseLineParms(pcBuf, usLength,                              \
594                              ucRingPattern, ucRingVolume, ulRingExists,    \
595                              ulLineActive, ucLineCallIndex,                \
596                              ulCallActive, ucCallStateChange, ucCallState) \
597         do                                                                 \
598         {                                                                  \
599             (WORD(pcBuf)) = (usLength);                                    \
600             SetResponseRingerParams(((uint8 *)(pcBuf) + 2),        \
601                                     (ucRingPattern), (ucRingVolume),       \
602                                     (ulRingExists));                       \
603             (LONG((uint8 *)(pcBuf) + 6)) =                         \
604                 (((ulLineActive) & USB_CDC_LINE_IS_ACTIVE) +               \
605                  ((ucLineCallIndex) & 0xFF)) ;                             \
606             SetResponseCallState((pcBuf), 0, (ulCallActive),               \
607                                  (ucCallStateChange), (ucCallState));      \
608         }                                                                  \
609         while(0)
610 
611 //*****************************************************************************
612 //
613 // Notification Element definitions
614 //
615 //*****************************************************************************
616 #define USB_CDC_NOTIFY_NETWORK_CONNECTION               0x00
617 #define USB_CDC_NOTIFY_RESPONSE_AVAILABLE               0x01
618 #define USB_CDC_NOTIFY_AUX_JACK_HOOK_STATE              0x08
619 #define USB_CDC_NOTIFY_RING_DETECT                      0x09
620 #define USB_CDC_NOTIFY_SERIAL_STATE                     0x20
621 #define USB_CDC_NOTIFY_CALL_STATE_CHANGE                0x28
622 #define USB_CDC_NOTIFY_LINE_STATE_CHANGE                0x29
623 #define USB_CDC_NOTIFY_CONNECTION_SPEED_CHANGE          0x2A
624 
625 //*****************************************************************************
626 //
627 // USB_CDC_NOTIFY_NETWORK_CONNECTION, wValue
628 //
629 //*****************************************************************************
630 #define USB_CDC_NETWORK_DISCONNECTED                    0x0000
631 #define USB_CDC_NETWORK_CONNECTED                       0x0001
632 
633 //*****************************************************************************
634 //
635 // USB_CDC_NOTIFY_AUX_JACK_HOOK_STATE, wValue
636 //
637 //*****************************************************************************
638 #define USB_CDC_AUX_JACK_ON_HOOK                        0x0000
639 #define USB_CDC_AUX_JACK_OFF_HOOK                       0x0001
640 
641 //*****************************************************************************
642 //
643 // USB_CDC_NOTIFY_SERIAL_STATE, Data
644 //
645 //*****************************************************************************
646 
647 //*****************************************************************************
648 //
649 // Number of bytes of data returned alongside this notification.
650 //
651 //*****************************************************************************
652 #define USB_CDC_NOTIFY_SERIAL_STATE_SIZE                2
653 
654 #define USB_CDC_SERIAL_STATE_OVERRUN                    0x0040
655 #define USB_CDC_SERIAL_STATE_PARITY                     0x0020
656 #define USB_CDC_SERIAL_STATE_FRAMING                    0x0010
657 #define USB_CDC_SERIAL_STATE_RING_SIGNAL                0x0008
658 #define USB_CDC_SERIAL_STATE_BREAK                      0x0004
659 #define USB_CDC_SERIAL_STATE_TXCARRIER                  0x0002
660 #define USB_CDC_SERIAL_STATE_RXCARRIER                  0x0001
661 
662 //*****************************************************************************
663 //
664 // USB_CDC_NOTIFY_CALL_STATE_CHANGE, wValue
665 //
666 // Call state values are defined above in the group beginning
667 // USB_CDC_CALL_STATE_IDLE.  Note that the data returned alongside this
668 // notification are heavily dependent upon the call state being reported so no
669 // specific lengths or access macros are provided here.
670 //
671 // Macro to construct the correct wValue for this notification given a state
672 // and call index.
673 //
674 //*****************************************************************************
675 #define SetNotifyCallStatewValue(psResult, ucCallState, ucIndex) \
676         do                                                       \
677         {                                                        \
678             (WORD(psResult)) = (((ucCallState) & 0xFF) +         \
679                                 (((ucIndex) & 0xFF) << 8));      \
680         }                                                        \
681         while(0)
682 
683 //*****************************************************************************
684 //
685 // USB_CDC_NOTIFY_LINE_STATE_CHANGE, wValue
686 //
687 // Note that the data returned alongside this notification are heavily
688 // dependent upon the call state being reported so no specific lengths or
689 // access macros are provided here.
690 //
691 //*****************************************************************************
692 #define USB_CDC_LINE_STATE_IDLE                         0x0000
693 #define USB_CDC_LINE_STATE_HOLD                         0x0001
694 #define USB_CDC_LINE_STATE_OFF_HOOK                     0x0002
695 #define USB_CDC_LINE_STATE_ON_HOOK                      0x0003
696 
697 //*****************************************************************************
698 //
699 // USB_CDC_NOTIFY_CONNECTION_SPEED_CHANGE, Data
700 //
701 // Macro to populate the 8 byte data structure returned alongside this
702 // notification.
703 //
704 //*****************************************************************************
705 #define SetNotifyConnectionSpeedChange(pcBuf, ulUSBitRate, ulDSBitRate) \
706         do                                                              \
707         {                                                               \
708             LONG(pcBuf) = ulUSBitRate;                                  \
709             LONG((uint8 *)(pcBuf) + 4) = ulDSBitRate;           \
710         }                                                               \
711         while(0)
712 
713 //*****************************************************************************
714 //
715 // Packed structure definitions for request/response data blocks
716 //
717 //*****************************************************************************
718 
719 //*****************************************************************************
720 //
721 // All structures defined in this section of the header require byte packing of
722 // fields.  This is usually accomplished using the PACKED macro but, for IAR
723 // Embedded Workbench, this requires a pragma.
724 //
725 //*****************************************************************************
726 #if defined(ewarm) || defined(__IAR_SYSTEMS_ICC__)
727 #pragma pack(1)
728 #endif
729 
730 //*****************************************************************************
731 //
732 //! USB_CDC_GET/SET_LINE_CODING request-specific data.
733 //
734 //*****************************************************************************
735 typedef struct
736 {
737     //
738     //! The data terminal rate in bits per second.
739     //
740     uint32 ulRate;
741 
742     //
743     //! The number of stop bits.  Valid values are USB_CDC_STOP_BITS_1,
744     //! USB_CDC_STOP_BITS_1_5 or USB_CDC_STOP_BITS_2
745     //
746     uint8 ucStop;
747 
748     //
749     //! The parity setting.  Valid values are USB_CDC_PARITY_NONE,
750     //! USB_CDC_PARITY_ODD, USB_CDC_PARITY_EVEN, USB_CDC_PARITY_MARK and
751     //! USB_CDC_PARITY_SPACE.
752     //
753     uint8 ucParity;
754 
755     //
756     //! The number of data bits per character.  Valid values are 5, 6, 7 and 8
757     //! in this implementation.
758     //
759     uint8 ucDatabits;
760 }
761 PACKED tLineCoding;
762 
763 //*****************************************************************************
764 //
765 // Return to default packing when using the IAR Embedded Workbench compiler.
766 //
767 //*****************************************************************************
768 #if defined(ewarm) || defined(__IAR_SYSTEMS_ICC__)
769 #pragma pack()
770 #endif
771 
772 //*****************************************************************************
773 //
774 // Close the Doxygen group.
775 //! @}
776 //
777 //*****************************************************************************
778 
779 //*****************************************************************************
780 //
781 // Mark the end of the C bindings section for C++ compilers.
782 //
783 //*****************************************************************************
784 #ifdef __cplusplus
785 }
786 #endif
787 
788 #endif // __USBCDC_H__
789