blob: eb30b9994f8faff26849c9b7d4a927da2b37dc50 [file] [log] [blame]
Christina Quastb123d742014-12-23 13:03:36 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2010, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30/** \file
31 *
32 * Definitions and classes for USB CDC class requests
33 * (mostly for ACM).
34 *
35 * \section CDCLineCoding
36 *
37 * -# Initialize a CDCLineCoding instance using CDCLineCoding_Initialize.
38 * -# Send a CDCLineCoding object to the host in response to a GetLineCoding
39 * request.
40 * -# Receive a CDCLineCoding object from the host after a SetLineCoding
41 * request.
42 *
43 */
44
45#ifndef _CDCREQUESTS_H_
46#define _CDCREQUESTS_H_
47/** \addtogroup usb_cdc
48 *@{
49 */
50
51/*----------------------------------------------------------------------------
52 * Includes
53 *----------------------------------------------------------------------------*/
54
55#include <stdint.h>
56
57#include <USBRequests.h>
58
59/*----------------------------------------------------------------------------
60 * Definitions
61 *----------------------------------------------------------------------------*/
62
63/** \addtogroup usb_cdc_request USB CDC Request Codes
64 * @{
65 * This section lists USB CDC Request Codes.
66 * - \ref CDCGenericRequest_SETLINECODING
67 * - \ref CDCGenericRequest_GETLINECODING
68 * - \ref CDCGenericRequest_SETCONTROLLINESTATE
69 */
70
71/** SetLineCoding request code. */
72#define CDCGenericRequest_SETLINECODING 0x20
73/** GetLineCoding request code. */
74#define CDCGenericRequest_GETLINECODING 0x21
75/** SetControlLineState request code. */
76#define CDCGenericRequest_SETCONTROLLINESTATE 0x22
77/** @}*/
78
79/** \addtogroup usb_cdc_ctrl_line_state USB CDC ControlLineState bitmap
80 * @{
81 * This section lists CDC ControlLineState bitmap.
82 * - \ref CDCControlLineState_DTR, CDCControlLineState_DTE_PRESENT
83 * - \ref CDCControlLineState_RTS, CDCControlLineState_CARRIER_ON
84 */
85/** Indicates to DCE if DTE is present or not. */
86#define CDCControlLineState_DTE_PRESENT (1 << 0)
87/** RS232 signal DTR: Data Terminal Ready. */
88#define CDCControlLineState_DTR (1 << 0)
89/** Carrier control for half duplex modems. */
90#define CDCControlLineState_CARRIER_ON (1 << 1)
91/** RS232 signal RTS: Request to send. */
92#define CDCControlLineState_RTS (1 << 1)
93/** @}*/
94
95/** \addtogroup usb_cdc_stop USB CDC LineCoding StopBits
96 * @{
97 * This section lists Stop Bits for CDC Line Coding.
98 * - \ref CDCLineCoding_ONESTOPBIT
99 * - \ref CDCLineCoding_ONE5STOPBIT
100 * - \ref CDCLineCoding_TWOSTOPBITS
101 */
102/** The transmission protocol uses one stop bit. */
103#define CDCLineCoding_ONESTOPBIT 0
104/** The transmission protocol uses 1.5 stop bit. */
105#define CDCLineCoding_ONE5STOPBIT 1
106/** The transmissin protocol uses two stop bits. */
107#define CDCLineCoding_TWOSTOPBITS 2
108/** @}*/
109
110/** \addtogroup usb_cdc_parity USB CDC LineCoding ParityCheckings
111 * @{
112 * This section lists Parity checkings for CDC Line Coding.
113 * - \ref CDCLineCoding_NOPARITY
114 * - \ref CDCLineCoding_ODDPARITY
115 * - \ref CDCLineCoding_EVENPARITY
116 * - \ref CDCLineCoding_MARKPARITY
117 * - \ref CDCLineCoding_SPACEPARITY
118 */
119/** No parity checking. */
120#define CDCLineCoding_NOPARITY 0
121/** Odd parity checking. */
122#define CDCLineCoding_ODDPARITY 1
123/** Even parity checking. */
124#define CDCLineCoding_EVENPARITY 2
125/** Mark parity checking. */
126#define CDCLineCoding_MARKPARITY 3
127/** Space parity checking. */
128#define CDCLineCoding_SPACEPARITY 4
129/** @}*/
130
131/*----------------------------------------------------------------------------
132 * Types
133 *----------------------------------------------------------------------------*/
134
135#ifdef __ICCARM__ /* IAR */
136#pragma pack(1) /* IAR */
137#define __attribute__(...) /* IAR */
138#endif /* IAR */
139
140/**
141 * \typedef CDCLineCoding
142 * \brief Format of the data returned when a GetLineCoding request is received.
143 */
144typedef struct _CDCLineCoding {
145
146 /** Data terminal rate in bits per second. */
147 uint32_t dwDTERate;
148 /** Number of stop bits.
149 \sa usb_cdc_stop CDC LineCoding StopBits. */
150 uint8_t bCharFormat;
151 /** Type of parity checking used.
152 \sa usb_cdc_parity CDC LineCoding ParityCheckings. */
153 uint8_t bParityType;
154 /** Number of data bits (5, 6, 7, 8 or 16). */
155 uint8_t bDataBits;
156
157} __attribute__ ((packed)) CDCLineCoding; /* GCC */
158
159#ifdef __ICCARM__ /* IAR */
160#pragma pack() /* IAR */
161#endif /* IAR */
162
163/*----------------------------------------------------------------------------
164 * Functions
165 *----------------------------------------------------------------------------*/
166
167extern uint8_t CDCSetControlLineStateRequest_IsDtePresent(
168 const USBGenericRequest *request);
169
170extern uint8_t CDCSetControlLineStateRequest_ActivateCarrier(
171 const USBGenericRequest *request);
172
173extern void CDCLineCoding_Initialize(CDCLineCoding *lineCoding,
174 uint32_t bitrate,
175 uint8_t stopbits,
176 uint8_t parity,
177 uint8_t databits);
178
179
180/**@}*/
181#endif /* #define _CDCREQUESTS_H_ */
182