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 /** 00031 * \file 00032 * 00033 * \section Purpose 00034 * 00035 * Definition of a class for implementing a USB device CDC EEM driver. 00036 * 00037 * \section Usage 00038 * 00039 * -# Re-implement the USBDCallbacks_RequestReceived method to pass 00040 * received requests to CDCDEEMDriver_RequestHandler. *This is 00041 * automatically done unless the NOAUTOCALLBACK symbol is defined*. 00042 * -# Initialize the CDC EEM and USB drivers using 00043 * CDCDEEMDriver_Initialize. 00044 * -# Logically connect the device to the host using USBD_Connect. 00045 * -# Send serial data to the USB host using CDCDEEMDriver_Write. 00046 * -# Receive serial data from the USB host using CDCDEEMDriver_Read. 00047 */ 00048 00049 #ifndef CDCDEEMDRIVER_H 00050 #define CDCDEEMDRIVER_H 00051 00052 /** \addtogroup usbd_cdc 00053 *@{ 00054 */ 00055 00056 /*------------------------------------------------------------------------------ 00057 * Headers 00058 *------------------------------------------------------------------------------*/ 00059 00060 /* These headers were introduced in C99 00061 by working group ISO/IEC JTC1/SC22/WG14. */ 00062 #include <stdint.h> 00063 00064 #include <USBRequests.h> 00065 #include <CDCRequests.h> 00066 #include <CDCDescriptors.h> 00067 #include <CDCNotifications.h> 00068 00069 #include <CDCDEEM.h> 00070 00071 /*------------------------------------------------------------------------------ 00072 * Definitions 00073 *------------------------------------------------------------------------------*/ 00074 00075 /** \addtogroup usbd_cdc_if USB Device CDC EEM Interface IDs 00076 * @{ 00077 */ 00078 /** Communication Class Interface ID */ 00079 #define CDCDEEMDriver_CC_INTERFACE 0 00080 /** @}*/ 00081 00082 /*------------------------------------------------------------------------------ 00083 * Types 00084 *------------------------------------------------------------------------------*/ 00085 #pragma pack(1) 00086 #if defined ( __CC_ARM ) /* Keil ¦̀Vision 4 */ 00087 #elif defined ( __ICCARM__ ) /* IAR Ewarm */ 00088 #define __attribute__(...) 00089 #define __packed__ packed 00090 #elif defined ( __GNUC__ ) /* GCC CS3 */ 00091 #define __packed__ aligned(1) 00092 #endif 00093 00094 /** 00095 * \typedef CDCDEEMDriverConfigurationDescriptors 00096 * \brief Configuration descriptor list for a device implementing a 00097 * CDC EEM driver. 00098 */ 00099 typedef struct _CDCDEEMDriverConfigurationDescriptors { 00100 00101 /** Standard configuration descriptor. */ 00102 USBConfigurationDescriptor configuration; 00103 /** Communication interface descriptor. */ 00104 USBInterfaceDescriptor communication; 00105 /** Data OUT endpoint descriptor. */ 00106 USBEndpointDescriptor dataOut; 00107 /** Data IN endpoint descriptor. */ 00108 USBEndpointDescriptor dataIn; 00109 00110 } __attribute__ ((__packed__)) CDCDEEMDriverConfigurationDescriptors; 00111 00112 /** 00113 * \typedef CDCDEEMDriverConfigurationDescriptorsOTG 00114 * \brief Configuration descriptor list for a device implementing a 00115 * CDC EEM OTG driver. 00116 */ 00117 typedef struct _CDCDEEMDriverConfigurationDescriptorsOTG { 00118 00119 /** Standard configuration descriptor. */ 00120 USBConfigurationDescriptor configuration; 00121 /* OTG descriptor */ 00122 USBOtgDescriptor otgDescriptor; 00123 /** Communication interface descriptor. */ 00124 USBInterfaceDescriptor communication; 00125 /** Data OUT endpoint descriptor. */ 00126 USBEndpointDescriptor dataOut; 00127 /** Data IN endpoint descriptor. */ 00128 USBEndpointDescriptor dataIn; 00129 00130 } __attribute__ ((__packed__)) CDCDEEMDriverConfigurationDescriptorsOTG; 00131 00132 #pragma pack() 00133 00134 /*------------------------------------------------------------------------------ 00135 * Exported functions 00136 *------------------------------------------------------------------------------*/ 00137 00138 extern void CDCDEEMDriver_Initialize( 00139 const USBDDriverDescriptors *pDescriptors); 00140 00141 extern void CDCDEEMDriver_ConfigurationChangedHandler(uint8_t cfgnum); 00142 00143 extern void CDCDEEMDriver_RequestHandler( 00144 const USBGenericRequest *request); 00145 00146 /** 00147 * Sends a data buffer through the virtual COM port created by the CDC 00148 * device serial driver. This function behaves exactly like USBD_Write. 00149 * \param data Pointer to the data buffer to send. 00150 * \param size Size of the data buffer in bytes. 00151 * \param callback Optional callback function to invoke when the transfer 00152 * finishes. 00153 * \param argument Optional argument to the callback function. 00154 * \return USBD_STATUS_SUCCESS if the read operation has been started normally; 00155 * otherwise, the corresponding error code. 00156 */ 00157 static inline uint32_t CDCDEEMDriver_Write( 00158 void *data, 00159 uint32_t size, 00160 TransferCallback callback, 00161 void *argument) 00162 { 00163 return CDCDEEM_Write(data, size, callback, argument); 00164 } 00165 00166 /** 00167 * Receives data from the host through the virtual COM port created by 00168 * the CDC device serial driver. This function behaves like USBD_Read. 00169 * \param data Pointer to the data buffer to put received data. 00170 * \param size Size of the data buffer in bytes. 00171 * \param callback Optional callback function to invoke when the transfer 00172 * finishes. 00173 * \param argument Optional argument to the callback function. 00174 * \return USBD_STATUS_SUCCESS if the read operation has been started normally; 00175 * otherwise, the corresponding error code. 00176 */ 00177 static inline uint32_t CDCDEEMDriver_Read( 00178 void *data, 00179 uint32_t size, 00180 TransferCallback callback, 00181 void *argument) 00182 { 00183 return CDCDEEM_Read(data, size, callback, argument); 00184 } 00185 /**@}*/ 00186 00187 #endif /*#ifndef CDCEEMDRIVER_H*/ 00188