SAMV71 Xplained Ultra Software Package 1.4

AUDDSpeakerDriver.h

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *         SAM Software Package License 
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2014, 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 /**
00031  * \file
00032  *
00033  * \section Purpose
00034  *
00035  *   Definition of a USB Audio Speaker Driver with two playback channels.
00036  *
00037  * \section Usage
00038  *
00039  *   -# Enable and setup USB related pins (see pio & board.h).
00040  *   -# Configure the USB Audio Speaker driver using AUDDSpeakerDriver_Initialize
00041  *   -# To get %audio stream frames from host, use AUDDSpeakerDriver_Read
00042  */
00043 
00044 #ifndef AUDDSPEAKERDRIVER_H
00045 #define AUDDSPEAKERDRIVER_H
00046 
00047 /** \addtogroup usbd_audio_speaker
00048  *@{
00049  */
00050 
00051 /*----------------------------------------------------------------------------
00052  *         Headers
00053  *----------------------------------------------------------------------------*/
00054 
00055 #include <USBLib_Types.h>
00056 
00057 #include <USBRequests.h>
00058 #include <USBDescriptors.h>
00059 #include <AUDDescriptors.h>
00060 
00061 #include "USBD.h"
00062 #include <USBDDriver.h>
00063 
00064 #include <AUDDSpeakerPhone.h>
00065 
00066 /*----------------------------------------------------------------------------
00067  *         Definitions
00068  *----------------------------------------------------------------------------*/
00069 
00070 /** \addtogroup usbd_audio_ch USB Device Audio Speaker Channel Numbers
00071  *      @{
00072  * This page lists codes for USB Audio Speaker channel numbers.
00073  *
00074  * \par Playback channel numbers
00075  * - \ref AUDDSpeakerDriver_MASTERCHANNEL
00076  * - \ref AUDDSpeakerDriver_LEFTCHANNEL
00077  * - \ref AUDDSpeakerDriver_RIGHTCHANNEL
00078  *
00079  * \par Record channel number
00080  * - \ref AUDDSpeakerDriver_RECCHANNEL
00081  */
00082 /** Master channel of playback. */
00083 #define AUDDSpeakerDriver_MASTERCHANNEL     0
00084 /** Front left channel of playback. */
00085 #define AUDDSpeakerDriver_LEFTCHANNEL       1
00086 /** Front right channel of playback. */
00087 #define AUDDSpeakerDriver_RIGHTCHANNEL      2
00088 
00089 /** Channel of record. */
00090 #define AUDDSpeakerDriver_RECCHANNEL        0
00091 
00092 /** Max Number of channels in audio stream (excluding master). */
00093 #define AUDDSpeakerDriver_NUMCHANNELS       2
00094 /**     @}*/
00095 
00096 /** \addtogroup usbd_audio_speaker_if USB Device Audio Speaker Interface IDs
00097  *      @{
00098  * This page lists the interface numbers for USB Audio Speaker device.
00099  * - \ref AUDDSpeakerDriverDescriptors_CONTROL
00100  * - \ref AUDDSpeakerDriverDescriptors_STREAMING
00101  * Total number of integrated interfaces
00102  * - \ref AUDDSpeakerDriver_NUMINTERFACES
00103  */
00104 /** Audio control interface ID. */
00105 #define AUDDSpeakerDriverDescriptors_CONTROL            0
00106 /** Audio streaming interface ID (OUT, for playback). */
00107 #define AUDDSpeakerDriverDescriptors_STREAMING          1
00108 
00109 /** Audio speaker total number of interfaces */
00110 #define AUDDSpeakerDriver_NUMINTERFACES                 2
00111 /**     @}*/
00112 
00113 /** \addtogroup usbd_audio_entity USB Device Audio Speaker Entity IDs
00114  *      @{
00115  * This page lists the entity IDs for USB Audio Speaker device.
00116  * - \ref AUDDSpeakerDriverDescriptors_INPUTTERMINAL
00117  * - \ref AUDDSpeakerDriverDescriptors_OUTPUTTERMINAL
00118  * - \ref AUDDSpeakerDriverDescriptors_FEATUREUNIT
00119  */
00120 /** Playback input terminal ID. */
00121 #define AUDDSpeakerDriverDescriptors_INPUTTERMINAL      AUDD_ID_SpeakerIT
00122 /** Playback output terminal ID. */
00123 #define AUDDSpeakerDriverDescriptors_OUTPUTTERMINAL     AUDD_ID_SpeakerOT
00124 /** Playback feature unit ID. */
00125 #define AUDDSpeakerDriverDescriptors_FEATUREUNIT        AUDD_ID_SpeakerFU
00126 /**     @}*/
00127 
00128 /*----------------------------------------------------------------------------
00129  *         Types
00130  *----------------------------------------------------------------------------*/
00131 #pragma pack(1)
00132 #if defined   ( __CC_ARM   ) /* Keil ¦̀Vision 4 */
00133 #elif defined ( __ICCARM__ ) /* IAR Ewarm */
00134 #define __attribute__(...)
00135 #define __packed__  packed
00136 #elif defined (  __GNUC__  ) /* GCC CS3 */
00137 #define __packed__  aligned(1)
00138 #endif
00139 
00140 /**
00141  * \typedef AUDHeaderDescriptor1
00142  * \brief Header descriptor with 1 interface.
00143  */
00144 typedef struct _AUDHeaderDescriptor1 {
00145 
00146     /** Header descriptor. */
00147     AUDHeaderDescriptor header;
00148     /** Id of the first grouped interface - Speaker. */
00149     uint8_t bInterface0;
00150 
00151 } __attribute__ ((__packed__)) AUDHeaderDescriptor1; /* GCC*/
00152 
00153 /**
00154  * \typedef AUDFeatureUnitDescriptor3
00155  * \brief Feature unit descriptor with 3 channel controls
00156  *        (master, right, left).
00157  */
00158 typedef struct _AUDFeatureUnitDescriptor3 {
00159 
00160     /** Feature unit descriptor. */
00161     AUDFeatureUnitDescriptor feature;
00162     /** Available controls for each channel. */
00163     uint8_t bmaControls[3];
00164     /** Index of a string descriptor for the feature unit. */
00165     uint8_t iFeature;
00166 
00167 } __attribute__ ((__packed__)) AUDFeatureUnitDescriptor3; /* GCC */
00168 
00169 /**
00170  * \typedef AUDDSpeakerDriverAudioControlDescriptors
00171  * \brief List of descriptors for detailing the audio control interface of a
00172  *        device using a USB audio speaker driver.
00173  */
00174 typedef struct _AUDDSpeakerDriverAudioControlDescriptors {
00175 
00176     /** Header descriptor (with one slave interface). */
00177     AUDHeaderDescriptor1 header;
00178     /** Input terminal descriptor. */
00179     AUDInputTerminalDescriptor input;
00180     /** Output terminal descriptor. */
00181     AUDOutputTerminalDescriptor output;
00182     /** Feature unit descriptor. */
00183     AUDFeatureUnitDescriptor3 feature;
00184 
00185 } __attribute__ ((__packed__)) AUDDSpeakerDriverAudioControlDescriptors; /* GCC*/
00186 
00187 /**
00188  * \typedef AUDFormatTypeOneDescriptor1
00189  * \brief Format type I descriptor with one discrete sampling frequency.
00190  */
00191 typedef struct _AUDFormatTypeOneDescriptor1 {
00192 
00193     /** Format type I descriptor. */
00194     AUDFormatTypeOneDescriptor formatType;
00195     /** Sampling frequency in Hz. */
00196     uint8_t tSamFreq[3];
00197 
00198 } __attribute__ ((__packed__)) AUDFormatTypeOneDescriptor1; /* GCC*/
00199 
00200 /**
00201  * \typedef AUDDSpeakerDriverConfigurationDescriptors
00202  * \brief Holds a list of descriptors returned as part of the configuration of
00203  *        a USB audio speaker device.
00204  */
00205 typedef struct _AUDDSpeakerDriverConfigurationDescriptors {
00206 
00207     /** Standard configuration. */
00208     USBConfigurationDescriptor configuration;
00209     /** Audio control interface. */
00210     USBInterfaceDescriptor control;
00211     /** Descriptors for the audio control interface. */
00212     AUDDSpeakerDriverAudioControlDescriptors controlDescriptors;
00213     /* - AUDIO OUT */
00214     /** Streaming out interface descriptor (with no endpoint, required). */
00215     USBInterfaceDescriptor streamingOutNoIsochronous;
00216     /** Streaming out interface descriptor. */
00217     USBInterfaceDescriptor streamingOut;
00218     /** Audio class descriptor for the streaming out interface. */
00219     AUDStreamingInterfaceDescriptor streamingOutClass;
00220     /** Stream format descriptor. */
00221     AUDFormatTypeOneDescriptor1 streamingOutFormatType;
00222     /** Streaming out endpoint descriptor. */
00223     AUDEndpointDescriptor streamingOutEndpoint;
00224     /** Audio class descriptor for the streaming out endpoint. */
00225     AUDDataEndpointDescriptor streamingOutDataEndpoint;
00226 
00227 } __attribute__ ((__packed__)) AUDDSpeakerDriverConfigurationDescriptors; /* GCC */
00228 
00229 #pragma pack()
00230 
00231 /*----------------------------------------------------------------------------
00232  *         Exported functions
00233  *----------------------------------------------------------------------------*/
00234 
00235 extern void AUDDSpeakerDriver_Initialize(
00236     const USBDDriverDescriptors *pDescriptors);
00237 
00238 extern void AUDDSpeakerDriver_ConfigurationChangeHandler(uint8_t cfgnum);
00239 
00240 extern void AUDDSpeakerDriver_InterfaceSettingChangedHandler(
00241     uint8_t interface, uint8_t setting);
00242 
00243 extern void AUDDSpeakerDriver_RequestHandler(const USBGenericRequest *request);
00244 
00245 extern uint8_t AUDDSpeakerDriver_Read(void *buffer,
00246                                       uint32_t length,
00247                                       TransferCallback callback,
00248                                       void *argument);
00249 
00250 extern void AUDDSpeakerDriver_MuteChanged(uint8_t channel,uint8_t muted);
00251 
00252 extern void AUDDSpeakerDriver_StreamSettingChanged(uint8_t newSetting);
00253 
00254 /**@}*/
00255 #endif /*#ifndef AUDDSPEAKERDRIVER_H */
00256 
00257 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines