SAMV71 Xplained Ultra Software Package 1.5

HIDAUDDDriver.c

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 /** \addtogroup usbd_composite_hidaud
00031  *@{
00032  */
00033 /*---------------------------------------------------------------------------
00034  *      Headers
00035  *---------------------------------------------------------------------------*/
00036 
00037 #include <USBLib_Trace.h>
00038 
00039 #include <HIDAUDDDriver.h>
00040 #include <HIDDKeyboard.h>
00041 #include <AUDDFunction.h>
00042 
00043 /*---------------------------------------------------------------------------
00044  *         Defines
00045  *---------------------------------------------------------------------------*/
00046 
00047 /*---------------------------------------------------------------------------
00048  *         Types
00049  *---------------------------------------------------------------------------*/
00050 
00051 /*---------------------------------------------------------------------------
00052  *         Internal variables
00053  *---------------------------------------------------------------------------*/
00054 
00055 /** Array for storing the current setting of each interface */
00056 static uint8_t bAltInterfaces[HIDAUDDDriverDescriptors_NUMINTERFACE];
00057 
00058 /*---------------------------------------------------------------------------
00059  *         Internal functions
00060  *---------------------------------------------------------------------------*/
00061 
00062 /*---------------------------------------------------------------------------
00063  *         Exported functions
00064  *---------------------------------------------------------------------------*/
00065 
00066 /**
00067  * Initializes the USB device composite device driver.
00068  */
00069 void HIDAUDDDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
00070 {
00071     USBDDriver *pUsbd = USBD_GetDriver();
00072 
00073     /* Initialize the standard USB driver */
00074     USBDDriver_Initialize(pUsbd,
00075                           pDescriptors,
00076                           bAltInterfaces);
00077 
00078     /* HID */
00079     HIDDKeyboard_Initialize(pUsbd, HIDAUDDDriverDescriptors_HID_INTERFACE);
00080     /* Audio */
00081     AUDDFunction_Initialize(pUsbd, HIDAUDDDriverDescriptors_AUD_INTERFACE);
00082 
00083     /* Initialize the USB driver */
00084     USBD_Init();
00085 }
00086 
00087 /**
00088  * Invoked whenever the configuration value of a device is changed by the host
00089  * \param cfgnum Configuration number.
00090  */
00091 void HIDAUDDDriver_ConfigurationChangedHandler(uint8_t cfgnum)
00092 {
00093     USBDDriver *pUsbd = USBD_GetDriver();
00094     USBConfigurationDescriptor *pDesc;
00095 
00096     if (cfgnum > 0) {
00097         pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
00098         /* CDC */
00099         HIDDKeyboard_ConfigureFunction((USBGenericDescriptor *)pDesc,
00100                         pDesc->wTotalLength);
00101         /* AUD */
00102         AUDDFunction_Configure((USBGenericDescriptor *)pDesc,
00103                         pDesc->wTotalLength);
00104     }
00105 }
00106 
00107 /**
00108  * Invoked whenever the active setting of an interface is changed by the
00109  * host. Changes the status of the third LED accordingly.
00110  * \param interface Interface number.
00111  * \param setting Newly active setting.
00112  */
00113 void HIDAUDDDriver_InterfaceSettingChangedHandler(uint8_t interface,
00114         uint8_t setting)
00115 {
00116     AUDDFunction_InterfaceSettingChangedHandler(interface, setting);
00117 }
00118 
00119 /**
00120  * Handles composite-specific USB requests sent by the host, and forwards
00121  * standard ones to the USB device driver.
00122  * \param request Pointer to a USBGenericRequest instance.
00123  */
00124 void HIDAUDDDriver_RequestHandler(const USBGenericRequest *request)
00125 {
00126     USBDDriver *pUsbd = USBD_GetDriver();
00127 
00128     TRACE_INFO_WP("NewReq ");
00129 
00130     if (HIDDKeyboard_RequestHandler(request) == USBRC_SUCCESS)
00131         return;
00132 
00133     if (AUDDFunction_RequestHandler(request) == USBRC_SUCCESS)
00134         return;
00135 
00136     USBDDriver_RequestHandler(pUsbd, request);
00137 }
00138 
00139 /**@}*/
00140 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines