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 /** 00031 * \file 00032 * 00033 * \section Purpose 00034 * 00035 * Definitions and methods for USB composite device implement. 00036 * 00037 */ 00038 00039 #ifndef HIDAUDDDRIVER_H 00040 #define HIDAUDDDRIVER_H 00041 /** \addtogroup usbd_composite_hidaud 00042 *@{ 00043 */ 00044 00045 /*--------------------------------------------------------------------------- 00046 * Headers 00047 *---------------------------------------------------------------------------*/ 00048 00049 #include <USBRequests.h> 00050 #include <HIDDescriptors.h> 00051 #include <AUDDescriptors.h> 00052 #include "USBD.h" 00053 #include <USBDDriver.h> 00054 00055 /*--------------------------------------------------------------------------- 00056 * Definitions 00057 *---------------------------------------------------------------------------*/ 00058 00059 /** \addtogroup usbd_hid_aud_desc USB HID(Keyboard) + AUD(Speaker) Definitions 00060 * @{ 00061 */ 00062 /** Number of interfaces of the device 1+2 */ 00063 #define HIDAUDDDriverDescriptors_NUMINTERFACE 3 00064 /** Number of the CDC interface. */ 00065 #define HIDAUDDDriverDescriptors_HID_INTERFACE 0 00066 /** Number of the Audio interface. */ 00067 #define HIDAUDDDriverDescriptors_AUD_INTERFACE 1 00068 /** @}*/ 00069 00070 /*--------------------------------------------------------------------------- 00071 * Types 00072 *---------------------------------------------------------------------------*/ 00073 #pragma pack(1) 00074 #if defined ( __CC_ARM ) /* Keil ¦̀Vision 4 */ 00075 #elif defined ( __ICCARM__ ) /* IAR Ewarm */ 00076 #define __attribute__(...) 00077 #define __packed__ packed 00078 #elif defined ( __GNUC__ ) /* GCC CS3 */ 00079 #define __packed__ aligned(1) 00080 #endif 00081 /** Structure of audio header descriptor*/ 00082 typedef struct _AUDHeaderDescriptor1{ 00083 00084 /** Header descriptor.*/ 00085 AUDHeaderDescriptor header; 00086 /** Id of the first grouped interface.*/ 00087 unsigned char bInterface0; 00088 00089 } __attribute__ ((__packed__)) AUDHeaderDescriptor1; 00090 00091 /** 00092 * Feature unit descriptor with 3 channel controls (master, right, left). 00093 */ 00094 typedef struct _AUDFeatureUnitDescriptor3{ 00095 00096 /** Feature unit descriptor.*/ 00097 AUDFeatureUnitDescriptor feature; 00098 /** Available controls for each channel.*/ 00099 unsigned char bmaControls[3]; 00100 /** Index of a string descriptor for the feature unit.*/ 00101 unsigned char iFeature; 00102 00103 } __attribute__ ((__packed__)) AUDFeatureUnitDescriptor3; 00104 00105 /** 00106 * List of descriptors for detailing the audio control interface of a 00107 * device using a USB audio speaker driver. 00108 */ 00109 typedef struct _AUDDSpeakerDriverAudioControlDescriptors{ 00110 00111 /** Header descriptor (with one slave interface).*/ 00112 AUDHeaderDescriptor1 header; 00113 /** Input terminal descriptor.*/ 00114 AUDInputTerminalDescriptor input; 00115 /** Output terminal descriptor.*/ 00116 AUDOutputTerminalDescriptor output; 00117 /** Feature unit descriptor.*/ 00118 AUDFeatureUnitDescriptor3 feature; 00119 00120 } __attribute__ ((__packed__)) AUDDSpeakerDriverAudioControlDescriptors; // GCC 00121 00122 /** 00123 * Format type I descriptor with one discrete sampling frequency. 00124 */ 00125 typedef struct _AUDFormatTypeOneDescriptor1{ 00126 00127 /** Format type I descriptor.*/ 00128 AUDFormatTypeOneDescriptor formatType; 00129 /** Sampling frequency in Hz.*/ 00130 unsigned char tSamFreq[3]; 00131 00132 } __attribute__ ((__packed__)) AUDFormatTypeOneDescriptor1; // GCC 00133 00134 /** 00135 * \typedef CdcAudDriverConfigurationDescriptors 00136 * \brief Configuration descriptor list for a device implementing a 00137 * composite HID (Keyboard) + Audio (Speaker) driver. 00138 */ 00139 typedef struct _HidAuddDriverConfigurationDescriptors { 00140 00141 /** Standard configuration descriptor. */ 00142 USBConfigurationDescriptor configuration; 00143 00144 /* --- HID */ 00145 /** HID interface. */ 00146 USBInterfaceDescriptor hidInterface; 00147 /** HID descriptor */ 00148 HIDDescriptor1 hid; 00149 /** HID interrupt IN */ 00150 USBEndpointDescriptor hidInterruptIn; 00151 /** HID interrupt OUT */ 00152 USBEndpointDescriptor hidInterruptOut; 00153 00154 /* --- AUDIO (AC) */ 00155 /** Audio IAD */ 00156 USBInterfaceAssociationDescriptor audIAD; 00157 /** Audio control interface.*/ 00158 USBInterfaceDescriptor audInterface; 00159 /** Descriptors for the audio control interface.*/ 00160 AUDDSpeakerDriverAudioControlDescriptors audControl; 00161 /* -- AUDIO out (AS) */ 00162 /** Streaming out interface descriptor (with no endpoint, required).*/ 00163 USBInterfaceDescriptor audStreamingOutNoIsochronous; 00164 /** Streaming out interface descriptor.*/ 00165 USBInterfaceDescriptor audStreamingOut; 00166 /** Audio class descriptor for the streaming out interface.*/ 00167 AUDStreamingInterfaceDescriptor audStreamingOutClass; 00168 /** Stream format descriptor.*/ 00169 AUDFormatTypeOneDescriptor1 audStreamingOutFormatType; 00170 /** Streaming out endpoint descriptor.*/ 00171 AUDEndpointDescriptor audStreamingOutEndpoint; 00172 /** Audio class descriptor for the streaming out endpoint.*/ 00173 AUDDataEndpointDescriptor audStreamingOutDataEndpoint; 00174 00175 } __attribute__ ((__packed__)) HidAuddDriverConfigurationDescriptors; 00176 00177 #pragma pack() 00178 00179 /*--------------------------------------------------------------------------- 00180 * Exported functions 00181 *---------------------------------------------------------------------------*/ 00182 00183 extern void HIDAUDDDriver_Initialize(const USBDDriverDescriptors * pDescriptors); 00184 extern void HIDAUDDDriver_ConfigurationChangedHandler(uint8_t cfgnum); 00185 extern void HIDAUDDDriver_InterfaceSettingChangedHandler( 00186 uint8_t interface, uint8_t setting); 00187 extern void HIDAUDDDriver_RequestHandler(const USBGenericRequest *request); 00188 00189 /**@}*/ 00190 #endif //#ifndef CDCHIDDDRIVER_H 00191