SAM3S8/SD8 Software Package: examples_usb/usb_iad_cdc_hid/device_descriptor.c Source File

SAM3S8/SD8 Software Package 1.2

# device_descriptor.c

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

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines