00001 /* ---------------------------------------------------------------------------- 00002 * ATMEL Microcontroller Software Support 00003 * ---------------------------------------------------------------------------- 00004 * Copyright (c) 2008, 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 /** \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 if (cfgnum > 0) { 00097 pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum); 00098 /* CDC */ 00099 CDCDSerial_ConfigureFunction((USBGenericDescriptor*)pDesc, 00100 pDesc->wTotalLength); 00101 /* MSD */ 00102 MSDFunction_Configure((USBGenericDescriptor*)pDesc, 00103 pDesc->wTotalLength); 00104 } 00105 } 00106 00107 /** 00108 * Handles CDCMSD-specific USB requests sent by the host, and forwards 00109 * standard ones to the USB device driver. 00110 * \param request Pointer to a USBGenericRequest instance. 00111 */ 00112 void CDCMSDDriver_RequestHandler(const USBGenericRequest *request) 00113 { 00114 USBDDriver *pUsbd = USBD_GetDriver(); 00115 00116 TRACE_INFO_WP("NewReq "); 00117 00118 if (CDCDSerial_RequestHandler(request) == USBRC_SUCCESS) 00119 return; 00120 00121 if (MSDFunction_RequestHandler(request) == USBRC_SUCCESS) 00122 return; 00123 00124 USBDDriver_RequestHandler(pUsbd, request); 00125 } 00126 00127 /**@}*/ 00128