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 /** \file */ 00030 /** \addtogroup usbd_composite_cdcmsd 00031 *@{ 00032 */ 00033 00034 /*--------------------------------------------------------------------------- 00035 * Headers 00036 *---------------------------------------------------------------------------*/ 00037 00038 #include <USBLib_Trace.h> 00039 00040 #include <CDCMSDDriver.h> 00041 00042 #include <CDCDSerial.h> 00043 #include <MSDFunction.h> 00044 00045 /*--------------------------------------------------------------------------- 00046 * Defines 00047 *---------------------------------------------------------------------------*/ 00048 00049 /*--------------------------------------------------------------------------- 00050 * Types 00051 *---------------------------------------------------------------------------*/ 00052 00053 /*--------------------------------------------------------------------------- 00054 * Internal variables 00055 *---------------------------------------------------------------------------*/ 00056 00057 /*--------------------------------------------------------------------------- 00058 * Internal functions 00059 *---------------------------------------------------------------------------*/ 00060 00061 /*--------------------------------------------------------------------------- 00062 * Exported functions 00063 *---------------------------------------------------------------------------*/ 00064 00065 /** 00066 * Initializes the USB device CDCMSD device driver. 00067 */ 00068 void CDCMSDDriver_Initialize( 00069 const USBDDriverDescriptors *pDescriptors, 00070 MSDLun *pLuns, unsigned char numLuns) 00071 { 00072 USBDDriver *pUsbd = USBD_GetDriver(); 00073 00074 /* Initialize the standard USB driver */ 00075 USBDDriver_Initialize(pUsbd, pDescriptors, 0); 00076 00077 /* CDC */ 00078 CDCDSerial_Initialize(pUsbd, CDCMSDDriverDescriptors_CDC_INTERFACE); 00079 00080 /* MSD */ 00081 MSDFunction_Initialize(pUsbd, CDCMSDDriverDescriptors_MSD_INTERFACE, 00082 pLuns, numLuns); 00083 00084 /* Initialize the USB driver */ 00085 USBD_Init(); 00086 } 00087 00088 /** 00089 * Invoked whenever the configuration value of a device is changed by the host 00090 * \param cfgnum Configuration number. 00091 */ 00092 void CDCMSDDriver_ConfigurationChangedHandler(unsigned char cfgnum) 00093 { 00094 USBDDriver *pUsbd = USBD_GetDriver(); 00095 USBConfigurationDescriptor *pDesc; 00096 00097 if (cfgnum > 0) { 00098 pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum); 00099 /* CDC */ 00100 CDCDSerial_ConfigureFunction((USBGenericDescriptor *)pDesc, 00101 pDesc->wTotalLength); 00102 /* MSD */ 00103 MSDFunction_Configure((USBGenericDescriptor *)pDesc, 00104 pDesc->wTotalLength); 00105 } 00106 } 00107 00108 /** 00109 * Handles CDCMSD-specific USB requests sent by the host, and forwards 00110 * standard ones to the USB device driver. 00111 * \param request Pointer to a USBGenericRequest instance. 00112 */ 00113 void CDCMSDDriver_RequestHandler(const USBGenericRequest *request) 00114 { 00115 USBDDriver *pUsbd = USBD_GetDriver(); 00116 00117 TRACE_INFO_WP("NewReq "); 00118 00119 if (CDCDSerial_RequestHandler(request) == USBRC_SUCCESS) 00120 return; 00121 00122 if (MSDFunction_RequestHandler(request) == USBRC_SUCCESS) 00123 return; 00124 00125 USBDDriver_RequestHandler(pUsbd, request); 00126 } 00127 00128 /**@}*/ 00129