Added USE_INTERNAL_SERIAL compile time option to automatically read out the internal...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / Audio.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2009.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
12 Permission to use, copy, modify, and distribute this software
13 and its documentation for any purpose and without fee is hereby
14 granted, provided that the above copyright notice appear in all
15 copies and that both that the copyright notice and this
16 permission notice and warranty disclaimer appear in supporting
17 documentation, and that the name of the author not be used in
18 advertising or publicity pertaining to distribution of the
19 software without specific, written prior permission.
20
21 The author disclaim all warranties with regard to this
22 software, including all implied warranties of merchantability
23 and fitness. In no event shall the author be liable for any
24 special, indirect or consequential damages or any damages
25 whatsoever resulting from loss of use, data or profits, whether
26 in an action of contract, negligence or other tortious action,
27 arising out of or in connection with the use or performance of
28 this software.
29 */
30
31 /** \ingroup Group_USBClassAudio
32 * @defgroup Group_USBClassAudioDevice Audio Class Device Mode Driver
33 *
34 * \section Module Description
35 * Device Mode USB Class driver framework interface, for the Audio USB Class driver.
36 *
37 * @{
38 */
39
40 #ifndef _AUDIO_CLASS_DEVICE_H_
41 #define _AUDIO_CLASS_DEVICE_H_
42
43 /* Includes: */
44 #include "../../USB.h"
45 #include "../Common/Audio.h"
46
47 #include <string.h>
48
49 /* Enable C linkage for C++ Compilers: */
50 #if defined(__cplusplus)
51 extern "C" {
52 #endif
53
54 /* Public Interface - May be used in end-application: */
55 /* Type Defines: */
56 /** Configuration information structure for \ref USB_ClassInfo_Audio_Device_t Audio device interface structures. */
57 typedef struct
58 {
59 uint8_t StreamingInterfaceNumber; /**< Index of the Audio Streaming interface within the device this
60 * structure controls.
61 */
62
63 uint8_t DataINEndpointNumber; /**< Endpoint number of the incomming Audio Streaming data, if available
64 * (zero if unused).
65 */
66 uint16_t DataINEndpointSize; /**< Size in bytes of the incomming Audio Streaming data endpoint, if available
67 * (zero if unused).
68 */
69
70 uint8_t DataOUTEndpointNumber; /**< Endpoint number of the outgoing Audio Streaming data, if available
71 * (zero if unused).
72 */
73 uint16_t DataOUTEndpointSize; /**< Size in bytes of the outgoing Audio Streaming data endpoint, if available
74 * (zero if unused).
75 */
76 } USB_ClassInfo_Audio_Device_Config_t;
77
78 /** Current State information structure for \ref USB_ClassInfo_Audio_Device_t Audio device interface structures. */
79 typedef struct
80 {
81 bool InterfaceEnabled; /**< Set and cleared by the class driver to indicate if the host has enabled the streaming endpoints
82 * of the Audio Streaming interface.
83 */
84 } USB_ClassInfo_Audio_Device_State_t;
85
86 /** Class state structure. An instance of this structure should be made for each Audio interface
87 * within the user application, and passed to each of the Audio class driver functions as the
88 * AudioInterfaceInfo parameter. This stores each Audio interface's configuration and state information.
89 */
90 typedef struct
91 {
92 const USB_ClassInfo_Audio_Device_Config_t Config; /**< Config data for the USB class interface within
93 * the device. All elements in this section
94 * <b>must</b> be set or the interface will fail
95 * to enumerate and operate correctly.
96 */
97
98 USB_ClassInfo_Audio_Device_State_t State; /**< State data for the USB class interface within
99 * the device. All elements in this section
100 * <b>may</b> be set to initial values, but may
101 * also be ignored to default to sane values when
102 * the interface is enumerated.
103 */
104 } USB_ClassInfo_Audio_Device_t;
105
106 /* Function Prototypes: */
107 /** Configures the endpoints of a given Audio interface, ready for use. This should be linked to the library
108 * \ref EVENT_USB_ConfigurationChanged() event so that the endpoints are configured when the configuration containing the
109 * given Audio interface is selected.
110 *
111 * \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
112 *
113 * \return Boolean true if the endpoints were sucessfully configured, false otherwise
114 */
115 bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo);
116
117 /** Processes incomming control requests from the host, that are directed to the given Audio class interface. This should be
118 * linked to the library \ref EVENT_USB_UnhandledControlPacket() event.
119 *
120 * \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
121 */
122 void Audio_Device_ProcessControlPacket(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo);
123
124 /** General management task for a given Audio class interface, required for the correct operation of the interface. This should
125 * be called frequently in the main program loop, before the master USB management task \ref USB_USBTask().
126 *
127 * \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
128 */
129 void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo);
130
131 /** Reads the next 8-bit audio sample from the current audio interface.
132 *
133 * \note This should be preceeded immediately by a call to the USB_Audio_IsSampleReceived() function to ensure that
134 * the correct endpoint is selected and ready for data.
135 *
136 * \return Signed 8-bit audio sample from the audio interface
137 */
138 int8_t Audio_Device_ReadSample8(void);
139
140 /** Reads the next 16-bit audio sample from the current audio interface.
141 *
142 * \note This should be preceeded immediately by a call to the USB_Audio_IsSampleReceived() function to ensure that
143 * the correct endpoint is selected and ready for data.
144 *
145 * \return Signed 16-bit audio sample from the audio interface
146 */
147 int16_t Audio_Device_ReadSample16(void);
148
149 /** Reads the next 24-bit audio sample from the current audio interface.
150 *
151 * \note This should be preceeded immediately by a call to the USB_Audio_IsSampleReceived() function to ensure that
152 * the correct endpoint is selected and ready for data.
153 *
154 * \return Signed 24-bit audio sample from the audio interface
155 */
156 int32_t Audio_Device_ReadSample24(void);
157
158 /** Writes the next 8-bit audio sample to the current audio interface.
159 *
160 * \note This should be preceeded immediately by a call to the USB_Audio_IsReadyForNextSample() function to ensure that
161 * the correct endpoint is selected and ready for data.
162 *
163 * \param Sample Signed 8-bit audio sample
164 */
165 void Audio_Device_WriteSample8(int8_t Sample);
166
167 /** Writes the next 16-bit audio sample to the current audio interface.
168 *
169 * \note This should be preceeded immediately by a call to the USB_Audio_IsReadyForNextSample() function to ensure that
170 * the correct endpoint is selected and ready for data.
171 *
172 * \param Sample Signed 16-bit audio sample
173 */
174 void Audio_Device_WriteSample16(int16_t Sample);
175
176 /** Writes the next 24-bit audio sample to the current audio interface.
177 *
178 * \note This should be preceeded immediately by a call to the USB_Audio_IsReadyForNextSample() function to ensure that
179 * the correct endpoint is selected and ready for data.
180 *
181 * \param Sample Signed 24-bit audio sample
182 */
183 void Audio_Device_WriteSample24(int32_t Sample);
184
185 /** Determines if the given audio interface is ready for a sample to be read from it.
186 *
187 * \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
188 *
189 * \return Boolean true if the given Audio interface has a sample to be read, false otherwise
190 */
191 bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo);
192
193 /** Determines if the given audio interface is ready to accept the next sample to be written to it.
194 *
195 * \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
196 *
197 * \return Boolean true if the given Audio interface is ready to accept the next sample, false otherwise
198 */
199 bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t* AudioInterfaceInfo);
200
201 /* Disable C linkage for C++ Compilers: */
202 #if defined(__cplusplus)
203 }
204 #endif
205
206 #endif
207
208 /** @} */