SAMV71 Xplained Ultra Software Package 1.3

CDCDEEMDriver.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2014, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
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 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines