SAMV71 Xplained Ultra Software Package 1.4

USBDDriverDescriptors.c

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 
00030 /** \addtogroup usbd_composite_hidmsd
00031  *@{
00032  */
00033 
00034 /*----------------------------------------------------------------------------
00035  *      Headers
00036  *----------------------------------------------------------------------------*/
00037 
00038 #include <USBD_Config.h>
00039 
00040 #include <HIDMSDDriver.h>
00041 #include <HIDDKeyboard.h>
00042 #include <MSDFunction.h>
00043 
00044 /*---------------------------------------------------------------------------
00045  *         Definitions
00046  *---------------------------------------------------------------------------*/
00047 
00048 /** Device product ID. */
00049 #define HIDMSDDDriverDescriptors_PRODUCTID       USBD_PID_HIDMSD
00050 /** Device vendor ID (Atmel). */
00051 #define HIDMSDDDriverDescriptors_VENDORID        USBD_VID_ATMEL
00052 /** Device release number. */
00053 #define HIDMSDDDriverDescriptors_RELEASE         0x0003
00054 
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 structures
00065  *---------------------------------------------------------------------------*/
00066 
00067 
00068 /*----------------------------------------------------------------------------
00069  *         Internal variables
00070  *----------------------------------------------------------------------------*/
00071 
00072 /** Standard USB device descriptor for the composite device driver */
00073 static const USBDeviceDescriptor deviceDescriptor =
00074 {
00075 
00076     sizeof(USBDeviceDescriptor),
00077     USBGenericDescriptor_DEVICE,
00078     USBDeviceDescriptor_USB2_00,
00079     0x00,
00080     0x00,
00081     0x00,
00082     CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
00083     HIDMSDDDriverDescriptors_VENDORID,
00084     HIDMSDDDriverDescriptors_PRODUCTID,
00085     HIDMSDDDriverDescriptors_RELEASE,
00086     1, /* No string descriptor for manufacturer */
00087     2, /* Index of product string descriptor is #1 */
00088     3, /* No string descriptor for serial number */
00089     1 /* Device has 1 possible configuration */
00090 };
00091 
00092 /** Device qualifier descriptor (Necessary to pass USB test). */
00093 static const USBDeviceQualifierDescriptor qualifierDescriptor = {
00094 
00095     sizeof(USBDeviceQualifierDescriptor),
00096     USBGenericDescriptor_DEVICEQUALIFIER,
00097     USBDeviceDescriptor_USB2_00,
00098     0x00,
00099     0x00,
00100     0x00,                           
00101     CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),    
00102     0, // Device has one possible configuration.
00103     0x00
00104 };
00105 
00106 /** USB FS configuration descriptors for the composite device driver */
00107 static const HidMsdDriverConfigurationDescriptors configurationDescriptorsFS =
00108 {
00109 
00110     /* Standard configuration descriptor */
00111     {
00112         sizeof(USBConfigurationDescriptor),
00113         USBGenericDescriptor_CONFIGURATION,
00114         sizeof(HidMsdDriverConfigurationDescriptors),
00115         HIDMSDDriverDescriptors_NUMINTERFACE,
00116         1, /* This is configuration #1 */
00117         0, /* No string descriptor for this configuration */
00118         USBD_BMATTRIBUTES,
00119         USBConfigurationDescriptor_POWER(100)
00120     },
00121 
00122     /* Interface descriptor */
00123     {
00124         sizeof(USBInterfaceDescriptor),
00125         USBGenericDescriptor_INTERFACE,
00126         HIDMSDDriverDescriptors_HID_INTERFACE,
00127         0, /* This is alternate setting #0 */
00128         2, /* Two endpoints used */
00129         HIDInterfaceDescriptor_CLASS,
00130         HIDInterfaceDescriptor_SUBCLASS_NONE,
00131         HIDInterfaceDescriptor_PROTOCOL_NONE,
00132         0  /* No associated string descriptor */
00133     },
00134     /* HID descriptor */
00135     {
00136         sizeof(HIDDescriptor1),
00137         HIDGenericDescriptor_HID,
00138         HIDDescriptor_HID1_11,
00139         0, /* Device is not localized, no country code */
00140         1, /* One HID-specific descriptor (apart from this one) */
00141         HIDGenericDescriptor_REPORT,
00142         {HIDDKeyboard_REPORTDESCRIPTORSIZE}
00143     },
00144     /* Interrupt IN endpoint descriptor */
00145     {
00146         sizeof(USBEndpointDescriptor),
00147         USBGenericDescriptor_ENDPOINT,
00148         USBEndpointDescriptor_ADDRESS(
00149             USBEndpointDescriptor_IN,
00150             HIDMSDD_Descriptors_INTERRUPTIN),
00151         USBEndpointDescriptor_INTERRUPT,
00152         sizeof(HIDDKeyboardInputReport),
00153         HIDDKeyboardDescriptors_INTERRUPTIN_POLLING_FS
00154     },
00155     /* Interrupt OUT endpoint descriptor */
00156     {
00157         sizeof(USBEndpointDescriptor),
00158         USBGenericDescriptor_ENDPOINT,
00159         USBEndpointDescriptor_ADDRESS(
00160             USBEndpointDescriptor_OUT,
00161             HIDMSDD_Descriptors_INTERRUPTOUT),
00162         USBEndpointDescriptor_INTERRUPT,
00163         sizeof(HIDDKeyboardOutputReport),
00164         HIDDKeyboardDescriptors_INTERRUPTIN_POLLING_FS
00165     },
00166 
00167     /* Mass Storage interface descriptor. */
00168     {
00169         sizeof(USBInterfaceDescriptor),
00170         USBGenericDescriptor_INTERFACE,
00171         HIDMSDDriverDescriptors_MSD_INTERFACE,
00172         0, /* This is alternate setting #0. */
00173         2, /* Interface uses two endpoints. */
00174         MSInterfaceDescriptor_CLASS,
00175         MSInterfaceDescriptor_SCSI,
00176         MSInterfaceDescriptor_BULKONLY,
00177         0 /* No string descriptor for interface. */
00178     },
00179     /* Bulk-OUT endpoint descriptor */
00180     {
00181         sizeof(USBEndpointDescriptor), 
00182         USBGenericDescriptor_ENDPOINT,
00183         USBEndpointDescriptor_ADDRESS(
00184             USBEndpointDescriptor_OUT,
00185             HIDMSDD_Descriptors_BULKOUT),
00186         USBEndpointDescriptor_BULK,
00187         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(HIDMSDD_Descriptors_BULKOUT),
00188             USBEndpointDescriptor_MAXBULKSIZE_FS),
00189         0 /* No string descriptor for endpoint. */
00190     },
00191     /* Bulk-IN endpoint descriptor */
00192     {
00193         sizeof(USBEndpointDescriptor),
00194         USBGenericDescriptor_ENDPOINT,
00195         USBEndpointDescriptor_ADDRESS(
00196             USBEndpointDescriptor_IN,
00197             HIDMSDD_Descriptors_BULKIN),
00198         USBEndpointDescriptor_BULK,
00199         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(HIDMSDD_Descriptors_BULKIN),
00200             USBEndpointDescriptor_MAXBULKSIZE_FS),
00201         0 /* No string descriptor for endpoint. */
00202     }
00203 
00204 };
00205 
00206 
00207 /** USB FS configuration descriptors for the composite device driver */
00208 static const HidMsdDriverConfigurationDescriptors configurationDescriptorsHS =
00209 {
00210 
00211     /* Standard configuration descriptor */
00212     {
00213         sizeof(USBConfigurationDescriptor),
00214         USBGenericDescriptor_CONFIGURATION,
00215         sizeof(HidMsdDriverConfigurationDescriptors),
00216         HIDMSDDriverDescriptors_NUMINTERFACE,
00217         1, /* This is configuration #1 */
00218         0, /* No string descriptor for this configuration */
00219         USBD_BMATTRIBUTES,
00220         USBConfigurationDescriptor_POWER(100)
00221     },
00222 
00223     /* Interface descriptor */
00224     {
00225         sizeof(USBInterfaceDescriptor),
00226         USBGenericDescriptor_INTERFACE,
00227         HIDMSDDriverDescriptors_HID_INTERFACE,
00228         0, /* This is alternate setting #0 */
00229         2, /* Two endpoints used */
00230         HIDInterfaceDescriptor_CLASS,
00231         HIDInterfaceDescriptor_SUBCLASS_NONE,
00232         HIDInterfaceDescriptor_PROTOCOL_NONE,
00233         0  /* No associated string descriptor */
00234     },
00235     /* HID descriptor */
00236     {
00237         sizeof(HIDDescriptor1),
00238         HIDGenericDescriptor_HID,
00239         HIDDescriptor_HID1_11,
00240         0, /* Device is not localized, no country code */
00241         1, /* One HID-specific descriptor (apart from this one) */
00242         HIDGenericDescriptor_REPORT,
00243         {HIDDKeyboard_REPORTDESCRIPTORSIZE}
00244     },
00245     /* Interrupt IN endpoint descriptor */
00246     {
00247         sizeof(USBEndpointDescriptor),
00248         USBGenericDescriptor_ENDPOINT,
00249         USBEndpointDescriptor_ADDRESS(
00250             USBEndpointDescriptor_IN,
00251             HIDMSDD_Descriptors_INTERRUPTIN),
00252         USBEndpointDescriptor_INTERRUPT,
00253         sizeof(HIDDKeyboardInputReport),
00254         HIDDKeyboardDescriptors_INTERRUPTIN_POLLING_FS
00255     },
00256     /* Interrupt OUT endpoint descriptor */
00257     {
00258         sizeof(USBEndpointDescriptor),
00259         USBGenericDescriptor_ENDPOINT,
00260         USBEndpointDescriptor_ADDRESS(
00261             USBEndpointDescriptor_OUT,
00262             HIDMSDD_Descriptors_INTERRUPTOUT),
00263         USBEndpointDescriptor_INTERRUPT,
00264         sizeof(HIDDKeyboardOutputReport),
00265         HIDDKeyboardDescriptors_INTERRUPTIN_POLLING_FS
00266     },
00267 
00268     /* Mass Storage interface descriptor. */
00269     {
00270         sizeof(USBInterfaceDescriptor),
00271         USBGenericDescriptor_INTERFACE,
00272         HIDMSDDriverDescriptors_MSD_INTERFACE,
00273         0, /* This is alternate setting #0. */
00274         2, /* Interface uses two endpoints. */
00275         MSInterfaceDescriptor_CLASS,            
00276         MSInterfaceDescriptor_SCSI,                 
00277         MSInterfaceDescriptor_BULKONLY,            
00278         0 /* No string descriptor for interface. */
00279     },
00280     /* Bulk-OUT endpoint descriptor */
00281     {
00282         sizeof(USBEndpointDescriptor), 
00283         USBGenericDescriptor_ENDPOINT,
00284         USBEndpointDescriptor_ADDRESS(
00285             USBEndpointDescriptor_OUT,
00286             HIDMSDD_Descriptors_BULKOUT),
00287         USBEndpointDescriptor_BULK,
00288         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(HIDMSDD_Descriptors_BULKOUT),
00289             USBEndpointDescriptor_MAXBULKSIZE_HS),
00290         0 /* No string descriptor for endpoint. */
00291     },
00292     /* Bulk-IN endpoint descriptor */
00293     {
00294         sizeof(USBEndpointDescriptor),
00295         USBGenericDescriptor_ENDPOINT,
00296         USBEndpointDescriptor_ADDRESS(
00297             USBEndpointDescriptor_IN,
00298             HIDMSDD_Descriptors_BULKIN),
00299         USBEndpointDescriptor_BULK,
00300         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(HIDMSDD_Descriptors_BULKIN),
00301             USBEndpointDescriptor_MAXBULKSIZE_HS),
00302         0 /* No string descriptor for endpoint. */
00303     }
00304 
00305 };
00306 
00307 /** String descriptor with the supported languages. */
00308 static const unsigned char languageIdDescriptor[] = {
00309 
00310     USBStringDescriptor_LENGTH(1),
00311     USBGenericDescriptor_STRING,
00312     USBStringDescriptor_ENGLISH_US
00313 };
00314 
00315 /** Manufacturer name. */
00316 static const unsigned char manufacturerDescriptor[] = {
00317 
00318     USBStringDescriptor_LENGTH(5),
00319     USBGenericDescriptor_STRING,
00320     USBStringDescriptor_UNICODE('A'),
00321     USBStringDescriptor_UNICODE('t'),
00322     USBStringDescriptor_UNICODE('m'),
00323     USBStringDescriptor_UNICODE('e'),
00324     USBStringDescriptor_UNICODE('l')
00325 };
00326 
00327 /** Product name. */
00328 static const unsigned char productDescriptor[] = {
00329 
00330     USBStringDescriptor_LENGTH(14),
00331     USBGenericDescriptor_STRING,
00332     USBStringDescriptor_UNICODE('C'),
00333     USBStringDescriptor_UNICODE('o'),
00334     USBStringDescriptor_UNICODE('m'),
00335     USBStringDescriptor_UNICODE('p'),
00336     USBStringDescriptor_UNICODE('o'),
00337     USBStringDescriptor_UNICODE('s'),
00338     USBStringDescriptor_UNICODE('i'),
00339     USBStringDescriptor_UNICODE('t'),
00340     USBStringDescriptor_UNICODE('e'),
00341     USBStringDescriptor_UNICODE(' '),
00342     USBStringDescriptor_UNICODE('D'),
00343     USBStringDescriptor_UNICODE('e'),
00344     USBStringDescriptor_UNICODE('m'),
00345     USBStringDescriptor_UNICODE('o')
00346 };
00347 
00348 /** Product serial number. */
00349 static const unsigned char serialNumberDescriptor[] = {
00350 
00351     USBStringDescriptor_LENGTH(12),
00352     USBGenericDescriptor_STRING,
00353     USBStringDescriptor_UNICODE('0'),
00354     USBStringDescriptor_UNICODE('1'),
00355     USBStringDescriptor_UNICODE('2'),
00356     USBStringDescriptor_UNICODE('3'),
00357     USBStringDescriptor_UNICODE('4'),
00358     USBStringDescriptor_UNICODE('5'),
00359     USBStringDescriptor_UNICODE('6'),
00360     USBStringDescriptor_UNICODE('7'),
00361     USBStringDescriptor_UNICODE('8'),
00362     USBStringDescriptor_UNICODE('9'),
00363     USBStringDescriptor_UNICODE('A'),
00364     USBStringDescriptor_UNICODE('B')
00365 };
00366 
00367 /** Array of pointers to the four string descriptors. */
00368 static const unsigned char *stringDescriptors[] = {
00369 
00370     languageIdDescriptor,
00371     manufacturerDescriptor,
00372     productDescriptor,
00373     serialNumberDescriptor,
00374 };
00375 
00376 /*----------------------------------------------------------------------------
00377  *         Exported variables
00378  *----------------------------------------------------------------------------*/
00379 
00380 /** List of descriptors required by an USB audio speaker device driver. */
00381 const USBDDriverDescriptors hidmsddDriverDescriptors = {
00382 
00383     &deviceDescriptor,
00384     (const USBConfigurationDescriptor *) &configurationDescriptorsFS,
00385     &qualifierDescriptor,
00386     0, 0,
00387     (const USBConfigurationDescriptor *) &configurationDescriptorsHS,
00388     &qualifierDescriptor,
00389     0,
00390     stringDescriptors,
00391     4 /* Number of string descriptors */
00392 };
00393 /**@}*/
00394 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines