SAMV71 Xplained Ultra Software Package 1.5

USBDDriverDescriptors.c

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