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 * \file 00031 * 00032 * \section Purpose 00033 * 00034 * Definitions and methods for USB composite device implement. 00035 * 00036 */ 00037 00038 #ifndef CDCAUDDDRIVER_H 00039 #define CDCAUDDDRIVER_H 00040 /** \addtogroup usbd_composite_cdcaud 00041 *@{ 00042 */ 00043 00044 /*--------------------------------------------------------------------------- 00045 * Headers 00046 *---------------------------------------------------------------------------*/ 00047 00048 #include <USBRequests.h> 00049 #include <CDCDescriptors.h> 00050 #include <AUDDescriptors.h> 00051 #include "USBD.h" 00052 #include <USBDDriver.h> 00053 00054 /*--------------------------------------------------------------------------- 00055 * Definitions 00056 *---------------------------------------------------------------------------*/ 00057 00058 /** \addtogroup usbd_cdc_aud_desc USB CDC(Serial) + AUD(Speaker) Definitions 00059 * @{ 00060 */ 00061 /** Number of interfaces of the device (5, can be 4 if no mic support */ 00062 #define CDCAUDDDriverDescriptors_MaxNumInterfaces 5 00063 /** Number of the CDC interface. */ 00064 #define CDCAUDDDriverDescriptors_CDC_INTERFACE 0 00065 /** Number of the Audio interface. */ 00066 #define CDCAUDDDriverDescriptors_AUD_INTERFACE 2 00067 /** Number of Audio function channels (M,L,R) */ 00068 #define AUDD_NumChannels 3 00069 /** @}*/ 00070 00071 /*--------------------------------------------------------------------------- 00072 * Types 00073 *---------------------------------------------------------------------------*/ 00074 #pragma pack(1) 00075 #if defined ( __CC_ARM ) /* Keil ¦̀Vision 4 */ 00076 #elif defined ( __ICCARM__ ) /* IAR Ewarm */ 00077 #define __attribute__(...) 00078 #define __packed__ packed 00079 #elif defined ( __GNUC__ ) /* GCC CS3 */ 00080 #define __packed__ aligned(1) 00081 #endif 00082 00083 /** Audio header descriptor with 1 interface */ 00084 typedef struct _AUDHeaderDescriptor1{ 00085 00086 /** Header descriptor.*/ 00087 AUDHeaderDescriptor header; 00088 /** Id of the first grouped interface.*/ 00089 uint8_t bInterface0; 00090 00091 } __attribute__ ((__packed__)) AUDHeaderDescriptor1; 00092 00093 /** Audio header descriptor with 2 interface */ 00094 typedef struct _AUDHeaderDescriptor2 { 00095 00096 /** Header descriptor. */ 00097 AUDHeaderDescriptor header; 00098 /** Id of the first grouped interface - Speaker. */ 00099 uint8_t bInterface0; 00100 /** Id of the second grouped interface - Speakerphone. */ 00101 uint8_t bInterface1; 00102 00103 } __attribute__ ((__packed__)) AUDHeaderDescriptor2; /* GCC */ 00104 00105 /** 00106 * Feature unit descriptor with 3 channel controls (master, right, left). 00107 */ 00108 typedef struct _AUDFeatureUnitDescriptor3{ 00109 00110 /** Feature unit descriptor.*/ 00111 AUDFeatureUnitDescriptor feature; 00112 /** Available controls for each channel.*/ 00113 uint8_t bmaControls[AUDD_NumChannels]; 00114 /** Index of a string descriptor for the feature unit.*/ 00115 uint8_t iFeature; 00116 00117 } __attribute__ ((__packed__)) AUDFeatureUnitDescriptor3; 00118 00119 /** 00120 * List of descriptors for detailing the audio control interface of a 00121 * device using a USB audio speaker function. 00122 */ 00123 typedef struct _AUDDSpeakerAcDescriptors{ 00124 00125 /** Header descriptor (with one slave interface).*/ 00126 AUDHeaderDescriptor1 header; 00127 /** Input terminal descriptor.*/ 00128 AUDInputTerminalDescriptor input; 00129 /** Output terminal descriptor.*/ 00130 AUDOutputTerminalDescriptor output; 00131 /** Feature unit descriptor.*/ 00132 AUDFeatureUnitDescriptor3 feature; 00133 00134 } __attribute__ ((__packed__)) AUDDSpeakerAcDescriptors; 00135 00136 /** 00137 * List of descriptors for detailing the audio control interface of a 00138 * device using a USB Audio Speakerphoneer function. 00139 */ 00140 typedef struct _AUDDSpeakerPhoneAcDescriptors { 00141 00142 /** Header descriptor (with one slave interface). */ 00143 AUDHeaderDescriptor2 header; 00144 /** Input terminal descriptor. */ 00145 AUDInputTerminalDescriptor inputSpeakerPhone; 00146 /** Output terminal descriptor. */ 00147 AUDOutputTerminalDescriptor outputSpeakerPhone; 00148 /** Feature unit descriptor - SpeakerPhone. */ 00149 AUDFeatureUnitDescriptor3 featureSpeakerPhone; 00150 /** Input terminal descriptor. */ 00151 AUDInputTerminalDescriptor inputRec; 00152 /** Output terminal descriptor. */ 00153 AUDOutputTerminalDescriptor outputRec; 00154 /** Feature unit descriptor - SpeakerPhonephone. */ 00155 AUDFeatureUnitDescriptor3 featureRec; 00156 00157 } __attribute__ ((__packed__)) AUDDSpeakerPhoneAcDescriptors; 00158 00159 /** 00160 * Format type I descriptor with one discrete sampling frequency. 00161 */ 00162 typedef struct _AUDFormatTypeOneDescriptor1{ 00163 00164 /** Format type I descriptor.*/ 00165 AUDFormatTypeOneDescriptor formatType; 00166 /** Sampling frequency in Hz.*/ 00167 uint8_t tSamFreq[3]; 00168 00169 } __attribute__ ((__packed__)) AUDFormatTypeOneDescriptor1; 00170 00171 /** 00172 * Configuration descriptor list for a device implementing 00173 * CDC(Serial) + Audio(Speaker) composite driver. 00174 */ 00175 typedef struct _CdcAudspkdDriverConfigurationDescriptors { 00176 00177 /** Standard configuration descriptor. */ 00178 USBConfigurationDescriptor configuration; 00179 00180 /* --- CDC 0 */ 00181 /** IAD 0 */ 00182 USBInterfaceAssociationDescriptor cdcIAD0; 00183 /** Communication interface descriptor */ 00184 USBInterfaceDescriptor cdcCommunication0; 00185 /** CDC header functional descriptor. */ 00186 CDCHeaderDescriptor cdcHeader0; 00187 /** CDC call management functional descriptor. */ 00188 CDCCallManagementDescriptor cdcCallManagement0; 00189 /** CDC abstract control management functional descriptor. */ 00190 CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0; 00191 /** CDC union functional descriptor (with one slave interface). */ 00192 CDCUnionDescriptor cdcUnion0; 00193 /** Notification endpoint descriptor. */ 00194 USBEndpointDescriptor cdcNotification0; 00195 /** Data interface descriptor. */ 00196 USBInterfaceDescriptor cdcData0; 00197 /** Data OUT endpoint descriptor. */ 00198 USBEndpointDescriptor cdcDataOut0; 00199 /** Data IN endpoint descriptor. */ 00200 USBEndpointDescriptor cdcDataIn0; 00201 00202 /* --- AUDIO (AC) */ 00203 /** IAD 1*/ 00204 USBInterfaceAssociationDescriptor audIAD; 00205 /** Audio control interface.*/ 00206 USBInterfaceDescriptor audInterface; 00207 /** Descriptors for the audio control interface.*/ 00208 AUDDSpeakerAcDescriptors audControl; 00209 /* -- AUDIO out (AS) */ 00210 /** Streaming out interface descriptor (with no endpoint, required).*/ 00211 USBInterfaceDescriptor audStreamingOutNoIsochronous; 00212 /** Streaming out interface descriptor.*/ 00213 USBInterfaceDescriptor audStreamingOut; 00214 /** Audio class descriptor for the streaming out interface.*/ 00215 AUDStreamingInterfaceDescriptor audStreamingOutClass; 00216 /** Stream format descriptor.*/ 00217 AUDFormatTypeOneDescriptor1 audStreamingOutFormatType; 00218 /** Streaming out endpoint descriptor.*/ 00219 AUDEndpointDescriptor audStreamingOutEndpoint; 00220 /** Audio class descriptor for the streaming out endpoint.*/ 00221 AUDDataEndpointDescriptor audStreamingOutDataEndpoint; 00222 00223 } __attribute__ ((__packed__)) CdcAudspkdDriverConfigurationDescriptors; 00224 00225 /** 00226 * Configuration descriptor list for a device implementing 00227 * CDC(Serial) + Audio(SpeakerPhone) composite driver. 00228 */ 00229 typedef struct _CdcAuddDriverConfigurationDescriptors { 00230 00231 /** Standard configuration descriptor. */ 00232 USBConfigurationDescriptor configuration; 00233 00234 /* --- CDC 0 */ 00235 /** IAD 0 */ 00236 USBInterfaceAssociationDescriptor cdcIAD0; 00237 /** Communication interface descriptor */ 00238 USBInterfaceDescriptor cdcCommunication0; 00239 /** CDC header functional descriptor. */ 00240 CDCHeaderDescriptor cdcHeader0; 00241 /** CDC call management functional descriptor. */ 00242 CDCCallManagementDescriptor cdcCallManagement0; 00243 /** CDC abstract control management functional descriptor. */ 00244 CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0; 00245 /** CDC union functional descriptor (with one slave interface). */ 00246 CDCUnionDescriptor cdcUnion0; 00247 /** Notification endpoint descriptor. */ 00248 USBEndpointDescriptor cdcNotification0; 00249 /** Data interface descriptor. */ 00250 USBInterfaceDescriptor cdcData0; 00251 /** Data OUT endpoint descriptor. */ 00252 USBEndpointDescriptor cdcDataOut0; 00253 /** Data IN endpoint descriptor. */ 00254 USBEndpointDescriptor cdcDataIn0; 00255 00256 /* --- AUDIO (AC) */ 00257 /** IAD 1*/ 00258 USBInterfaceAssociationDescriptor audIAD; 00259 /** Audio control interface.*/ 00260 USBInterfaceDescriptor audInterface; 00261 /** Descriptors for the audio control interface.*/ 00262 AUDDSpeakerPhoneAcDescriptors audControl; 00263 /* -- AUDIO out (AS) */ 00264 /** Streaming out interface descriptor (with no endpoint, required).*/ 00265 USBInterfaceDescriptor audStreamingOutNoIsochronous; 00266 /** Streaming out interface descriptor.*/ 00267 USBInterfaceDescriptor audStreamingOut; 00268 /** Audio class descriptor for the streaming out interface.*/ 00269 AUDStreamingInterfaceDescriptor audStreamingOutClass; 00270 /** Stream format descriptor.*/ 00271 AUDFormatTypeOneDescriptor1 audStreamingOutFormatType; 00272 /** Streaming out endpoint descriptor.*/ 00273 AUDEndpointDescriptor audStreamingOutEndpoint; 00274 /** Audio class descriptor for the streaming out endpoint.*/ 00275 AUDDataEndpointDescriptor audStreamingOutDataEndpoint; 00276 /*- AUDIO IN */ 00277 /** Streaming in interface descriptor (with no endpoint, required). */ 00278 USBInterfaceDescriptor streamingInNoIsochronous; 00279 /** Streaming in interface descriptor. */ 00280 USBInterfaceDescriptor streamingIn; 00281 /** Audio class descriptor for the streaming in interface. */ 00282 AUDStreamingInterfaceDescriptor streamingInClass; 00283 /** Stream format descriptor. */ 00284 AUDFormatTypeOneDescriptor1 streamingInFormatType; 00285 /** Streaming in endpoint descriptor. */ 00286 AUDEndpointDescriptor streamingInEndpoint; 00287 /** Audio class descriptor for the streaming in endpoint. */ 00288 AUDDataEndpointDescriptor streamingInDataEndpoint; 00289 00290 } __attribute__ ((__packed__)) CdcAuddDriverConfigurationDescriptors; 00291 00292 #pragma pack() 00293 00294 /*--------------------------------------------------------------------------- 00295 * Exported functions 00296 *---------------------------------------------------------------------------*/ 00297 00298 extern void CDCAUDDDriver_Initialize(const USBDDriverDescriptors * pDescriptors); 00299 extern void CDCAUDDDriver_ConfigurationChangedHandler(uint8_t cfgnum); 00300 extern void CDCAUDDDriver_InterfaceSettingChangedHandler( 00301 uint8_t interface, uint8_t setting); 00302 extern void CDCAUDDDriver_RequestHandler(const USBGenericRequest *request); 00303 00304 /**@}*/ 00305 #endif //#ifndef CDCHIDDDRIVER_H 00306