Added Doxygen documentation to the Audio class driver. Added new modules for each...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / CDC.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 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 /** \ingroup Group_USBDeviceClassDrivers
32 * @defgroup Group_USBClassCDCDevice CDC Device Class Driver - LUFA/Drivers/Class/Device/CDC.h
33 *
34 * \section Sec_Dependencies Module Source Dependencies
35 * The following files must be built with any user project that uses this module:
36 * - LUFA/Drivers/USB/Class/Device/CDC.c
37 *
38 * \section Module Description
39 * Functions, macros, variables, enums and types related to the management of USB CDC Class interfaces
40 * within a USB device, for the implementation of CDC-ACM virtual serial ports.
41 *
42 * @{
43 */
44
45 #ifndef _CDC_CLASS_H_
46 #define _CDC_CLASS_H_
47
48 /* Includes: */
49 #include "../../USB.h"
50
51 #include <string.h>
52
53 /* Enable C linkage for C++ Compilers: */
54 #if defined(__cplusplus)
55 extern "C" {
56 #endif
57
58 /* Macros: */
59 /** CDC Class specific request to get the current virtual serial port configuration settings. */
60 #define REQ_GetLineEncoding 0x21
61
62 /** CDC Class specific request to set the current virtual serial port configuration settings. */
63 #define REQ_SetLineEncoding 0x20
64
65 /** CDC Class specific request to set the current virtual serial port handshake line states. */
66 #define REQ_SetControlLineState 0x22
67
68 /** Notification type constant for a change in the virtual serial port handshake line states, for
69 * use with a USB_Notification_Header_t notification structure when sent to the host via the CDC
70 * notification endpoint.
71 */
72 #define NOTIF_SerialState 0x20
73
74 /** Mask for the DTR handshake line for use with the REQ_SetControlLineState class specific request
75 * from the host, to indicate that the DTR line state should be high.
76 */
77 #define CDC_CONTROL_LINE_OUT_DTR (1 << 0)
78
79 /** Mask for the RTS handshake line for use with the REQ_SetControlLineState class specific request
80 * from the host, to indicate that theRTS line state should be high.
81 */
82 #define CDC_CONTROL_LINE_OUT_RTS (1 << 1)
83
84 /** Mask for the DCD handshake line for use with the a NOTIF_SerialState class specific notification
85 * from the device to the host, to indicate that the DCD line state is currently high.
86 */
87 #define CDC_CONTROL_LINE_IN_DCD (1 << 0)
88
89 /** Mask for the DSR handshake line for use with the a NOTIF_SerialState class specific notification
90 * from the device to the host, to indicate that the DSR line state is currently high.
91 */
92 #define CDC_CONTROL_LINE_IN_DSR (1 << 1)
93
94 /** Mask for the BREAK handshake line for use with the a NOTIF_SerialState class specific notification
95 * from the device to the host, to indicate that the BREAK line state is currently high.
96 */
97 #define CDC_CONTROL_LINE_IN_BREAK (1 << 2)
98
99 /** Mask for the RING handshake line for use with the a NOTIF_SerialState class specific notification
100 * from the device to the host, to indicate that the RING line state is currently high.
101 */
102 #define CDC_CONTROL_LINE_IN_RING (1 << 3)
103
104 /** Mask for use with the a NOTIF_SerialState class specific notification from the device to the host,
105 * to indicate that a framing error has occurred on the virtual serial port.
106 */
107 #define CDC_CONTROL_LINE_IN_FRAMEERROR (1 << 4)
108
109 /** Mask for use with the a NOTIF_SerialState class specific notification from the device to the host,
110 * to indicate that a parity error has occurred on the virtual serial port.
111 */
112 #define CDC_CONTROL_LINE_IN_PARITYERROR (1 << 5)
113
114 /** Mask for use with the a NOTIF_SerialState class specific notification from the device to the host,
115 * to indicate that a data overrun error has occurred on the virtual serial port.
116 */
117 #define CDC_CONTROL_LINE_IN_OVERRUNERROR (1 << 6)
118
119 /** Macro to define a CDC class-specific functional descriptor. CDC functional descriptors have a
120 * uniform structure but variable sized data payloads, thus cannot be represented accurately by
121 * a single typedef struct. A macro is used instead so that functional descriptors can be created
122 * easily by specifying the size of the payload. This allows sizeof() to work correctly.
123 *
124 * \param DataSize Size in bytes of the CDC functional descriptor's data payload
125 */
126 #define CDC_FUNCTIONAL_DESCRIPTOR(DataSize) \
127 struct \
128 { \
129 USB_Descriptor_Header_t Header; \
130 uint8_t SubType; \
131 uint8_t Data[DataSize]; \
132 }
133
134 /* Enums: */
135 /** Enum for the possible line encoding formats of a virtual serial port. */
136 enum CDCDevice_CDC_LineCodingFormats_t
137 {
138 CDC_LINEENCODING_OneStopBit = 0, /**< Each frame contains one stop bit */
139 CDC_LINEENCODING_OneAndAHalfStopBits = 1, /**< Each frame contains one and a half stop bits */
140 CDC_LINEENCODING_TwoStopBits = 2, /**< Each frame contains two stop bits */
141 };
142
143 /** Enum for the possible line encoding parity settings of a virtual serial port. */
144 enum CDCDevice_LineCodingParity_t
145 {
146 CDC_PARITY_None = 0, /**< No parity bit mode on each frame */
147 CDC_PARITY_Odd = 1, /**< Odd parity bit mode on each frame */
148 CDC_PARITY_Even = 2, /**< Even parity bit mode on each frame */
149 CDC_PARITY_Mark = 3, /**< Mark parity bit mode on each frame */
150 CDC_PARITY_Space = 4, /**< Space parity bit mode on each frame */
151 };
152
153 /* Type Defines: */
154 /** Type define for the virtual serial port line encoding settings, for storing the current USART configuration
155 * as set by the host via a class specific request.
156 */
157 typedef struct
158 {
159 uint8_t ControlInterfaceNumber; /**< Interface number of the CDC control interface within the device */
160
161 uint8_t DataINEndpointNumber; /**< Endpoint number of the CDC interface's IN data endpoint */
162 uint16_t DataINEndpointSize; /**< Size in bytes of the CDC interface's IN data endpoint */
163
164 uint8_t DataOUTEndpointNumber; /**< Endpoint number of the CDC interface's OUT data endpoint */
165 uint16_t DataOUTEndpointSize; /**< Size in bytes of the CDC interface's OUT data endpoint */
166
167 uint8_t NotificationEndpointNumber; /**< Endpoint number of the CDC interface's IN notification endpoint, if used */
168 uint16_t NotificationEndpointSize; /**< Size in bytes of the CDC interface's IN notification endpoint, if used */
169
170 uint8_t ControlLineState;
171
172 struct
173 {
174 uint32_t BaudRateBPS; /**< Baud rate of the virtual serial port, in bits per second */
175 uint8_t CharFormat; /**< Character format of the virtual serial port, a value from the
176 * CDCDevice_CDC_LineCodingFormats_t enum
177 */
178 uint8_t ParityType; /**< Parity setting of the virtual serial port, a value from the
179 * CDCDevice_LineCodingParity_t enum
180 */
181 uint8_t DataBits; /**< Bits of data per character of the virtual serial port */
182 } LineEncoding;
183 } USB_ClassInfo_CDC_t;
184
185 /* Function Prototypes: */
186 #if defined(INCLUDE_FROM_CDC_CLASS_C)
187 void USB_CDC_Event_Stub(void);
188 void EVENT_USB_CDC_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo)
189 ATTR_WEAK ATTR_ALIAS(USB_CDC_Event_Stub);
190 void EVENT_USB_CDC_ControLineStateChanged(void) ATTR_WEAK ATTR_ALIAS(USB_CDC_Event_Stub);;
191 #endif
192
193 bool USB_CDC_ConfigureEndpoints(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
194 void USB_CDC_ProcessControlPacket(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
195 void USB_CDC_USBTask(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
196
197 void EVENT_USB_CDC_LineEncodingChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
198 void EVENT_USB_CDC_ControLineStateChanged(void);
199
200 void USB_CDC_SendString(USB_ClassInfo_CDC_t* CDCInterfaceInfo, char* Data, uint16_t Length);
201 void USB_CDC_SendByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint8_t Data);
202 uint16_t USB_CDC_BytesReceived(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
203 uint8_t USB_CDC_ReceiveByte(USB_ClassInfo_CDC_t* CDCInterfaceInfo);
204 void USB_CDC_SendSerialLineStateChanged(USB_ClassInfo_CDC_t* CDCInterfaceInfo, uint16_t LineStateMask);
205
206 /* Disable C linkage for C++ Compilers: */
207 #if defined(__cplusplus)
208 }
209 #endif
210
211 #endif
212
213 /** @} */