Fixed LowLevel JoystickHostWithParser demo not saving the chosen HID interface's...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Common / CDC.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, distribute, and sell this
13 software and its documentation for any purpose is hereby granted
14 without fee, provided that the above copyright notice appear in
15 all copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \file
32 * \brief Common definitions and declarations for the library USB CDC Class driver.
33 *
34 * Common definitions and declarations for the library USB CDC Class driver.
35 *
36 * \note This file should not be included directly. It is automatically included as needed by the class driver
37 * dispatch header located in LUFA/Drivers/USB/Class/CDC.h.
38 */
39
40 /** \ingroup Group_USBClassCDC
41 * @defgroup Group_USBClassCDCCommon Common Class Definitions
42 *
43 * \section Module Description
44 * Constants, Types and Enum definitions that are common to both Device and Host modes for the USB
45 * CDC Class.
46 *
47 * @{
48 */
49
50 #ifndef _CDC_CLASS_COMMON_H_
51 #define _CDC_CLASS_COMMON_H_
52
53 /* Includes: */
54 #include "../../USB.h"
55
56 #include <string.h>
57
58 /* Enable C linkage for C++ Compilers: */
59 #if defined(__cplusplus)
60 extern "C" {
61 #endif
62
63 /* Preprocessor Checks: */
64 #if !defined(__INCLUDE_FROM_CDC_DRIVER)
65 #error Do not include this file directly. Include LUFA/Drivers/Class/CDC.h instead.
66 #endif
67
68 /* Macros: */
69 /** Mask for the DTR handshake line for use with the REQ_SetControlLineState class-specific request
70 * from the host, to indicate that the DTR line state should be high.
71 */
72 #define CDC_CONTROL_LINE_OUT_DTR (1 << 0)
73
74 /** Mask for the RTS handshake line for use with the REQ_SetControlLineState class-specific request
75 * from the host, to indicate that theRTS line state should be high.
76 */
77 #define CDC_CONTROL_LINE_OUT_RTS (1 << 1)
78
79 /** Mask for the DCD handshake line for use with the a NOTIF_SerialState class-specific notification
80 * from the device to the host, to indicate that the DCD line state is currently high.
81 */
82 #define CDC_CONTROL_LINE_IN_DCD (1 << 0)
83
84 /** Mask for the DSR handshake line for use with the a NOTIF_SerialState class-specific notification
85 * from the device to the host, to indicate that the DSR line state is currently high.
86 */
87 #define CDC_CONTROL_LINE_IN_DSR (1 << 1)
88
89 /** Mask for the BREAK handshake line for use with the a NOTIF_SerialState class-specific notification
90 * from the device to the host, to indicate that the BREAK line state is currently high.
91 */
92 #define CDC_CONTROL_LINE_IN_BREAK (1 << 2)
93
94 /** Mask for the RING handshake line for use with the a NOTIF_SerialState class-specific notification
95 * from the device to the host, to indicate that the RING line state is currently high.
96 */
97 #define CDC_CONTROL_LINE_IN_RING (1 << 3)
98
99 /** Mask for use with the a NOTIF_SerialState class-specific notification from the device to the host,
100 * to indicate that a framing error has occurred on the virtual serial port.
101 */
102 #define CDC_CONTROL_LINE_IN_FRAMEERROR (1 << 4)
103
104 /** Mask for use with the a NOTIF_SerialState class-specific notification from the device to the host,
105 * to indicate that a parity error has occurred on the virtual serial port.
106 */
107 #define CDC_CONTROL_LINE_IN_PARITYERROR (1 << 5)
108
109 /** Mask for use with the a NOTIF_SerialState class-specific notification from the device to the host,
110 * to indicate that a data overrun error has occurred on the virtual serial port.
111 */
112 #define CDC_CONTROL_LINE_IN_OVERRUNERROR (1 << 6)
113
114 /** Macro to define a CDC class-specific functional descriptor. CDC functional descriptors have a
115 * uniform structure but variable sized data payloads, thus cannot be represented accurately by
116 * a single typedef struct. A macro is used instead so that functional descriptors can be created
117 * easily by specifying the size of the payload. This allows sizeof() to work correctly.
118 *
119 * \param[in] DataSize Size in bytes of the CDC functional descriptor's data payload.
120 */
121 #define CDC_FUNCTIONAL_DESCRIPTOR(DataSize) \
122 struct \
123 { \
124 USB_Descriptor_Header_t Header; \
125 uint8_t SubType; \
126 uint8_t Data[DataSize]; \
127 }
128
129 /* Enums: */
130 /** Enum for the CDC class specific control requests that can be issued by the USB bus host. */
131 enum CDC_ClassRequests_t
132 {
133 CDC_REQ_SendEncapsulatedCommand = 0x00, /**< CDC class-specific request to send an encapsulated command to the device. */
134 CDC_REQ_GetEncapsulatedResponse = 0x01, /**< CDC class-specific request to retrieve an encapsulated command response from the device. */
135 CDC_REQ_SetLineEncoding = 0x20, /**< CDC class-specific request to set the current virtual serial port configuration settings. */
136 CDC_REQ_GetLineEncoding = 0x21, /**< CDC class-specific request to get the current virtual serial port configuration settings. */
137 CDC_REQ_SetControlLineState = 0x22, /**< CDC class-specific request to set the current virtual serial port handshake line states. */
138 CDC_REQ_SendBreak = 0x23, /**< CDC class-specific request to send a break to the receiver via the carrier channel. */
139 };
140
141 /** Enum for the CDC class specific notification requests that can be issued by a CDC device to a host. */
142 enum CDC_ClassNotifications_t
143 {
144 CDC_NOTIF_SerialState = 0x20, /**< Notification type constant for a change in the virtual serial port
145 * handshake line states, for use with a USB_Notification_Header_t
146 * notification structure when sent to the host via the CDC notification
147 * endpoint.
148 */
149 };
150
151 /** Enum for the CDC class specific interface descriptor subtypes. */
152 enum CDC_DescriptorSubtypes_t
153 {
154 CDC_DSUBTYPE_CSInterface_Header = 0x00, /**< CDC class-specific Header functional descriptor. */
155 CDC_DSUBTYPE_CSInterface_CallManagement = 0x01, /**< CDC class-specific Call Managment functional descriptor. */
156 CDC_DSUBTYPE_CSInterface_ACM = 0x02, /**< CDC class-specific Abstract Control Model functional descriptor. */
157 CDC_DSUBTYPE_CSInterface_DirectLine = 0x03, /**< CDC class-specific Direct Line functional descriptor. */
158 CDC_DSUBTYPE_CSInterface_TelephoneRinger = 0x04, /**< CDC class-specific Telephone Ringer functional descriptor. */
159 CDC_DSUBTYPE_CSInterface_TelephoneCall = 0x05, /**< CDC class-specific Telephone Call functional descriptor. */
160 CDC_DSUBTYPE_CSInterface_Union = 0x06, /**< CDC class-specific Union functional descriptor. */
161 CDC_DSUBTYPE_CSInterface_CountrySelection = 0x07, /**< CDC class-specific Country Selection functional descriptor. */
162 CDC_DSUBTYPE_CSInterface_TelephoneOpModes = 0x08, /**< CDC class-specific Telephone Operation Modes functional descriptor. */
163 CDC_DSUBTYPE_CSInterface_USBTerminal = 0x09, /**< CDC class-specific USB Terminal functional descriptor. */
164 CDC_DSUBTYPE_CSInterface_NetworkChannel = 0x0A, /**< CDC class-specific Network Channel functional descriptor. */
165 CDC_DSUBTYPE_CSInterface_ProtocolUnit = 0x0B, /**< CDC class-specific Protocol Unit functional descriptor. */
166 CDC_DSUBTYPE_CSInterface_ExtensionUnit = 0x0C, /**< CDC class-specific Extension Unit functional descriptor. */
167 CDC_DSUBTYPE_CSInterface_MultiChannel = 0x0D, /**< CDC class-specific Multi-Channel Management functional descriptor. */
168 CDC_DSUBTYPE_CSInterface_CAPI = 0x0E, /**< CDC class-specific Common ISDN API functional descriptor. */
169 CDC_DSUBTYPE_CSInterface_Ethernet = 0x0F, /**< CDC class-specific Ethernet functional descriptor. */
170 CDC_DSUBTYPE_CSInterface_ATM = 0x10, /**< CDC class-specific Asynchronous Transfer Mode functional descriptor. */
171 };
172
173 /** Enum for the possible line encoding formats of a virtual serial port. */
174 enum CDC_LineEncodingFormats_t
175 {
176 CDC_LINEENCODING_OneStopBit = 0, /**< Each frame contains one stop bit. */
177 CDC_LINEENCODING_OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits. */
178 CDC_LINEENCODING_TwoStopBits = 2, /**< Each frame contains two stop bits. */
179 };
180
181 /** Enum for the possible line encoding parity settings of a virtual serial port. */
182 enum CDC_LineEncodingParity_t
183 {
184 CDC_PARITY_None = 0, /**< No parity bit mode on each frame. */
185 CDC_PARITY_Odd = 1, /**< Odd parity bit mode on each frame. */
186 CDC_PARITY_Even = 2, /**< Even parity bit mode on each frame. */
187 CDC_PARITY_Mark = 3, /**< Mark parity bit mode on each frame. */
188 CDC_PARITY_Space = 4, /**< Space parity bit mode on each frame. */
189 };
190
191 /* Type Defines: */
192 /** \brief CDC class-specific Functional Header Descriptor (LUFA naming conventions).
193 *
194 * Type define for a CDC class-specific functional header descriptor. This indicates to the host that the device
195 * contains one or more CDC functional data descriptors, which give the CDC interface's capabilities and configuration.
196 * See the CDC class specification for more details.
197 *
198 * \see \ref USB_CDC_StdDescriptor_FunctionalHeader_t for the version of this type with standard element names.
199 */
200 typedef struct
201 {
202 USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
203 uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors,
204 * must be \ref CDC_DSUBTYPE_CSInterface_Header.
205 */
206 uint16_t CDCSpecification; /**< Version number of the CDC specification implemented by the device,
207 * encoded in BCD format.
208 */
209 } USB_CDC_Descriptor_FunctionalHeader_t;
210
211 /** \brief CDC class-specific Functional Header Descriptor (USB-IF naming conventions).
212 *
213 * Type define for a CDC class-specific functional header descriptor. This indicates to the host that the device
214 * contains one or more CDC functional data descriptors, which give the CDC interface's capabilities and configuration.
215 * See the CDC class specification for more details.
216 *
217 * \see \ref USB_CDC_Descriptor_FunctionalHeader_t for the version of this type with non-standard LUFA specific
218 * element names.
219 */
220 typedef struct
221 {
222 uint8_t bFunctionLength; /**< Size of the descriptor, in bytes. */
223 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
224 * given by the specific class.
225 */
226 uint8_t bDescriptorSubType; /**< Sub type value used to distinguish between CDC class-specific descriptors,
227 * must be \ref CDC_DSUBTYPE_CSInterface_Header.
228 */
229 uint16_t bcdCDC; /**< Version number of the CDC specification implemented by the device, encoded in BCD format. */
230 } USB_CDC_StdDescriptor_FunctionalHeader_t;
231
232 /** \brief CDC class-specific Functional ACM Descriptor (LUFA naming conventions).
233 *
234 * Type define for a CDC class-specific functional ACM descriptor. This indicates to the host that the CDC interface
235 * supports the CDC ACM subclass of the CDC specification. See the CDC class specification for more details.
236 *
237 * \see \ref USB_CDC_StdDescriptor_FunctionalACM_t for the version of this type with standard element names.
238 */
239 typedef struct
240 {
241 USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
242 uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors,
243 * must be \ref CDC_DSUBTYPE_CSInterface_ACM.
244 */
245 uint8_t Capabilities; /**< Capabilities of the ACM interface, given as a bit mask. For most devices,
246 * this should be set to a fixed value of 0x06 - for other capabiltiies, refer
247 * to the CDC ACM specification.
248 */
249 } USB_CDC_Descriptor_FunctionalACM_t;
250
251 /** \brief CDC class-specific Functional ACM Descriptor (USB-IF naming conventions).
252 *
253 * Type define for a CDC class-specific functional ACM descriptor. This indicates to the host that the CDC interface
254 * supports the CDC ACM subclass of the CDC specification. See the CDC class specification for more details.
255 *
256 * \see \ref USB_CDC_Descriptor_FunctionalACM_t for the version of this type with non-standard LUFA specific
257 * element names.
258 */
259 typedef struct
260 {
261 uint8_t bFunctionLength; /**< Size of the descriptor, in bytes. */
262 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
263 * given by the specific class.
264 */
265 uint8_t bDescriptorSubType; /**< Sub type value used to distinguish between CDC class-specific descriptors,
266 * must be \ref CDC_DSUBTYPE_CSInterface_ACM.
267 */
268 uint8_t bmCapabilities; /**< Capabilities of the ACM interface, given as a bit mask. For most devices,
269 * this should be set to a fixed value of 0x06 - for other capabiltiies, refer
270 * to the CDC ACM specification.
271 */
272 } USB_CDC_StdDescriptor_FunctionalACM_t;
273
274 /** \brief CDC class-specific Functional Union Descriptor (LUFA naming conventions).
275 *
276 * Type define for a CDC class-specific functional Union descriptor. This indicates to the host that specific
277 * CDC control and data interfaces are related. See the CDC class specification for more details.
278 *
279 * \see \ref USB_CDC_StdDescriptor_FunctionalUnion_t for the version of this type with standard element names.
280 */
281 typedef struct
282 {
283 USB_Descriptor_Header_t Header; /**< Regular descriptor header containing the descriptor's type and length. */
284 uint8_t Subtype; /**< Sub type value used to distinguish between CDC class-specific descriptors,
285 * must be \ref CDC_DSUBTYPE_CSInterface_Union.
286 */
287 uint8_t MasterInterfaceNumber; /**< Interface number of the CDC Control interface. */
288 uint8_t SlaveInterfaceNumber; /**< Interface number of the CDC Data interface. */
289 } USB_CDC_Descriptor_FunctionalUnion_t;
290
291 /** \brief CDC class-specific Functional Union Descriptor (USB-IF naming conventions).
292 *
293 * Type define for a CDC class-specific functional Union descriptor. This indicates to the host that specific
294 * CDC control and data interfaces are related. See the CDC class specification for more details.
295 *
296 * \see \ref USB_CDC_Descriptor_FunctionalUnion_t for the version of this type with non-standard LUFA specific
297 * element names.
298 */
299 typedef struct
300 {
301 uint8_t bFunctionLength; /**< Size of the descriptor, in bytes. */
302 uint8_t bDescriptorType; /**< Type of the descriptor, either a value in \ref USB_DescriptorTypes_t or a value
303 * given by the specific class.
304 */
305 uint8_t bDescriptorSubType; /**< Sub type value used to distinguish between CDC class-specific descriptors,
306 * must be \ref CDC_DSUBTYPE_CSInterface_Union.
307 */
308 uint8_t bMasterInterface; /**< Interface number of the CDC Control interface. */
309 uint8_t bSlaveInterface0; /**< Interface number of the CDC Data interface. */
310 } USB_CDC_StdDescriptor_FunctionalUnion_t;
311
312 /* Disable C linkage for C++ Compilers: */
313 #if defined(__cplusplus)
314 }
315 #endif
316
317 #endif
318
319 /** @} */