00001 /* ---------------------------------------------------------------------------- */ 00002 /* Atmel Microcontroller Software Support */ 00003 /* SAM Software Package License */ 00004 /* ---------------------------------------------------------------------------- */ 00005 /* Copyright (c) 2015, Atmel Corporation */ 00006 /* */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without */ 00010 /* modification, are permitted provided that the following condition is met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, */ 00013 /* this list of conditions and the disclaimer below. */ 00014 /* */ 00015 /* Atmel's name may not be used to endorse or promote products derived from */ 00016 /* this software without specific prior written permission. */ 00017 /* */ 00018 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00028 /* ---------------------------------------------------------------------------- */ 00029 00030 /** \file 00031 * 00032 * Definitions and classes for USB CDC class requests 00033 * (mostly for ACM). 00034 * 00035 * \section CDCLineCoding 00036 * 00037 * -# Initialize a CDCLineCoding instance using CDCLineCoding_Initialize. 00038 * -# Send a CDCLineCoding object to the host in response to a GetLineCoding 00039 * request. 00040 * -# Receive a CDCLineCoding object from the host after a SetLineCoding 00041 * request. 00042 * 00043 */ 00044 00045 #ifndef _CDCREQUESTS_H_ 00046 #define _CDCREQUESTS_H_ 00047 /** \addtogroup usb_cdc 00048 *@{ 00049 */ 00050 00051 /*---------------------------------------------------------------------------- 00052 * Includes 00053 *----------------------------------------------------------------------------*/ 00054 00055 #include <stdint.h> 00056 #include <USBRequests.h> 00057 00058 /*---------------------------------------------------------------------------- 00059 * Definitions 00060 *----------------------------------------------------------------------------*/ 00061 00062 /** \addtogroup usb_cdc_request USB CDC Request Codes 00063 * @{ 00064 * This section lists USB CDC Request Codes. 00065 * - \ref CDCGenericRequest_SETLINECODING 00066 * - \ref CDCGenericRequest_GETLINECODING 00067 * - \ref CDCGenericRequest_SETCONTROLLINESTATE 00068 */ 00069 00070 /** SetLineCoding request code. */ 00071 #define CDCGenericRequest_SETLINECODING 0x20 00072 /** GetLineCoding request code. */ 00073 #define CDCGenericRequest_GETLINECODING 0x21 00074 /** SetControlLineState request code. */ 00075 #define CDCGenericRequest_SETCONTROLLINESTATE 0x22 00076 /** @}*/ 00077 00078 /** \addtogroup usb_cdc_ctrl_line_state USB CDC ControlLineState bitmap 00079 * @{ 00080 * This section lists CDC ControlLineState bitmap. 00081 * - \ref CDCControlLineState_DTR, CDCControlLineState_DTE_PRESENT 00082 * - \ref CDCControlLineState_RTS, CDCControlLineState_CARRIER_ON 00083 */ 00084 /** Indicates to DCE if DTE is present or not. */ 00085 #define CDCControlLineState_DTE_PRESENT (1 << 0) 00086 /** RS232 signal DTR: Data Terminal Ready. */ 00087 #define CDCControlLineState_DTR (1 << 0) 00088 /** Carrier control for half duplex modems. */ 00089 #define CDCControlLineState_CARRIER_ON (1 << 1) 00090 /** RS232 signal RTS: Request to send. */ 00091 #define CDCControlLineState_RTS (1 << 1) 00092 /** @}*/ 00093 00094 /** \addtogroup usb_cdc_stop USB CDC LineCoding StopBits 00095 * @{ 00096 * This section lists Stop Bits for CDC Line Coding. 00097 * - \ref CDCLineCoding_ONESTOPBIT 00098 * - \ref CDCLineCoding_ONE5STOPBIT 00099 * - \ref CDCLineCoding_TWOSTOPBITS 00100 */ 00101 /** The transmission protocol uses one stop bit. */ 00102 #define CDCLineCoding_ONESTOPBIT 0 00103 /** The transmission protocol uses 1.5 stop bit. */ 00104 #define CDCLineCoding_ONE5STOPBIT 1 00105 /** The transmission protocol uses two stop bits. */ 00106 #define CDCLineCoding_TWOSTOPBITS 2 00107 /** @}*/ 00108 00109 /** \addtogroup usb_cdc_parity USB CDC LineCoding ParityCheckings 00110 * @{ 00111 * This section lists Parity checkings for CDC Line Coding. 00112 * - \ref CDCLineCoding_NOPARITY 00113 * - \ref CDCLineCoding_ODDPARITY 00114 * - \ref CDCLineCoding_EVENPARITY 00115 * - \ref CDCLineCoding_MARKPARITY 00116 * - \ref CDCLineCoding_SPACEPARITY 00117 */ 00118 /** No parity checking. */ 00119 #define CDCLineCoding_NOPARITY 0 00120 /** Odd parity checking. */ 00121 #define CDCLineCoding_ODDPARITY 1 00122 /** Even parity checking. */ 00123 #define CDCLineCoding_EVENPARITY 2 00124 /** Mark parity checking. */ 00125 #define CDCLineCoding_MARKPARITY 3 00126 /** Space parity checking. */ 00127 #define CDCLineCoding_SPACEPARITY 4 00128 /** @}*/ 00129 00130 /*---------------------------------------------------------------------------- 00131 * Types 00132 *----------------------------------------------------------------------------*/ 00133 #pragma pack(1) 00134 #if defined ( __CC_ARM ) /* Keil ¦̀Vision 4 */ 00135 #elif defined ( __ICCARM__ ) /* IAR Ewarm */ 00136 #define __attribute__(...) 00137 #define __packed__ packed 00138 #elif defined ( __GNUC__ ) /* GCC CS3 */ 00139 #define __packed__ aligned(1) 00140 #endif 00141 00142 /** 00143 * \typedef CDCLineCoding 00144 * \brief Format of the data returned when a GetLineCoding request is received. 00145 */ 00146 typedef struct _CDCLineCoding { 00147 00148 /** Data terminal rate in bits per second. */ 00149 uint32_t dwDTERate; 00150 /** Number of stop bits. 00151 \sa usb_cdc_stop CDC LineCoding StopBits. */ 00152 uint8_t bCharFormat; 00153 /** Type of parity checking used. 00154 \sa usb_cdc_parity CDC LineCoding ParityCheckings. */ 00155 uint8_t bParityType; 00156 /** Number of data bits (5, 6, 7, 8 or 16). */ 00157 uint8_t bDataBits; 00158 00159 } __attribute__ ((__packed__)) CDCLineCoding; /* GCC */ 00160 00161 #pragma pack() 00162 00163 /*---------------------------------------------------------------------------- 00164 * Functions 00165 *----------------------------------------------------------------------------*/ 00166 00167 extern uint8_t CDCSetControlLineStateRequest_IsDtePresent( 00168 const USBGenericRequest *request); 00169 00170 extern uint8_t CDCSetControlLineStateRequest_ActivateCarrier( 00171 const USBGenericRequest *request); 00172 00173 extern void CDCLineCoding_Initialize(CDCLineCoding *lineCoding, 00174 uint32_t bitrate, 00175 uint8_t stopbits, 00176 uint8_t parity, 00177 uint8_t databits); 00178 00179 00180 /**@}*/ 00181 #endif /* #define _CDCREQUESTS_H_ */ 00182