3 Copyright (C) Dean Camera, 2009.
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
10 Copyright 2009 Dean Camera (dean [at] fourwalledcubicle [dot] com)
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.
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
31 /** \ingroup Group_USBClassAudio
32 * @defgroup Group_USBClassAudioDevice Audio Class Device Mode Driver
34 * \section Module Description
35 * Device Mode USB Class driver framework interface, for the Audio USB Class driver.
40 #ifndef _AUDIO_CLASS_DEVICE_H_
41 #define _AUDIO_CLASS_DEVICE_H_
44 #include "../../USB.h"
45 #include "../Common/Audio.h"
49 /* Enable C linkage for C++ Compilers: */
50 #if defined(__cplusplus)
54 /* Public Interface - May be used in end-application: */
56 /** Configuration information structure for \ref USB_ClassInfo_Audio_Device_t Audio device interface structures. */
59 uint8_t StreamingInterfaceNumber
; /**< Index of the Audio Streaming interface within the device this
63 uint8_t DataINEndpointNumber
; /**< Endpoint number of the incomming Audio Streaming data, if available
66 uint16_t DataINEndpointSize
; /**< Size in bytes of the incomming Audio Streaming data endpoint, if available
70 uint8_t DataOUTEndpointNumber
; /**< Endpoint number of the outgoing Audio Streaming data, if available
73 uint16_t DataOUTEndpointSize
; /**< Size in bytes of the outgoing Audio Streaming data endpoint, if available
76 } USB_ClassInfo_Audio_Device_Config_t
;
78 /** Current State information structure for \ref USB_ClassInfo_Audio_Device_t Audio device interface structures. */
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.
84 } USB_ClassInfo_Audio_Device_State_t
;
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.
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.
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.
104 } USB_ClassInfo_Audio_Device_t
;
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.
111 * \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
113 * \return Boolean true if the endpoints were sucessfully configured, false otherwise
115 bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t
* AudioInterfaceInfo
);
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.
120 * \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
122 void Audio_Device_ProcessControlPacket(USB_ClassInfo_Audio_Device_t
* AudioInterfaceInfo
);
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().
127 * \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
129 void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t
* AudioInterfaceInfo
);
131 /** Reads the next 8-bit audio sample from the current audio interface.
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.
136 * \return Signed 8-bit audio sample from the audio interface
138 int8_t Audio_Device_ReadSample8(void);
140 /** Reads the next 16-bit audio sample from the current audio interface.
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.
145 * \return Signed 16-bit audio sample from the audio interface
147 int16_t Audio_Device_ReadSample16(void);
149 /** Reads the next 24-bit audio sample from the current audio interface.
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.
154 * \return Signed 24-bit audio sample from the audio interface
156 int32_t Audio_Device_ReadSample24(void);
158 /** Writes the next 8-bit audio sample to the current audio interface.
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.
163 * \param Sample Signed 8-bit audio sample
165 void Audio_Device_WriteSample8(int8_t Sample
);
167 /** Writes the next 16-bit audio sample to the current audio interface.
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.
172 * \param Sample Signed 16-bit audio sample
174 void Audio_Device_WriteSample16(int16_t Sample
);
176 /** Writes the next 24-bit audio sample to the current audio interface.
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.
181 * \param Sample Signed 24-bit audio sample
183 void Audio_Device_WriteSample24(int32_t Sample
);
185 /** Determines if the given audio interface is ready for a sample to be read from it.
187 * \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
189 * \return Boolean true if the given Audio interface has a sample to be read, false otherwise
191 bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t
* AudioInterfaceInfo
);
193 /** Determines if the given audio interface is ready to accept the next sample to be written to it.
195 * \param AudioInterfaceInfo Pointer to a structure containing an Audio Class configuration and state.
197 * \return Boolean true if the given Audio interface is ready to accept the next sample, false otherwise
199 bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t
* AudioInterfaceInfo
);
201 /* Disable C linkage for C++ Compilers: */
202 #if defined(__cplusplus)