LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
AudioClassDevice.c
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 
33 
34 #define __INCLUDE_FROM_USB_DRIVER
35 #include "../../Core/USBMode.h"
36 
37 #if defined(USB_CAN_BE_DEVICE)
38 
39 #define __INCLUDE_FROM_AUDIO_DRIVER
40 #define __INCLUDE_FROM_AUDIO_DEVICE_C
41 #include "AudioClassDevice.h"
42 
44 {
45  if (!(Endpoint_IsSETUPReceived()))
46  return;
47 
49  {
50  if (USB_ControlRequest.wIndex != AudioInterfaceInfo->Config.StreamingInterfaceNumber)
51  return;
52  }
53  else if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT) == REQREC_ENDPOINT)
54  {
55  bool EndpointFilterMatch = false;
56 
57  EndpointFilterMatch |= (AudioInterfaceInfo->Config.DataINEndpointNumber &&
58  ((uint8_t)USB_ControlRequest.wIndex == (ENDPOINT_DIR_IN | AudioInterfaceInfo->Config.DataINEndpointNumber)));
59 
60  EndpointFilterMatch |= (AudioInterfaceInfo->Config.DataOUTEndpointNumber &&
61  ((uint8_t)USB_ControlRequest.wIndex == (ENDPOINT_DIR_OUT | AudioInterfaceInfo->Config.DataOUTEndpointNumber)));
62 
63  if (!(EndpointFilterMatch))
64  return;
65  }
66 
67  switch (USB_ControlRequest.bRequest)
68  {
69  case REQ_SetInterface:
71  {
74 
75  AudioInterfaceInfo->State.InterfaceEnabled = ((USB_ControlRequest.wValue & 0xFF) != 0);
76  EVENT_Audio_Device_StreamStartStop(AudioInterfaceInfo);
77  }
78 
79  break;
83  {
86  }
87 
88  break;
94  {
95  uint8_t EndpointProperty = USB_ControlRequest.bRequest;
96  uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
97  uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
98 
99  if (CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
100  EndpointControl, NULL, NULL))
101  {
102  uint16_t ValueLength = USB_ControlRequest.wLength;
103  uint8_t Value[ValueLength];
104 
106  Endpoint_Read_Control_Stream_LE(Value, ValueLength);
107  Endpoint_ClearIN();
108 
109  CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
110  EndpointControl, &ValueLength, Value);
111  }
112  }
113 
114  break;
120  {
121  uint8_t EndpointProperty = USB_ControlRequest.bRequest;
122  uint8_t EndpointAddress = (uint8_t)USB_ControlRequest.wIndex;
123  uint8_t EndpointControl = (USB_ControlRequest.wValue >> 8);
124  uint16_t ValueLength = USB_ControlRequest.wLength;
125  uint8_t Value[ValueLength];
126 
127  if (CALLBACK_Audio_Device_GetSetEndpointProperty(AudioInterfaceInfo, EndpointProperty, EndpointAddress,
128  EndpointControl, &ValueLength, Value))
129  {
131  Endpoint_Write_Control_Stream_LE(Value, ValueLength);
133  }
134  }
135 
136  break;
137  }
138 }
139 
141 {
142  memset(&AudioInterfaceInfo->State, 0x00, sizeof(AudioInterfaceInfo->State));
143 
144  for (uint8_t EndpointNum = 1; EndpointNum < ENDPOINT_TOTAL_ENDPOINTS; EndpointNum++)
145  {
146  uint16_t Size;
147  uint8_t Type;
148  uint8_t Direction;
149  bool DoubleBanked;
150 
151  if (EndpointNum == AudioInterfaceInfo->Config.DataINEndpointNumber)
152  {
153  Size = AudioInterfaceInfo->Config.DataINEndpointSize;
154  Direction = ENDPOINT_DIR_IN;
155  Type = EP_TYPE_ISOCHRONOUS;
156  DoubleBanked = true;
157  }
158  else if (EndpointNum == AudioInterfaceInfo->Config.DataOUTEndpointNumber)
159  {
160  Size = AudioInterfaceInfo->Config.DataOUTEndpointSize;
161  Direction = ENDPOINT_DIR_OUT;
162  Type = EP_TYPE_ISOCHRONOUS;
163  DoubleBanked = true;
164  }
165  else
166  {
167  continue;
168  }
169 
170  if (!(Endpoint_ConfigureEndpoint(EndpointNum, Type, Direction, Size,
171  DoubleBanked ? ENDPOINT_BANK_DOUBLE : ENDPOINT_BANK_SINGLE)))
172  {
173  return false;
174  }
175  }
176 
177  return true;
178 }
179 
181 {
182 
183 }
184 
185 #endif