| 1 |
/** |
| 2 |
****************************************************************************** |
| 3 |
* @file usbh_audio.c |
| 4 |
* @author MCD Application Team |
| 5 |
* @version V3.0.0 |
| 6 |
* @date 18-February-2014 |
| 7 |
* @brief This file is the AC Layer Handlers for USB Host AC class. |
| 8 |
* |
| 9 |
****************************************************************************** |
| 10 |
* @attention |
| 11 |
* |
| 12 |
* <h2><center>© COPYRIGHT 2014 STMicroelectronics</center></h2> |
| 13 |
* |
| 14 |
* Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); |
| 15 |
* You may not use this file except in compliance with the License. |
| 16 |
* You may obtain a copy of the License at: |
| 17 |
* |
| 18 |
* http://www.st.com/software_license_agreement_liberty_v2 |
| 19 |
* |
| 20 |
* Unless required by applicable law or agreed to in writing, software |
| 21 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 22 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 23 |
* See the License for the specific language governing permissions and |
| 24 |
* limitations under the License. |
| 25 |
* |
| 26 |
****************************************************************************** |
| 27 |
*/ |
| 28 |
|
| 29 |
/* Includes ------------------------------------------------------------------*/ |
| 30 |
#include "usbh_audio.h" |
| 31 |
|
| 32 |
/** @addtogroup USBH_LIB |
| 33 |
* @{ |
| 34 |
*/ |
| 35 |
|
| 36 |
/** @addtogroup USBH_CLASS |
| 37 |
* @{ |
| 38 |
*/ |
| 39 |
|
| 40 |
/** @addtogroup USBH_AUDIO_CLASS |
| 41 |
* @{ |
| 42 |
*/ |
| 43 |
|
| 44 |
/** @defgroup USBH_AUDIO_CORE |
| 45 |
* @brief This file includes HID Layer Handlers for USB Host HID class. |
| 46 |
* @{ |
| 47 |
*/ |
| 48 |
|
| 49 |
/** @defgroup USBH_AUDIO_CORE_Private_TypesDefinitions |
| 50 |
* @{ |
| 51 |
*/ |
| 52 |
/** |
| 53 |
* @} |
| 54 |
*/ |
| 55 |
|
| 56 |
|
| 57 |
/** @defgroup USBH_AUDIO_CORE_Private_Defines |
| 58 |
* @{ |
| 59 |
*/ |
| 60 |
|
| 61 |
/** |
| 62 |
* @} |
| 63 |
*/ |
| 64 |
|
| 65 |
|
| 66 |
/** @defgroup USBH_AUDIO_CORE_Private_Macros |
| 67 |
* @{ |
| 68 |
*/ |
| 69 |
/** |
| 70 |
* @} |
| 71 |
*/ |
| 72 |
|
| 73 |
|
| 74 |
/** @defgroup USBH_AUDIO_CORE_Private_Variables |
| 75 |
* @{ |
| 76 |
*/ |
| 77 |
|
| 78 |
/** |
| 79 |
* @} |
| 80 |
*/ |
| 81 |
|
| 82 |
|
| 83 |
/** @defgroup USBH_AUDIO_CORE_Private_FunctionPrototypes |
| 84 |
* @{ |
| 85 |
*/ |
| 86 |
|
| 87 |
static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit (USBH_HandleTypeDef *phost); |
| 88 |
static USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit (USBH_HandleTypeDef *phost); |
| 89 |
static USBH_StatusTypeDef USBH_AUDIO_Process(USBH_HandleTypeDef *phost); |
| 90 |
static USBH_StatusTypeDef USBH_AUDIO_SOFProcess(USBH_HandleTypeDef *phost); |
| 91 |
static USBH_StatusTypeDef USBH_AUDIO_ClassRequest(USBH_HandleTypeDef *phost); |
| 92 |
static USBH_StatusTypeDef USBH_AUDIO_CSRequest(USBH_HandleTypeDef *phost, |
| 93 |
uint8_t feature, |
| 94 |
uint8_t channel); |
| 95 |
|
| 96 |
static USBH_StatusTypeDef USBH_AUDIO_HandleCSRequest(USBH_HandleTypeDef *phost); |
| 97 |
|
| 98 |
static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingIN(USBH_HandleTypeDef *phost); |
| 99 |
static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingOUT(USBH_HandleTypeDef *phost); |
| 100 |
static USBH_StatusTypeDef USBH_AUDIO_FindHIDControl(USBH_HandleTypeDef *phost); |
| 101 |
static USBH_StatusTypeDef USBH_AUDIO_ParseCSDescriptors(USBH_HandleTypeDef *phost); |
| 102 |
|
| 103 |
static USBH_StatusTypeDef USBH_AUDIO_BuildHeadphonePath(USBH_HandleTypeDef *phost); |
| 104 |
static USBH_StatusTypeDef USBH_AUDIO_BuildMicrophonePath(USBH_HandleTypeDef *phost); |
| 105 |
int32_t USBH_AUDIO_FindLinkedUnitIN(USBH_HandleTypeDef *phost, uint8_t UnitID); |
| 106 |
int32_t USBH_AUDIO_FindLinkedUnitOUT(USBH_HandleTypeDef *phost, uint8_t UnitID); |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
static USBH_StatusTypeDef ParseCSDescriptors(AUDIO_ClassSpecificDescTypedef *class_desc, |
| 111 |
uint8_t ac_subclass, |
| 112 |
uint8_t *pdesc); |
| 113 |
|
| 114 |
|
| 115 |
static USBH_StatusTypeDef USBH_AUDIO_Transmit (USBH_HandleTypeDef *phost); |
| 116 |
|
| 117 |
|
| 118 |
static USBH_StatusTypeDef USBH_AC_SetCur(USBH_HandleTypeDef *phost, |
| 119 |
uint8_t subtype, |
| 120 |
uint8_t feature, |
| 121 |
uint8_t controlSelector, |
| 122 |
uint8_t channel, |
| 123 |
uint16_t length); |
| 124 |
|
| 125 |
static USBH_StatusTypeDef USBH_AC_GetCur(USBH_HandleTypeDef *phost, |
| 126 |
uint8_t subtype, |
| 127 |
uint8_t feature, |
| 128 |
uint8_t controlSelector, |
| 129 |
uint8_t channel, |
| 130 |
uint16_t length); |
| 131 |
|
| 132 |
static USBH_StatusTypeDef USBH_AC_GetMin(USBH_HandleTypeDef *phost, |
| 133 |
uint8_t subtype, |
| 134 |
uint8_t feature, |
| 135 |
uint8_t controlSelector, |
| 136 |
uint8_t channel, |
| 137 |
uint16_t length); |
| 138 |
|
| 139 |
static USBH_StatusTypeDef USBH_AC_GetMax(USBH_HandleTypeDef *phost, |
| 140 |
uint8_t subtype, |
| 141 |
uint8_t feature, |
| 142 |
uint8_t controlSelector, |
| 143 |
uint8_t channel, |
| 144 |
uint16_t length); |
| 145 |
|
| 146 |
static USBH_StatusTypeDef USBH_AC_GetRes(USBH_HandleTypeDef *phost, |
| 147 |
uint8_t subtype, |
| 148 |
uint8_t feature, |
| 149 |
uint8_t controlSelector, |
| 150 |
uint8_t channel, |
| 151 |
uint16_t length); |
| 152 |
|
| 153 |
static USBH_StatusTypeDef USBH_AUDIO_SetEndpointControls(USBH_HandleTypeDef *phost, |
| 154 |
uint8_t Ep, |
| 155 |
uint8_t *buff); |
| 156 |
|
| 157 |
static USBH_StatusTypeDef AUDIO_SetVolume (USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel, uint16_t volume); |
| 158 |
|
| 159 |
static USBH_StatusTypeDef USBH_AUDIO_InputStream (USBH_HandleTypeDef *phost); |
| 160 |
static USBH_StatusTypeDef USBH_AUDIO_OutputStream (USBH_HandleTypeDef *phost); |
| 161 |
static USBH_StatusTypeDef USBH_AUDIO_Control (USBH_HandleTypeDef *phost); |
| 162 |
static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute (USBH_HandleTypeDef *phost, uint8_t attrib); |
| 163 |
static int32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t UnitID); |
| 164 |
|
| 165 |
USBH_ClassTypeDef AUDIO_Class = |
| 166 |
{ |
| 167 |
"AUDIO", |
| 168 |
AC_CLASS, |
| 169 |
USBH_AUDIO_InterfaceInit, |
| 170 |
USBH_AUDIO_InterfaceDeInit, |
| 171 |
USBH_AUDIO_ClassRequest, |
| 172 |
USBH_AUDIO_Process, |
| 173 |
USBH_AUDIO_SOFProcess, |
| 174 |
NULL, |
| 175 |
}; |
| 176 |
|
| 177 |
/** |
| 178 |
* @} |
| 179 |
*/ |
| 180 |
|
| 181 |
/** @defgroup USBH_AUDIO_CORE_Private_Functions |
| 182 |
* @{ |
| 183 |
*/ |
| 184 |
|
| 185 |
/** |
| 186 |
* @brief USBH_AUDIO_InterfaceInit |
| 187 |
* The function init the Audio class. |
| 188 |
* @param phost: Host handle |
| 189 |
* @retval USBH Status |
| 190 |
*/ |
| 191 |
static USBH_StatusTypeDef USBH_AUDIO_InterfaceInit (USBH_HandleTypeDef *phost) |
| 192 |
{ |
| 193 |
USBH_StatusTypeDef status = USBH_FAIL ; |
| 194 |
USBH_StatusTypeDef out_status, in_status ; |
| 195 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 196 |
uint8_t interface, index; |
| 197 |
uint16_t ep_size_out = 0; |
| 198 |
uint16_t ep_size_in = 0; |
| 199 |
|
| 200 |
interface = USBH_FindInterface(phost, AC_CLASS, USB_SUBCLASS_AUDIOCONTROL, 0x00); |
| 201 |
|
| 202 |
if(interface == 0xFF) /* Not Valid Interface */ |
| 203 |
{ |
| 204 |
USBH_DbgLog ("Cannot Find the interface for %s class.", phost->pActiveClass->Name); |
| 205 |
status = USBH_FAIL; |
| 206 |
} |
| 207 |
else |
| 208 |
{ |
| 209 |
|
| 210 |
|
| 211 |
phost->pActiveClass->pData = (AUDIO_HandleTypeDef *)USBH_malloc (sizeof(AUDIO_HandleTypeDef)); |
| 212 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 213 |
USBH_memset(AUDIO_Handle, 0, sizeof(AUDIO_HandleTypeDef)); |
| 214 |
|
| 215 |
|
| 216 |
/* 1st Step: Find Audio Interfaces */ |
| 217 |
out_status = USBH_AUDIO_FindAudioStreamingIN (phost); |
| 218 |
|
| 219 |
in_status = USBH_AUDIO_FindAudioStreamingOUT(phost); |
| 220 |
|
| 221 |
if((out_status == USBH_FAIL) && (in_status == USBH_FAIL)) |
| 222 |
{ |
| 223 |
USBH_DbgLog ("%s class configuration not supported.", phost->pActiveClass->Name); |
| 224 |
} |
| 225 |
else |
| 226 |
{ |
| 227 |
/* 2nd Step: Select Audio Streaming Interfaces with largest endpoint size : default behavior*/ |
| 228 |
for (index = 0; index < AUDIO_MAX_AUDIO_STD_INTERFACE; index ++) |
| 229 |
{ |
| 230 |
if( AUDIO_Handle->stream_out[index].valid == 1) |
| 231 |
{ |
| 232 |
if(ep_size_out < AUDIO_Handle->stream_out[index].EpSize) |
| 233 |
{ |
| 234 |
ep_size_out = AUDIO_Handle->stream_out[index].EpSize; |
| 235 |
AUDIO_Handle->headphone.interface = AUDIO_Handle->stream_out[index].interface; |
| 236 |
AUDIO_Handle->headphone.AltSettings = AUDIO_Handle->stream_out[index].AltSettings; |
| 237 |
AUDIO_Handle->headphone.Ep = AUDIO_Handle->stream_out[index].Ep; |
| 238 |
AUDIO_Handle->headphone.EpSize = AUDIO_Handle->stream_out[index].EpSize; |
| 239 |
AUDIO_Handle->headphone.Poll = AUDIO_Handle->stream_out[index].Poll; |
| 240 |
AUDIO_Handle->headphone.supported = 1; |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
if( AUDIO_Handle->stream_in[index].valid == 1) |
| 245 |
{ |
| 246 |
if(ep_size_in < AUDIO_Handle->stream_in[index].EpSize) |
| 247 |
{ |
| 248 |
ep_size_in = AUDIO_Handle->stream_in[index].EpSize; |
| 249 |
AUDIO_Handle->microphone.interface = AUDIO_Handle->stream_in[index].interface; |
| 250 |
AUDIO_Handle->microphone.AltSettings = AUDIO_Handle->stream_in[index].AltSettings; |
| 251 |
AUDIO_Handle->microphone.Ep = AUDIO_Handle->stream_in[index].Ep; |
| 252 |
AUDIO_Handle->microphone.EpSize = AUDIO_Handle->stream_in[index].EpSize; |
| 253 |
AUDIO_Handle->microphone.Poll = AUDIO_Handle->stream_out[index].Poll; |
| 254 |
AUDIO_Handle->microphone.supported = 1; |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
|
| 259 |
if(USBH_AUDIO_FindHIDControl(phost) == USBH_OK) |
| 260 |
{ |
| 261 |
AUDIO_Handle->control.supported = 1; |
| 262 |
} |
| 263 |
|
| 264 |
/* 3rd Step: Find and Parse Audio interfaces */ |
| 265 |
USBH_AUDIO_ParseCSDescriptors (phost); |
| 266 |
|
| 267 |
|
| 268 |
/* 4th Step: Open the Audio streaming pipes*/ |
| 269 |
if(AUDIO_Handle->headphone.supported == 1) |
| 270 |
{ |
| 271 |
USBH_AUDIO_BuildHeadphonePath (phost); |
| 272 |
|
| 273 |
AUDIO_Handle->headphone.Pipe = USBH_AllocPipe(phost, AUDIO_Handle->headphone.Ep); |
| 274 |
|
| 275 |
/* Open pipe for IN endpoint */ |
| 276 |
USBH_OpenPipe (phost, |
| 277 |
AUDIO_Handle->headphone.Pipe, |
| 278 |
AUDIO_Handle->headphone.Ep, |
| 279 |
phost->device.address, |
| 280 |
phost->device.speed, |
| 281 |
USB_EP_TYPE_ISOC, |
| 282 |
AUDIO_Handle->headphone.EpSize); |
| 283 |
|
| 284 |
USBH_LL_SetToggle (phost, AUDIO_Handle->headphone.Pipe, 0); |
| 285 |
|
| 286 |
} |
| 287 |
|
| 288 |
if(AUDIO_Handle->microphone.supported == 1) |
| 289 |
{ |
| 290 |
USBH_AUDIO_BuildMicrophonePath (phost); |
| 291 |
AUDIO_Handle->microphone.Pipe = USBH_AllocPipe(phost, AUDIO_Handle->microphone.Ep); |
| 292 |
|
| 293 |
/* Open pipe for IN endpoint */ |
| 294 |
USBH_OpenPipe (phost, |
| 295 |
AUDIO_Handle->microphone.Pipe, |
| 296 |
AUDIO_Handle->microphone.Ep, |
| 297 |
phost->device.address, |
| 298 |
phost->device.speed, |
| 299 |
USB_EP_TYPE_ISOC, |
| 300 |
AUDIO_Handle->microphone.EpSize); |
| 301 |
|
| 302 |
USBH_LL_SetToggle (phost, AUDIO_Handle->microphone.Pipe, 0); |
| 303 |
} |
| 304 |
|
| 305 |
if(AUDIO_Handle->control.supported == 1) |
| 306 |
{ |
| 307 |
AUDIO_Handle->control.Pipe = USBH_AllocPipe(phost, AUDIO_Handle->control.Ep); |
| 308 |
|
| 309 |
/* Open pipe for IN endpoint */ |
| 310 |
USBH_OpenPipe (phost, |
| 311 |
AUDIO_Handle->control.Pipe, |
| 312 |
AUDIO_Handle->control.Ep, |
| 313 |
phost->device.address, |
| 314 |
phost->device.speed, |
| 315 |
USB_EP_TYPE_INTR, |
| 316 |
AUDIO_Handle->control.EpSize); |
| 317 |
|
| 318 |
USBH_LL_SetToggle (phost, AUDIO_Handle->control.Pipe, 0); |
| 319 |
|
| 320 |
} |
| 321 |
|
| 322 |
AUDIO_Handle->req_state = AUDIO_REQ_INIT; |
| 323 |
AUDIO_Handle->control_state = AUDIO_CONTROL_INIT; |
| 324 |
|
| 325 |
status = USBH_OK; |
| 326 |
} |
| 327 |
} |
| 328 |
return status; |
| 329 |
} |
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
/** |
| 334 |
* @brief USBH_AUDIO_InterfaceDeInit |
| 335 |
* The function DeInit the Pipes used for the Audio class. |
| 336 |
* @param phost: Host handle |
| 337 |
* @retval USBH Status |
| 338 |
*/ |
| 339 |
USBH_StatusTypeDef USBH_AUDIO_InterfaceDeInit (USBH_HandleTypeDef *phost) |
| 340 |
{ |
| 341 |
AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData; |
| 342 |
|
| 343 |
if(AUDIO_Handle->microphone.Pipe != 0x00) |
| 344 |
{ |
| 345 |
USBH_ClosePipe (phost, AUDIO_Handle->microphone.Pipe); |
| 346 |
USBH_FreePipe (phost, AUDIO_Handle->microphone.Pipe); |
| 347 |
AUDIO_Handle->microphone.Pipe = 0; /* Reset the pipe as Free */ |
| 348 |
} |
| 349 |
|
| 350 |
if( AUDIO_Handle->headphone.Pipe != 0x00) |
| 351 |
{ |
| 352 |
USBH_ClosePipe(phost, AUDIO_Handle->headphone.Pipe); |
| 353 |
USBH_FreePipe (phost, AUDIO_Handle->headphone.Pipe); |
| 354 |
AUDIO_Handle->headphone.Pipe = 0; /* Reset the pipe as Free */ |
| 355 |
} |
| 356 |
|
| 357 |
if( AUDIO_Handle->control.Pipe != 0x00) |
| 358 |
{ |
| 359 |
USBH_ClosePipe(phost, AUDIO_Handle->control.Pipe); |
| 360 |
USBH_FreePipe (phost, AUDIO_Handle->control.Pipe); |
| 361 |
AUDIO_Handle->control.Pipe = 0; /* Reset the pipe as Free */ |
| 362 |
} |
| 363 |
|
| 364 |
if(phost->pActiveClass->pData) |
| 365 |
{ |
| 366 |
USBH_free (phost->pActiveClass->pData); |
| 367 |
phost->pActiveClass->pData = 0; |
| 368 |
} |
| 369 |
return USBH_OK ; |
| 370 |
} |
| 371 |
|
| 372 |
/** |
| 373 |
* @brief USBH_AUDIO_ClassRequest |
| 374 |
* The function is responsible for handling Standard requests |
| 375 |
* for Audio class. |
| 376 |
* @param phost: Host handle |
| 377 |
* @retval USBH Status |
| 378 |
*/ |
| 379 |
static USBH_StatusTypeDef USBH_AUDIO_ClassRequest(USBH_HandleTypeDef *phost) |
| 380 |
{ |
| 381 |
AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData; |
| 382 |
USBH_StatusTypeDef status = USBH_BUSY; |
| 383 |
USBH_StatusTypeDef req_status = USBH_BUSY; |
| 384 |
|
| 385 |
/* Switch AUDIO REQ state machine */ |
| 386 |
switch (AUDIO_Handle->req_state) |
| 387 |
{ |
| 388 |
case AUDIO_REQ_INIT: |
| 389 |
case AUDIO_REQ_SET_DEFAULT_IN_INTERFACE: |
| 390 |
if(AUDIO_Handle->microphone.supported == 1) |
| 391 |
{ |
| 392 |
req_status = USBH_SetInterface(phost, |
| 393 |
AUDIO_Handle->microphone.interface, |
| 394 |
0); |
| 395 |
|
| 396 |
if(req_status == USBH_OK) |
| 397 |
{ |
| 398 |
AUDIO_Handle->req_state = AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE; |
| 399 |
} |
| 400 |
|
| 401 |
} |
| 402 |
else |
| 403 |
{ |
| 404 |
AUDIO_Handle->req_state = AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE; |
| 405 |
#if (USBH_USE_OS == 1) |
| 406 |
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0); |
| 407 |
#endif |
| 408 |
} |
| 409 |
break; |
| 410 |
|
| 411 |
case AUDIO_REQ_SET_DEFAULT_OUT_INTERFACE: |
| 412 |
if(AUDIO_Handle->headphone.supported == 1) |
| 413 |
{ |
| 414 |
req_status = USBH_SetInterface(phost, |
| 415 |
AUDIO_Handle->headphone.interface, |
| 416 |
0); |
| 417 |
|
| 418 |
if(req_status == USBH_OK) |
| 419 |
{ |
| 420 |
AUDIO_Handle->req_state = AUDIO_REQ_CS_REQUESTS; |
| 421 |
AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME; |
| 422 |
|
| 423 |
AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; |
| 424 |
AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels; |
| 425 |
} |
| 426 |
} |
| 427 |
else |
| 428 |
{ |
| 429 |
AUDIO_Handle->req_state = AUDIO_REQ_CS_REQUESTS; |
| 430 |
AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME; |
| 431 |
#if (USBH_USE_OS == 1) |
| 432 |
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0); |
| 433 |
#endif |
| 434 |
} |
| 435 |
break; |
| 436 |
|
| 437 |
case AUDIO_REQ_CS_REQUESTS: |
| 438 |
if(USBH_AUDIO_HandleCSRequest (phost) == USBH_OK) |
| 439 |
{ |
| 440 |
AUDIO_Handle->req_state = AUDIO_REQ_SET_IN_INTERFACE; |
| 441 |
} |
| 442 |
break; |
| 443 |
|
| 444 |
case AUDIO_REQ_SET_IN_INTERFACE: |
| 445 |
if(AUDIO_Handle->microphone.supported == 1) |
| 446 |
{ |
| 447 |
req_status = USBH_SetInterface(phost, |
| 448 |
AUDIO_Handle->microphone.interface, |
| 449 |
AUDIO_Handle->microphone.AltSettings); |
| 450 |
|
| 451 |
if(req_status == USBH_OK) |
| 452 |
{ |
| 453 |
AUDIO_Handle->req_state = AUDIO_REQ_SET_OUT_INTERFACE; |
| 454 |
} |
| 455 |
} |
| 456 |
else |
| 457 |
{ |
| 458 |
AUDIO_Handle->req_state = AUDIO_REQ_SET_OUT_INTERFACE; |
| 459 |
#if (USBH_USE_OS == 1) |
| 460 |
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0); |
| 461 |
#endif |
| 462 |
} |
| 463 |
break; |
| 464 |
case AUDIO_REQ_SET_OUT_INTERFACE: |
| 465 |
if(AUDIO_Handle->headphone.supported == 1) |
| 466 |
{ |
| 467 |
req_status = USBH_SetInterface(phost, |
| 468 |
AUDIO_Handle->headphone.interface, |
| 469 |
AUDIO_Handle->headphone.AltSettings); |
| 470 |
|
| 471 |
if(req_status == USBH_OK) |
| 472 |
{ |
| 473 |
AUDIO_Handle->req_state = AUDIO_REQ_IDLE; |
| 474 |
} |
| 475 |
|
| 476 |
} |
| 477 |
else |
| 478 |
{ |
| 479 |
AUDIO_Handle->req_state = AUDIO_REQ_IDLE; |
| 480 |
#if (USBH_USE_OS == 1) |
| 481 |
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0); |
| 482 |
#endif |
| 483 |
} |
| 484 |
break; |
| 485 |
case AUDIO_REQ_IDLE: |
| 486 |
AUDIO_Handle->play_state = AUDIO_PLAYBACK_INIT; |
| 487 |
phost->pUser(phost, HOST_USER_CLASS_ACTIVE); |
| 488 |
status = USBH_OK; |
| 489 |
#if (USBH_USE_OS == 1) |
| 490 |
osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0); |
| 491 |
#endif |
| 492 |
default: |
| 493 |
break; |
| 494 |
} |
| 495 |
return status; |
| 496 |
} |
| 497 |
|
| 498 |
/** |
| 499 |
* @brief USBH_AUDIO_CSRequest |
| 500 |
* The function is responsible for handling AC Specific requests for a specific feature and channel |
| 501 |
* for Audio class. |
| 502 |
* @param phost: Host handle |
| 503 |
* @retval USBH Status |
| 504 |
*/ |
| 505 |
static USBH_StatusTypeDef USBH_AUDIO_CSRequest(USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel) |
| 506 |
{ |
| 507 |
AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData; |
| 508 |
USBH_StatusTypeDef status = USBH_BUSY; |
| 509 |
USBH_StatusTypeDef req_status = USBH_BUSY; |
| 510 |
|
| 511 |
/* Switch AUDIO REQ state machine */ |
| 512 |
switch (AUDIO_Handle->cs_req_state) |
| 513 |
{ |
| 514 |
case AUDIO_REQ_GET_VOLUME: |
| 515 |
req_status = USBH_AC_GetCur(phost, |
| 516 |
UAC_FEATURE_UNIT, /* subtype */ |
| 517 |
feature, /* feature */ |
| 518 |
VOLUME_CONTROL, /* Selector */ |
| 519 |
channel, /* channel */ |
| 520 |
0x02); /* length */ |
| 521 |
if(req_status != USBH_BUSY) |
| 522 |
{ |
| 523 |
AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_MIN_VOLUME; |
| 524 |
AUDIO_Handle->headphone.attribute.volume = LE16(&(AUDIO_Handle->mem[0])); |
| 525 |
} |
| 526 |
break; |
| 527 |
|
| 528 |
case AUDIO_REQ_GET_MIN_VOLUME: |
| 529 |
req_status = USBH_AC_GetMin(phost, |
| 530 |
UAC_FEATURE_UNIT, /* subtype */ |
| 531 |
feature, /* feature */ |
| 532 |
VOLUME_CONTROL, /* Selector */ |
| 533 |
channel, /* channel */ |
| 534 |
0x02); /* length */ |
| 535 |
if(req_status != USBH_BUSY) |
| 536 |
{ |
| 537 |
AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_MAX_VOLUME; |
| 538 |
AUDIO_Handle->headphone.attribute.volumeMin = LE16(&AUDIO_Handle->mem[0]); |
| 539 |
} |
| 540 |
break; |
| 541 |
|
| 542 |
case AUDIO_REQ_GET_MAX_VOLUME: |
| 543 |
req_status = USBH_AC_GetMax(phost, |
| 544 |
UAC_FEATURE_UNIT, /* subtype */ |
| 545 |
feature, /* feature */ |
| 546 |
VOLUME_CONTROL, /* Selector */ |
| 547 |
channel, /* channel */ |
| 548 |
0x02); /* length */ |
| 549 |
if(req_status != USBH_BUSY) |
| 550 |
{ |
| 551 |
AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_RESOLUTION; |
| 552 |
AUDIO_Handle->headphone.attribute.volumeMax = LE16(&AUDIO_Handle->mem[0]); |
| 553 |
|
| 554 |
if (AUDIO_Handle->headphone.attribute.volumeMax < AUDIO_Handle->headphone.attribute.volumeMin) |
| 555 |
{ |
| 556 |
AUDIO_Handle->headphone.attribute.volumeMax = 0xFF00; |
| 557 |
} |
| 558 |
} |
| 559 |
break; |
| 560 |
|
| 561 |
case AUDIO_REQ_GET_RESOLUTION: |
| 562 |
req_status = USBH_AC_GetRes(phost, |
| 563 |
UAC_FEATURE_UNIT, /* subtype */ |
| 564 |
feature, /* feature */ |
| 565 |
VOLUME_CONTROL, /* Selector */ |
| 566 |
channel, /* channel */ |
| 567 |
0x02); /* length */ |
| 568 |
if(req_status != USBH_BUSY) |
| 569 |
{ |
| 570 |
AUDIO_Handle->cs_req_state = AUDIO_REQ_CS_IDLE; |
| 571 |
AUDIO_Handle->headphone.attribute.resolution = LE16(&AUDIO_Handle->mem[0]); |
| 572 |
} |
| 573 |
break; |
| 574 |
|
| 575 |
|
| 576 |
case AUDIO_REQ_CS_IDLE: |
| 577 |
status = USBH_OK; |
| 578 |
default: |
| 579 |
break; |
| 580 |
} |
| 581 |
return status; |
| 582 |
} |
| 583 |
|
| 584 |
/** |
| 585 |
* @brief USBH_AUDIO_HandleCSRequest |
| 586 |
* The function is responsible for handling AC Specific requests for a all features |
| 587 |
* and associated channels for Audio class. |
| 588 |
* @param phost: Host handle |
| 589 |
* @retval USBH Status |
| 590 |
*/ |
| 591 |
static USBH_StatusTypeDef USBH_AUDIO_HandleCSRequest(USBH_HandleTypeDef *phost) |
| 592 |
{ |
| 593 |
|
| 594 |
USBH_StatusTypeDef status = USBH_BUSY; |
| 595 |
USBH_StatusTypeDef cs_status = USBH_BUSY; |
| 596 |
AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData; |
| 597 |
|
| 598 |
cs_status = USBH_AUDIO_CSRequest(phost, |
| 599 |
AUDIO_Handle->temp_feature, |
| 600 |
AUDIO_Handle->temp_channels); |
| 601 |
|
| 602 |
if(cs_status != USBH_BUSY) |
| 603 |
{ |
| 604 |
|
| 605 |
if(AUDIO_Handle->temp_channels == 1) |
| 606 |
{ |
| 607 |
AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; |
| 608 |
AUDIO_Handle->temp_channels = 0; |
| 609 |
status = USBH_OK; |
| 610 |
} |
| 611 |
else |
| 612 |
{ |
| 613 |
AUDIO_Handle->temp_channels--; |
| 614 |
} |
| 615 |
AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME; |
| 616 |
#if (USBH_USE_OS == 1) |
| 617 |
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0); |
| 618 |
#endif |
| 619 |
} |
| 620 |
|
| 621 |
return status; |
| 622 |
} |
| 623 |
|
| 624 |
/** |
| 625 |
* @brief USBH_AUDIO_Process |
| 626 |
* The function is for managing state machine for Audio data transfers |
| 627 |
* @param phost: Host handle |
| 628 |
* @retval USBH Status |
| 629 |
*/ |
| 630 |
static USBH_StatusTypeDef USBH_AUDIO_Process (USBH_HandleTypeDef *phost) |
| 631 |
{ |
| 632 |
USBH_StatusTypeDef status = USBH_BUSY; |
| 633 |
AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData; |
| 634 |
|
| 635 |
if(AUDIO_Handle->headphone.supported == 1) |
| 636 |
{ |
| 637 |
USBH_AUDIO_OutputStream (phost); |
| 638 |
} |
| 639 |
|
| 640 |
if(AUDIO_Handle->microphone.supported == 1) |
| 641 |
{ |
| 642 |
USBH_AUDIO_InputStream (phost); |
| 643 |
} |
| 644 |
|
| 645 |
return status; |
| 646 |
} |
| 647 |
|
| 648 |
/** |
| 649 |
* @brief USBH_AUDIO_SOFProcess |
| 650 |
* The function is for managing the SOF callback |
| 651 |
* @param phost: Host handle |
| 652 |
* @retval USBH Status |
| 653 |
*/ |
| 654 |
static USBH_StatusTypeDef USBH_AUDIO_SOFProcess (USBH_HandleTypeDef *phost) |
| 655 |
{ |
| 656 |
return USBH_OK; |
| 657 |
} |
| 658 |
/** |
| 659 |
* @brief Find IN Audio Streaming interfaces |
| 660 |
* @param phost: Host handle |
| 661 |
* @retval USBH Status |
| 662 |
*/ |
| 663 |
static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingIN(USBH_HandleTypeDef *phost) |
| 664 |
{ |
| 665 |
uint8_t interface, alt_settings; |
| 666 |
USBH_StatusTypeDef status = USBH_FAIL ; |
| 667 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 668 |
|
| 669 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 670 |
|
| 671 |
/* Look For AUDIOSTREAMING IN interface */ |
| 672 |
alt_settings = 0; |
| 673 |
for (interface = 0; interface < USBH_MAX_NUM_INTERFACES ; interface ++ ) |
| 674 |
{ |
| 675 |
if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == AC_CLASS)&& |
| 676 |
(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass == USB_SUBCLASS_AUDIOSTREAMING)) |
| 677 |
{ |
| 678 |
if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80)&& |
| 679 |
(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0)) |
| 680 |
{ |
| 681 |
AUDIO_Handle->stream_in[alt_settings].Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; |
| 682 |
AUDIO_Handle->stream_in[alt_settings].EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; |
| 683 |
AUDIO_Handle->stream_in[alt_settings].interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber; |
| 684 |
AUDIO_Handle->stream_in[alt_settings].AltSettings = phost->device.CfgDesc.Itf_Desc[interface].bAlternateSetting; |
| 685 |
AUDIO_Handle->stream_in[alt_settings].Poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bInterval; |
| 686 |
AUDIO_Handle->stream_in[alt_settings].valid = 1; |
| 687 |
alt_settings++; |
| 688 |
} |
| 689 |
} |
| 690 |
} |
| 691 |
|
| 692 |
if(alt_settings > 0) |
| 693 |
{ |
| 694 |
status = USBH_OK; |
| 695 |
} |
| 696 |
|
| 697 |
return status; |
| 698 |
} |
| 699 |
|
| 700 |
/** |
| 701 |
* @brief Find OUT Audio Streaming interfaces |
| 702 |
* @param phost: Host handle |
| 703 |
* @retval USBH Status |
| 704 |
*/ |
| 705 |
static USBH_StatusTypeDef USBH_AUDIO_FindAudioStreamingOUT(USBH_HandleTypeDef *phost) |
| 706 |
{ |
| 707 |
uint8_t interface, alt_settings; |
| 708 |
USBH_StatusTypeDef status = USBH_FAIL ; |
| 709 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 710 |
|
| 711 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 712 |
|
| 713 |
/* Look For AUDIOSTREAMING IN interface */ |
| 714 |
alt_settings = 0; |
| 715 |
for (interface = 0; interface < USBH_MAX_NUM_INTERFACES ; interface ++ ) |
| 716 |
{ |
| 717 |
if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == AC_CLASS)&& |
| 718 |
(phost->device.CfgDesc.Itf_Desc[interface].bInterfaceSubClass == USB_SUBCLASS_AUDIOSTREAMING)) |
| 719 |
{ |
| 720 |
if(((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80) == 0x00)&& |
| 721 |
(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0)) |
| 722 |
{ |
| 723 |
AUDIO_Handle->stream_out[alt_settings].Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; |
| 724 |
AUDIO_Handle->stream_out[alt_settings].EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; |
| 725 |
AUDIO_Handle->stream_out[alt_settings].interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber; |
| 726 |
AUDIO_Handle->stream_out[alt_settings].AltSettings = phost->device.CfgDesc.Itf_Desc[interface].bAlternateSetting; |
| 727 |
AUDIO_Handle->stream_out[alt_settings].Poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bInterval; |
| 728 |
AUDIO_Handle->stream_out[alt_settings].valid = 1; |
| 729 |
alt_settings++; |
| 730 |
} |
| 731 |
} |
| 732 |
} |
| 733 |
|
| 734 |
if(alt_settings > 0) |
| 735 |
{ |
| 736 |
status = USBH_OK; |
| 737 |
} |
| 738 |
|
| 739 |
return status; |
| 740 |
} |
| 741 |
|
| 742 |
/** |
| 743 |
* @brief Find HID Control interfaces |
| 744 |
* @param phost: Host handle |
| 745 |
* @retval USBH Status |
| 746 |
*/ |
| 747 |
static USBH_StatusTypeDef USBH_AUDIO_FindHIDControl(USBH_HandleTypeDef *phost) |
| 748 |
{ |
| 749 |
uint8_t interface; |
| 750 |
USBH_StatusTypeDef status = USBH_FAIL ; |
| 751 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 752 |
|
| 753 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 754 |
|
| 755 |
/* Look For AUDIOCONTROL interface */ |
| 756 |
interface = USBH_FindInterface(phost, AC_CLASS, USB_SUBCLASS_AUDIOCONTROL, 0xFF); |
| 757 |
if(interface != 0xFF) |
| 758 |
{ |
| 759 |
for (interface = 0; interface < USBH_MAX_NUM_INTERFACES ; interface ++ ) |
| 760 |
{ |
| 761 |
if((phost->device.CfgDesc.Itf_Desc[interface].bInterfaceClass == 0x03)&& /*HID*/ |
| 762 |
(phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize > 0)) |
| 763 |
{ |
| 764 |
if((phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress & 0x80) == 0x80) |
| 765 |
{ |
| 766 |
AUDIO_Handle->control.Ep = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bEndpointAddress; |
| 767 |
AUDIO_Handle->control.EpSize = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].wMaxPacketSize; |
| 768 |
AUDIO_Handle->control.interface = phost->device.CfgDesc.Itf_Desc[interface].bInterfaceNumber; |
| 769 |
AUDIO_Handle->control.Poll = phost->device.CfgDesc.Itf_Desc[interface].Ep_Desc[0].bInterval; |
| 770 |
AUDIO_Handle->control.supported = 1; |
| 771 |
status = USBH_OK; |
| 772 |
break; |
| 773 |
} |
| 774 |
} |
| 775 |
} |
| 776 |
} |
| 777 |
return status; |
| 778 |
} |
| 779 |
|
| 780 |
/** |
| 781 |
* @brief Parse AC and interfaces Descriptors |
| 782 |
* @param phost: Host handle |
| 783 |
* @retval USBH Status |
| 784 |
*/ |
| 785 |
static USBH_StatusTypeDef USBH_AUDIO_ParseCSDescriptors(USBH_HandleTypeDef *phost) |
| 786 |
{ |
| 787 |
USBH_DescHeader_t *pdesc ; |
| 788 |
uint16_t ptr; |
| 789 |
int8_t itf_index = 0; |
| 790 |
int8_t itf_number = 0; |
| 791 |
int8_t alt_setting; |
| 792 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 793 |
|
| 794 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 795 |
pdesc = (USBH_DescHeader_t *)(phost->device.CfgDesc_Raw); |
| 796 |
ptr = USB_LEN_CFG_DESC; |
| 797 |
|
| 798 |
AUDIO_Handle->class_desc.FeatureUnitNum = 0; |
| 799 |
AUDIO_Handle->class_desc.InputTerminalNum = 0; |
| 800 |
AUDIO_Handle->class_desc.OutputTerminalNum = 0; |
| 801 |
AUDIO_Handle->class_desc.ASNum = 0; |
| 802 |
|
| 803 |
while(ptr < phost->device.CfgDesc.wTotalLength) |
| 804 |
{ |
| 805 |
pdesc = USBH_GetNextDesc((void *)pdesc, &ptr); |
| 806 |
|
| 807 |
switch (pdesc->bDescriptorType) |
| 808 |
{ |
| 809 |
|
| 810 |
case USB_DESC_TYPE_INTERFACE: |
| 811 |
itf_number = *((uint8_t *)pdesc + 2); |
| 812 |
alt_setting = *((uint8_t *)pdesc + 3); |
| 813 |
itf_index = USBH_FindInterfaceIndex (phost, itf_number, alt_setting); |
| 814 |
break; |
| 815 |
|
| 816 |
case USB_DESC_TYPE_CS_INTERFACE: |
| 817 |
if(itf_number <= phost->device.CfgDesc.bNumInterfaces) |
| 818 |
{ |
| 819 |
|
| 820 |
ParseCSDescriptors(&AUDIO_Handle->class_desc, |
| 821 |
phost->device.CfgDesc.Itf_Desc[itf_index].bInterfaceSubClass, |
| 822 |
(uint8_t *)pdesc); |
| 823 |
} |
| 824 |
break; |
| 825 |
|
| 826 |
default: |
| 827 |
break; |
| 828 |
} |
| 829 |
} |
| 830 |
return USBH_OK; |
| 831 |
} |
| 832 |
|
| 833 |
/** |
| 834 |
* @brief Parse AC interfaces |
| 835 |
* @param phost: Host handle |
| 836 |
* @retval USBH Status |
| 837 |
*/ |
| 838 |
static USBH_StatusTypeDef ParseCSDescriptors(AUDIO_ClassSpecificDescTypedef *class_desc, |
| 839 |
uint8_t ac_subclass, |
| 840 |
uint8_t *pdesc) |
| 841 |
{ |
| 842 |
if(ac_subclass == USB_SUBCLASS_AUDIOCONTROL) |
| 843 |
{ |
| 844 |
switch(pdesc[2]) |
| 845 |
{ |
| 846 |
case UAC_HEADER: |
| 847 |
class_desc->cs_desc.HeaderDesc = (AUDIO_HeaderDescTypeDef *)pdesc; |
| 848 |
break; |
| 849 |
|
| 850 |
case UAC_INPUT_TERMINAL: |
| 851 |
class_desc->cs_desc.InputTerminalDesc[class_desc->InputTerminalNum++] = (AUDIO_ITDescTypeDef*) pdesc; |
| 852 |
break; |
| 853 |
|
| 854 |
case UAC_OUTPUT_TERMINAL: |
| 855 |
class_desc->cs_desc.OutputTerminalDesc[class_desc->OutputTerminalNum++] = (AUDIO_OTDescTypeDef*) pdesc; |
| 856 |
break; |
| 857 |
|
| 858 |
case UAC_FEATURE_UNIT: |
| 859 |
class_desc->cs_desc.FeatureUnitDesc[class_desc->FeatureUnitNum++] = (AUDIO_FeatureDescTypeDef*) pdesc; |
| 860 |
break; |
| 861 |
|
| 862 |
case UAC_SELECTOR_UNIT: |
| 863 |
class_desc->cs_desc.SelectorUnitDesc[class_desc->SelectorUnitNum++] = (AUDIO_SelectorDescTypeDef*) pdesc; |
| 864 |
break; |
| 865 |
|
| 866 |
case UAC_MIXER_UNIT: |
| 867 |
class_desc->cs_desc.MixerUnitDesc[class_desc->MixerUnitNum++] = (AUDIO_MixerDescTypeDef*) pdesc; |
| 868 |
break; |
| 869 |
|
| 870 |
default: |
| 871 |
break; |
| 872 |
} |
| 873 |
} |
| 874 |
else if(ac_subclass == USB_SUBCLASS_AUDIOSTREAMING) |
| 875 |
{ |
| 876 |
switch(pdesc[2]) |
| 877 |
{ |
| 878 |
case UAC_AS_GENERAL: |
| 879 |
class_desc->as_desc[class_desc->ASNum].GeneralDesc = (AUDIO_ASGeneralDescTypeDef*) pdesc; |
| 880 |
break; |
| 881 |
case UAC_FORMAT_TYPE: |
| 882 |
class_desc->as_desc[class_desc->ASNum++].FormatTypeDesc = (AUDIO_ASFormatTypeDescTypeDef*) pdesc; |
| 883 |
break; |
| 884 |
default: |
| 885 |
break; |
| 886 |
} |
| 887 |
} |
| 888 |
|
| 889 |
return USBH_OK; |
| 890 |
} |
| 891 |
|
| 892 |
|
| 893 |
/** |
| 894 |
* @brief Link a Unit to next associated one |
| 895 |
* @param phost: Host handle |
| 896 |
* @param UnitID: Unit identifer |
| 897 |
* @retval UnitID, Index and Type of the assicated Unit |
| 898 |
*/ |
| 899 |
static int32_t USBH_AUDIO_FindLinkedUnit(USBH_HandleTypeDef *phost, uint8_t UnitID) |
| 900 |
{ |
| 901 |
uint8_t Index; |
| 902 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 903 |
|
| 904 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 905 |
|
| 906 |
/* Find Feature Unit */ |
| 907 |
for(Index = 0; Index < AUDIO_Handle->class_desc.FeatureUnitNum; Index ++) |
| 908 |
{ |
| 909 |
if(AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[Index]->bSourceID == UnitID) |
| 910 |
{ |
| 911 |
UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[Index]->bUnitID; |
| 912 |
|
| 913 |
return ((UnitID << 16) | (UAC_FEATURE_UNIT << 8) | Index); |
| 914 |
} |
| 915 |
} |
| 916 |
|
| 917 |
/* Find Mixer Unit */ |
| 918 |
for(Index = 0; Index < AUDIO_Handle->class_desc.MixerUnitNum; Index ++) |
| 919 |
{ |
| 920 |
if((AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bSourceID0 == UnitID)|| |
| 921 |
(AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bSourceID1 == UnitID)) |
| 922 |
{ |
| 923 |
UnitID = AUDIO_Handle->class_desc.cs_desc.MixerUnitDesc[Index]->bUnitID; |
| 924 |
|
| 925 |
return ((UnitID << 16) | (UAC_MIXER_UNIT << 8) | Index); |
| 926 |
} |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
/* Find Selector Unit */ |
| 931 |
for(Index = 0; Index < AUDIO_Handle->class_desc.SelectorUnitNum; Index ++) |
| 932 |
{ |
| 933 |
if(AUDIO_Handle->class_desc.cs_desc.SelectorUnitDesc[Index]->bSourceID0 == UnitID) |
| 934 |
{ |
| 935 |
UnitID = AUDIO_Handle->class_desc.cs_desc.SelectorUnitDesc[Index]->bUnitID; |
| 936 |
|
| 937 |
return ((UnitID << 16) | (UAC_SELECTOR_UNIT << 8) | Index); |
| 938 |
} |
| 939 |
} |
| 940 |
|
| 941 |
|
| 942 |
/* Find OT Unit */ |
| 943 |
for(Index = 0; Index < AUDIO_Handle->class_desc.OutputTerminalNum; Index ++) |
| 944 |
{ |
| 945 |
if(AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->bSourceID == UnitID) |
| 946 |
{ |
| 947 |
UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->bTerminalID; |
| 948 |
|
| 949 |
return ((UnitID << 16) | (UAC_OUTPUT_TERMINAL << 8) | Index); |
| 950 |
} |
| 951 |
} |
| 952 |
|
| 953 |
/* No associated Unit found */ |
| 954 |
return -1; |
| 955 |
} |
| 956 |
|
| 957 |
/** |
| 958 |
* @brief Build full path for Microphone device |
| 959 |
* @param phost: Host handle |
| 960 |
* @retval USBH Status |
| 961 |
*/ |
| 962 |
USBH_StatusTypeDef USBH_AUDIO_BuildMicrophonePath(USBH_HandleTypeDef *phost) |
| 963 |
{ |
| 964 |
uint8_t UnitID = 0, Type, Index; |
| 965 |
uint32_t value; |
| 966 |
uint8_t terminalIndex; |
| 967 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 968 |
|
| 969 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 970 |
|
| 971 |
/*Find microphone IT*/ |
| 972 |
for(terminalIndex = 0; terminalIndex < AUDIO_Handle->class_desc.InputTerminalNum; terminalIndex++) |
| 973 |
{ |
| 974 |
if(LE16(AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->wTerminalType) == 0x201) |
| 975 |
{ |
| 976 |
UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bTerminalID; |
| 977 |
AUDIO_Handle->microphone.asociated_channels = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bNrChannels; |
| 978 |
break; |
| 979 |
} |
| 980 |
} |
| 981 |
|
| 982 |
do |
| 983 |
{ |
| 984 |
value = USBH_AUDIO_FindLinkedUnit(phost, UnitID); |
| 985 |
Index = value & 0xFF; |
| 986 |
Type = (value >> 8) & 0xFF; |
| 987 |
UnitID = (value >> 16) & 0xFF; |
| 988 |
|
| 989 |
switch (Type) |
| 990 |
{ |
| 991 |
case UAC_FEATURE_UNIT: |
| 992 |
AUDIO_Handle->microphone.asociated_feature = Index; |
| 993 |
break; |
| 994 |
|
| 995 |
case UAC_MIXER_UNIT: |
| 996 |
AUDIO_Handle->microphone.asociated_mixer = Index; |
| 997 |
break; |
| 998 |
|
| 999 |
case UAC_SELECTOR_UNIT: |
| 1000 |
AUDIO_Handle->microphone.asociated_selector = Index; |
| 1001 |
break; |
| 1002 |
|
| 1003 |
case UAC_OUTPUT_TERMINAL: |
| 1004 |
AUDIO_Handle->microphone.asociated_terminal = Index; |
| 1005 |
break; |
| 1006 |
} |
| 1007 |
} |
| 1008 |
while ((Type != UAC_OUTPUT_TERMINAL) && (value > 0)); |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
return USBH_OK; |
| 1013 |
} |
| 1014 |
|
| 1015 |
/** |
| 1016 |
* @brief Build full path for Headphone device |
| 1017 |
* @param phost: Host handle |
| 1018 |
* @retval USBH Status |
| 1019 |
*/ |
| 1020 |
USBH_StatusTypeDef USBH_AUDIO_BuildHeadphonePath(USBH_HandleTypeDef *phost) |
| 1021 |
{ |
| 1022 |
uint8_t UnitID = 0, Type, Index; |
| 1023 |
uint32_t value; |
| 1024 |
uint8_t terminalIndex; |
| 1025 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1026 |
|
| 1027 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1028 |
|
| 1029 |
/*Find association betwen audio streaming and microphone*/ |
| 1030 |
for(terminalIndex = 0; terminalIndex < AUDIO_Handle->class_desc.InputTerminalNum; terminalIndex++) |
| 1031 |
{ |
| 1032 |
if(LE16(AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->wTerminalType) == 0x101) |
| 1033 |
{ |
| 1034 |
UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bTerminalID; |
| 1035 |
AUDIO_Handle->headphone.asociated_channels = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[terminalIndex]->bNrChannels; |
| 1036 |
break; |
| 1037 |
} |
| 1038 |
} |
| 1039 |
|
| 1040 |
for(Index = 0; Index < AUDIO_Handle->class_desc.ASNum; Index++) |
| 1041 |
{ |
| 1042 |
if(AUDIO_Handle->class_desc.as_desc[Index].GeneralDesc->bTerminalLink == UnitID) |
| 1043 |
{ |
| 1044 |
AUDIO_Handle->headphone.asociated_as = Index; |
| 1045 |
break; |
| 1046 |
} |
| 1047 |
} |
| 1048 |
|
| 1049 |
do |
| 1050 |
{ |
| 1051 |
value = USBH_AUDIO_FindLinkedUnit(phost, UnitID); |
| 1052 |
Index = value & 0xFF; |
| 1053 |
Type = (value >> 8) & 0xFF; |
| 1054 |
UnitID = (value >> 16) & 0xFF; |
| 1055 |
|
| 1056 |
switch (Type) |
| 1057 |
{ |
| 1058 |
case UAC_FEATURE_UNIT: |
| 1059 |
AUDIO_Handle->headphone.asociated_feature = Index; |
| 1060 |
break; |
| 1061 |
|
| 1062 |
case UAC_MIXER_UNIT: |
| 1063 |
AUDIO_Handle->headphone.asociated_mixer = Index; |
| 1064 |
break; |
| 1065 |
|
| 1066 |
case UAC_SELECTOR_UNIT: |
| 1067 |
AUDIO_Handle->headphone.asociated_selector = Index; |
| 1068 |
break; |
| 1069 |
|
| 1070 |
case UAC_OUTPUT_TERMINAL: |
| 1071 |
AUDIO_Handle->headphone.asociated_terminal = Index; |
| 1072 |
if(LE16(AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[Index]->wTerminalType) != 0x103) |
| 1073 |
{ |
| 1074 |
return USBH_OK; |
| 1075 |
} |
| 1076 |
break; |
| 1077 |
} |
| 1078 |
} |
| 1079 |
while ((Type != UAC_OUTPUT_TERMINAL) && (value > 0)); |
| 1080 |
|
| 1081 |
return USBH_FAIL; |
| 1082 |
} |
| 1083 |
|
| 1084 |
|
| 1085 |
/** |
| 1086 |
* @brief Handle Set Cur request |
| 1087 |
* @param phost: Host handle |
| 1088 |
* @param subtype: subtype index |
| 1089 |
* @param feature: feature index |
| 1090 |
* @param controlSelector: control code |
| 1091 |
* @param channel: channel index |
| 1092 |
* @param length: Command length |
| 1093 |
* @retval USBH Status |
| 1094 |
*/ |
| 1095 |
static USBH_StatusTypeDef USBH_AC_SetCur(USBH_HandleTypeDef *phost, |
| 1096 |
uint8_t subtype, |
| 1097 |
uint8_t feature, |
| 1098 |
uint8_t controlSelector, |
| 1099 |
uint8_t channel, |
| 1100 |
uint16_t length) |
| 1101 |
{ |
| 1102 |
uint16_t wValue,wIndex,wLength; |
| 1103 |
uint8_t UnitID,InterfaceNum; |
| 1104 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1105 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1106 |
|
| 1107 |
switch(subtype) |
| 1108 |
{ |
| 1109 |
case UAC_INPUT_TERMINAL: |
| 1110 |
UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; |
| 1111 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1112 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1113 |
wValue = (COPY_PROTECT_CONTROL << 8 ) ; |
| 1114 |
AUDIO_Handle->mem[0] = 0x00; |
| 1115 |
|
| 1116 |
wLength = 1; |
| 1117 |
break; |
| 1118 |
case UAC_FEATURE_UNIT: |
| 1119 |
UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; |
| 1120 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1121 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1122 |
/*holds the CS(control selector ) and CN (channel number)*/ |
| 1123 |
wValue = (controlSelector << 8) | channel; |
| 1124 |
wLength = length; |
| 1125 |
break; |
| 1126 |
} |
| 1127 |
|
| 1128 |
phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_INTERFACE | \ |
| 1129 |
USB_REQ_TYPE_CLASS; |
| 1130 |
|
| 1131 |
phost->Control.setup.b.bRequest = UAC_SET_CUR; |
| 1132 |
phost->Control.setup.b.wValue.w = wValue; |
| 1133 |
phost->Control.setup.b.wIndex.w = wIndex; |
| 1134 |
phost->Control.setup.b.wLength.w = wLength; |
| 1135 |
|
| 1136 |
return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength )); |
| 1137 |
|
| 1138 |
} |
| 1139 |
|
| 1140 |
/** |
| 1141 |
* @brief Handle Get Cur request |
| 1142 |
* @param phost: Host handle |
| 1143 |
* @param subtype: subtype index |
| 1144 |
* @param feature: feature index |
| 1145 |
* @param controlSelector: control code |
| 1146 |
* @param channel: channel index |
| 1147 |
* @param length: Command length |
| 1148 |
* @retval USBH Status |
| 1149 |
*/ |
| 1150 |
static USBH_StatusTypeDef USBH_AC_GetCur(USBH_HandleTypeDef *phost, |
| 1151 |
uint8_t subtype, |
| 1152 |
uint8_t feature, |
| 1153 |
uint8_t controlSelector, |
| 1154 |
uint8_t channel, |
| 1155 |
uint16_t length) |
| 1156 |
{ |
| 1157 |
uint16_t wValue = 0, wIndex = 0,wLength = 0; |
| 1158 |
uint8_t UnitID = 0, InterfaceNum = 0; |
| 1159 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1160 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1161 |
|
| 1162 |
switch(subtype) |
| 1163 |
{ |
| 1164 |
case UAC_INPUT_TERMINAL: |
| 1165 |
UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; |
| 1166 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1167 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1168 |
wValue = (COPY_PROTECT_CONTROL << 8 ) ; |
| 1169 |
AUDIO_Handle->mem[0] = 0x00; |
| 1170 |
|
| 1171 |
wLength = 1; |
| 1172 |
break; |
| 1173 |
case UAC_FEATURE_UNIT: |
| 1174 |
UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; |
| 1175 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1176 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1177 |
/*holds the CS(control selector ) and CN (channel number)*/ |
| 1178 |
wValue = (controlSelector << 8) | channel; |
| 1179 |
wLength = length; |
| 1180 |
break; |
| 1181 |
|
| 1182 |
case UAC_OUTPUT_TERMINAL: |
| 1183 |
UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; |
| 1184 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1185 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1186 |
wValue = (COPY_PROTECT_CONTROL << 8 ) ; |
| 1187 |
wLength = 1; |
| 1188 |
break; |
| 1189 |
} |
| 1190 |
|
| 1191 |
phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \ |
| 1192 |
USB_REQ_TYPE_CLASS; |
| 1193 |
|
| 1194 |
phost->Control.setup.b.bRequest = UAC_GET_CUR; |
| 1195 |
phost->Control.setup.b.wValue.w = wValue; |
| 1196 |
phost->Control.setup.b.wIndex.w = wIndex; |
| 1197 |
phost->Control.setup.b.wLength.w = wLength; |
| 1198 |
|
| 1199 |
return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength )); |
| 1200 |
|
| 1201 |
} |
| 1202 |
|
| 1203 |
|
| 1204 |
/** |
| 1205 |
* @brief Handle Get Max request |
| 1206 |
* @param phost: Host handle |
| 1207 |
* @param subtype: subtype index |
| 1208 |
* @param feature: feature index |
| 1209 |
* @param controlSelector: control code |
| 1210 |
* @param channel: channel index |
| 1211 |
* @param length: Command length |
| 1212 |
* @retval USBH Status |
| 1213 |
*/ |
| 1214 |
static USBH_StatusTypeDef USBH_AC_GetMax(USBH_HandleTypeDef *phost, |
| 1215 |
uint8_t subtype, |
| 1216 |
uint8_t feature, |
| 1217 |
uint8_t controlSelector, |
| 1218 |
uint8_t channel, |
| 1219 |
uint16_t length) |
| 1220 |
{ |
| 1221 |
uint16_t wValue = 0, wIndex = 0, wLength = 0; |
| 1222 |
uint8_t UnitID = 0, InterfaceNum = 0; |
| 1223 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1224 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1225 |
|
| 1226 |
switch(subtype) |
| 1227 |
{ |
| 1228 |
case UAC_INPUT_TERMINAL: |
| 1229 |
UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; |
| 1230 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1231 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1232 |
wValue = (COPY_PROTECT_CONTROL << 8 ) ; |
| 1233 |
AUDIO_Handle->mem[0] = 0x00; |
| 1234 |
|
| 1235 |
wLength = 1; |
| 1236 |
break; |
| 1237 |
case UAC_FEATURE_UNIT: |
| 1238 |
UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; |
| 1239 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1240 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1241 |
/*holds the CS(control selector ) and CN (channel number)*/ |
| 1242 |
wValue = (controlSelector << 8) | channel; |
| 1243 |
wLength = length; |
| 1244 |
break; |
| 1245 |
|
| 1246 |
case UAC_OUTPUT_TERMINAL: |
| 1247 |
UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; |
| 1248 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1249 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1250 |
wValue = (COPY_PROTECT_CONTROL << 8 ) ; |
| 1251 |
wLength = 1; |
| 1252 |
break; |
| 1253 |
} |
| 1254 |
|
| 1255 |
phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \ |
| 1256 |
USB_REQ_TYPE_CLASS; |
| 1257 |
|
| 1258 |
phost->Control.setup.b.bRequest = UAC_GET_MAX; |
| 1259 |
phost->Control.setup.b.wValue.w = wValue; |
| 1260 |
phost->Control.setup.b.wIndex.w = wIndex; |
| 1261 |
phost->Control.setup.b.wLength.w = wLength; |
| 1262 |
|
| 1263 |
return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength )); |
| 1264 |
|
| 1265 |
} |
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
/** |
| 1270 |
* @brief Handle Get Res request |
| 1271 |
* @param phost: Host handle |
| 1272 |
* @param subtype: subtype index |
| 1273 |
* @param feature: feature index |
| 1274 |
* @param controlSelector: control code |
| 1275 |
* @param channel: channel index |
| 1276 |
* @param length: Command length |
| 1277 |
* @retval USBH Status |
| 1278 |
*/ |
| 1279 |
static USBH_StatusTypeDef USBH_AC_GetRes(USBH_HandleTypeDef *phost, |
| 1280 |
uint8_t subtype, |
| 1281 |
uint8_t feature, |
| 1282 |
uint8_t controlSelector, |
| 1283 |
uint8_t channel, |
| 1284 |
uint16_t length) |
| 1285 |
{ |
| 1286 |
uint16_t wValue = 0, wIndex = 0, wLength = 0; |
| 1287 |
uint8_t UnitID = 0, InterfaceNum = 0; |
| 1288 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1289 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1290 |
|
| 1291 |
switch(subtype) |
| 1292 |
{ |
| 1293 |
case UAC_INPUT_TERMINAL: |
| 1294 |
UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; |
| 1295 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1296 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1297 |
wValue = (COPY_PROTECT_CONTROL << 8 ) ; |
| 1298 |
AUDIO_Handle->mem[0] = 0x00; |
| 1299 |
|
| 1300 |
wLength = 1; |
| 1301 |
break; |
| 1302 |
case UAC_FEATURE_UNIT: |
| 1303 |
UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; |
| 1304 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1305 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1306 |
/*holds the CS(control selector ) and CN (channel number)*/ |
| 1307 |
wValue = (controlSelector << 8) | channel; |
| 1308 |
wLength = length; |
| 1309 |
break; |
| 1310 |
|
| 1311 |
case UAC_OUTPUT_TERMINAL: |
| 1312 |
UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; |
| 1313 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1314 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1315 |
wValue = (COPY_PROTECT_CONTROL << 8 ) ; |
| 1316 |
wLength = 1; |
| 1317 |
break; |
| 1318 |
} |
| 1319 |
|
| 1320 |
phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \ |
| 1321 |
USB_REQ_TYPE_CLASS; |
| 1322 |
|
| 1323 |
phost->Control.setup.b.bRequest = UAC_GET_RES; |
| 1324 |
phost->Control.setup.b.wValue.w = wValue; |
| 1325 |
phost->Control.setup.b.wIndex.w = wIndex; |
| 1326 |
phost->Control.setup.b.wLength.w = wLength; |
| 1327 |
|
| 1328 |
return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength )); |
| 1329 |
|
| 1330 |
} |
| 1331 |
|
| 1332 |
/** |
| 1333 |
* @brief Handle Get Min request |
| 1334 |
* @param phost: Host handle |
| 1335 |
* @param subtype: subtype index |
| 1336 |
* @param feature: feature index |
| 1337 |
* @param controlSelector: control code |
| 1338 |
* @param channel: channel index |
| 1339 |
* @param length: Command length |
| 1340 |
* @retval USBH Status |
| 1341 |
*/ |
| 1342 |
static USBH_StatusTypeDef USBH_AC_GetMin(USBH_HandleTypeDef *phost, |
| 1343 |
uint8_t subtype, |
| 1344 |
uint8_t feature, |
| 1345 |
uint8_t controlSelector, |
| 1346 |
uint8_t channel, |
| 1347 |
uint16_t length) |
| 1348 |
{ |
| 1349 |
uint16_t wValue = 0, wIndex = 0, wLength = 0; |
| 1350 |
uint8_t UnitID = 0, InterfaceNum = 0; |
| 1351 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1352 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1353 |
|
| 1354 |
switch(subtype) |
| 1355 |
{ |
| 1356 |
case UAC_INPUT_TERMINAL: |
| 1357 |
UnitID = AUDIO_Handle->class_desc.cs_desc.InputTerminalDesc[0]->bTerminalID; |
| 1358 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1359 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1360 |
wValue = (COPY_PROTECT_CONTROL << 8 ) ; |
| 1361 |
AUDIO_Handle->mem[0] = 0x00; |
| 1362 |
|
| 1363 |
wLength = 1; |
| 1364 |
break; |
| 1365 |
case UAC_FEATURE_UNIT: |
| 1366 |
UnitID = AUDIO_Handle->class_desc.cs_desc.FeatureUnitDesc[feature]->bUnitID; |
| 1367 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1368 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1369 |
/*holds the CS(control selector ) and CN (channel number)*/ |
| 1370 |
wValue = (controlSelector << 8) | channel; |
| 1371 |
wLength = length; |
| 1372 |
break; |
| 1373 |
|
| 1374 |
case UAC_OUTPUT_TERMINAL: |
| 1375 |
UnitID = AUDIO_Handle->class_desc.cs_desc.OutputTerminalDesc[0]->bTerminalID; |
| 1376 |
InterfaceNum = 0; /*Always zero Control Interface */ |
| 1377 |
wIndex = ( UnitID << 8 ) | InterfaceNum ; |
| 1378 |
wValue = (COPY_PROTECT_CONTROL << 8 ) ; |
| 1379 |
wLength = 1; |
| 1380 |
break; |
| 1381 |
} |
| 1382 |
|
| 1383 |
phost->Control.setup.b.bmRequestType = USB_D2H | USB_REQ_RECIPIENT_INTERFACE | \ |
| 1384 |
USB_REQ_TYPE_CLASS; |
| 1385 |
|
| 1386 |
phost->Control.setup.b.bRequest = UAC_GET_MIN; |
| 1387 |
phost->Control.setup.b.wValue.w = wValue; |
| 1388 |
phost->Control.setup.b.wIndex.w = wIndex; |
| 1389 |
phost->Control.setup.b.wLength.w = wLength; |
| 1390 |
|
| 1391 |
return(USBH_CtlReq(phost, (uint8_t *)(AUDIO_Handle->mem) , wLength )); |
| 1392 |
|
| 1393 |
} |
| 1394 |
|
| 1395 |
/** |
| 1396 |
* @brief Handle Set Endpoint Controls Request |
| 1397 |
* @param phost: Host handle |
| 1398 |
* @param Ep: Endpoint address |
| 1399 |
* @param buf: pointer to data |
| 1400 |
* @retval USBH Status |
| 1401 |
*/ |
| 1402 |
static USBH_StatusTypeDef USBH_AUDIO_SetEndpointControls(USBH_HandleTypeDef *phost, |
| 1403 |
uint8_t Ep, |
| 1404 |
uint8_t *buff) |
| 1405 |
{ |
| 1406 |
uint16_t wValue, wIndex, wLength; |
| 1407 |
|
| 1408 |
|
| 1409 |
wValue = SAMPLING_FREQ_CONTROL << 8; |
| 1410 |
wIndex = Ep; |
| 1411 |
wLength = 3; /*length of the frequency parameter*/ |
| 1412 |
|
| 1413 |
phost->Control.setup.b.bmRequestType = USB_H2D | USB_REQ_RECIPIENT_ENDPOINT | \ |
| 1414 |
USB_REQ_TYPE_CLASS; |
| 1415 |
|
| 1416 |
phost->Control.setup.b.bRequest = UAC_SET_CUR; |
| 1417 |
phost->Control.setup.b.wValue.w = wValue; |
| 1418 |
phost->Control.setup.b.wIndex.w = wIndex; |
| 1419 |
phost->Control.setup.b.wLength.w = wLength; |
| 1420 |
|
| 1421 |
return(USBH_CtlReq(phost, (uint8_t *)buff, wLength )); |
| 1422 |
|
| 1423 |
} |
| 1424 |
|
| 1425 |
/** |
| 1426 |
* @brief Handle Input stream process |
| 1427 |
* @param phost: Host handle |
| 1428 |
* @retval USBH Status |
| 1429 |
*/ |
| 1430 |
static USBH_StatusTypeDef USBH_AUDIO_InputStream (USBH_HandleTypeDef *phost) |
| 1431 |
{ |
| 1432 |
USBH_StatusTypeDef status = USBH_BUSY ; |
| 1433 |
|
| 1434 |
return status; |
| 1435 |
} |
| 1436 |
|
| 1437 |
/** |
| 1438 |
* @brief Handle HID Control process |
| 1439 |
* @param phost: Host handle |
| 1440 |
* @retval USBH Status |
| 1441 |
*/ |
| 1442 |
static USBH_StatusTypeDef USBH_AUDIO_Control (USBH_HandleTypeDef *phost) |
| 1443 |
{ |
| 1444 |
USBH_StatusTypeDef status = USBH_BUSY ; |
| 1445 |
AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData; |
| 1446 |
uint16_t attribute = 0; |
| 1447 |
|
| 1448 |
|
| 1449 |
switch(AUDIO_Handle->control_state) |
| 1450 |
{ |
| 1451 |
case AUDIO_CONTROL_INIT: |
| 1452 |
if((phost->Timer & 1) == 0) |
| 1453 |
{ |
| 1454 |
AUDIO_Handle->control.timer = phost->Timer; |
| 1455 |
USBH_InterruptReceiveData(phost, |
| 1456 |
(uint8_t *)(AUDIO_Handle->mem), |
| 1457 |
AUDIO_Handle->control.EpSize, |
| 1458 |
AUDIO_Handle->control.Pipe); |
| 1459 |
|
| 1460 |
AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; |
| 1461 |
AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels; |
| 1462 |
|
| 1463 |
AUDIO_Handle->control_state = AUDIO_CONTROL_CHANGE ; |
| 1464 |
} |
| 1465 |
break; |
| 1466 |
case AUDIO_CONTROL_CHANGE: |
| 1467 |
if(USBH_LL_GetURBState(phost , AUDIO_Handle->control.Pipe) == USBH_URB_DONE) |
| 1468 |
{ |
| 1469 |
attribute = LE16(&AUDIO_Handle->mem[0]); |
| 1470 |
if(USBH_AUDIO_SetControlAttribute (phost, attribute) == USBH_BUSY) |
| 1471 |
{ |
| 1472 |
break; |
| 1473 |
} |
| 1474 |
} |
| 1475 |
|
| 1476 |
if(( phost->Timer - AUDIO_Handle->control.timer) >= AUDIO_Handle->control.Poll) |
| 1477 |
{ |
| 1478 |
AUDIO_Handle->control.timer = phost->Timer; |
| 1479 |
|
| 1480 |
USBH_InterruptReceiveData(phost, |
| 1481 |
(uint8_t *)(AUDIO_Handle->mem), |
| 1482 |
AUDIO_Handle->control.EpSize, |
| 1483 |
AUDIO_Handle->control.Pipe); |
| 1484 |
|
| 1485 |
} |
| 1486 |
break; |
| 1487 |
|
| 1488 |
case AUDIO_CONTROL_VOLUME_UP: |
| 1489 |
if( USBH_AUDIO_SetControlAttribute (phost, 1) == USBH_OK) |
| 1490 |
{ |
| 1491 |
AUDIO_Handle->control_state = AUDIO_CONTROL_INIT; |
| 1492 |
status = USBH_OK; |
| 1493 |
} |
| 1494 |
break; |
| 1495 |
|
| 1496 |
case AUDIO_CONTROL_VOLUME_DOWN: |
| 1497 |
if( USBH_AUDIO_SetControlAttribute (phost, 2) == USBH_OK) |
| 1498 |
{ |
| 1499 |
AUDIO_Handle->control_state = AUDIO_CONTROL_INIT; |
| 1500 |
status = USBH_OK; |
| 1501 |
} |
| 1502 |
break; |
| 1503 |
|
| 1504 |
case AUDIO_CONTROL_IDLE: |
| 1505 |
default: |
| 1506 |
break; |
| 1507 |
} |
| 1508 |
|
| 1509 |
return status; |
| 1510 |
} |
| 1511 |
|
| 1512 |
/** |
| 1513 |
* @brief Handle Output stream process |
| 1514 |
* @param phost: Host handle |
| 1515 |
* @retval USBH Status |
| 1516 |
*/ |
| 1517 |
static USBH_StatusTypeDef USBH_AUDIO_OutputStream (USBH_HandleTypeDef *phost) |
| 1518 |
{ |
| 1519 |
USBH_StatusTypeDef status = USBH_BUSY ; |
| 1520 |
AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData; |
| 1521 |
uint8_t *buff; |
| 1522 |
|
| 1523 |
|
| 1524 |
switch(AUDIO_Handle->play_state) |
| 1525 |
{ |
| 1526 |
case AUDIO_PLAYBACK_INIT: |
| 1527 |
|
| 1528 |
if( AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bSamFreqType == 0) |
| 1529 |
{ |
| 1530 |
AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP_FREQ; |
| 1531 |
} |
| 1532 |
else |
| 1533 |
{ |
| 1534 |
AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP; |
| 1535 |
} |
| 1536 |
#if (USBH_USE_OS == 1) |
| 1537 |
osMessagePut ( phost->os_event, USBH_URB_EVENT, 0); |
| 1538 |
#endif |
| 1539 |
break; |
| 1540 |
|
| 1541 |
case AUDIO_PLAYBACK_SET_EP_FREQ: |
| 1542 |
|
| 1543 |
buff = (uint8_t*)AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[0]; |
| 1544 |
|
| 1545 |
status = USBH_AUDIO_SetEndpointControls(phost, AUDIO_Handle->headphone.Ep, buff); |
| 1546 |
if(status == USBH_OK) |
| 1547 |
{ |
| 1548 |
AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; |
| 1549 |
} |
| 1550 |
break; |
| 1551 |
|
| 1552 |
case AUDIO_PLAYBACK_SET_EP: |
| 1553 |
buff = (uint8_t *)&AUDIO_Handle->headphone.frequency; |
| 1554 |
status = USBH_AUDIO_SetEndpointControls(phost,AUDIO_Handle->headphone.Ep, buff); |
| 1555 |
if(status == USBH_OK) |
| 1556 |
{ |
| 1557 |
AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; |
| 1558 |
USBH_AUDIO_FrequencySet(phost); |
| 1559 |
} |
| 1560 |
break; |
| 1561 |
case AUDIO_PLAYBACK_IDLE: |
| 1562 |
#if (USBH_USE_OS == 1) |
| 1563 |
osMessagePut ( phost->os_event, USBH_CLASS_EVENT, 0); |
| 1564 |
#endif |
| 1565 |
status = USBH_OK; |
| 1566 |
break; |
| 1567 |
|
| 1568 |
case AUDIO_PLAYBACK_PLAY: |
| 1569 |
USBH_AUDIO_Transmit(phost); |
| 1570 |
status = USBH_OK; |
| 1571 |
break; |
| 1572 |
|
| 1573 |
default: |
| 1574 |
break; |
| 1575 |
} |
| 1576 |
|
| 1577 |
return status; |
| 1578 |
} |
| 1579 |
|
| 1580 |
/** |
| 1581 |
* @brief Handle Transmission process |
| 1582 |
* @param phost: Host handle |
| 1583 |
* @retval USBH Status |
| 1584 |
*/ |
| 1585 |
static USBH_StatusTypeDef USBH_AUDIO_Transmit (USBH_HandleTypeDef *phost) |
| 1586 |
{ |
| 1587 |
USBH_StatusTypeDef status = USBH_BUSY ; |
| 1588 |
AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData; |
| 1589 |
|
| 1590 |
switch(AUDIO_Handle->processing_state) |
| 1591 |
{ |
| 1592 |
case AUDIO_DATA_START_OUT: |
| 1593 |
/* Sync with start of Even Frame */ |
| 1594 |
if((phost->Timer & 1) == 0) |
| 1595 |
{ |
| 1596 |
AUDIO_Handle->headphone.timer = phost->Timer; |
| 1597 |
AUDIO_Handle->processing_state = AUDIO_DATA_OUT; |
| 1598 |
USBH_IsocSendData(phost, |
| 1599 |
AUDIO_Handle->headphone.buf, |
| 1600 |
AUDIO_Handle->headphone.frame_length, |
| 1601 |
AUDIO_Handle->headphone.Pipe); |
| 1602 |
|
| 1603 |
AUDIO_Handle->headphone.partial_ptr = AUDIO_Handle->headphone.frame_length; |
| 1604 |
AUDIO_Handle->headphone.global_ptr = AUDIO_Handle->headphone.frame_length; |
| 1605 |
AUDIO_Handle->headphone.cbuf = AUDIO_Handle->headphone.buf; |
| 1606 |
|
| 1607 |
} |
| 1608 |
break; |
| 1609 |
|
| 1610 |
case AUDIO_DATA_OUT: |
| 1611 |
if((USBH_LL_GetURBState(phost , AUDIO_Handle->headphone.Pipe) == USBH_URB_DONE)&& |
| 1612 |
(( phost->Timer - AUDIO_Handle->headphone.timer) >= AUDIO_Handle->headphone.Poll)) |
| 1613 |
{ |
| 1614 |
AUDIO_Handle->headphone.timer = phost->Timer; |
| 1615 |
|
| 1616 |
if(AUDIO_Handle->control.supported == 1) |
| 1617 |
{ |
| 1618 |
USBH_AUDIO_Control (phost); |
| 1619 |
} |
| 1620 |
|
| 1621 |
if(AUDIO_Handle->headphone.global_ptr <= AUDIO_Handle->headphone.total_length) |
| 1622 |
{ |
| 1623 |
USBH_IsocSendData(phost, |
| 1624 |
AUDIO_Handle->headphone.cbuf, |
| 1625 |
AUDIO_Handle->headphone.frame_length, |
| 1626 |
AUDIO_Handle->headphone.Pipe); |
| 1627 |
|
| 1628 |
AUDIO_Handle->headphone.cbuf += AUDIO_Handle->headphone.frame_length; |
| 1629 |
AUDIO_Handle->headphone.partial_ptr += AUDIO_Handle->headphone.frame_length; |
| 1630 |
AUDIO_Handle->headphone.global_ptr += AUDIO_Handle->headphone.frame_length; |
| 1631 |
} |
| 1632 |
else |
| 1633 |
{ |
| 1634 |
AUDIO_Handle->headphone.partial_ptr = 0xFFFFFFFF; |
| 1635 |
AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; |
| 1636 |
} |
| 1637 |
} |
| 1638 |
break; |
| 1639 |
} |
| 1640 |
return status; |
| 1641 |
} |
| 1642 |
|
| 1643 |
/** |
| 1644 |
* @brief USBH_AUDIO_SetFrequency |
| 1645 |
* Set Audio sampling parameters |
| 1646 |
* @param phost: Host handle |
| 1647 |
* @param SampleRate: Sample Rate |
| 1648 |
* @param NbrChannels: Number of Channels |
| 1649 |
* @param BitPerSample: Bit Per Sample |
| 1650 |
* @retval USBH Status |
| 1651 |
*/ |
| 1652 |
USBH_StatusTypeDef USBH_AUDIO_SetFrequency (USBH_HandleTypeDef *phost, |
| 1653 |
uint16_t SampleRate, |
| 1654 |
uint8_t NbrChannels, |
| 1655 |
uint8_t BitPerSample) |
| 1656 |
{ |
| 1657 |
USBH_StatusTypeDef Status = USBH_BUSY; |
| 1658 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1659 |
uint8_t index; |
| 1660 |
uint8_t change_freq = FALSE; |
| 1661 |
uint32_t freq_min, freq_max; |
| 1662 |
uint8_t num_supported_freq; |
| 1663 |
|
| 1664 |
if(phost->gState == HOST_CLASS) |
| 1665 |
{ |
| 1666 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1667 |
if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE) |
| 1668 |
{ |
| 1669 |
|
| 1670 |
if(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bSamFreqType == 0) |
| 1671 |
{ |
| 1672 |
freq_min = LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[0]); |
| 1673 |
freq_max = LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[1]); |
| 1674 |
|
| 1675 |
if(( SampleRate >= freq_min)&& (SampleRate <= freq_max)) |
| 1676 |
{ |
| 1677 |
change_freq = TRUE; |
| 1678 |
} |
| 1679 |
} |
| 1680 |
else |
| 1681 |
{ |
| 1682 |
|
| 1683 |
num_supported_freq = (AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->bLength - 8)/3; |
| 1684 |
|
| 1685 |
|
| 1686 |
for(index = 0; index < num_supported_freq; index++) |
| 1687 |
{ |
| 1688 |
if(SampleRate == LE24(AUDIO_Handle->class_desc.as_desc[AUDIO_Handle->headphone.asociated_as].FormatTypeDesc->tSamFreq[index])) |
| 1689 |
{ |
| 1690 |
change_freq = TRUE; |
| 1691 |
break; |
| 1692 |
} |
| 1693 |
} |
| 1694 |
} |
| 1695 |
|
| 1696 |
if(change_freq == TRUE) |
| 1697 |
{ |
| 1698 |
AUDIO_Handle->headphone.frequency = SampleRate; |
| 1699 |
AUDIO_Handle->headphone.frame_length = (SampleRate * BitPerSample * NbrChannels) / 8000; |
| 1700 |
AUDIO_Handle->play_state = AUDIO_PLAYBACK_SET_EP; |
| 1701 |
Status = USBH_OK; |
| 1702 |
|
| 1703 |
} |
| 1704 |
} |
| 1705 |
} |
| 1706 |
return Status; |
| 1707 |
} |
| 1708 |
|
| 1709 |
/** |
| 1710 |
* @brief USBH_AUDIO_Play |
| 1711 |
* Start playback process |
| 1712 |
* @param phost: Host handle |
| 1713 |
* @param buf: pointer to raw audio data |
| 1714 |
* @param length: total length of the audio data |
| 1715 |
* @retval USBH Status |
| 1716 |
*/ |
| 1717 |
USBH_StatusTypeDef USBH_AUDIO_Play (USBH_HandleTypeDef *phost, uint8_t *buf, uint32_t length) |
| 1718 |
{ |
| 1719 |
USBH_StatusTypeDef Status = USBH_FAIL; |
| 1720 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1721 |
|
| 1722 |
if(phost->gState == HOST_CLASS) |
| 1723 |
{ |
| 1724 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1725 |
if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE) |
| 1726 |
{ |
| 1727 |
AUDIO_Handle->headphone.buf = buf; |
| 1728 |
AUDIO_Handle->headphone.total_length = length; |
| 1729 |
AUDIO_Handle->play_state = AUDIO_PLAYBACK_PLAY; |
| 1730 |
AUDIO_Handle->control_state = AUDIO_CONTROL_INIT; |
| 1731 |
AUDIO_Handle->processing_state = AUDIO_DATA_START_OUT; |
| 1732 |
Status = USBH_OK; |
| 1733 |
} |
| 1734 |
} |
| 1735 |
return Status; |
| 1736 |
} |
| 1737 |
|
| 1738 |
/** |
| 1739 |
* @brief USBH_AUDIO_Pause |
| 1740 |
* Stop the playback process |
| 1741 |
* @param phost: Host handle |
| 1742 |
* @retval USBH Status |
| 1743 |
*/ |
| 1744 |
USBH_StatusTypeDef USBH_AUDIO_Stop (USBH_HandleTypeDef *phost) |
| 1745 |
{ |
| 1746 |
USBH_StatusTypeDef Status = USBH_FAIL; |
| 1747 |
Status = USBH_AUDIO_Suspend(phost); |
| 1748 |
return Status; |
| 1749 |
} |
| 1750 |
|
| 1751 |
/** |
| 1752 |
* @brief USBH_AUDIO_Suspend |
| 1753 |
* Suspend the playback process |
| 1754 |
* @param phost: Host handle |
| 1755 |
* @retval USBH Status |
| 1756 |
*/ |
| 1757 |
USBH_StatusTypeDef USBH_AUDIO_Suspend (USBH_HandleTypeDef *phost) |
| 1758 |
{ |
| 1759 |
USBH_StatusTypeDef Status = USBH_FAIL; |
| 1760 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1761 |
|
| 1762 |
if(phost->gState == HOST_CLASS) |
| 1763 |
{ |
| 1764 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1765 |
if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) |
| 1766 |
{ |
| 1767 |
AUDIO_Handle->control_state = AUDIO_CONTROL_IDLE; |
| 1768 |
AUDIO_Handle->play_state = AUDIO_PLAYBACK_IDLE; |
| 1769 |
Status = USBH_OK; |
| 1770 |
} |
| 1771 |
} |
| 1772 |
return Status; |
| 1773 |
} |
| 1774 |
/** |
| 1775 |
* @brief USBH_AUDIO_Resume |
| 1776 |
* Resume the playback process |
| 1777 |
* @param phost: Host handle |
| 1778 |
* @retval USBH Status |
| 1779 |
*/ |
| 1780 |
USBH_StatusTypeDef USBH_AUDIO_Resume (USBH_HandleTypeDef *phost) |
| 1781 |
{ |
| 1782 |
USBH_StatusTypeDef Status = USBH_FAIL; |
| 1783 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1784 |
|
| 1785 |
if(phost->gState == HOST_CLASS) |
| 1786 |
{ |
| 1787 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1788 |
if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_IDLE) |
| 1789 |
{ |
| 1790 |
AUDIO_Handle->control_state = AUDIO_CONTROL_INIT; |
| 1791 |
AUDIO_Handle->play_state = AUDIO_PLAYBACK_PLAY; |
| 1792 |
} |
| 1793 |
} |
| 1794 |
return Status; |
| 1795 |
} |
| 1796 |
/** |
| 1797 |
* @brief USBH_AUDIO_GetOutOffset |
| 1798 |
* return the current buffer pointer for OUT proces |
| 1799 |
* @param phost: Host handle |
| 1800 |
* @retval USBH Status |
| 1801 |
*/ |
| 1802 |
int32_t USBH_AUDIO_GetOutOffset (USBH_HandleTypeDef *phost) |
| 1803 |
{ |
| 1804 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1805 |
|
| 1806 |
if(phost->gState == HOST_CLASS) |
| 1807 |
{ |
| 1808 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1809 |
if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) |
| 1810 |
{ |
| 1811 |
return AUDIO_Handle->headphone.partial_ptr; |
| 1812 |
} |
| 1813 |
} |
| 1814 |
return -1; |
| 1815 |
} |
| 1816 |
|
| 1817 |
/** |
| 1818 |
* @brief USBH_AUDIO_ChangeOutBuffer |
| 1819 |
* Change audio data buffer address |
| 1820 |
* @param phost: Host handle |
| 1821 |
* @param buf: buffer address |
| 1822 |
* @retval USBH Status |
| 1823 |
*/ |
| 1824 |
USBH_StatusTypeDef USBH_AUDIO_ChangeOutBuffer (USBH_HandleTypeDef *phost, uint8_t *buf) |
| 1825 |
{ |
| 1826 |
USBH_StatusTypeDef Status = USBH_FAIL; |
| 1827 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1828 |
|
| 1829 |
if(phost->gState == HOST_CLASS) |
| 1830 |
{ |
| 1831 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1832 |
if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) |
| 1833 |
{ |
| 1834 |
if(AUDIO_Handle->headphone.buf <= buf) |
| 1835 |
{ |
| 1836 |
AUDIO_Handle->headphone.cbuf = buf; |
| 1837 |
if ( AUDIO_Handle->headphone.buf == buf) |
| 1838 |
{ |
| 1839 |
AUDIO_Handle->headphone.partial_ptr = 0; |
| 1840 |
} |
| 1841 |
Status = USBH_OK; |
| 1842 |
} |
| 1843 |
} |
| 1844 |
} |
| 1845 |
return Status; |
| 1846 |
} |
| 1847 |
|
| 1848 |
/** |
| 1849 |
* @brief USBH_AUDIO_SetControlAttribute |
| 1850 |
* Set Control Attribute |
| 1851 |
* @param phost: Host handle |
| 1852 |
* @param attrib: control attribute |
| 1853 |
* @retval USBH Status |
| 1854 |
*/ |
| 1855 |
static USBH_StatusTypeDef USBH_AUDIO_SetControlAttribute (USBH_HandleTypeDef *phost, uint8_t attrib) |
| 1856 |
{ |
| 1857 |
USBH_StatusTypeDef status = USBH_BUSY ; |
| 1858 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1859 |
|
| 1860 |
|
| 1861 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1862 |
|
| 1863 |
switch (attrib) |
| 1864 |
{ |
| 1865 |
case 0x01: |
| 1866 |
AUDIO_Handle->headphone.attribute.volume += AUDIO_Handle->headphone.attribute.resolution; |
| 1867 |
break; |
| 1868 |
|
| 1869 |
case 0x02: |
| 1870 |
AUDIO_Handle->headphone.attribute.volume -= AUDIO_Handle->headphone.attribute.resolution; |
| 1871 |
break; |
| 1872 |
|
| 1873 |
} |
| 1874 |
|
| 1875 |
if(AUDIO_Handle->headphone.attribute.volume > AUDIO_Handle->headphone.attribute.volumeMax) |
| 1876 |
{ |
| 1877 |
AUDIO_Handle->headphone.attribute.volume =AUDIO_Handle->headphone.attribute.volumeMax; |
| 1878 |
} |
| 1879 |
|
| 1880 |
if(AUDIO_Handle->headphone.attribute.volume < AUDIO_Handle->headphone.attribute.volumeMin) |
| 1881 |
{ |
| 1882 |
AUDIO_Handle->headphone.attribute.volume =AUDIO_Handle->headphone.attribute.volumeMin; |
| 1883 |
} |
| 1884 |
|
| 1885 |
if(AUDIO_SetVolume (phost, |
| 1886 |
AUDIO_Handle->temp_feature, |
| 1887 |
AUDIO_Handle->temp_channels, |
| 1888 |
AUDIO_Handle->headphone.attribute.volume) != USBH_BUSY) |
| 1889 |
{ |
| 1890 |
|
| 1891 |
if(AUDIO_Handle->temp_channels == 1) |
| 1892 |
{ |
| 1893 |
AUDIO_Handle->temp_feature = AUDIO_Handle->headphone.asociated_feature; |
| 1894 |
AUDIO_Handle->temp_channels = AUDIO_Handle->headphone.asociated_channels; |
| 1895 |
status = USBH_OK; |
| 1896 |
} |
| 1897 |
else |
| 1898 |
{ |
| 1899 |
AUDIO_Handle->temp_channels--; |
| 1900 |
} |
| 1901 |
AUDIO_Handle->cs_req_state = AUDIO_REQ_GET_VOLUME; |
| 1902 |
} |
| 1903 |
|
| 1904 |
|
| 1905 |
return status; |
| 1906 |
} |
| 1907 |
|
| 1908 |
|
| 1909 |
/** |
| 1910 |
* @brief USBH_AUDIO_SetVolume |
| 1911 |
* Set Volume |
| 1912 |
* @param phost: Host handle |
| 1913 |
* @param volume: VOLUME_UP/ VOLUME_DOWN |
| 1914 |
* @retval USBH Status |
| 1915 |
*/ |
| 1916 |
USBH_StatusTypeDef USBH_AUDIO_SetVolume (USBH_HandleTypeDef *phost, AUDIO_VolumeCtrlTypeDef volume_ctl) |
| 1917 |
{ |
| 1918 |
AUDIO_HandleTypeDef *AUDIO_Handle = phost->pActiveClass->pData; |
| 1919 |
|
| 1920 |
if((volume_ctl == VOLUME_UP) || (volume_ctl == VOLUME_DOWN)) |
| 1921 |
{ |
| 1922 |
if(phost->gState == HOST_CLASS) |
| 1923 |
{ |
| 1924 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1925 |
if(AUDIO_Handle->play_state == AUDIO_PLAYBACK_PLAY) |
| 1926 |
{ |
| 1927 |
AUDIO_Handle->control_state = (volume_ctl == VOLUME_UP)? AUDIO_CONTROL_VOLUME_UP : AUDIO_CONTROL_VOLUME_DOWN; |
| 1928 |
return USBH_OK; |
| 1929 |
} |
| 1930 |
} |
| 1931 |
} |
| 1932 |
return USBH_FAIL; |
| 1933 |
} |
| 1934 |
/** |
| 1935 |
* @brief AUDIO_SetVolume |
| 1936 |
* Set Volume |
| 1937 |
* @param phost: Host handle |
| 1938 |
* @param feature: feature Unit index |
| 1939 |
* @param channel: channel index |
| 1940 |
* @param volume: new volume |
| 1941 |
* @retval USBH Status |
| 1942 |
*/ |
| 1943 |
static USBH_StatusTypeDef AUDIO_SetVolume (USBH_HandleTypeDef *phost, uint8_t feature, uint8_t channel, uint16_t volume) |
| 1944 |
{ |
| 1945 |
USBH_StatusTypeDef status = USBH_BUSY ; |
| 1946 |
AUDIO_HandleTypeDef *AUDIO_Handle; |
| 1947 |
|
| 1948 |
|
| 1949 |
AUDIO_Handle = phost->pActiveClass->pData; |
| 1950 |
|
| 1951 |
AUDIO_Handle->mem[0] = volume; |
| 1952 |
|
| 1953 |
status = USBH_AC_SetCur(phost, |
| 1954 |
UAC_FEATURE_UNIT, |
| 1955 |
feature, |
| 1956 |
VOLUME_CONTROL, |
| 1957 |
channel, |
| 1958 |
2); |
| 1959 |
|
| 1960 |
return status; |
| 1961 |
} |
| 1962 |
|
| 1963 |
/** |
| 1964 |
* @brief The function informs user that Settings have been changed |
| 1965 |
* @param pdev: Selected device |
| 1966 |
* @retval None |
| 1967 |
*/ |
| 1968 |
__weak void USBH_AUDIO_FrequencySet(USBH_HandleTypeDef *phost) |
| 1969 |
{ |
| 1970 |
|
| 1971 |
} |
| 1972 |
/** |
| 1973 |
* @} |
| 1974 |
*/ |
| 1975 |
|
| 1976 |
/** |
| 1977 |
* @} |
| 1978 |
*/ |
| 1979 |
|
| 1980 |
/** |
| 1981 |
* @} |
| 1982 |
*/ |
| 1983 |
|
| 1984 |
|
| 1985 |
/** |
| 1986 |
* @} |
| 1987 |
*/ |
| 1988 |
|
| 1989 |
|
| 1990 |
/** |
| 1991 |
* @} |
| 1992 |
*/ |
| 1993 |
|
| 1994 |
/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |