| 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
AudioClassHost.h
Go to the documentation of this file.
1 /*
2 * @brief Host 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_HOST_H__
47 #define __AUDIO_CLASS_HOST_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 struct
74 {
75 uint8_t DataINPipeNumber;
79 uint8_t DataOUTPipeNumber;
83 uint8_t PortNumber;
84 } Config;
87 struct
88 {
89 bool IsActive;
93 uint8_t ControlInterfaceNumber;
94 uint8_t StreamingInterfaceNumber;
96 uint8_t EnabledStreamingAltIndex;
98 uint16_t DataINPipeSize;
99 uint16_t DataOUTPipeSize;
100 } State;
104 } USB_ClassInfo_Audio_Host_t;
105
106 /* Enums: */
108 enum AUDIO_Host_EnumerationFailure_ErrorCodes_t
109 {
110 AUDIO_ENUMERROR_NoError = 0,
111 AUDIO_ENUMERROR_InvalidConfigDescriptor = 1,
112 AUDIO_ENUMERROR_NoCompatibleInterfaceFound = 2,
113 AUDIO_ENUMERROR_PipeConfigurationFailed = 3,
114 };
115
116 /* Function Prototypes: */
130 uint8_t Audio_Host_ConfigurePipes(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo,
131 uint16_t ConfigDescriptorSize,
132 void* DeviceConfigDescriptor) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(3);
133
143 uint8_t Audio_Host_StartStopStreaming(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo,
144 const bool EnableStreaming) ATTR_NON_NULL_PTR_ARG(1);
145
160 uint8_t Audio_Host_GetSetEndpointProperty(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo,
161 const uint8_t DataPipeIndex,
162 const uint8_t EndpointProperty,
163 const uint8_t EndpointControl,
164 const uint16_t DataLength,
165 void* const Data) ATTR_NON_NULL_PTR_ARG(1) ATTR_NON_NULL_PTR_ARG(6);
166
167 /* Inline Functions: */
175 static inline void Audio_Host_USBTask(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
176 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
177 static inline void Audio_Host_USBTask(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
178 {
179 (void)AudioInterfaceInfo;
180 }
181
192 static inline bool Audio_Host_IsSampleReceived(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
193 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
194 static inline bool Audio_Host_IsSampleReceived(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
195 {
196 uint8_t portnum = AudioInterfaceInfo->Config.PortNumber;
197 bool SampleReceived = false;
198
199 if ((USB_HostState[portnum] != HOST_STATE_Configured) || !(AudioInterfaceInfo->State.IsActive))
200 return false;
201
202 Pipe_SelectPipe(portnum,AudioInterfaceInfo->Config.DataINPipeNumber);
203 Pipe_Unfreeze();
204 SampleReceived = Pipe_IsINReceived(portnum);
205 Pipe_Freeze();
206
207 return SampleReceived;
208 }
209
220 static inline bool Audio_Host_IsReadyForNextSample(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
221 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
222 static inline bool Audio_Host_IsReadyForNextSample(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
223 {
224 uint8_t portnum = AudioInterfaceInfo->Config.PortNumber;
225
226 if ((USB_HostState[portnum] != HOST_STATE_Configured) || !(AudioInterfaceInfo->State.IsActive))
227 return false;
228
229 Pipe_SelectPipe(portnum,AudioInterfaceInfo->Config.DataOUTPipeNumber);
230 return Pipe_IsOUTReady(portnum);
231 }
232
242 static inline int8_t Audio_Host_ReadSample8(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
243 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
244 static inline int8_t Audio_Host_ReadSample8(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
245 {
246 int8_t Sample;
247 uint8_t portnum = AudioInterfaceInfo->Config.PortNumber;
248
249 (void)AudioInterfaceInfo;
250
251 Sample = Pipe_Read_8(portnum);
252
253 if (!(Pipe_BytesInPipe(portnum)))
254 {
255 Pipe_Unfreeze();
256 Pipe_ClearIN(portnum);
257 Pipe_Freeze();
258 }
259
260 return Sample;
261 }
262
272 static inline int16_t Audio_Host_ReadSample16(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
273 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
274 static inline int16_t Audio_Host_ReadSample16(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
275 {
276 int16_t Sample;
277 uint8_t portnum = AudioInterfaceInfo->Config.PortNumber;
278 (void)AudioInterfaceInfo;
279
280 Sample = (int16_t)Pipe_Read_16_LE(portnum);
281
282 if (!(Pipe_BytesInPipe(portnum)))
283 {
284 Pipe_Unfreeze();
285 Pipe_ClearIN(portnum);
286 Pipe_Freeze();
287 }
288
289 return Sample;
290 }
291
301 static inline int32_t Audio_Host_ReadSample24(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
302 ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
303 static inline int32_t Audio_Host_ReadSample24(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo)
304 {
305 int32_t Sample;
306 uint8_t portnum = AudioInterfaceInfo->Config.PortNumber;
307 (void)AudioInterfaceInfo;
308
309 Sample = (((uint32_t)Pipe_Read_8(portnum) << 16)
310 | Pipe_Read_16_LE(portnum));
311
312 if (!(Pipe_BytesInPipe(portnum)))
313 {
314 Pipe_Unfreeze();
315 Pipe_ClearIN(portnum);
316 Pipe_Freeze();
317 }
318
319 return Sample;
320 }
321
331 static inline void Audio_Host_WriteSample8(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo,
332 const int8_t Sample) ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
333 static inline void Audio_Host_WriteSample8(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo,
334 const int8_t Sample)
335 {
336 uint8_t portnum = AudioInterfaceInfo->Config.PortNumber;
337
338 (void)AudioInterfaceInfo;
339
340 Pipe_Write_8(portnum,Sample);
341
342 if (!(Pipe_IsReadWriteAllowed(portnum)))
343 {
344 Pipe_Unfreeze();
345 Pipe_ClearOUT(portnum);
346 Pipe_WaitUntilReady(portnum);
347 Pipe_Freeze();
348 }
349 }
350
360 static inline void Audio_Host_WriteSample16(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo,
361 const int16_t Sample) ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
362 static inline void Audio_Host_WriteSample16(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo,
363 const int16_t Sample)
364 {
365 uint8_t portnum = AudioInterfaceInfo->Config.PortNumber;
366
367 (void)AudioInterfaceInfo;
368
369 Pipe_Write_16_LE(portnum,Sample);
370
371 if (!(Pipe_IsReadWriteAllowed(portnum)))
372 {
373 Pipe_Unfreeze();
374 Pipe_ClearOUT(portnum);
375 Pipe_WaitUntilReady(portnum);
376 Pipe_Freeze();
377 }
378 }
379
389 static inline void Audio_Host_WriteSample24(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo,
390 const int32_t Sample) ATTR_NON_NULL_PTR_ARG(1) ATTR_ALWAYS_INLINE;
391 static inline void Audio_Host_WriteSample24(USB_ClassInfo_Audio_Host_t* const AudioInterfaceInfo,
392 const int32_t Sample)
393 {
394 uint8_t portnum = AudioInterfaceInfo->Config.PortNumber;
395
396 (void)AudioInterfaceInfo;
397
398 Pipe_Write_16_LE(portnum,Sample);
399 Pipe_Write_8(portnum,Sample >> 16);
400
401 if (!(Pipe_IsReadWriteAllowed(portnum)))
402 {
403 Pipe_Unfreeze();
404 Pipe_ClearOUT(portnum);
405 Pipe_WaitUntilReady(portnum);
406 Pipe_Freeze();
407 }
408 }
409
410 /* Private Interface - For use in library only: */
411 #if !defined(__DOXYGEN__)
412 /* Function Prototypes: */
413 #if defined(__INCLUDE_FROM_AUDIO_HOST_C)
414 static uint8_t DCOMP_Audio_Host_NextAudioControlInterface(void* CurrentDescriptor)
415 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
416 static uint8_t DCOMP_Audio_Host_NextAudioStreamInterface(void* CurrentDescriptor)
417 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
418 static uint8_t DCOMP_Audio_Host_NextAudioInterfaceDataEndpoint(void* CurrentDescriptor)
419 ATTR_WARN_UNUSED_RESULT ATTR_NON_NULL_PTR_ARG(1);
420 #endif
421 #endif
422
423 /* Disable C linkage for C++ Compilers: */
424 #if defined(__cplusplus)
425 }
426 #endif
427
428 #endif
429