| LPCOpen Platform v1.03 LPCOpen Platform for NXP LPC Microcontrollers

- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AudioClassDevice.h
Go to the documentation of this file.
1 /*
2 * @brief Device mode driver for the library USB Audio 1.0 Class driver
3 *
4 * @note
5 * Copyright(C) NXP Semiconductors, 2012
6 * Copyright(C) Dean Camera, 2011, 2012
7 * All rights reserved.
8 *
9 * @par
10 * Software that is described herein is for illustrative purposes only
11 * which provides customers with programming information regarding the
12 * LPC products. This software is supplied "AS IS" without any warranties of
13 * any kind, and NXP Semiconductors and its licensor disclaim any and
14 * all warranties, express or implied, including all implied warranties of
15 * merchantability, fitness for a particular purpose and non-infringement of
16 * intellectual property rights. NXP Semiconductors assumes no responsibility
17 * or liability for the use of the software, conveys no license or rights under any
18 * patent, copyright, mask work right, or any other intellectual property rights in
19 * or to any products. NXP Semiconductors reserves the right to make changes
20 * in the software without notification. NXP Semiconductors also makes no
21 * representation or warranty that such application will be suitable for the
22 * specified use without further testing or modification.
23 *
24 * @par
25 * Permission to use, copy, modify, and distribute this software and its
26 * documentation is hereby granted, under NXP Semiconductors' and its
27 * licensor's relevant copyrights in the software, without fee, provided that it
28 * is used in conjunction with NXP Semiconductors microcontrollers. This
29 * copyright, permission, and disclaimer notice must appear in all copies of
30 * this code.
31 */
32
46 #ifndef _AUDIO_CLASS_DEVICE_H_
47 #define _AUDIO_CLASS_DEVICE_H_
48
49 /* Includes: */
50 #include "../../USB.h"
51 #include "../Common/AudioClassCommon.h"
52
53 /* Enable C linkage for C++ Compilers: */
54 #if defined(__cplusplus)
55 extern "C" {
56 #endif
57
58 /* Preprocessor Checks: */
59 #if !defined(__INCLUDE_FROM_AUDIO_DRIVER)
60 #error Do not include this file directly. Include LPCUSBlib/Drivers/USB.h instead.
61 #endif
62
63 /* Public Interface - May be used in end-application: */
64 /* Type Defines: */
71 typedef struct
72 {
73 const struct
74 {
75 uint8_t ControlInterfaceNumber;
78 uint8_t StreamingInterfaceNumber;
82 uint8_t DataINEndpointNumber;
85 uint16_t DataINEndpointSize;
89 uint8_t DataOUTEndpointNumber;
92 uint16_t DataOUTEndpointSize;
95 uint8_t PortNumber;
96 } Config;
99 struct
100 {
101 bool InterfaceEnabled;
104 } State;
107 } USB_ClassInfo_Audio_Device_t;
108
109 /* Function Prototypes: */
110
119 bool Audio_Device_ConfigureEndpoints(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
120
128 void Audio_Device_ProcessControlRequest(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);
129
152 bool CALLBACK_Audio_Device_GetSetEndpointProperty(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo,
153 const uint8_t EndpointProperty,
154 const uint8_t EndpointAddress,
155 const uint8_t EndpointControl,
156 uint16_t* const DataLength,
157 uint8_t* Data);
158
167 void EVENT_Audio_Device_StreamStartStop(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo);
168
169 /* Inline Functions: */
177 PRAGMA_ALWAYS_INLINE
178 static inline void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
179 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
180 static inline void Audio_Device_USBTask(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
181 {
182 (void)AudioInterfaceInfo;
183 }
184
195 PRAGMA_ALWAYS_INLINE
196 static inline bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
197 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
198 static inline bool Audio_Device_IsSampleReceived(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
199 {
200 if ((USB_DeviceState[AudioInterfaceInfo->Config.PortNumber] != DEVICE_STATE_Configured) || !(AudioInterfaceInfo->State.InterfaceEnabled))
201 return false;
202
203 Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.PortNumber, AudioInterfaceInfo->Config.DataOUTEndpointNumber);
204 return Endpoint_IsOUTReceived(AudioInterfaceInfo->Config.PortNumber);
205 }
206
217 PRAGMA_ALWAYS_INLINE
218 static inline bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
219 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
220 static inline bool Audio_Device_IsReadyForNextSample(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
221 {
222 if ((USB_DeviceState[AudioInterfaceInfo->Config.PortNumber] != DEVICE_STATE_Configured) || !(AudioInterfaceInfo->State.InterfaceEnabled))
223 return false;
224
225 Endpoint_SelectEndpoint(AudioInterfaceInfo->Config.PortNumber, AudioInterfaceInfo->Config.DataINEndpointNumber);
226 return Endpoint_IsINReady(USB_DeviceState[AudioInterfaceInfo->Config.PortNumber]);
227 }
228
238 PRAGMA_ALWAYS_INLINE
239 static inline int8_t Audio_Device_ReadSample8(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
240 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
241 static inline int8_t Audio_Device_ReadSample8(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
242 {
243 int8_t Sample;
244
245 (void)AudioInterfaceInfo;
246
247 Sample = Endpoint_Read_8(AudioInterfaceInfo->Config.PortNumber);
248
249 if (!(Endpoint_BytesInEndpoint(AudioInterfaceInfo->Config.PortNumber)))
250 Endpoint_ClearOUT(AudioInterfaceInfo->Config.PortNumber);
251
252 return Sample;
253 }
254
264 PRAGMA_ALWAYS_INLINE
265 static inline int16_t Audio_Device_ReadSample16(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
266 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
267 static inline int16_t Audio_Device_ReadSample16(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
268 {
269 int16_t Sample;
270
271 (void)AudioInterfaceInfo;
272
273 Sample = (int16_t)Endpoint_Read_16_LE(AudioInterfaceInfo->Config.PortNumber);
274
275 if (!(Endpoint_BytesInEndpoint(AudioInterfaceInfo->Config.PortNumber)))
276 Endpoint_ClearOUT(AudioInterfaceInfo->Config.PortNumber);
277
278 return Sample;
279 }
280
290 PRAGMA_ALWAYS_INLINE
291 static inline int32_t Audio_Device_ReadSample24(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
292 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
293 static inline int32_t Audio_Device_ReadSample24(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
294 {
295 int32_t Sample;
296
297 (void)AudioInterfaceInfo;
298
299 Sample = (((uint32_t)Endpoint_Read_8(AudioInterfaceInfo->Config.PortNumber) << 16) | Endpoint_Read_16_LE(AudioInterfaceInfo->Config.PortNumber));
300
301 if (!(Endpoint_BytesInEndpoint(AudioInterfaceInfo->Config.PortNumber)))
302 Endpoint_ClearOUT(AudioInterfaceInfo->Config.PortNumber);
303
304 return Sample;
305 }
306
317 PRAGMA_ALWAYS_INLINE
318 static inline void Audio_Device_WriteSample8(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo,
319 const int8_t Sample) ATTR_NON_NULL_PTR_ARG(1);
320 static inline void Audio_Device_WriteSample8(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo,
321 const int8_t Sample)
322 {
323 Endpoint_Write_8(AudioInterfaceInfo->Config.PortNumber, Sample);
324
325 if (Endpoint_BytesInEndpoint(AudioInterfaceInfo->Config.PortNumber) == AudioInterfaceInfo->Config.DataINEndpointSize)
326 Endpoint_ClearIN(AudioInterfaceInfo->Config.PortNumber);
327 }
328
339 PRAGMA_ALWAYS_INLINE
340 static inline void Audio_Device_WriteSample16(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo,
341 const int16_t Sample) ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
342 static inline void Audio_Device_WriteSample16(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo,
343 const int16_t Sample)
344 {
345 Endpoint_Write_16_LE(AudioInterfaceInfo->Config.PortNumber, Sample);
346
347 if (Endpoint_BytesInEndpoint(AudioInterfaceInfo->Config.PortNumber) == AudioInterfaceInfo->Config.DataINEndpointSize)
348 Endpoint_ClearIN(AudioInterfaceInfo->Config.PortNumber);
349 }
350
361 PRAGMA_ALWAYS_INLINE
362 static inline void Audio_Device_WriteSample24(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo,
363 const int32_t Sample) ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
364 static inline void Audio_Device_WriteSample24(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo,
365 const int32_t Sample)
366 {
367 Endpoint_Write_16_LE(AudioInterfaceInfo->Config.PortNumber, Sample);
368 Endpoint_Write_8(AudioInterfaceInfo->Config.PortNumber, Sample >> 16);
369
370 if (Endpoint_BytesInEndpoint(AudioInterfaceInfo->Config.PortNumber) == AudioInterfaceInfo->Config.DataINEndpointSize)
371 Endpoint_ClearIN(AudioInterfaceInfo->Config.PortNumber);
372 }
373
374 /* Private Interface - For use in library only: */
375 #if !defined(__DOXYGEN__)
376 /* Function Prototypes: */
377 #if defined(__INCLUDE_FROM_AUDIO_DEVICE_C)
378 void Audio_Device_Event_Stub(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo) ATTR_CONST;
379 PRAGMA_WEAK(EVENT_Audio_Device_StreamStartStop,Audio_Device_Event_Stub)
380 void EVENT_Audio_Device_StreamStartStop(USB_ClassInfo_Audio_Device_t* const AudioInterfaceInfo)
381 ATTR_WEAK ATTR_NON_NULL_PTR_ARG(1) ATTR_ALIAS(Audio_Device_Event_Stub);
382 #endif
383
384 #endif
385
386
387 /* Disable C linkage for C++ Compilers: */
388 #if defined(__cplusplus)
389 }
390 #endif
391 #endif
392