SAM3S8/SD8 Software Package: libraries/usb/device/composite/HIDAUDDDriver.c Source File

SAM3S8/SD8 Software Package 1.2

# HIDAUDDDriver.c

    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 /** \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     if (cfgnum > 0) {
    00096         pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
    00097         /* CDC */
    00098         HIDDKeyboard_ConfigureFunction((USBGenericDescriptor*)pDesc,
    00099                                         pDesc->wTotalLength);
    00100         /* AUD */
    00101         AUDDFunction_Configure((USBGenericDescriptor*)pDesc,
    00102                                 pDesc->wTotalLength);
    00103     }
    00104 }
    00105
    00106 /**
    00107  * Invoked whenever the active setting of an interface is changed by the
    00108  * host. Changes the status of the third LED accordingly.
    00109  * \param interface Interface number.
    00110  * \param setting Newly active setting.
    00111  */
    00112 void HIDAUDDDriver_InterfaceSettingChangedHandler(uint8_t interface,
    00113                                                  uint8_t setting)
    00114 {
    00115     AUDDFunction_InterfaceSettingChangedHandler(interface, setting);
    00116 }
    00117
    00118 /**
    00119  * Handles composite-specific USB requests sent by the host, and forwards
    00120  * standard ones to the USB device driver.
    00121  * \param request Pointer to a USBGenericRequest instance.
    00122  */
    00123 void HIDAUDDDriver_RequestHandler(const USBGenericRequest *request)
    00124 {
    00125     USBDDriver *pUsbd = USBD_GetDriver();
    00126
    00127     TRACE_INFO_WP("NewReq ");
    00128
    00129     if (HIDDKeyboard_RequestHandler(request) == USBRC_SUCCESS)
    00130         return;
    00131
    00132     if (AUDDFunction_RequestHandler(request) == USBRC_SUCCESS)
    00133         return;
    00134
    00135     USBDDriver_RequestHandler(pUsbd, request);
    00136 }
    00137
    00138 /**@}*/
    00139

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines