blob: 50ee688df214d1925b6203a07133a4b601e8bb0a [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/**
31 * \file
32 *
33 * \section Purpose
34 *
35 * Definitions and methods for USB composite device implement.
36 *
37 */
38
39#ifndef CDCAUDDDRIVER_H
40#define CDCAUDDDRIVER_H
41/** \addtogroup usbd_cdc_aud
42 *@{
43 */
44
45/*---------------------------------------------------------------------------
46 * Headers
47 *---------------------------------------------------------------------------*/
48
49#include <USBRequests.h>
50#include <CDCDescriptors.h>
51#include <AUDDescriptors.h>
52#include <USBD.h>
53#include <USBDDriver.h>
54
55/*---------------------------------------------------------------------------
56 * Definitions
57 *---------------------------------------------------------------------------*/
58
59/** \addtogroup usbd_cdc_aud_desc USB CDC(Serial) + AUD(Speaker) Definitions
60 * @{
61 */
62/** Number of interfaces of the device (5, can be 4 if no mic support */
63#define CDCAUDDDriverDescriptors_MaxNumInterfaces 5
64/** Number of the CDC interface. */
65#define CDCAUDDDriverDescriptors_CDC_INTERFACE 0
66/** Number of the Audio interface. */
67#define CDCAUDDDriverDescriptors_AUD_INTERFACE 2
68/** Number of Audio function channels (M,L,R) */
69#define AUDD_NumChannels 3
70/** @}*/
71
72/*---------------------------------------------------------------------------
73 * Types
74 *---------------------------------------------------------------------------*/
75
76#ifdef __ICCARM__ /* IAR */
77#pragma pack(1) /* IAR */
78#define __attribute__(...) /* IAR */
79#endif /* IAR */
80
81/** Audio header descriptor with 1 interface */
82typedef struct _AUDHeaderDescriptor1{
83
84 /** Header descriptor.*/
85 AUDHeaderDescriptor header;
86 /** Id of the first grouped interface.*/
87 uint8_t bInterface0;
88
89} __attribute__ ((packed)) AUDHeaderDescriptor1;
90
91/** Audio header descriptor with 2 interface */
92typedef struct _AUDHeaderDescriptor2 {
93
94 /** Header descriptor. */
95 AUDHeaderDescriptor header;
96 /** Id of the first grouped interface - Speaker. */
97 uint8_t bInterface0;
98 /** Id of the second grouped interface - Speakerphone. */
99 uint8_t bInterface1;
100
101} __attribute__ ((packed)) AUDHeaderDescriptor2; /* GCC */
102
103/**
104 * Feature unit descriptor with 3 channel controls (master, right, left).
105 */
106typedef struct _AUDFeatureUnitDescriptor3{
107
108 /** Feature unit descriptor.*/
109 AUDFeatureUnitDescriptor feature;
110 /** Available controls for each channel.*/
111 uint8_t bmaControls[AUDD_NumChannels];
112 /** Index of a string descriptor for the feature unit.*/
113 uint8_t iFeature;
114
115} __attribute__ ((packed)) AUDFeatureUnitDescriptor3;
116
117/**
118 * List of descriptors for detailling the audio control interface of a
119 * device using a USB audio speaker function.
120 */
121typedef struct _AUDDSpeakerAcDescriptors{
122
123 /** Header descriptor (with one slave interface).*/
124 AUDHeaderDescriptor1 header;
125 /** Input terminal descriptor.*/
126 AUDInputTerminalDescriptor input;
127 /** Output terminal descriptor.*/
128 AUDOutputTerminalDescriptor output;
129 /** Feature unit descriptor.*/
130 AUDFeatureUnitDescriptor3 feature;
131
132} __attribute__ ((packed)) AUDDSpeakerAcDescriptors;
133
134/**
135 * List of descriptors for detailling the audio control interface of a
136 * device using a USB Audio Speakerphoneer function.
137 */
138typedef struct _AUDDSpeakerPhoneAcDescriptors {
139
140 /** Header descriptor (with one slave interface). */
141 AUDHeaderDescriptor2 header;
142 /** Input terminal descriptor. */
143 AUDInputTerminalDescriptor inputSpeakerPhone;
144 /** Output terminal descriptor. */
145 AUDOutputTerminalDescriptor outputSpeakerPhone;
146 /** Feature unit descriptor - SpeakerPhone. */
147 AUDFeatureUnitDescriptor3 featureSpeakerPhone;
148 /** Input terminal descriptor. */
149 AUDInputTerminalDescriptor inputRec;
150 /** Output terminal descriptor. */
151 AUDOutputTerminalDescriptor outputRec;
152 /** Feature unit descriptor - SpeakerPhonephone. */
153 AUDFeatureUnitDescriptor3 featureRec;
154
155} __attribute__ ((packed)) AUDDSpeakerPhoneAcDescriptors;
156
157/**
158 * Format type I descriptor with one discrete sampling frequency.
159 */
160typedef struct _AUDFormatTypeOneDescriptor1{
161
162 /** Format type I descriptor.*/
163 AUDFormatTypeOneDescriptor formatType;
164 /** Sampling frequency in Hz.*/
165 uint8_t tSamFreq[3];
166
167} __attribute__ ((packed)) AUDFormatTypeOneDescriptor1;
168
169/**
170 * Configuration descriptor list for a device implementing
171 * CDC(Serial) + Audio(Speaker) composite driver.
172 */
173typedef struct _CdcAudspkdDriverConfigurationDescriptors {
174
175 /** Standard configuration descriptor. */
176 USBConfigurationDescriptor configuration;
177
178 /* --- CDC 0 */
179 /** IAD 0 */
180 USBInterfaceAssociationDescriptor cdcIAD0;
181 /** Communication interface descriptor */
182 USBInterfaceDescriptor cdcCommunication0;
183 /** CDC header functional descriptor. */
184 CDCHeaderDescriptor cdcHeader0;
185 /** CDC call management functional descriptor. */
186 CDCCallManagementDescriptor cdcCallManagement0;
187 /** CDC abstract control management functional descriptor. */
188 CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
189 /** CDC union functional descriptor (with one slave interface). */
190 CDCUnionDescriptor cdcUnion0;
191 /** Notification endpoint descriptor. */
192 USBEndpointDescriptor cdcNotification0;
193 /** Data interface descriptor. */
194 USBInterfaceDescriptor cdcData0;
195 /** Data OUT endpoint descriptor. */
196 USBEndpointDescriptor cdcDataOut0;
197 /** Data IN endpoint descriptor. */
198 USBEndpointDescriptor cdcDataIn0;
199
200 /* --- AUDIO (AC) */
201 /** IAD 1*/
202 USBInterfaceAssociationDescriptor audIAD;
203 /** Audio control interface.*/
204 USBInterfaceDescriptor audInterface;
205 /** Descriptors for the audio control interface.*/
206 AUDDSpeakerAcDescriptors audControl;
207 /* -- AUDIO out (AS) */
208 /** Streaming out interface descriptor (with no endpoint, required).*/
209 USBInterfaceDescriptor audStreamingOutNoIsochronous;
210 /** Streaming out interface descriptor.*/
211 USBInterfaceDescriptor audStreamingOut;
212 /** Audio class descriptor for the streaming out interface.*/
213 AUDStreamingInterfaceDescriptor audStreamingOutClass;
214 /** Stream format descriptor.*/
215 AUDFormatTypeOneDescriptor1 audStreamingOutFormatType;
216 /** Streaming out endpoint descriptor.*/
217 AUDEndpointDescriptor audStreamingOutEndpoint;
218 /** Audio class descriptor for the streaming out endpoint.*/
219 AUDDataEndpointDescriptor audStreamingOutDataEndpoint;
220
221} __attribute__ ((packed)) CdcAudspkdDriverConfigurationDescriptors;
222
223/**
224 * Configuration descriptor list for a device implementing
225 * CDC(Serial) + Audio(SpeakerPhone) composite driver.
226 */
227typedef struct _CdcAuddDriverConfigurationDescriptors {
228
229 /** Standard configuration descriptor. */
230 USBConfigurationDescriptor configuration;
231
232 /* --- CDC 0 */
233 /** IAD 0 */
234 USBInterfaceAssociationDescriptor cdcIAD0;
235 /** Communication interface descriptor */
236 USBInterfaceDescriptor cdcCommunication0;
237 /** CDC header functional descriptor. */
238 CDCHeaderDescriptor cdcHeader0;
239 /** CDC call management functional descriptor. */
240 CDCCallManagementDescriptor cdcCallManagement0;
241 /** CDC abstract control management functional descriptor. */
242 CDCAbstractControlManagementDescriptor cdcAbstractControlManagement0;
243 /** CDC union functional descriptor (with one slave interface). */
244 CDCUnionDescriptor cdcUnion0;
245 /** Notification endpoint descriptor. */
246 USBEndpointDescriptor cdcNotification0;
247 /** Data interface descriptor. */
248 USBInterfaceDescriptor cdcData0;
249 /** Data OUT endpoint descriptor. */
250 USBEndpointDescriptor cdcDataOut0;
251 /** Data IN endpoint descriptor. */
252 USBEndpointDescriptor cdcDataIn0;
253
254 /* --- AUDIO (AC) */
255 /** IAD 1*/
256 USBInterfaceAssociationDescriptor audIAD;
257 /** Audio control interface.*/
258 USBInterfaceDescriptor audInterface;
259 /** Descriptors for the audio control interface.*/
260 AUDDSpeakerPhoneAcDescriptors audControl;
261 /* -- AUDIO out (AS) */
262 /** Streaming out interface descriptor (with no endpoint, required).*/
263 USBInterfaceDescriptor audStreamingOutNoIsochronous;
264 /** Streaming out interface descriptor.*/
265 USBInterfaceDescriptor audStreamingOut;
266 /** Audio class descriptor for the streaming out interface.*/
267 AUDStreamingInterfaceDescriptor audStreamingOutClass;
268 /** Stream format descriptor.*/
269 AUDFormatTypeOneDescriptor1 audStreamingOutFormatType;
270 /** Streaming out endpoint descriptor.*/
271 AUDEndpointDescriptor audStreamingOutEndpoint;
272 /** Audio class descriptor for the streaming out endpoint.*/
273 AUDDataEndpointDescriptor audStreamingOutDataEndpoint;
274 /*- AUDIO IN */
275 /** Streaming in interface descriptor (with no endpoint, required). */
276 USBInterfaceDescriptor streamingInNoIsochronous;
277 /** Streaming in interface descriptor. */
278 USBInterfaceDescriptor streamingIn;
279 /** Audio class descriptor for the streaming in interface. */
280 AUDStreamingInterfaceDescriptor streamingInClass;
281 /** Stream format descriptor. */
282 AUDFormatTypeOneDescriptor1 streamingInFormatType;
283 /** Streaming in endpoint descriptor. */
284 AUDEndpointDescriptor streamingInEndpoint;
285 /** Audio class descriptor for the streaming in endpoint. */
286 AUDDataEndpointDescriptor streamingInDataEndpoint;
287
288} __attribute__ ((packed)) CdcAuddDriverConfigurationDescriptors;
289
290
291#ifdef __ICCARM__ /* IAR */
292#pragma pack() /* IAR */
293#endif /* IAR */
294
295/*---------------------------------------------------------------------------
296 * Exported functions
297 *---------------------------------------------------------------------------*/
298
299extern void CDCAUDDDriver_Initialize(const USBDDriverDescriptors * pDescriptors);
300extern void CDCAUDDDriver_ConfigurationChangedHandler(uint8_t cfgnum);
301extern void CDCAUDDDriver_InterfaceSettingChangedHandler(
302 uint8_t interface, uint8_t setting);
303extern void CDCAUDDDriver_RequestHandler(const USBGenericRequest *request);
304
305/**@}*/
306#endif //#ifndef CDCHIDDDRIVER_H
307