SAMV71 Xplained Ultra Software Package 1.4

USBDDriverDescriptors.c

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, 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  *      Headers
00035  *----------------------------------------------------------------------------*/
00036 
00037 #include <USBD_Config.h>
00038 
00039 #include <CDCMSDDriver.h>
00040 #include <CDCDSerial.h>
00041 #include <MSDFunction.h>
00042 
00043 /*-----------------------------------------------------------------------------
00044  *         Definitions
00045  *---------------------------------------------------------------------------*/
00046 
00047 
00048 
00049 /** Device product ID. */
00050 #define CDCMSDDDriverDescriptors_PRODUCTID       USBD_PID_CDCMSD
00051 /** Device vendor ID (Atmel). */
00052 #define CDCMSDDDriverDescriptors_VENDORID        USBD_VID_ATMEL
00053 /** Device release number. */
00054 #define CDCMSDDDriverDescriptors_RELEASE         USBD_RELEASE_1_00
00055 
00056 /*-----------------------------------------------------------------------------
00057  *         Macros
00058  *---------------------------------------------------------------------------*/
00059 
00060 /** Returns the minimum between two values. */
00061 #define MIN(a, b)       ((a < b) ? a : b)
00062 
00063 /*------------------------------------------------------------------------------
00064  *         Internal variables
00065  *----------------------------------------------------------------------------*/
00066 
00067 /** Standard USB device descriptor for the CDCMSD device driver */
00068 static const USBDeviceDescriptor deviceDescriptor = {
00069 
00070     sizeof(USBDeviceDescriptor),
00071     USBGenericDescriptor_DEVICE,
00072     USBDeviceDescriptor_USB2_00,
00073     0xEF, /* MI */
00074     0x02,
00075     0x01,
00076     CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
00077     CDCMSDDDriverDescriptors_VENDORID,
00078     CDCMSDDDriverDescriptors_PRODUCTID,
00079     CDCMSDDDriverDescriptors_RELEASE,
00080     1, /* No string descriptor for manufacturer */
00081     2, /* Index of product string descriptor is #1 */
00082     3, /* No string descriptor for serial number */
00083     1  /* Device has 1 possible configuration */
00084 };
00085 
00086 /** Device qualifier descriptor (Necessary to pass USB test). */
00087 static const USBDeviceQualifierDescriptor qualifierDescriptor = {
00088 
00089     sizeof(USBDeviceQualifierDescriptor),
00090     USBGenericDescriptor_DEVICEQUALIFIER,
00091     USBDeviceDescriptor_USB2_00,
00092     0xEF,
00093     0x02,
00094     0x01,
00095     CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),    
00096     0, // Device has one possible configuration.
00097     0x00
00098 };
00099 
00100 
00101 /** USB configuration descriptors for the CDCMSD device driver */
00102 static const CDCMSDDriverConfigurationDescriptors configurationDescriptorsFS =
00103 {
00104 
00105     /* Standard configuration descriptor */
00106     {
00107         sizeof(USBConfigurationDescriptor),
00108         USBGenericDescriptor_CONFIGURATION,
00109         sizeof(CDCMSDDriverConfigurationDescriptors),
00110         CDCMSDDriverDescriptors_NUMINTERFACE,
00111         1, /* This is configuration #1 */
00112         0, /* No string descriptor for this configuration */
00113         USBD_BMATTRIBUTES,
00114         USBConfigurationDescriptor_POWER(100)
00115     },
00116 
00117     /* CDC */
00118     /* IAD for CDC/ACM port */
00119     {
00120         sizeof(USBInterfaceAssociationDescriptor),
00121         USBGenericDescriptor_INTERFACEASSOCIATION,
00122         CDCMSDDriverDescriptors_CDC_INTERFACE,
00123         2,
00124         CDCCommunicationInterfaceDescriptor_CLASS,
00125         CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
00126         CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
00127         0  /* No string descriptor for this interface */
00128     },
00129     /* Communication class interface standard descriptor */
00130     {
00131         sizeof(USBInterfaceDescriptor),
00132         USBGenericDescriptor_INTERFACE,
00133         CDCMSDDriverDescriptors_CDC_INTERFACE, /* This is interface #0 */
00134         0, /* This is alternate setting #0 for this interface */
00135         1, /* This interface uses 1 endpoint */
00136         CDCCommunicationInterfaceDescriptor_CLASS,
00137         CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
00138         CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
00139         0  /* No string descriptor for this interface */
00140     },
00141     /* Class-specific header functional descriptor */
00142     {
00143         sizeof(CDCHeaderDescriptor),
00144         CDCGenericDescriptor_INTERFACE,
00145         CDCGenericDescriptor_HEADER,
00146         CDCGenericDescriptor_CDC1_10
00147     },
00148     /* Class-specific call management functional descriptor */
00149     {
00150         sizeof(CDCCallManagementDescriptor),
00151         CDCGenericDescriptor_INTERFACE,
00152         CDCGenericDescriptor_CALLMANAGEMENT,
00153         CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
00154         CDCMSDDriverDescriptors_CDC_INTERFACE + 1 /* No associated data interface */
00155     },
00156     /* Class-specific abstract control management functional descriptor */
00157     {
00158         sizeof(CDCAbstractControlManagementDescriptor),
00159         CDCGenericDescriptor_INTERFACE,
00160         CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
00161         CDCAbstractControlManagementDescriptor_LINE
00162     },
00163     /* Class-specific union functional descriptor with one slave interface */
00164     {
00165         sizeof(CDCUnionDescriptor),
00166         CDCGenericDescriptor_INTERFACE,
00167         CDCGenericDescriptor_UNION,
00168         CDCMSDDriverDescriptors_CDC_INTERFACE, /* Number of master interface is #0 */
00169         CDCMSDDriverDescriptors_CDC_INTERFACE + 1 /* First slave interface is #1 */
00170     },
00171     /* Notification endpoint standard descriptor */
00172     {
00173         sizeof(USBEndpointDescriptor), 
00174         USBGenericDescriptor_ENDPOINT,
00175         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
00176                                       CDCD_Descriptors_NOTIFICATION0),
00177         USBEndpointDescriptor_INTERRUPT,
00178         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_NOTIFICATION0),
00179             CDCDSerialPort_INTERRUPT_MAXPACKETSIZE),
00180         CDCDSerialPort_INTERRUPT_INTERVAL_FS
00181     },
00182     /* Data class interface standard descriptor */
00183     {
00184         sizeof(USBInterfaceDescriptor),
00185         USBGenericDescriptor_INTERFACE,
00186         CDCMSDDriverDescriptors_CDC_INTERFACE + 1, /* This is interface #1 */
00187         0, /* This is alternate setting #0 for this interface */
00188         2, /* This interface uses 2 endpoints */
00189         CDCDataInterfaceDescriptor_CLASS,
00190         CDCDataInterfaceDescriptor_SUBCLASS,
00191         CDCDataInterfaceDescriptor_NOPROTOCOL,
00192         0  /* No string descriptor for this interface */
00193     },
00194     /* Bulk-OUT endpoint standard descriptor */
00195     {
00196         sizeof(USBEndpointDescriptor), 
00197         USBGenericDescriptor_ENDPOINT,
00198         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
00199                                     CDCD_Descriptors_DATAOUT0),
00200         USBEndpointDescriptor_BULK,
00201         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAOUT0),
00202             USBEndpointDescriptor_MAXBULKSIZE_FS),
00203         0 /* Must be 0 for full-speed bulk endpoints */
00204     },
00205     /* Bulk-IN endpoint descriptor */
00206     {
00207         sizeof(USBEndpointDescriptor),
00208         USBGenericDescriptor_ENDPOINT,
00209         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
00210                                     CDCD_Descriptors_DATAIN0),
00211         USBEndpointDescriptor_BULK,
00212         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAIN0),
00213             USBEndpointDescriptor_MAXBULKSIZE_FS),
00214         0 /* Must be 0 for full-speed bulk endpoints */
00215     },
00216 
00217     /* Mass Storage interface descriptor. */
00218     {
00219         sizeof(USBInterfaceDescriptor),
00220         USBGenericDescriptor_INTERFACE,
00221         CDCMSDDriverDescriptors_MSD_INTERFACE,
00222         0, /* This is alternate setting #0. */
00223         2, /* Interface uses two endpoints. */
00224         MSInterfaceDescriptor_CLASS,            
00225         MSInterfaceDescriptor_SCSI,                 
00226         MSInterfaceDescriptor_BULKONLY,            
00227         0 /* No string descriptor for interface. */
00228     },
00229     /* Bulk-OUT endpoint descriptor */
00230     {
00231         sizeof(USBEndpointDescriptor), 
00232         USBGenericDescriptor_ENDPOINT,
00233         USBEndpointDescriptor_ADDRESS(
00234             USBEndpointDescriptor_OUT,
00235             MSDD_Descriptors_BULKOUT),
00236         USBEndpointDescriptor_BULK,
00237         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDD_Descriptors_BULKOUT),
00238             USBEndpointDescriptor_MAXBULKSIZE_FS),
00239         0 /* No string descriptor for endpoint. */
00240     },
00241     /* Bulk-IN endpoint descriptor */
00242     {
00243         sizeof(USBEndpointDescriptor),
00244         USBGenericDescriptor_ENDPOINT,
00245         USBEndpointDescriptor_ADDRESS(
00246             USBEndpointDescriptor_IN,
00247             MSDD_Descriptors_BULKIN),
00248         USBEndpointDescriptor_BULK,
00249         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDD_Descriptors_BULKIN),
00250             USBEndpointDescriptor_MAXBULKSIZE_FS),
00251         0 /* No string descriptor for endpoint. */
00252     }
00253 
00254 };
00255 
00256 
00257 /** USB configuration descriptors for the CDCMSD device driver */
00258 static const CDCMSDDriverConfigurationDescriptors configurationDescriptorsHS =
00259 {
00260 
00261     /* Standard configuration descriptor */
00262     {
00263         sizeof(USBConfigurationDescriptor),
00264         USBGenericDescriptor_CONFIGURATION,
00265         sizeof(CDCMSDDriverConfigurationDescriptors),
00266         CDCMSDDriverDescriptors_NUMINTERFACE,
00267         1, /* This is configuration #1 */
00268         0, /* No string descriptor for this configuration */
00269         USBD_BMATTRIBUTES,
00270         USBConfigurationDescriptor_POWER(100)
00271     },
00272 
00273     /* CDC */
00274     /* IAD for CDC/ACM port */
00275     {
00276         sizeof(USBInterfaceAssociationDescriptor),
00277         USBGenericDescriptor_INTERFACEASSOCIATION,
00278         CDCMSDDriverDescriptors_CDC_INTERFACE,
00279         2,
00280         CDCCommunicationInterfaceDescriptor_CLASS,
00281         CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
00282         CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
00283         0  /* No string descriptor for this interface */
00284     },
00285     /* Communication class interface standard descriptor */
00286     {
00287         sizeof(USBInterfaceDescriptor),
00288         USBGenericDescriptor_INTERFACE,
00289         CDCMSDDriverDescriptors_CDC_INTERFACE, /* This is interface #0 */
00290         0, /* This is alternate setting #0 for this interface */
00291         1, /* This interface uses 1 endpoint */
00292         CDCCommunicationInterfaceDescriptor_CLASS,
00293         CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
00294         CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
00295         0  /* No string descriptor for this interface */
00296     },
00297     /* Class-specific header functional descriptor */
00298     {
00299         sizeof(CDCHeaderDescriptor),
00300         CDCGenericDescriptor_INTERFACE,
00301         CDCGenericDescriptor_HEADER,
00302         CDCGenericDescriptor_CDC1_10
00303     },
00304     /* Class-specific call management functional descriptor */
00305     {
00306         sizeof(CDCCallManagementDescriptor),
00307         CDCGenericDescriptor_INTERFACE,
00308         CDCGenericDescriptor_CALLMANAGEMENT,
00309         CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
00310         CDCMSDDriverDescriptors_CDC_INTERFACE + 1 /* No associated data interface */
00311     },
00312     /* Class-specific abstract control management functional descriptor */
00313     {
00314         sizeof(CDCAbstractControlManagementDescriptor),
00315         CDCGenericDescriptor_INTERFACE,
00316         CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
00317         CDCAbstractControlManagementDescriptor_LINE
00318     },
00319     /* Class-specific union functional descriptor with one slave interface */
00320     {
00321         sizeof(CDCUnionDescriptor),
00322         CDCGenericDescriptor_INTERFACE,
00323         CDCGenericDescriptor_UNION,
00324         CDCMSDDriverDescriptors_CDC_INTERFACE, /* Number of master interface is #0 */
00325         CDCMSDDriverDescriptors_CDC_INTERFACE + 1 /* First slave interface is #1 */
00326     },
00327     /* Notification endpoint standard descriptor */
00328     {
00329         sizeof(USBEndpointDescriptor), 
00330         USBGenericDescriptor_ENDPOINT,
00331         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
00332                                     CDCD_Descriptors_NOTIFICATION0),
00333         USBEndpointDescriptor_INTERRUPT,
00334         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_NOTIFICATION0),
00335             CDCDSerialPort_INTERRUPT_MAXPACKETSIZE),
00336         CDCDSerialPort_INTERRUPT_INTERVAL_FS
00337     },
00338     /* Data class interface standard descriptor */
00339     {
00340         sizeof(USBInterfaceDescriptor),
00341         USBGenericDescriptor_INTERFACE,
00342         CDCMSDDriverDescriptors_CDC_INTERFACE + 1, /* This is interface #1 */
00343         0, /* This is alternate setting #0 for this interface */
00344         2, /* This interface uses 2 endpoints */
00345         CDCDataInterfaceDescriptor_CLASS,
00346         CDCDataInterfaceDescriptor_SUBCLASS,
00347         CDCDataInterfaceDescriptor_NOPROTOCOL,
00348         0  /* No string descriptor for this interface */
00349     },
00350     /* Bulk-OUT endpoint standard descriptor */
00351     {
00352         sizeof(USBEndpointDescriptor), 
00353         USBGenericDescriptor_ENDPOINT,
00354         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
00355                                     CDCD_Descriptors_DATAOUT0),
00356         USBEndpointDescriptor_BULK,
00357         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAOUT0),
00358             USBEndpointDescriptor_MAXBULKSIZE_FS),
00359         0 /* Must be 0 for full-speed bulk endpoints */
00360     },
00361     /* Bulk-IN endpoint descriptor */
00362     {
00363         sizeof(USBEndpointDescriptor),
00364         USBGenericDescriptor_ENDPOINT,
00365         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
00366                                     CDCD_Descriptors_DATAIN0),
00367         USBEndpointDescriptor_BULK,
00368         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAIN0),
00369             USBEndpointDescriptor_MAXBULKSIZE_FS),
00370         0 /* Must be 0 for full-speed bulk endpoints */
00371     },
00372 
00373     /* Mass Storage interface descriptor. */
00374     {
00375         sizeof(USBInterfaceDescriptor),
00376         USBGenericDescriptor_INTERFACE,
00377         CDCMSDDriverDescriptors_MSD_INTERFACE,
00378         0, /* This is alternate setting #0. */
00379         2, /* Interface uses two endpoints. */
00380         MSInterfaceDescriptor_CLASS,
00381         MSInterfaceDescriptor_SCSI,
00382         MSInterfaceDescriptor_BULKONLY,
00383         0 /* No string descriptor for interface. */
00384     },
00385     /* Bulk-OUT endpoint descriptor */
00386     {
00387         sizeof(USBEndpointDescriptor), 
00388         USBGenericDescriptor_ENDPOINT,
00389         USBEndpointDescriptor_ADDRESS(
00390             USBEndpointDescriptor_OUT,
00391             MSDD_Descriptors_BULKOUT),
00392         USBEndpointDescriptor_BULK,
00393         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDD_Descriptors_BULKOUT),
00394              USBEndpointDescriptor_MAXBULKSIZE_HS),
00395         0 /* No string descriptor for endpoint. */
00396     },
00397     /* Bulk-IN endpoint descriptor */
00398     {
00399         sizeof(USBEndpointDescriptor),
00400         USBGenericDescriptor_ENDPOINT,
00401         USBEndpointDescriptor_ADDRESS(
00402             USBEndpointDescriptor_IN,
00403             MSDD_Descriptors_BULKIN),
00404         USBEndpointDescriptor_BULK,
00405         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(MSDD_Descriptors_BULKIN),
00406             USBEndpointDescriptor_MAXBULKSIZE_HS),
00407         0 /* No string descriptor for endpoint. */
00408     }
00409 
00410 };
00411 /** String descriptor with the supported languages. */
00412 static const unsigned char languageIdDescriptor[] = {
00413 
00414     USBStringDescriptor_LENGTH(1),
00415     USBGenericDescriptor_STRING,
00416     USBStringDescriptor_ENGLISH_US
00417 };
00418 
00419 /** Manufacturer name. */
00420 static const unsigned char manufacturerDescriptor[] = {
00421 
00422     USBStringDescriptor_LENGTH(5),
00423     USBGenericDescriptor_STRING,
00424     USBStringDescriptor_UNICODE('A'),
00425     USBStringDescriptor_UNICODE('t'),
00426     USBStringDescriptor_UNICODE('m'),
00427     USBStringDescriptor_UNICODE('e'),
00428     USBStringDescriptor_UNICODE('l')
00429 };
00430 
00431 /** Product name. */
00432 static const unsigned char productDescriptor[] = {
00433 
00434     USBStringDescriptor_LENGTH(14),
00435     USBGenericDescriptor_STRING,
00436     USBStringDescriptor_UNICODE('C'),
00437     USBStringDescriptor_UNICODE('o'),
00438     USBStringDescriptor_UNICODE('m'),
00439     USBStringDescriptor_UNICODE('p'),
00440     USBStringDescriptor_UNICODE('o'),
00441     USBStringDescriptor_UNICODE('s'),
00442     USBStringDescriptor_UNICODE('i'),
00443     USBStringDescriptor_UNICODE('t'),
00444     USBStringDescriptor_UNICODE('e'),
00445     USBStringDescriptor_UNICODE(' '),
00446     USBStringDescriptor_UNICODE('D'),
00447     USBStringDescriptor_UNICODE('e'),
00448     USBStringDescriptor_UNICODE('m'),
00449     USBStringDescriptor_UNICODE('o')
00450 };
00451 
00452 /** Product serial number. */
00453 static const unsigned char serialNumberDescriptor[] = {
00454 
00455     USBStringDescriptor_LENGTH(12),
00456     USBGenericDescriptor_STRING,
00457     USBStringDescriptor_UNICODE('0'),
00458     USBStringDescriptor_UNICODE('1'),
00459     USBStringDescriptor_UNICODE('2'),
00460     USBStringDescriptor_UNICODE('3'),
00461     USBStringDescriptor_UNICODE('4'),
00462     USBStringDescriptor_UNICODE('5'),
00463     USBStringDescriptor_UNICODE('6'),
00464     USBStringDescriptor_UNICODE('7'),
00465     USBStringDescriptor_UNICODE('8'),
00466     USBStringDescriptor_UNICODE('9'),
00467     USBStringDescriptor_UNICODE('A'),
00468     USBStringDescriptor_UNICODE('B')
00469 };
00470 
00471 /** Array of pointers to the four string descriptors. */
00472 static const unsigned char *stringDescriptors[] = {
00473 
00474     languageIdDescriptor,
00475     manufacturerDescriptor,
00476     productDescriptor,
00477     serialNumberDescriptor,
00478 };
00479 
00480 /*----------------------------------------------------------------------------
00481  *         Exported variables
00482  *----------------------------------------------------------------------------*/
00483 
00484 /** List of descriptors required by an USB audio speaker device driver. */
00485 const USBDDriverDescriptors cdcmsddDriverDescriptors = {
00486 
00487     &deviceDescriptor,
00488     (const USBConfigurationDescriptor *) &configurationDescriptorsFS,
00489     &qualifierDescriptor, 0, 0,
00490     (const USBConfigurationDescriptor *) &configurationDescriptorsHS,
00491     &qualifierDescriptor, 0,
00492     stringDescriptors,
00493     4 /* Number of string descriptors */
00494 };
00495 /**@}*/
00496 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines