blob: 95d56258d6d1d27e67a1bc23de31233047de6fd0 [file] [log] [blame]
Christina Quastb123d742014-12-23 13:03:36 +01001/* ----------------------------------------------------------------------------
2 * ATMEL Microcontroller Software Support
3 * ----------------------------------------------------------------------------
4 * Copyright (c) 2010, Atmel Corporation
5 *
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are met:
10 *
11 * - Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the disclaimer below.
13 *
14 * Atmel's name may not be used to endorse or promote products derived from
15 * this software without specific prior written permission.
16 *
17 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 * ----------------------------------------------------------------------------
28 */
29
30/** \addtogroup usbd_composite_hidaud
31 *@{
32 */
33/*---------------------------------------------------------------------------
34 * Headers
35 *---------------------------------------------------------------------------*/
36
37#include <USBLib_Trace.h>
38
39#include <HIDAUDDDriver.h>
40#include <HIDDKeyboard.h>
41#include <AUDDFunction.h>
42
43/*---------------------------------------------------------------------------
44 * Defines
45 *---------------------------------------------------------------------------*/
46
47/*---------------------------------------------------------------------------
48 * Types
49 *---------------------------------------------------------------------------*/
50
51/*---------------------------------------------------------------------------
52 * Internal variables
53 *---------------------------------------------------------------------------*/
54
55/** Array for storing the current setting of each interface */
56static uint8_t bAltInterfaces[HIDAUDDDriverDescriptors_NUMINTERFACE];
57
58/*---------------------------------------------------------------------------
59 * Internal functions
60 *---------------------------------------------------------------------------*/
61
62/*---------------------------------------------------------------------------
63 * Exported functions
64 *---------------------------------------------------------------------------*/
65
66/**
67 * Initializes the USB device composite device driver.
68 */
69void HIDAUDDDriver_Initialize(const USBDDriverDescriptors *pDescriptors)
70{
71 USBDDriver *pUsbd = USBD_GetDriver();
72
73 /* Initialize the standard USB driver */
74 USBDDriver_Initialize(pUsbd,
75 pDescriptors,
76 bAltInterfaces);
77
78 /* HID */
79 HIDDKeyboard_Initialize(pUsbd, HIDAUDDDriverDescriptors_HID_INTERFACE);
80 /* Audio */
81 AUDDFunction_Initialize(pUsbd, HIDAUDDDriverDescriptors_AUD_INTERFACE);
82
83 /* Initialize the USB driver */
84 USBD_Init();
85}
86
87/**
88 * Invoked whenever the configuration value of a device is changed by the host
89 * \param cfgnum Configuration number.
90 */
91void HIDAUDDDriver_ConfigurationChangedHandler(uint8_t cfgnum)
92{
93 USBDDriver *pUsbd = USBD_GetDriver();
94 USBConfigurationDescriptor *pDesc;
95 if (cfgnum > 0) {
96 pDesc = USBDDriver_GetCfgDescriptors(pUsbd, cfgnum);
97 /* CDC */
98 HIDDKeyboard_ConfigureFunction((USBGenericDescriptor*)pDesc,
99 pDesc->wTotalLength);
100 /* AUD */
101 AUDDFunction_Configure((USBGenericDescriptor*)pDesc,
102 pDesc->wTotalLength);
103 }
104}
105
106/**
107 * Invoked whenever the active setting of an interface is changed by the
108 * host. Changes the status of the third LED accordingly.
109 * \param interface Interface number.
110 * \param setting Newly active setting.
111 */
112void HIDAUDDDriver_InterfaceSettingChangedHandler(uint8_t interface,
113 uint8_t setting)
114{
115 AUDDFunction_InterfaceSettingChangedHandler(interface, setting);
116}
117
118/**
119 * Handles composite-specific USB requests sent by the host, and forwards
120 * standard ones to the USB device driver.
121 * \param request Pointer to a USBGenericRequest instance.
122 */
123void HIDAUDDDriver_RequestHandler(const USBGenericRequest *request)
124{
125 USBDDriver *pUsbd = USBD_GetDriver();
126
127 TRACE_INFO_WP("NewReq ");
128
129 if (HIDDKeyboard_RequestHandler(request) == USBRC_SUCCESS)
130 return;
131
132 if (AUDDFunction_RequestHandler(request) == USBRC_SUCCESS)
133 return;
134
135 USBDDriver_RequestHandler(pUsbd, request);
136}
137
138/**@}*/
139