SAMV71 Xplained Ultra Software Package 1.4

USBDDriverDescriptors.c

00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2012, 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_cdchid
00031  *@{
00032  */
00033 
00034 /*----------------------------------------------------------------------------
00035  *      Headers
00036  *----------------------------------------------------------------------------*/
00037 
00038 #include <USBD_Config.h>
00039 
00040 /*- Composite */
00041 #include <CDCHIDDDriver.h>
00042 #include <CDCDSerial.h>
00043 #include <HIDDKeyboard.h>
00044 
00045 /*---------------------------------------------------------------------------
00046  *         Definitions
00047  *---------------------------------------------------------------------------*/
00048 
00049 
00050 /** Device product ID. */
00051 #define CDCHIDDDriverDescriptors_PRODUCTID       USBD_PID_CDCHID
00052 /** Device vendor ID (Atmel). */
00053 #define CDCHIDDDriverDescriptors_VENDORID        USBD_VID_ATMEL
00054 /** Device release number. */
00055 #define CDCHIDDDriverDescriptors_RELEASE         0x0003
00056 
00057 /*---------------------------------------------------------------------------
00058  *         Macros
00059  *---------------------------------------------------------------------------*/
00060 
00061 /** Returns the minimum between two values. */
00062 #define MIN(a, b)       ((a < b) ? a : b)
00063 
00064 /*----------------------------------------------------------------------------
00065  *         Exported variables
00066  *----------------------------------------------------------------------------*/
00067 
00068 /** Standard USB device descriptor for the composite device driver */
00069 static const USBDeviceDescriptor deviceDescriptor = {
00070 
00071     sizeof(USBDeviceDescriptor),
00072     USBGenericDescriptor_DEVICE,
00073     USBDeviceDescriptor_USB2_00,
00074     0xEF,/* MI */
00075     0x02,/* */
00076     0x01,/* */
00077     CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
00078     CDCHIDDDriverDescriptors_VENDORID,
00079     CDCHIDDDriverDescriptors_PRODUCTID,
00080     CDCHIDDDriverDescriptors_RELEASE,
00081     0, /* No string descriptor for manufacturer */
00082     1, /* Index of product string descriptor is #1 */
00083     0, /* No string descriptor for serial number */
00084     1 /* Device has 1 possible configuration */
00085 };
00086 
00087 
00088 /** Device qualifier descriptor (Necessary to pass USB test). */
00089 static const USBDeviceQualifierDescriptor qualifierDescriptor = {
00090 
00091     sizeof(USBDeviceQualifierDescriptor),
00092     USBGenericDescriptor_DEVICEQUALIFIER,
00093     USBDeviceDescriptor_USB2_00,
00094     0xEF,
00095     0x02,
00096     0x01,
00097     CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),    
00098     0, // Device has one possible configuration.
00099     0x00
00100 };
00101 
00102 
00103 /** USB configuration descriptors for the composite device driver */
00104 static const CdcHidDriverConfigurationDescriptors configurationDescriptorsFS =
00105 {
00106 
00107     /* Standard configuration descriptor */
00108     {
00109         sizeof(USBConfigurationDescriptor),
00110         USBGenericDescriptor_CONFIGURATION,
00111         sizeof(CdcHidDriverConfigurationDescriptors),
00112         CDCHIDDDriverDescriptors_NUMINTERFACE,
00113         1, /* This is configuration #1 */
00114         0, /* No string descriptor for this configuration */
00115         USBD_BMATTRIBUTES,
00116         USBConfigurationDescriptor_POWER(100)
00117     },
00118 
00119     /* CDC 0 */
00120     /* IAD for CDC/ACM port */
00121     {
00122         sizeof(USBInterfaceAssociationDescriptor),
00123         USBGenericDescriptor_INTERFACEASSOCIATION,
00124         CDCHIDDDriverDescriptors_CDC_INTERFACE,
00125         2,
00126         CDCCommunicationInterfaceDescriptor_CLASS,
00127         CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
00128         CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
00129         0  /* No string descriptor for this interface */
00130     },
00131     /* Communication class interface standard descriptor */
00132     {
00133         sizeof(USBInterfaceDescriptor),
00134         USBGenericDescriptor_INTERFACE,
00135         CDCHIDDDriverDescriptors_CDC_INTERFACE, /* This is interface #0 */
00136         0, /* This is alternate setting #0 for this interface */
00137         1, /* This interface uses 1 endpoint */
00138         CDCCommunicationInterfaceDescriptor_CLASS,
00139         CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
00140         CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
00141         0  /* No string descriptor for this interface */
00142     },
00143     /* Class-specific header functional descriptor */
00144     {
00145         sizeof(CDCHeaderDescriptor),
00146         CDCGenericDescriptor_INTERFACE,
00147         CDCGenericDescriptor_HEADER,
00148         CDCGenericDescriptor_CDC1_10
00149     },
00150     /* Class-specific call management functional descriptor */
00151     {
00152         sizeof(CDCCallManagementDescriptor),
00153         CDCGenericDescriptor_INTERFACE,
00154         CDCGenericDescriptor_CALLMANAGEMENT,
00155         CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
00156         CDCHIDDDriverDescriptors_CDC_INTERFACE + 1 /* No associated data interface */
00157     },
00158     /* Class-specific abstract control management functional descriptor */
00159     {
00160         sizeof(CDCAbstractControlManagementDescriptor),
00161         CDCGenericDescriptor_INTERFACE,
00162         CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
00163         CDCAbstractControlManagementDescriptor_LINE
00164     },
00165     /* Class-specific union functional descriptor with one slave interface */
00166     {
00167         sizeof(CDCUnionDescriptor),
00168         CDCGenericDescriptor_INTERFACE,
00169         CDCGenericDescriptor_UNION,
00170         CDCHIDDDriverDescriptors_CDC_INTERFACE, /* Number of master interface is #0 */
00171         CDCHIDDDriverDescriptors_CDC_INTERFACE + 1 /* First slave interface is #1 */
00172     },
00173     /* Notification endpoint standard descriptor */
00174     {
00175         sizeof(USBEndpointDescriptor), 
00176         USBGenericDescriptor_ENDPOINT,
00177         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
00178                                       CDCD_Descriptors_NOTIFICATION0),
00179         USBEndpointDescriptor_INTERRUPT,
00180         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_NOTIFICATION0),
00181             USBEndpointDescriptor_MAXINTERRUPTSIZE_FS),
00182         CDCDSerialPort_INTERRUPT_INTERVAL_FS
00183     },
00184     /* Data class interface standard descriptor */
00185     {
00186         sizeof(USBInterfaceDescriptor),
00187         USBGenericDescriptor_INTERFACE,
00188         CDCHIDDDriverDescriptors_CDC_INTERFACE + 1, /* This is interface #1 */
00189         0, /* This is alternate setting #0 for this interface */
00190         2, /* This interface uses 2 endpoints */
00191         CDCDataInterfaceDescriptor_CLASS,
00192         CDCDataInterfaceDescriptor_SUBCLASS,
00193         CDCDataInterfaceDescriptor_NOPROTOCOL,
00194         0  /* No string descriptor for this interface */
00195     },
00196     /* Bulk-OUT endpoint standard descriptor */
00197     {
00198         sizeof(USBEndpointDescriptor), 
00199         USBGenericDescriptor_ENDPOINT,
00200         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
00201                                       CDCD_Descriptors_DATAOUT0),
00202         USBEndpointDescriptor_BULK,
00203         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAOUT0),
00204             USBEndpointDescriptor_MAXBULKSIZE_FS),
00205         0 /* Must be 0 for full-speed bulk endpoints */
00206     },
00207     /* Bulk-IN endpoint descriptor */
00208     {
00209         sizeof(USBEndpointDescriptor),
00210         USBGenericDescriptor_ENDPOINT,
00211         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
00212                                       CDCD_Descriptors_DATAIN0),
00213         USBEndpointDescriptor_BULK,
00214         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAIN0),
00215             USBEndpointDescriptor_MAXBULKSIZE_FS),
00216         0 /* Must be 0 for full-speed bulk endpoints */
00217     },
00218 
00219     /* HID */
00220     /* Interface descriptor */
00221     {
00222         sizeof(USBInterfaceDescriptor),
00223         USBGenericDescriptor_INTERFACE,
00224         CDCHIDDDriverDescriptors_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         {
00243          HIDDKeyboard_REPORTDESCRIPTORSIZE & 0xFF,
00244         (HIDDKeyboard_REPORTDESCRIPTORSIZE >> 8) & 0xFF
00245         }*/
00246     },
00247     /* Interrupt IN endpoint descriptor */
00248     {
00249         sizeof(USBEndpointDescriptor),
00250         USBGenericDescriptor_ENDPOINT,
00251         USBEndpointDescriptor_ADDRESS(
00252             USBEndpointDescriptor_IN,
00253             HIDD_Descriptors_INTERRUPTIN),
00254         USBEndpointDescriptor_INTERRUPT,
00255         sizeof(HIDDKeyboardInputReport),
00256         HIDDKeyboardDescriptors_INTERRUPTIN_POLLING_FS
00257     },
00258     /* Interrupt OUT endpoint descriptor */
00259     {
00260         sizeof(USBEndpointDescriptor),
00261         USBGenericDescriptor_ENDPOINT,
00262         USBEndpointDescriptor_ADDRESS(
00263             USBEndpointDescriptor_OUT,
00264             HIDD_Descriptors_INTERRUPTOUT),
00265         USBEndpointDescriptor_INTERRUPT,
00266         sizeof(HIDDKeyboardOutputReport),
00267         HIDDKeyboardDescriptors_INTERRUPTOUT_POLLING_FS
00268     }
00269 };
00270 
00271 /** String descriptor with the supported languages. */
00272 static const unsigned char languageIdDescriptor[] = {
00273 
00274     USBStringDescriptor_LENGTH(1),
00275     USBGenericDescriptor_STRING,
00276     USBStringDescriptor_ENGLISH_US
00277 };
00278 
00279 /** Manufacturer name. */
00280 static const unsigned char manufacturerDescriptor[] = {
00281 
00282     USBStringDescriptor_LENGTH(5),
00283     USBGenericDescriptor_STRING,
00284     USBStringDescriptor_UNICODE('A'),
00285     USBStringDescriptor_UNICODE('t'),
00286     USBStringDescriptor_UNICODE('m'),
00287     USBStringDescriptor_UNICODE('e'),
00288     USBStringDescriptor_UNICODE('l')
00289 };
00290 
00291 /** Product name. */
00292 static const unsigned char productDescriptor[] = {
00293 
00294     USBStringDescriptor_LENGTH(14),
00295     USBGenericDescriptor_STRING,
00296     USBStringDescriptor_UNICODE('C'),
00297     USBStringDescriptor_UNICODE('o'),
00298     USBStringDescriptor_UNICODE('m'),
00299     USBStringDescriptor_UNICODE('p'),
00300     USBStringDescriptor_UNICODE('o'),
00301     USBStringDescriptor_UNICODE('s'),
00302     USBStringDescriptor_UNICODE('i'),
00303     USBStringDescriptor_UNICODE('t'),
00304     USBStringDescriptor_UNICODE('e'),
00305     USBStringDescriptor_UNICODE(' '),
00306     USBStringDescriptor_UNICODE('D'),
00307     USBStringDescriptor_UNICODE('e'),
00308     USBStringDescriptor_UNICODE('m'),
00309     USBStringDescriptor_UNICODE('o')
00310 };
00311 
00312 /** Product serial number. */
00313 static const unsigned char serialNumberDescriptor[] = {
00314 
00315     USBStringDescriptor_LENGTH(4),
00316     USBGenericDescriptor_STRING,
00317     USBStringDescriptor_UNICODE('0'),
00318     USBStringDescriptor_UNICODE('1'),
00319     USBStringDescriptor_UNICODE('2'),
00320     USBStringDescriptor_UNICODE('3')
00321 };
00322 
00323 /** Array of pointers to the four string descriptors. */
00324 static const unsigned char *stringDescriptors[] = {
00325 
00326     languageIdDescriptor,
00327     manufacturerDescriptor,
00328     productDescriptor,
00329     serialNumberDescriptor,
00330 };
00331 
00332 /*----------------------------------------------------------------------------
00333  *         Exported variables
00334  *----------------------------------------------------------------------------*/
00335 
00336 /** List of descriptors required by an USB audio speaker device driver. */
00337 const USBDDriverDescriptors cdchiddDriverDescriptors = {
00338 
00339     &deviceDescriptor,
00340     (const USBConfigurationDescriptor *) &configurationDescriptorsFS,
00341     &qualifierDescriptor,
00342     0, 0, 0,
00343     &qualifierDescriptor, 0,
00344     stringDescriptors,
00345     4 /* Number of string descriptors */
00346 };
00347 /**@}*/
00348 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines