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

SAM3S8/SD8 Software Package 1.2

# device_descriptor.c

Go to the documentation of this file.

    00001 /* ----------------------------------------------------------------------------
    00002  *         ATMEL Microcontroller Software Support
    00003  * ----------------------------------------------------------------------------
    00004  * Copyright (c) 2010, 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 /** \file
    00031  * \addtogroup usbd_cdc_aud
    00032  *@{
    00033  */
    00034
    00035 /*------------------------------------------------------------------------------
    00036  *         Headers
    00037  *------------------------------------------------------------------------------*/
    00038 #include "board.h"
    00039
    00040 #include <include/USBD_Config.h>
    00041
    00042 #include <CDCAUDDDriver.h>
    00043 #include <CDCDSerial.h>
    00044 #include <AUDDFunction.h>
    00045
    00046 /*------------------------------------------------------------------------------
    00047  *         Definitions
    00048  *------------------------------------------------------------------------------*/
    00049
    00050 /** \addtogroup usbd_cdc_aud_dev_codes CDC(Serial) + Audio(Speaker) Device Codes
    00051  *      @{
    00052  * This page lists the %device IDs and release number of the USB composite
    00053  * %device.
    00054  *
    00055  * \section Codes
    00056  * - CDCAUDDDriverDescriptors_VENDORID
    00057  * - CDCAUDDDriverDescriptors_PRODUCTID
    00058  * - CDCAUDDDriverDescriptors_RELEASE
    00059  */
    00060
    00061 /** Device vendor ID. */
    00062 #define CDCAUDDDriverDescriptors_VENDORID            0x03EB
    00063 /** Device product ID. */
    00064 #define CDCAUDDDriverDescriptors_PRODUCTID           0x6131
    00065 /** Device release number in BCD format. */
    00066 #define CDCAUDDDriverDescriptors_RELEASE             0x0100
    00067 /**      @}*/
    00068
    00069 /** \addtogroup usbd_cdc_aud_eps CDC(Serial) + Audio(Speaker) Endpoints
    00070  *      @{
    00071  */
    00072 /** CDC(Serial) notification interrupt endpoint */
    00073 #define CDCD_Descriptors_NOTIFICATION0              3
    00074 /** CDC(Serial) data bulk in endpoint */
    00075 #define CDCD_Descriptors_DATAIN0                    2
    00076 /** CDC(Serial) data bulk out endpoint */
    00077 #define CDCD_Descriptors_DATAOUT0                   1
    00078 /** Audio(Speaker) stream ISO out endpoint */
    00079 #define AUDD_Descriptors_DATAOUT                    5
    00080 /**     @}*/
    00081
    00082 /*---------------------------------------------------------------------------
    00083  *         Macros
    00084  *---------------------------------------------------------------------------*/
    00085
    00086 /** Returns the minimum between two values. */
    00087 #define MIN(a, b)       ((a < b) ? a : b)
    00088
    00089 /*------------------------------------------------------------------------------
    00090  *         Exported variables
    00091  *------------------------------------------------------------------------------*/
    00092
    00093 /** Device descriptor for a USB Audio Speakerphone driver. */
    00094 const USBDeviceDescriptor deviceDescriptor = {
    00095
    00096     sizeof(USBDeviceDescriptor),
    00097     USBGenericDescriptor_DEVICE,
    00098     USBDeviceDescriptor_USB2_00,
    00099     0xEF,/* MI */
    00100     0x02,
    00101     0x01,
    00102     CHIP_USB_ENDPOINTS_MAXPACKETSIZE(0),
    00103     CDCAUDDDriverDescriptors_VENDORID,
    00104     CDCAUDDDriverDescriptors_PRODUCTID,
    00105     CDCAUDDDriverDescriptors_RELEASE,
    00106     1, /* Manufacturer string descriptor index */
    00107     2, /* Product string descriptor index */
    00108     3, /* Index of serial number string descriptor */
    00109     1  /* One possible configuration */
    00110 };
    00111
    00112 /** FS Configuration descriptors for a USB Audio Speakerphone driver. */
    00113 const CdcAudspkdDriverConfigurationDescriptors fsConfigurationDescriptors = {
    00114
    00115     /* Configuration descriptor */
    00116     {
    00117         sizeof(USBConfigurationDescriptor),
    00118         USBGenericDescriptor_CONFIGURATION,
    00119         sizeof(CdcAudspkdDriverConfigurationDescriptors),
    00120         4, /* This configuration has 5 interfaces */
    00121         1, /* This is configuration #1 */
    00122         0, /* No string descriptor */
    00123         BOARD_USB_BMATTRIBUTES,
    00124         USBConfigurationDescriptor_POWER(100)
    00125     },
    00126     /* CDC */
    00127     /* IAD for CDC/ACM port */
    00128     {
    00129         sizeof(USBInterfaceAssociationDescriptor),
    00130         USBGenericDescriptor_INTERFACEASSOCIATION,
    00131         CDCAUDDDriverDescriptors_CDC_INTERFACE,
    00132         2,
    00133         CDCCommunicationInterfaceDescriptor_CLASS,
    00134         CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
    00135         CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
    00136         0  /* No string descriptor for this interface*/
    00137     },
    00138     /* Communication class interface standard descriptor*/
    00139     {
    00140         sizeof(USBInterfaceDescriptor),
    00141         USBGenericDescriptor_INTERFACE,
    00142         CDCAUDDDriverDescriptors_CDC_INTERFACE, /* This is interface #0*/
    00143         0, /* This is alternate setting #0 for this interface*/
    00144         1, /* This interface uses 1 endpoint*/
    00145         CDCCommunicationInterfaceDescriptor_CLASS,
    00146         CDCCommunicationInterfaceDescriptor_ABSTRACTCONTROLMODEL,
    00147         CDCCommunicationInterfaceDescriptor_NOPROTOCOL,
    00148         0  /* No string descriptor for this interface*/
    00149     },
    00150     /* Class-specific header functional descriptor*/
    00151     {
    00152         sizeof(CDCHeaderDescriptor),
    00153         CDCGenericDescriptor_INTERFACE,
    00154         CDCGenericDescriptor_HEADER,
    00155         CDCGenericDescriptor_CDC1_10
    00156     },
    00157     /* Class-specific call management functional descriptor*/
    00158     {
    00159         sizeof(CDCCallManagementDescriptor),
    00160         CDCGenericDescriptor_INTERFACE,
    00161         CDCGenericDescriptor_CALLMANAGEMENT,
    00162         CDCCallManagementDescriptor_SELFCALLMANAGEMENT,
    00163         CDCAUDDDriverDescriptors_CDC_INTERFACE + 1 /* No associated data interface*/
    00164     },
    00165     /* Class-specific abstract control management functional descriptor*/
    00166     {
    00167         sizeof(CDCAbstractControlManagementDescriptor),
    00168         CDCGenericDescriptor_INTERFACE,
    00169         CDCGenericDescriptor_ABSTRACTCONTROLMANAGEMENT,
    00170         CDCAbstractControlManagementDescriptor_LINE
    00171     },
    00172     /* Class-specific union functional descriptor with one slave interface*/
    00173     {
    00174         sizeof(CDCUnionDescriptor),
    00175         CDCGenericDescriptor_INTERFACE,
    00176         CDCGenericDescriptor_UNION,
    00177         CDCAUDDDriverDescriptors_CDC_INTERFACE, /* Number of master interface is #0*/
    00178         CDCAUDDDriverDescriptors_CDC_INTERFACE + 1 /* First slave interface is #1*/
    00179     },
    00180     /* Notification endpoint standard descriptor*/
    00181     {
    00182         sizeof(USBEndpointDescriptor),
    00183         USBGenericDescriptor_ENDPOINT,
    00184         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
    00185                                       CDCD_Descriptors_NOTIFICATION0),
    00186         USBEndpointDescriptor_INTERRUPT,
    00187         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_NOTIFICATION0),
    00188             CDCDSerialPort_INTERRUPT_MAXPACKETSIZE),
    00189         CDCDSerialPort_INTERRUPT_INTERVAL_FS /* Endpoint is polled every 10ms*/
    00190     },
    00191     /* Data class interface standard descriptor*/
    00192     {
    00193         sizeof(USBInterfaceDescriptor),
    00194         USBGenericDescriptor_INTERFACE,
    00195         CDCAUDDDriverDescriptors_CDC_INTERFACE + 1, /* This is interface #1*/
    00196         0, /* This is alternate setting #0 for this interface*/
    00197         2, /* This interface uses 2 endpoints*/
    00198         CDCDataInterfaceDescriptor_CLASS,
    00199         CDCDataInterfaceDescriptor_SUBCLASS,
    00200         CDCDataInterfaceDescriptor_NOPROTOCOL,
    00201         0  /* No string descriptor for this interface*/
    00202     },
    00203     /* Bulk-OUT endpoint standard descriptor*/
    00204     {
    00205         sizeof(USBEndpointDescriptor),
    00206         USBGenericDescriptor_ENDPOINT,
    00207         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_OUT,
    00208                                       CDCD_Descriptors_DATAOUT0),
    00209         USBEndpointDescriptor_BULK,
    00210         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAOUT0),
    00211             USBEndpointDescriptor_MAXBULKSIZE_FS),
    00212         0 /* Must be 0 for full-speed bulk endpoints*/
    00213     },
    00214     /* Bulk-IN endpoint descriptor*/
    00215     {
    00216         sizeof(USBEndpointDescriptor),
    00217         USBGenericDescriptor_ENDPOINT,
    00218         USBEndpointDescriptor_ADDRESS(USBEndpointDescriptor_IN,
    00219                                       CDCD_Descriptors_DATAIN0),
    00220         USBEndpointDescriptor_BULK,
    00221         MIN(CHIP_USB_ENDPOINTS_MAXPACKETSIZE(CDCD_Descriptors_DATAIN0),
    00222             USBEndpointDescriptor_MAXBULKSIZE_FS),
    00223         0 /* Must be 0 for full-speed bulk endpoints*/
    00224     },
    00225
    00226     /* AUDIO */
    00227     /* IAD for AUDIO function */
    00228     {
    00229         sizeof(USBInterfaceAssociationDescriptor),
    00230         USBGenericDescriptor_INTERFACEASSOCIATION,
    00231         CDCAUDDDriverDescriptors_AUD_INTERFACE,
    00232         2, /* AS + Spk */
    00233         AUDControlInterfaceDescriptor_CLASS,
    00234         AUDControlInterfaceDescriptor_SUBCLASS,
    00235         AUDControlInterfaceDescriptor_PROTOCOL,
    00236         0  // No string descriptor for this interface
    00237     },
    00238     /* Audio control interface standard descriptor */
    00239     {
    00240         sizeof(USBInterfaceDescriptor),
    00241         USBGenericDescriptor_INTERFACE,
    00242         CDCAUDDDriverDescriptors_AUD_INTERFACE,
    00243         0, /* This is alternate setting #0 */
    00244         0, /* This interface uses no endpoint */
    00245         AUDControlInterfaceDescriptor_CLASS,
    00246         AUDControlInterfaceDescriptor_SUBCLASS,
    00247         AUDControlInterfaceDescriptor_PROTOCOL,
    00248         0 /* No string descriptor */
    00249     },
    00250     /* Audio control interface descriptors */
    00251     {
    00252         /* Header descriptor */
    00253         {
    00254             {
    00255                 sizeof(AUDHeaderDescriptor1),
    00256                 AUDGenericDescriptor_INTERFACE,
    00257                 AUDGenericDescriptor_HEADER,
    00258                 AUDHeaderDescriptor_AUD1_00,
    00259                 sizeof(AUDDSpeakerAcDescriptors),
    00260                 1 /* One streaming interface */
    00261             },
    00262             CDCAUDDDriverDescriptors_AUD_INTERFACE + 1,
    00263         },
    00264         /* Input terminal descriptor ( speaker ) */
    00265         {
    00266             sizeof(AUDInputTerminalDescriptor),
    00267             AUDGenericDescriptor_INTERFACE,
    00268             AUDGenericDescriptor_INPUTTERMINAL,
    00269             AUDDFunction_INPUTTERMINAL,
    00270             AUDInputTerminalDescriptor_USBSTREAMING,
    00271             AUDDFunction_OUTPUTTERMINAL,
    00272             AUDDevice_NUMCHANNELS, /* L,R */
    00273             AUDInputTerminalDescriptor_LEFTFRONT
    00274             | AUDInputTerminalDescriptor_RIGHTFRONT,
    00275             0, /* No string descriptor for channels */
    00276             0 /* No string descriptor for input terminal */
    00277         },
    00278         /* Output terminal descriptor ( speaker ) */
    00279         {
    00280             sizeof(AUDOutputTerminalDescriptor),
    00281             AUDGenericDescriptor_INTERFACE,
    00282             AUDGenericDescriptor_OUTPUTTERMINAL,
    00283             AUDDFunction_OUTPUTTERMINAL,
    00284             AUDOutputTerminalDescriptor_SPEAKER,
    00285             AUDDFunction_INPUTTERMINAL,
    00286             AUDDFunction_FEATUREUNIT,
    00287             0 /* No string descriptor */
    00288         },
    00289         /* Feature unit descriptor ( speaker ) */
    00290         {
    00291             {
    00292                 sizeof(AUDFeatureUnitDescriptor3),
    00293                 AUDGenericDescriptor_INTERFACE,
    00294                 AUDGenericDescriptor_FEATUREUNIT,
    00295                 AUDDFunction_FEATUREUNIT,
    00296                 AUDDFunction_INPUTTERMINAL,
    00297                 1, /* 1 byte per channel for controls */
    00298             },
    00299             {
    00300                 AUDFeatureUnitDescriptor_MUTE, /* Master channel controls */
    00301                 0, /* Right channel controls */
    00302                 0  /* Left channel controls */
    00303             },
    00304             0 /* No string descriptor */
    00305         }
    00306     },
    00307     /* - AUIDO OUT */
    00308     /* Audio streaming interface with 0 endpoints */
    00309     {
    00310         sizeof(USBInterfaceDescriptor),
    00311         USBGenericDescriptor_INTERFACE,
    00312         CDCAUDDDriverDescriptors_AUD_INTERFACE + 1,
    00313         0, /* This is alternate setting #0 */
    00314         0, /* This interface uses no endpoints */
    00315         AUDStreamingInterfaceDescriptor_CLASS,
    00316         AUDStreamingInterfaceDescriptor_SUBCLASS,
    00317         AUDStreamingInterfaceDescriptor_PROTOCOL,
    00318         0 /* No string descriptor */
    00319     },
    00320     /* Audio streaming interface with data endpoint */
    00321     {
    00322         sizeof(USBInterfaceDescriptor),
    00323         USBGenericDescriptor_INTERFACE,
    00324         CDCAUDDDriverDescriptors_AUD_INTERFACE + 1,
    00325         1, /* This is alternate setting #1 */
    00326         1, /* This interface uses 1 endpoint */
    00327         AUDStreamingInterfaceDescriptor_CLASS,
    00328         AUDStreamingInterfaceDescriptor_SUBCLASS,
    00329         AUDStreamingInterfaceDescriptor_PROTOCOL,
    00330         0 /* No string descriptor */
    00331     },
    00332     /* Audio streaming class-specific descriptor */
    00333     {
    00334         sizeof(AUDStreamingInterfaceDescriptor),
    00335         AUDGenericDescriptor_INTERFACE,
    00336         AUDStreamingInterfaceDescriptor_GENERAL,
    00337         AUDDFunction_INPUTTERMINAL,
    00338         0, /* No internal delay because of data path */
    00339         AUDFormatTypeOneDescriptor_PCM
    00340     },
    00341     /* Format type I descriptor */
    00342     {
    00343         {
    00344             sizeof(AUDFormatTypeOneDescriptor1),
    00345             AUDGenericDescriptor_INTERFACE,
    00346             AUDStreamingInterfaceDescriptor_FORMATTYPE,
    00347             AUDFormatTypeOneDescriptor_FORMATTYPEONE,
    00348             AUDDevice_NUMCHANNELS,
    00349             AUDDevice_BYTESPERSAMPLE,
    00350             AUDDevice_BYTESPERSAMPLE*8,
    00351             1 /* One discrete frequency supported */
    00352         },
    00353         {
    00354             AUDDevice_SAMPLERATE & 0xFF,
    00355             (AUDDevice_SAMPLERATE >> 8) & 0xFF,
    00356             (AUDDevice_SAMPLERATE >> 16) & 0xFF
    00357         }
    00358     },
    00359     /* Audio streaming endpoint standard descriptor */
    00360     {
    00361         sizeof(AUDEndpointDescriptor),
    00362         USBGenericDescriptor_ENDPOINT,
    00363         USBEndpointDescriptor_ADDRESS(
    00364             USBEndpointDescriptor_OUT, AUDD_Descriptors_DATAOUT),
    00365         USBEndpointDescriptor_ISOCHRONOUS,
    00366         AUDDevice_BYTESPERFRAME,
    00367         AUDDFunction_FS_INTERVAL, /* Polling interval = 1 ms */
    00368         0, /* This is not a synchronization endpoint */
    00369         0 /* No associated synchronization endpoint */
    00370     },
    00371     /* Audio streaming endpoint class-specific descriptor */
    00372     {
    00373         sizeof(AUDDataEndpointDescriptor),
    00374         AUDGenericDescriptor_ENDPOINT,
    00375         AUDDataEndpointDescriptor_SUBTYPE,
    00376         0, /* No attributes */
    00377         0, /* Endpoint is not synchronized */
    00378         0 /* Endpoint is not synchronized */
    00379     }
    00380 };
    00381
    00382 /** String descriptor with the supported languages. */
    00383 const unsigned char languageIdDescriptor[] = {
    00384
    00385     USBStringDescriptor_LENGTH(1),
    00386     USBGenericDescriptor_STRING,
    00387     USBStringDescriptor_ENGLISH_US
    00388 };
    00389
    00390 /** Manufacturer name. */
    00391 const unsigned char manufacturerDescriptor[] = {
    00392
    00393     USBStringDescriptor_LENGTH(5),
    00394     USBGenericDescriptor_STRING,
    00395     USBStringDescriptor_UNICODE('A'),
    00396     USBStringDescriptor_UNICODE('t'),
    00397     USBStringDescriptor_UNICODE('m'),
    00398     USBStringDescriptor_UNICODE('e'),
    00399     USBStringDescriptor_UNICODE('l')
    00400 };
    00401
    00402 /** Product name. */
    00403 const unsigned char productDescriptor[] = {
    00404
    00405     USBStringDescriptor_LENGTH(15),
    00406     USBGenericDescriptor_STRING,
    00407     USBStringDescriptor_UNICODE('C'),
    00408     USBStringDescriptor_UNICODE('D'),
    00409     USBStringDescriptor_UNICODE('C'),
    00410     USBStringDescriptor_UNICODE(' '),
    00411     USBStringDescriptor_UNICODE('C'),
    00412     USBStringDescriptor_UNICODE('O'),
    00413     USBStringDescriptor_UNICODE('M'),
    00414     USBStringDescriptor_UNICODE('&'),
    00415     USBStringDescriptor_UNICODE('S'),
    00416     USBStringDescriptor_UNICODE('p'),
    00417     USBStringDescriptor_UNICODE('e'),
    00418     USBStringDescriptor_UNICODE('a'),
    00419     USBStringDescriptor_UNICODE('k'),
    00420     USBStringDescriptor_UNICODE('e'),
    00421     USBStringDescriptor_UNICODE('r')
    00422 };
    00423
    00424 /** Product serial number. */
    00425 const unsigned char serialNumberDescriptor[] = {
    00426
    00427     USBStringDescriptor_LENGTH(4),
    00428     USBGenericDescriptor_STRING,
    00429     USBStringDescriptor_UNICODE('0'),
    00430     USBStringDescriptor_UNICODE('1'),
    00431     USBStringDescriptor_UNICODE('2'),
    00432     USBStringDescriptor_UNICODE('3')
    00433 };
    00434
    00435 /** Array of pointers to the four string descriptors. */
    00436 const unsigned char *stringDescriptors[] = {
    00437
    00438     languageIdDescriptor,
    00439     manufacturerDescriptor,
    00440     productDescriptor,
    00441     serialNumberDescriptor,
    00442 };
    00443
    00444 /*------------------------------------------------------------------------------
    00445  *         Exported functions
    00446  *------------------------------------------------------------------------------*/
    00447
    00448 /** List of descriptors required by an USB Audio Speakerphoneer device driver. */
    00449 const USBDDriverDescriptors cdcauddDriverDescriptors = {
    00450
    00451     &deviceDescriptor,
    00452     (const USBConfigurationDescriptor *) &fsConfigurationDescriptors,
    00453     0, 0, 0, 0, 0, 0,
    00454     stringDescriptors,
    00455     4 /* Number of string descriptors */
    00456 };
    00457
    00458 /**@}*/

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines