usb_audio.c 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145
  1. /******************************************************************************
  2. *
  3. * Freescale Semiconductor Inc.
  4. * (c) Copyright 2004-2010 Freescale Semiconductor, Inc.
  5. * ALL RIGHTS RESERVED.
  6. *
  7. ******************************************************************************
  8. *
  9. * THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
  10. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  11. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  12. * IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  13. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  14. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  15. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  16. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  17. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  18. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  19. * THE POSSIBILITY OF SUCH DAMAGE.
  20. *
  21. **************************************************************************//*!
  22. *
  23. * @file usb_audio.c
  24. *
  25. * @author
  26. *
  27. * @version
  28. *
  29. * @date
  30. *
  31. * @brief The file contains USB stack Audio layer implementation.
  32. *
  33. *****************************************************************************/
  34. /******************************************************************************
  35. * Includes
  36. *****************************************************************************/
  37. #include "usb_audio.h" /* USB Audio Class Header File */
  38. #include "usb_devapi.h" /* USB device Header File */
  39. #include "usb_framework.h" /* USB device Header File */
  40. /*****************************************************************************
  41. * Constant and Macro's
  42. *****************************************************************************/
  43. /****************************************************************************
  44. * Global Variables
  45. ****************************************************************************/
  46. /* Audio endpoint info array */
  47. static USB_CLASS_AUDIO_ENDPOINT_DATA g_audio_endpoint_data;
  48. /* Audio Class Callback Function Pointer */
  49. static USB_CLASS_CALLBACK g_audio_class_callback=NULL;
  50. /* Audio Class Vendor Callback Function Pointer */
  51. static USB_REQ_FUNC g_vendor_req_callback=NULL;
  52. /* Audio Class requests Callback Function Pointer */
  53. static USB_CLASS_CALLBACK g_param_callback = NULL;
  54. /*****************************************************************************
  55. * Local Types - None
  56. *****************************************************************************/
  57. /*****************************************************************************
  58. * Local Functions Prototypes
  59. *****************************************************************************/
  60. #ifndef COMPOSITE_DEV
  61. static uint_8 USB_Other_Requests(uint_8 controller_ID,
  62. USB_SETUP_STRUCT * setup_packet,
  63. uint_8_ptr *data,
  64. USB_PACKET_SIZE *size);
  65. #endif
  66. /*****************************************************************************
  67. * Local Variables
  68. *****************************************************************************/
  69. #ifdef USE_FEEDBACK_ENDPOINT
  70. uint_32 feedback_data = 0;
  71. uint_32 gNrSamples = 0;
  72. #endif
  73. /*****************************************************************************
  74. * Local Functions
  75. *****************************************************************************/
  76. /**************************************************************************//*!
  77. *
  78. * @name USB_Service_Audio_Status_Interrupt
  79. *
  80. * @brief The funtion is callback function of Audio Status Interrupt endpoint
  81. *
  82. * @param event
  83. *
  84. * @return None
  85. *
  86. ****************************************************************************
  87. * This function is called in response to Status Interrupt Service
  88. ****************************************************************************/
  89. void USB_Service_Audio_Status_Interrupt(PTR_USB_DEV_EVENT_STRUCT event)
  90. {
  91. #if IMPLEMENT_QUEUING
  92. uint_8 index;
  93. uint_8 producer, consumer;
  94. USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
  95. USB_Desc_Get_Endpoints(event->controller_ID);
  96. /* map the endpoint num to the index of the endpoint structure */
  97. for(index = 0; index < usb_ep_data->count; index++)
  98. {
  99. if(usb_ep_data->ep[index].ep_num == event->ep_num)
  100. break;
  101. }
  102. producer = g_audio_endpoint_data.ep[index].bin_producer;
  103. consumer = g_audio_endpoint_data.ep[index].bin_consumer;
  104. UNUSED(producer);
  105. /* if there are no errors de-queue the queue and decrement the no. of
  106. transfers left, else send the same data again */
  107. if (event->errors == 0)
  108. {
  109. /* de-queue if the send is complete without an error */
  110. if((MAX_QUEUE_ELEMS-1) == consumer)
  111. {
  112. g_audio_endpoint_data.ep[index].bin_consumer = 0;
  113. }
  114. else
  115. {
  116. g_audio_endpoint_data.ep[index].bin_consumer++;
  117. }
  118. }
  119. consumer = g_audio_endpoint_data.ep[index].bin_consumer;
  120. g_audio_endpoint_data.ep[index].queue_num--;
  121. if(0 == g_audio_endpoint_data.ep[index].queue_num)
  122. {
  123. /*if bin is not empty */
  124. USB_CLASS_AUDIO_QUEUE queue;
  125. /* send the next packet in queue */
  126. queue = g_audio_endpoint_data.ep[index].queue[consumer];
  127. (void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
  128. queue.app_buff, queue.size);
  129. }
  130. #endif
  131. if(g_param_callback != NULL)
  132. {
  133. uint_8 event_type = USB_APP_SEND_COMPLETE;
  134. if(event->errors != 0)
  135. {
  136. event_type = USB_APP_ERROR;
  137. }
  138. g_param_callback(event->controller_ID, event_type,
  139. (uint_8*)(&(event->errors)));
  140. }
  141. }
  142. /**************************************************************************//*!
  143. *
  144. * @name USB_Service_Audio_Isochronous_IN
  145. *
  146. * @brief The funtion ic callback function of Audio Isochronous IN endpoint
  147. *
  148. * @param event
  149. *
  150. * @return None
  151. *
  152. ****************************************************************************
  153. * The function is called in response to Isochronous IN Service
  154. ******************************************************************************/
  155. void USB_Service_Audio_Isochronous_IN(PTR_USB_DEV_EVENT_STRUCT event)
  156. {
  157. #if IMPLEMENT_QUEUING
  158. uint_8 index;
  159. uint_8 producer, consumer;
  160. APP_DATA_STRUCT iso_in_recv;
  161. USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
  162. USB_Desc_Get_Endpoints(event->controller_ID);
  163. iso_in_recv.data_ptr = event->buffer_ptr;
  164. iso_in_recv.data_size = event->len;
  165. /* map the endpoint num to the index of the endpoint structure */
  166. for(index = 0; index < usb_ep_data->count; index++)
  167. {
  168. if(usb_ep_data->ep[index].ep_num ==event->ep_num)
  169. break;
  170. }
  171. producer = g_audio_endpoint_data.ep[index].bin_producer;
  172. UNUSED(producer);
  173. /* if there are no errors de-queue the queue and decrement the no. of
  174. transfers left, else send the same data again */
  175. if(event->errors == 0)
  176. {
  177. /* de-queue if the send is complete without an error */
  178. if ((MAX_QUEUE_ELEMS-1) == g_audio_endpoint_data.ep[index].bin_consumer)
  179. {
  180. g_audio_endpoint_data.ep[index].bin_consumer = 0;
  181. } else {
  182. g_audio_endpoint_data.ep[index].bin_consumer++;
  183. }
  184. g_audio_endpoint_data.ep[index].queue_num--;
  185. }
  186. consumer = g_audio_endpoint_data.ep[index].bin_consumer;
  187. if(0 != g_audio_endpoint_data.ep[index].queue_num)
  188. {
  189. /*if bin is not empty */
  190. USB_CLASS_AUDIO_QUEUE queue;
  191. /* send the next packet in queue */
  192. queue = g_audio_endpoint_data.ep[index].queue[consumer];
  193. (void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
  194. queue.app_buff, queue.size);
  195. }
  196. #endif
  197. if(g_audio_class_callback != NULL)
  198. {
  199. uint_8 event_type = USB_APP_SEND_COMPLETE;
  200. if(event->errors != 0)
  201. {
  202. event_type = USB_APP_ERROR;
  203. }
  204. g_audio_class_callback(event->controller_ID, event_type,
  205. (uint_8*)(&iso_in_recv));
  206. }
  207. }
  208. /**************************************************************************//*!
  209. *
  210. * @name USB_Service_Audio_Isochronous_OUT
  211. *
  212. * @brief The funtion is callback function of Isochronous Out Endpoint
  213. *
  214. * @param event
  215. *
  216. * @return None
  217. *
  218. ****************************************************************************
  219. * The function is called in response to Isochronous OUT Service
  220. *****************************************************************************/
  221. void USB_Service_Audio_Isochronous_OUT(PTR_USB_DEV_EVENT_STRUCT event)
  222. {
  223. APP_DATA_STRUCT iso_out_recv;
  224. if(g_audio_class_callback != NULL)
  225. {
  226. if(event->errors != 0)
  227. {
  228. g_audio_class_callback(event->controller_ID, USB_APP_ERROR,
  229. (uint_8*)(&(event->errors)));
  230. } else {
  231. iso_out_recv.data_ptr = event->buffer_ptr;
  232. iso_out_recv.data_size = event->len;
  233. g_audio_class_callback(event->controller_ID, USB_APP_DATA_RECEIVED,
  234. (uint_8*)(&(iso_out_recv)));
  235. }
  236. }
  237. }
  238. /**************************************************************************//*!
  239. *
  240. * @name USB_Class_Audio_Event
  241. *
  242. * @brief The funtion initializes Audio endpoint
  243. *
  244. * @param controller_ID : Controller ID
  245. * @param event : Event Type
  246. * @param val : Pointer to configuration Value
  247. *
  248. * @return None
  249. *
  250. ******************************************************************************
  251. * The funtion initializes the Audio endpoints when event of comleted enumeration is
  252. * received
  253. *****************************************************************************/
  254. void USB_Class_Audio_Event (
  255. uint_8 controller_ID, /* [IN] Controller ID */
  256. uint_8 event, /* [IN] Event Type */
  257. void* val /* [IN] Pointer to configuration Value */
  258. )
  259. {
  260. uint_8 index;
  261. if(event == USB_APP_ENUM_COMPLETE)
  262. {
  263. uint_8 index_num = 0;
  264. uint_8 count = 0,ep_count = 0;
  265. USB_ENDPOINTS *ep_desc_data;
  266. #ifdef COMPOSITE_DEV
  267. DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
  268. CLASS_ARC_STRUCT_PTR dev_class_ptr;
  269. dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);
  270. for(count = 0; count < dev_arc_ptr->cl_count; count++)
  271. {
  272. dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
  273. /* Initializes sub_classes */
  274. ep_count = dev_class_ptr->value[0];
  275. if(dev_class_ptr->class_type == 0x01/*AUDIO_CC*/)
  276. break;
  277. index_num +=dev_class_ptr->value[0];
  278. }
  279. /* get the endpoints from the descriptor module */
  280. ep_desc_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID);
  281. #else
  282. /* get the endpoints from the descriptor module */
  283. ep_desc_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID);
  284. ep_count = ep_desc_data->count;
  285. #endif
  286. /* deinitialize all endpoints in case they were initialized */
  287. for(count=index_num; count<ep_count+index_num; count++)
  288. {
  289. USB_EP_STRUCT_PTR ep_struct_ptr=
  290. (USB_EP_STRUCT_PTR) (&ep_desc_data->ep[count]);
  291. (void)_usb_device_deinit_endpoint(&controller_ID,
  292. ep_struct_ptr->ep_num, ep_struct_ptr->direction);
  293. }
  294. /* intialize all non control endpoints */
  295. for(count=index_num; count<ep_count+index_num; count++)
  296. {
  297. USB_EP_STRUCT_PTR ep_struct=
  298. (USB_EP_STRUCT_PTR)&ep_desc_data->ep[count];
  299. (void)_usb_device_init_endpoint(&controller_ID, ep_struct->ep_num,
  300. ep_struct->size, ep_struct->direction, ep_struct->type, FALSE);
  301. /* register callback service for the endpoint */
  302. switch(ep_struct->type)
  303. {
  304. case USB_INTERRUPT_PIPE:
  305. (void)_usb_device_register_service(controller_ID,
  306. (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
  307. USB_Service_Audio_Status_Interrupt);
  308. break;
  309. case USB_ISOCHRONOUS_PIPE:
  310. if (ep_struct->direction == USB_RECV)
  311. {
  312. (void)_usb_device_register_service(controller_ID,
  313. (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
  314. USB_Service_Audio_Isochronous_OUT);
  315. }
  316. else
  317. {
  318. (void)_usb_device_register_service(controller_ID,
  319. (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
  320. USB_Service_Audio_Isochronous_IN);
  321. }
  322. break;
  323. default:
  324. break;
  325. }
  326. /* set the EndPoint Status as Idle in the device layer */
  327. (void)_usb_device_set_status(&controller_ID,
  328. (uint_8)(USB_STATUS_ENDPOINT | 1|
  329. (ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
  330. USB_STATUS_IDLE);
  331. }
  332. }
  333. else if(event == USB_APP_BUS_RESET)
  334. {
  335. /* clear producer and consumer on reset */
  336. for(index = 0; index < g_audio_endpoint_data.count; index++)
  337. {
  338. g_audio_endpoint_data.ep[index].bin_consumer = 0x00;
  339. g_audio_endpoint_data.ep[index].bin_producer = 0x00;
  340. g_audio_endpoint_data.ep[index].queue_num = 0x00;
  341. }
  342. }
  343. if(g_audio_class_callback != NULL)
  344. {
  345. /* notify the event to the application */
  346. g_audio_class_callback(controller_ID, event, val);
  347. }
  348. }
  349. #if AUDIO_CLASS_2_0
  350. /**************************************************************************
  351. *
  352. * @name: USB_Set_Cur_Audio_Clock
  353. *
  354. * @brief The function sets current attributes of Feature Unit
  355. *
  356. * @param controller_ID : Controller ID
  357. * @param interface : Interface number
  358. * @param control_selector : Control Selector of Request
  359. * @param data : Data to be send back
  360. * @param size : Size to be returned
  361. *
  362. * @return status:
  363. * USB_OK : When Successfull
  364. * USBERR_INVALID_REQ_TYPE : When request for invalid
  365. * Interface is presented
  366. *
  367. ******************************************************************************
  368. * This function is called by USB_Audio_Set_Control_Clock function
  369. *****************************************************************************/
  370. static uint_8 USB_Set_Cur_Audio_Clock(
  371. uint_8 controller_ID, /* [IN] Controller ID */
  372. uint_8 interface, /* [IN] interface */
  373. uint_8 control_selector, /* [IN] control selector */
  374. uint_8_ptr *data, /* [IN] Pointer to Data */
  375. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  376. )
  377. {
  378. uint_8 status = USBERR_INVALID_REQ_TYPE;
  379. switch(control_selector)
  380. {
  381. case CS_SAM_FREQ_CONTROL:
  382. status = USB_Desc_Set_Cur_Sampling_Frequency(controller_ID,interface,data, size);
  383. break;
  384. default:
  385. break;
  386. }
  387. return status;
  388. }
  389. /**************************************************************************
  390. *
  391. * @name: USB_Set_Min_Audio_Clock
  392. *
  393. * @brief The function sets current attributes of Feature Unit
  394. *
  395. * @param controller_ID : Controller ID
  396. * @param interface : Interface number
  397. * @param control_selector : Control Selector of Request
  398. * @param data : Data to be send back
  399. * @param size : Size to be returned
  400. *
  401. * @return status:
  402. * USB_OK : When Successfull
  403. * USBERR_INVALID_REQ_TYPE : When request for invalid
  404. * Interface is presented
  405. *
  406. ******************************************************************************
  407. * This function is called by USB_Audio_Set_Control_Clock function
  408. *****************************************************************************/
  409. static uint_8 USB_Set_Min_Audio_Clock(
  410. uint_8 controller_ID, /* [IN] Controller ID */
  411. uint_8 interface, /* [IN] interface */
  412. uint_8 control_selector, /* [IN] control selector */
  413. uint_8_ptr *data, /* [IN] Pointer to Data */
  414. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  415. )
  416. {
  417. uint_8 status = USBERR_INVALID_REQ_TYPE;
  418. switch(control_selector)
  419. {
  420. case CS_SAM_FREQ_CONTROL:
  421. status = USB_Desc_Set_Min_Sampling_Frequency(controller_ID,interface,data, size);
  422. break;
  423. default:
  424. break;
  425. }
  426. return status;
  427. }
  428. /**************************************************************************
  429. *
  430. * @name: USB_Set_Max_Audio_Clock
  431. *
  432. * @brief The function sets current attributes of Feature Unit
  433. *
  434. * @param controller_ID : Controller ID
  435. * @param interface : Interface number
  436. * @param control_selector : Control Selector of Request
  437. * @param data : Data to be send back
  438. * @param size : Size to be returned
  439. *
  440. * @return status:
  441. * USB_OK : When Successfull
  442. * USBERR_INVALID_REQ_TYPE : When request for invalid
  443. * Interface is presented
  444. *
  445. ******************************************************************************
  446. * This function is called by USB_Audio_Set_Control_Clock function
  447. *****************************************************************************/
  448. static uint_8 USB_Set_Max_Audio_Clock(
  449. uint_8 controller_ID, /* [IN] Controller ID */
  450. uint_8 interface, /* [IN] interface */
  451. uint_8 control_selector, /* [IN] control selector */
  452. uint_8_ptr *data, /* [IN] Pointer to Data */
  453. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  454. )
  455. {
  456. uint_8 status = USBERR_INVALID_REQ_TYPE;
  457. switch(control_selector)
  458. {
  459. case CS_SAM_FREQ_CONTROL:
  460. status = USB_Desc_Set_Max_Sampling_Frequency(controller_ID,interface,data, size);
  461. break;
  462. default:
  463. break;
  464. }
  465. return status;
  466. }
  467. /**************************************************************************
  468. *
  469. * @name: USB_Set_Res_Audio_Clock
  470. *
  471. * @brief The function sets current attributes of Feature Unit
  472. *
  473. * @param controller_ID : Controller ID
  474. * @param interface : Interface number
  475. * @param control_selector : Control Selector of Request
  476. * @param data : Data to be send back
  477. * @param size : Size to be returned
  478. *
  479. * @return status:
  480. * USB_OK : When Successfull
  481. * USBERR_INVALID_REQ_TYPE : When request for invalid
  482. * Interface is presented
  483. *
  484. ******************************************************************************
  485. * This function is called by USB_Audio_Set_Control_Clock function
  486. *****************************************************************************/
  487. static uint_8 USB_Set_Res_Audio_Clock(
  488. uint_8 controller_ID, /* [IN] Controller ID */
  489. uint_8 interface, /* [IN] interface */
  490. uint_8 control_selector, /* [IN] control selector */
  491. uint_8_ptr *data, /* [IN] Pointer to Data */
  492. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  493. )
  494. {
  495. uint_8 status = USBERR_INVALID_REQ_TYPE;
  496. switch(control_selector)
  497. {
  498. case CS_SAM_FREQ_CONTROL:
  499. status = USB_Desc_Set_Res_Sampling_Frequency(controller_ID,interface,data, size);
  500. break;
  501. default:
  502. break;
  503. }
  504. return status;
  505. }
  506. /**************************************************************************//*!
  507. *
  508. * @name: USB_Get_Cur_Audio_Clock
  509. *
  510. * @brief The function gets Current attributes of Feature Unit
  511. *
  512. * @param controller_ID : Controller ID
  513. * @param interface : Interface number
  514. * @param control_selector : Control Selector of Request
  515. * @param data : Data to be send back
  516. * @param size : Size to be returned
  517. *
  518. * @return status:
  519. * USB_OK : When Successfull
  520. * USBERR_INVALID_REQ_TYPE : When request for invalid
  521. * Interface is presented
  522. *
  523. ******************************************************************************
  524. * This function is called by USB_Audio_Get_Control_Clock function
  525. *****************************************************************************/
  526. static uint_8 USB_Get_Cur_Audio_Clock(
  527. uint_8 controller_ID, /* [IN] Controller ID */
  528. uint_8 interface, /* [IN] interface */
  529. uint_8 control_selector, /* [IN] control selector */
  530. uint_8_ptr *data, /* [OUT] Pointer to Data */
  531. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  532. )
  533. {
  534. uint_8 status = USBERR_INVALID_REQ_TYPE;
  535. /* check control selector */
  536. switch(control_selector)
  537. {
  538. case CS_SAM_FREQ_CONTROL:
  539. status = USB_Desc_Get_Cur_Sampling_Frequency(controller_ID,interface,data,size);
  540. break;
  541. case CS_CLOCK_VALID_CONTROL:
  542. status = USB_Desc_Get_Cur_Clock_Validity(controller_ID,interface,data,size);
  543. break;
  544. default:
  545. break;
  546. }
  547. return status;
  548. }
  549. /**************************************************************************//*!
  550. *
  551. * @name: USB_Get_Min_Audio_Clock
  552. *
  553. * @brief The function gets Min attributes of Feature Unit
  554. *
  555. * @param controller_ID : Controller ID
  556. * @param interface : Interface number
  557. * @param control_selector : Control Selector of Request
  558. * @param data : Data to be send back
  559. * @param size : Size to be returned
  560. *
  561. * @return status:
  562. * USB_OK : When Successfull
  563. * USBERR_INVALID_REQ_TYPE : When request for invalid
  564. * Interface is presented
  565. *
  566. ******************************************************************************
  567. * This function is called by USB_Audio_Get_Control_Clock function
  568. *****************************************************************************/
  569. static uint_8 USB_Get_Min_Audio_Clock(
  570. uint_8 controller_ID, /* [IN] Controller ID */
  571. uint_8 interface, /* [IN] interface */
  572. uint_8 control_selector, /* [IN] control selector */
  573. uint_8_ptr *data, /* [OUT] Pointer to Data */
  574. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  575. )
  576. {
  577. uint_8 status = USBERR_INVALID_REQ_TYPE;
  578. switch(control_selector)
  579. {
  580. case CS_SAM_FREQ_CONTROL:
  581. status = USB_Desc_Get_Min_Sampling_Frequency(controller_ID,interface,data,size);
  582. break;
  583. default:
  584. break;
  585. }
  586. return status;
  587. }
  588. /**************************************************************************//*!
  589. *
  590. * @name: USB_Get_Max_Audio_Clock
  591. *
  592. * @brief The function gets Max attributes of Feature Unit
  593. *
  594. * @param controller_ID : Controller ID
  595. * @param interface : Interface number
  596. * @param control_selector : Control Selector of Request
  597. * @param data : Data to be send back
  598. * @param size : Size to be returned
  599. *
  600. * @return status:
  601. * USB_OK : When Successfull
  602. * USBERR_INVALID_REQ_TYPE : When request for invalid
  603. * Interface is presented
  604. *
  605. ******************************************************************************
  606. * This function is called by USB_Audio_Get_Control_Clock function
  607. *****************************************************************************/
  608. static uint_8 USB_Get_Max_Audio_Clock(
  609. uint_8 controller_ID, /* [IN] Controller ID */
  610. uint_8 interface, /* [IN] interface */
  611. uint_8 control_selector, /* [IN] control selector */
  612. uint_8_ptr *data, /* [OUT] Pointer to Data */
  613. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  614. )
  615. {
  616. uint_8 status = USBERR_INVALID_REQ_TYPE;
  617. switch(control_selector)
  618. {
  619. case CS_SAM_FREQ_CONTROL:
  620. status = USB_Desc_Get_Max_Sampling_Frequency(controller_ID,interface,data,size);
  621. break;
  622. default:
  623. break;
  624. }
  625. return status;
  626. }
  627. /**************************************************************************//*!
  628. *
  629. * @name: USB_Get_Res_Audio_Clock
  630. *
  631. * @brief The function gets Resolution attributes of Feature Unit
  632. *
  633. * @param controller_ID : Controller ID
  634. * @param interface : Interface number
  635. * @param control_selector : Control Selector of Request
  636. * @param data : Data to be send back
  637. * @param size : Size to be returned
  638. *
  639. * @return status:
  640. * USB_OK : When Successfull
  641. * USBERR_INVALID_REQ_TYPE : When request for invalid
  642. * Interface is presented
  643. *
  644. ******************************************************************************
  645. * This function is called by USB_Audio_Get_Control_Clock function
  646. *****************************************************************************/
  647. static uint_8 USB_Get_Res_Audio_Clock(
  648. uint_8 controller_ID, /* [IN] Controller ID */
  649. uint_8 interface, /* [IN] interface */
  650. uint_8 control_selector, /* [IN] control selector */
  651. uint_8_ptr *data, /* [OUT] Pointer to Data */
  652. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  653. )
  654. {
  655. uint_8 status = USBERR_INVALID_REQ_TYPE;
  656. switch(control_selector)
  657. {
  658. case CS_SAM_FREQ_CONTROL:
  659. status = USB_Desc_Get_Res_Sampling_Frequency(controller_ID,interface,data,size);
  660. break;
  661. default:
  662. break;
  663. }
  664. return status;
  665. }
  666. #endif /* AUDIO_CLASS_2_0 */
  667. /**************************************************************************//*!
  668. *
  669. * @name: USB_Set_Cur_Audio_Feature_Unit
  670. *
  671. * @brief The function sets current attributes of Feature Unit
  672. *
  673. * @param controller_ID : Controller ID
  674. * @param interface : Interface number
  675. * @param control_selector : Control Selector of Request
  676. * @param data : Data to be send back
  677. * @param size : Size to be returned
  678. *
  679. * @return status:
  680. * USB_OK : When Successfull
  681. * USBERR_INVALID_REQ_TYPE : When request for invalid
  682. * Interface is presented
  683. *
  684. ******************************************************************************
  685. * This function is called by USB_Audio_Set_Feature_Unit function
  686. *****************************************************************************/
  687. static uint_8 USB_Set_Cur_Audio_Feature_Unit(
  688. uint_8 controller_ID, /* [IN] Controller ID */
  689. uint_8 interface, /* [IN] interface */
  690. uint_8 control_selector, /* [IN] control selector */
  691. uint_8_ptr *data, /* [IN] Pointer to Data */
  692. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  693. )
  694. {
  695. uint_8 status = USBERR_INVALID_REQ_TYPE;
  696. switch(control_selector)
  697. {
  698. case MUTE_CONTROL:
  699. status = USB_Desc_Set_Cur_Mute(controller_ID,interface,data, size);
  700. break;
  701. case VOLUME_CONTROL:
  702. status = USB_Desc_Set_Cur_Volume(controller_ID,interface,data,size);
  703. break;
  704. case BASS_CONTROL:
  705. status = USB_Desc_Set_Cur_Bass(controller_ID,interface,data,size);
  706. break;
  707. case MID_CONTROL:
  708. status = USB_Desc_Set_Cur_Mid(controller_ID,interface,data,size);
  709. break;
  710. case TREBLE_CONTROL:
  711. status = USB_Desc_Set_Cur_Treble(controller_ID,interface,data,size);
  712. break;
  713. case GRAPHIC_EQUALIZER_CONTROL:
  714. status=USB_Desc_Set_Cur_Graphic_Equalizer(controller_ID,interface,data,size);
  715. break;
  716. case AUTOMATIC_GAIN_CONTROL:
  717. status = USB_Desc_Set_Cur_Automatic_Gain(controller_ID,interface,data,size);
  718. break;
  719. case DELAY_CONTROL:
  720. status = USB_Desc_Set_Cur_Delay(controller_ID,interface,data,size);
  721. break;
  722. case BASS_BOOST_CONTROL:
  723. status = USB_Desc_Set_Cur_Bass_Boost(controller_ID,interface,data,size);
  724. break;
  725. case LOUDNESS_CONTROL:
  726. status = USB_Desc_Set_Cur_Loudness(controller_ID,interface,data,size);
  727. break;
  728. default:
  729. break;
  730. }
  731. return status;
  732. }
  733. /**************************************************************************//*!
  734. *
  735. * @name: USB_Set_Min_Audio_Feature_Unit
  736. *
  737. * @brief The function sets Min attributes of Feature Unit
  738. *
  739. * @param controller_ID : Controller ID
  740. * @param interface : Interface number
  741. * @param control_selector : Control Selector of Request
  742. * @param data : Data to be send back
  743. * @param size : Size to be returned
  744. *
  745. * @return status:
  746. * USB_OK : When Successfull
  747. * USBERR_INVALID_REQ_TYPE : When request for invalid
  748. * Interface is presented
  749. *
  750. ******************************************************************************
  751. * This function is called by USB_Audio_Set_Feature_Unit function
  752. *****************************************************************************/
  753. static uint_8 USB_Set_Min_Audio_Feature_Unit(
  754. uint_8 controller_ID, /* [IN] Controller ID */
  755. uint_8 interface, /* [IN] interface */
  756. uint_8 control_selector, /* [IN] control selector */
  757. uint_8_ptr *data, /* [IN] Pointer to Data */
  758. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  759. )
  760. {
  761. uint_8 status = USBERR_INVALID_REQ_TYPE;
  762. switch(control_selector)
  763. {
  764. case VOLUME_CONTROL:
  765. status = USB_Desc_Set_Min_Volume(controller_ID,interface,data,size);
  766. break;
  767. case BASS_CONTROL:
  768. status = USB_Desc_Set_Min_Bass(controller_ID,interface,data,size);
  769. break;
  770. case MID_CONTROL:
  771. status = USB_Desc_Set_Min_Mid(controller_ID,interface,data,size);
  772. break;
  773. case TREBLE_CONTROL:
  774. status = USB_Desc_Set_Min_Treble(controller_ID,interface,data,size);
  775. break;
  776. case GRAPHIC_EQUALIZER_CONTROL:
  777. status = USB_Desc_Set_Min_Graphic_Equalizer(controller_ID,interface,data,size);
  778. break;
  779. case DELAY_CONTROL:
  780. status = USB_Desc_Set_Min_Delay(controller_ID,interface,data,size);
  781. break;
  782. default:
  783. break;
  784. }
  785. return status;
  786. }
  787. /**************************************************************************//*!
  788. *
  789. * @name: USB_Set_Max_Audio_Feature_Unit
  790. *
  791. * @brief The function sets Max attributes of Feature Unit
  792. *
  793. * @param controller_ID : Controller ID
  794. * @param interface : Interface number
  795. * @param control_selector : Control Selector of Request
  796. * @param data : Data to be send back
  797. * @param size : Size to be returned
  798. *
  799. * @return status:
  800. * USB_OK : When Successfull
  801. * USBERR_INVALID_REQ_TYPE : When request for invalid
  802. * Interface is presented
  803. *
  804. ******************************************************************************
  805. * This function is called by USB_Audio_Set_Feature_Unit function
  806. *****************************************************************************/
  807. static uint_8 USB_Set_Max_Audio_Feature_Unit(
  808. uint_8 controller_ID, /* [IN] Controller ID */
  809. uint_8 interface, /* [IN] interface */
  810. uint_8 control_selector, /* [IN] control selector */
  811. uint_8_ptr *data, /* [IN] Pointer to Data */
  812. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  813. )
  814. {
  815. uint_8 status = USBERR_INVALID_REQ_TYPE;
  816. switch(control_selector)
  817. {
  818. case VOLUME_CONTROL:
  819. status = USB_Desc_Set_Max_Volume(controller_ID,interface,data,size);
  820. break;
  821. case BASS_CONTROL:
  822. status = USB_Desc_Set_Max_Bass(controller_ID,interface,data,size);
  823. break;
  824. case MID_CONTROL:
  825. status = USB_Desc_Set_Max_Mid(controller_ID,interface,data,size);
  826. break;
  827. case TREBLE_CONTROL:
  828. status = USB_Desc_Set_Max_Treble(controller_ID,interface,data,size);
  829. break;
  830. case GRAPHIC_EQUALIZER_CONTROL:
  831. status =USB_Desc_Set_Max_Graphic_Equalizer(controller_ID,interface,data,size);
  832. break;
  833. case DELAY_CONTROL:
  834. status = USB_Desc_Set_Max_Delay(controller_ID,interface,data,size);
  835. break;
  836. default:
  837. break;
  838. }
  839. return status;
  840. }
  841. /**************************************************************************//*!
  842. *
  843. * @name: USB_Set_Res_Audio_Feature_Unit
  844. *
  845. * @brief The function sets Resolution attributes of Feature Unit
  846. *
  847. * @param controller_ID : Controller ID
  848. * @param interface : Interface number
  849. * @param control_selector : Control Selector of Request
  850. * @param data : Data to be send back
  851. * @param size : Size to be returned
  852. *
  853. * @return status:
  854. * USB_OK : When Successfull
  855. * USBERR_INVALID_REQ_TYPE : When request for invalid
  856. * Interface is presented
  857. *
  858. ******************************************************************************
  859. * This function is called by USB_Audio_Set_Feature_Unit function
  860. *****************************************************************************/
  861. static uint_8 USB_Set_Res_Audio_Feature_Unit(
  862. uint_8 controller_ID, /* [IN] Controller ID */
  863. uint_8 interface, /* [IN] interface */
  864. uint_8 control_selector, /* [IN] control selector */
  865. uint_8_ptr *data, /* [IN] Pointer to Data */
  866. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  867. )
  868. {
  869. uint_8 status = USBERR_INVALID_REQ_TYPE;
  870. switch(control_selector)
  871. {
  872. case VOLUME_CONTROL:
  873. status = USB_Desc_Set_Res_Volume(controller_ID,interface,data,size);
  874. break;
  875. case BASS_CONTROL:
  876. status = USB_Desc_Set_Res_Bass(controller_ID,interface,data,size);
  877. break;
  878. case MID_CONTROL:
  879. status = USB_Desc_Set_Res_Mid(controller_ID,interface,data,size);
  880. break;
  881. case TREBLE_CONTROL:
  882. status = USB_Desc_Set_Res_Treble(controller_ID,interface,data,size);
  883. break;
  884. case GRAPHIC_EQUALIZER_CONTROL:
  885. status = USB_Desc_Set_Res_Graphic_Equalizer(controller_ID,interface,data,size);
  886. break;
  887. case DELAY_CONTROL:
  888. status = USB_Desc_Set_Res_Delay(controller_ID,interface,data,size);
  889. break;
  890. default:
  891. break;
  892. }
  893. return status;
  894. }
  895. /**************************************************************************//*!
  896. *
  897. * @name: USB_Get_Cur_Audio_Feature_Unit
  898. *
  899. * @brief The function gets Current attributes of Feature Unit
  900. *
  901. * @param controller_ID : Controller ID
  902. * @param interface : Interface number
  903. * @param control_selector : Control Selector of Request
  904. * @param data : Data to be send back
  905. * @param size : Size to be returned
  906. *
  907. * @return status:
  908. * USB_OK : When Successfull
  909. * USBERR_INVALID_REQ_TYPE : When request for invalid
  910. * Interface is presented
  911. *
  912. ******************************************************************************
  913. * This function is called by USB_Audio_Get_Feature_Unit function
  914. *****************************************************************************/
  915. static uint_8 USB_Get_Cur_Audio_Feature_Unit(
  916. uint_8 controller_ID, /* [IN] Controller ID */
  917. uint_8 interface, /* [IN] interface */
  918. uint_8 control_selector, /* [IN] control selector */
  919. uint_8_ptr *data, /* [OUT] Pointer to Data */
  920. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  921. )
  922. {
  923. uint_8 status = USBERR_INVALID_REQ_TYPE;
  924. /* check control selector */
  925. switch(control_selector)
  926. {
  927. case MUTE_CONTROL:
  928. status = USB_Desc_Get_Cur_Mute(controller_ID,interface,data,size);
  929. break;
  930. case VOLUME_CONTROL:
  931. status = USB_Desc_Get_Cur_Volume(controller_ID,interface,data,size);
  932. break;
  933. case BASS_CONTROL:
  934. status = USB_Desc_Get_Cur_Bass(controller_ID,interface,data,size);
  935. break;
  936. case MID_CONTROL:
  937. status = USB_Desc_Get_Cur_Mid(controller_ID,interface,data,size);
  938. break;
  939. case TREBLE_CONTROL:
  940. status = USB_Desc_Get_Cur_Treble(controller_ID,interface,data,size);
  941. break;
  942. case GRAPHIC_EQUALIZER_CONTROL:
  943. status = USB_Desc_Get_Cur_Graphic_Equalizer(controller_ID,interface,data,size);
  944. break;
  945. case AUTOMATIC_GAIN_CONTROL:
  946. status = USB_Desc_Get_Cur_Automatic_Gain(controller_ID,interface,data,size);
  947. break;
  948. case DELAY_CONTROL:
  949. status = USB_Desc_Get_Cur_Delay(controller_ID,interface,data,size);
  950. break;
  951. case BASS_BOOST_CONTROL:
  952. status = USB_Desc_Get_Cur_Bass_Boost(controller_ID,interface,data,size);
  953. break;
  954. case LOUDNESS_CONTROL:
  955. status = USB_Desc_Get_Cur_Loudness(controller_ID,interface,data,size);
  956. break;
  957. default:
  958. break;
  959. }
  960. return status;
  961. }
  962. /**************************************************************************//*!
  963. *
  964. * @name: USB_Get_Min_Audio_Feature_Unit
  965. *
  966. * @brief The function gets Min attributes of Feature Unit
  967. *
  968. * @param controller_ID : Controller ID
  969. * @param interface : Interface number
  970. * @param control_selector : Control Selector of Request
  971. * @param data : Data to be send back
  972. * @param size : Size to be returned
  973. *
  974. * @return status:
  975. * USB_OK : When Successfull
  976. * USBERR_INVALID_REQ_TYPE : When request for invalid
  977. * Interface is presented
  978. *
  979. ******************************************************************************
  980. * This function is called by USB_Audio_Get_Feature_Unit function
  981. *****************************************************************************/
  982. static uint_8 USB_Get_Min_Audio_Feature_Unit(
  983. uint_8 controller_ID, /* [IN] Controller ID */
  984. uint_8 interface, /* [IN] interface */
  985. uint_8 control_selector, /* [IN] control selector */
  986. uint_8_ptr *data, /* [OUT] Pointer to Data */
  987. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  988. )
  989. {
  990. uint_8 status = USBERR_INVALID_REQ_TYPE;
  991. switch(control_selector)
  992. {
  993. case VOLUME_CONTROL:
  994. status = USB_Desc_Get_Min_Volume(controller_ID,interface,data,size);
  995. break;
  996. case BASS_CONTROL:
  997. status = USB_Desc_Get_Min_Bass(controller_ID,interface,data,size);
  998. break;
  999. case MID_CONTROL:
  1000. status = USB_Desc_Get_Min_Mid(controller_ID,interface,data,size);
  1001. break;
  1002. case TREBLE_CONTROL:
  1003. status = USB_Desc_Get_Min_Treble(controller_ID,interface,data,size);
  1004. break;
  1005. case GRAPHIC_EQUALIZER_CONTROL:
  1006. status = USB_Desc_Get_Min_Graphic_Equalizer(controller_ID,interface,data,size);
  1007. break;
  1008. case DELAY_CONTROL:
  1009. status = USB_Desc_Get_Min_Delay(controller_ID,interface,data,size);
  1010. break;
  1011. default:
  1012. break;
  1013. }
  1014. return status;
  1015. }
  1016. /**************************************************************************//*!
  1017. *
  1018. * @name: USB_Get_Max_Audio_Feature_Unit
  1019. *
  1020. * @brief The function gets Max attributes of Feature Unit
  1021. *
  1022. * @param controller_ID : Controller ID
  1023. * @param interface : Interface number
  1024. * @param control_selector : Control Selector of Request
  1025. * @param data : Data to be send back
  1026. * @param size : Size to be returned
  1027. *
  1028. * @return status:
  1029. * USB_OK : When Successfull
  1030. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1031. * Interface is presented
  1032. *
  1033. ******************************************************************************
  1034. * This function is called by USB_Audio_Get_Feature_Unit function
  1035. *****************************************************************************/
  1036. static uint_8 USB_Get_Max_Audio_Feature_Unit(
  1037. uint_8 controller_ID, /* [IN] Controller ID */
  1038. uint_8 interface, /* [IN] interface */
  1039. uint_8 control_selector, /* [IN] control selector */
  1040. uint_8_ptr *data, /* [OUT] Pointer to Data */
  1041. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  1042. )
  1043. {
  1044. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1045. switch(control_selector)
  1046. {
  1047. case VOLUME_CONTROL:
  1048. status = USB_Desc_Get_Max_Volume(controller_ID,interface,data,size);
  1049. break;
  1050. case BASS_CONTROL:
  1051. status = USB_Desc_Get_Max_Bass(controller_ID,interface,data,size);
  1052. break;
  1053. case MID_CONTROL:
  1054. status = USB_Desc_Get_Max_Mid(controller_ID,interface,data,size);
  1055. break;
  1056. case TREBLE_CONTROL:
  1057. status = USB_Desc_Get_Max_Treble(controller_ID,interface,data,size);
  1058. break;
  1059. case GRAPHIC_EQUALIZER_CONTROL:
  1060. status = USB_Desc_Get_Max_Graphic_Equalizer(controller_ID,interface,data,size);
  1061. break;
  1062. case DELAY_CONTROL:
  1063. status = USB_Desc_Get_Max_Delay(controller_ID,interface,data,size);
  1064. break;
  1065. default:
  1066. break;
  1067. }
  1068. return status;
  1069. }
  1070. /**************************************************************************//*!
  1071. *
  1072. * @name: USB_Get_Res_Audio_Feature_Unit
  1073. *
  1074. * @brief The function gets Resolution attributes of Feature Unit
  1075. *
  1076. * @param controller_ID : Controller ID
  1077. * @param interface : Interface number
  1078. * @param control_selector : Control Selector of Request
  1079. * @param data : Data to be send back
  1080. * @param size : Size to be returned
  1081. *
  1082. * @return status:
  1083. * USB_OK : When Successfull
  1084. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1085. * Interface is presented
  1086. *
  1087. ******************************************************************************
  1088. * This function is called by USB_Audio_Get_Feature_Unit function
  1089. *****************************************************************************/
  1090. static uint_8 USB_Get_Res_Audio_Feature_Unit(
  1091. uint_8 controller_ID, /* [IN] Controller ID */
  1092. uint_8 interface, /* [IN] interface */
  1093. uint_8 control_selector, /* [IN] control selector */
  1094. uint_8_ptr *data, /* [OUT] Pointer to Data */
  1095. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  1096. )
  1097. {
  1098. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1099. switch(control_selector)
  1100. {
  1101. case VOLUME_CONTROL:
  1102. status = USB_Desc_Get_Res_Volume(controller_ID,interface,data,size);
  1103. break;
  1104. case BASS_CONTROL:
  1105. status = USB_Desc_Get_Res_Bass(controller_ID,interface,data,size);
  1106. break;
  1107. case MID_CONTROL:
  1108. status = USB_Desc_Get_Res_Mid(controller_ID,interface,data,size);
  1109. break;
  1110. case TREBLE_CONTROL:
  1111. status = USB_Desc_Get_Res_Treble(controller_ID,interface,data,size);
  1112. break;
  1113. case GRAPHIC_EQUALIZER_CONTROL:
  1114. status = USB_Desc_Get_Res_Graphic_Equalizer(controller_ID,interface,data,size);
  1115. break;
  1116. case DELAY_CONTROL:
  1117. status=USB_Desc_Get_Res_Delay(controller_ID,interface,data,size);
  1118. break;
  1119. default:
  1120. break;
  1121. }
  1122. return status;
  1123. }
  1124. /**************************************************************************//*!
  1125. *
  1126. * @name: USB_Audio_Set_Control_Terminal
  1127. *
  1128. * @brief The function sets Copy protect level for I/O Terminal
  1129. *
  1130. * @param controller_ID : Controller ID
  1131. * @param setup_packet : Pointer to setup packet
  1132. * @param data : Data to be send back
  1133. * @param size : Size to be returned
  1134. *
  1135. * @return status:
  1136. * USB_OK : When Successfull
  1137. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1138. * Interface is presented
  1139. *
  1140. ******************************************************************************
  1141. * This funtion is called in USB_Set_Request_Interface function
  1142. *****************************************************************************/
  1143. static uint_8 USB_Audio_Set_Control_Terminal(
  1144. uint_8 controller_ID, /* [IN] Controller ID */
  1145. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  1146. uint_8_ptr *data, /* [IN] Pointer to Data */
  1147. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  1148. )
  1149. {
  1150. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1151. switch(setup_packet -> request)
  1152. {
  1153. /*Copy Protect Control only supports the CUR attribute! */
  1154. case SET_CUR:
  1155. if((setup_packet->value >>8) == COPY_PROTECT_CONTROL )
  1156. {
  1157. status = USB_Desc_Set_Copy_Protect(controller_ID,(uint_8)setup_packet->index,data,size);
  1158. }
  1159. break;
  1160. default:
  1161. break;
  1162. }
  1163. return status;
  1164. }
  1165. /**************************************************************************//*!
  1166. *
  1167. * @name: USB_Audio_Get_Control_Terminal
  1168. *
  1169. * @brief The function gets Copy protect level for I/O Terminal
  1170. *
  1171. * @param controller_ID : Controller ID
  1172. * @param setup_packet : Pointer to setup packet
  1173. * @param data : Data to be send back
  1174. * @param size : Size to be returned
  1175. *
  1176. * @return status:
  1177. * USB_OK : When Successfull
  1178. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1179. * Interface is presented
  1180. *
  1181. ******************************************************************************
  1182. * This funtion is called in USB_Get_Request_Interface function
  1183. *****************************************************************************/
  1184. static uint_8 USB_Audio_Get_Control_Terminal(
  1185. uint_8 controller_ID, /* [IN] Controller ID */
  1186. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  1187. uint_8_ptr *data, /* [OUT] Pointer to Data */
  1188. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  1189. )
  1190. {
  1191. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1192. switch(setup_packet -> request)
  1193. {
  1194. /* Copy Protect Control only supports the CUR attribute!*/
  1195. case GET_CUR:
  1196. if((setup_packet ->value >>8) == COPY_PROTECT_CONTROL )
  1197. {
  1198. status = USB_Desc_Get_Copy_Protect(controller_ID,(uint_8)setup_packet->index,data,size);
  1199. }
  1200. break;
  1201. default:
  1202. break;
  1203. }
  1204. return status;
  1205. }
  1206. /**************************************************************************//*!
  1207. *
  1208. * @name: USB_Audio_Set_Feature_Unit
  1209. *
  1210. * @brief The function sets Feature Unit requests
  1211. *
  1212. * @param controller_ID : Controller ID
  1213. * @param setup_packet : Pointer to setup packet
  1214. * @param data : Data to be send back
  1215. * @param size : Size to be returned
  1216. *
  1217. * @return:
  1218. * USB_OK : When Successfull
  1219. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1220. * Interface is presented
  1221. *
  1222. ******************************************************************************
  1223. * This funtion is called in Set_Request_Interface function
  1224. *****************************************************************************/
  1225. static uint_8 USB_Audio_Set_Feature_Unit(
  1226. uint_8 controller_ID, /* [IN] Controller ID */
  1227. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  1228. uint_8_ptr *data, /* [IN] Pointer to Data */
  1229. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  1230. )
  1231. {
  1232. uint_8 interface, control_selector;
  1233. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1234. /* get current interface */
  1235. interface = (uint_8)setup_packet->index;
  1236. /* get control selector */
  1237. control_selector = (uint_8)(setup_packet->value>>8);
  1238. /* Select SET request Control Feature Unit Module */
  1239. switch(setup_packet->request)
  1240. {
  1241. case SET_CUR:
  1242. /*Set current attributes of Feature Unit*/
  1243. status = USB_Set_Cur_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
  1244. break;
  1245. case SET_MIN:
  1246. /*Set Min attributes of Feature Unit*/
  1247. status = USB_Set_Min_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
  1248. break;
  1249. case SET_MAX:
  1250. /*Set Max attributes of Feature Unit*/
  1251. status = USB_Set_Max_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
  1252. break;
  1253. case SET_RES:
  1254. /*Set Resolution attributes of Feature Unit*/
  1255. status = USB_Set_Res_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
  1256. break;
  1257. default:
  1258. break;
  1259. }
  1260. return status;
  1261. }
  1262. /**************************************************************************//*!
  1263. *
  1264. * @name: USB_Audio_Get_Feature_Unit
  1265. *
  1266. * @brief The function gets Feature Unit requests
  1267. *
  1268. * @param controller_ID : Controller ID
  1269. * @param setup_packet : Pointer to setup packet
  1270. * @param data : Data to be send back
  1271. * @param size : Size to be returned
  1272. *
  1273. * @return status:
  1274. * USB_OK : When Successfull
  1275. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1276. * Interface is presented
  1277. *
  1278. ******************************************************************************
  1279. * This funtion is called in the Get_Request_Interface function
  1280. *****************************************************************************/
  1281. static uint_8 USB_Audio_Get_Feature_Unit(
  1282. uint_8 controller_ID, /* [IN] Controller ID */
  1283. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  1284. uint_8_ptr *data, /* [OUT] Pointer to Data */
  1285. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  1286. )
  1287. {
  1288. uint_8 interface, control_selector;
  1289. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1290. interface = (uint_8)setup_packet->index;
  1291. control_selector = (uint_8)(setup_packet->value>>8);
  1292. /* Select SET request Control Feature Unit Module */
  1293. switch(setup_packet->request)
  1294. {
  1295. case GET_CUR:
  1296. status = USB_Get_Cur_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
  1297. break;
  1298. case GET_MIN:
  1299. status = USB_Get_Min_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
  1300. break;
  1301. case GET_MAX:
  1302. status = USB_Get_Max_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
  1303. break;
  1304. case GET_RES:
  1305. status = USB_Get_Res_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
  1306. break;
  1307. default:
  1308. break;
  1309. }
  1310. UNUSED(status);
  1311. return USB_OK;
  1312. }
  1313. #if AUDIO_CLASS_2_0
  1314. /**************************************************************************//*!
  1315. *
  1316. * @name: USB_Audio_Set_Control_Clock
  1317. *
  1318. * @brief The function sets Clock requests
  1319. *
  1320. * @param controller_ID : Controller ID
  1321. * @param setup_packet : Pointer to setup packet
  1322. * @param data : Data to be send back
  1323. * @param size : Size to be returned
  1324. *
  1325. * @return:
  1326. * USB_OK : When Successfull
  1327. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1328. * Interface is presented
  1329. *
  1330. ******************************************************************************
  1331. * This function is called in Set_Request_Interface function
  1332. *****************************************************************************/
  1333. static uint_8 USB_Audio_Set_Control_Clock(
  1334. uint_8 controller_ID, /* [IN] Controller ID */
  1335. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  1336. uint_8_ptr *data, /* [IN] Pointer to Data */
  1337. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  1338. )
  1339. {
  1340. uint_8 interface, control_selector;
  1341. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1342. /* get current interface */
  1343. interface = (uint_8)setup_packet->index;
  1344. /* get control selector */
  1345. control_selector = (uint_8)(setup_packet->value>>8);
  1346. /* Select SET request Control Clock Control Module */
  1347. switch(setup_packet->request)
  1348. {
  1349. case SET_CUR:
  1350. /*Set current attributes for Clock Control*/
  1351. status = USB_Set_Cur_Audio_Clock(controller_ID,interface,control_selector,data,size);
  1352. break;
  1353. case SET_MIN:
  1354. /*Set Min attributes of Clock Control */
  1355. status = USB_Set_Min_Audio_Clock(controller_ID,interface,control_selector,data,size);
  1356. break;
  1357. case SET_MAX:
  1358. /*Set Max attributes of Clock Control */
  1359. status = USB_Set_Max_Audio_Clock(controller_ID,interface,control_selector,data,size);
  1360. break;
  1361. case SET_RES:
  1362. /*Set Resolution attributes of Clock Control */
  1363. status = USB_Set_Res_Audio_Clock(controller_ID,interface,control_selector,data,size);
  1364. break;
  1365. default:
  1366. break;
  1367. }
  1368. return status;
  1369. }
  1370. /**************************************************************************//*!
  1371. *
  1372. * @name: USB_Audio_Get_Control_Clock
  1373. *
  1374. * @brief The function gets Clock requests
  1375. *
  1376. * @param controller_ID : Controller ID
  1377. * @param setup_packet : Pointer to setup packet
  1378. * @param data : Data to be send back
  1379. * @param size : Size to be returned
  1380. *
  1381. * @return status:
  1382. * USB_OK : When Successfull
  1383. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1384. * Interface is presented
  1385. *
  1386. ******************************************************************************
  1387. * This function is called in the Get_Request_Interface function
  1388. *****************************************************************************/
  1389. static uint_8 USB_Audio_Get_Control_Clock(
  1390. uint_8 controller_ID, /* [IN] Controller ID */
  1391. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  1392. uint_8_ptr *data, /* [OUT] Pointer to Data */
  1393. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  1394. )
  1395. {
  1396. uint_8 interface, control_selector;
  1397. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1398. interface = (uint_8)setup_packet->index;
  1399. control_selector = (uint_8)(setup_packet->value>>8);
  1400. /* Select GET request Control Feature Unit Module */
  1401. switch(setup_packet->request)
  1402. {
  1403. case GET_CUR:
  1404. status = USB_Get_Cur_Audio_Clock(controller_ID,interface,control_selector,data,size);
  1405. break;
  1406. case GET_MIN:
  1407. status = USB_Get_Min_Audio_Clock(controller_ID,interface,control_selector,data,size);
  1408. break;
  1409. case GET_MAX:
  1410. status = USB_Get_Max_Audio_Clock(controller_ID,interface,control_selector,data,size);
  1411. break;
  1412. case GET_RES:
  1413. status = USB_Get_Res_Audio_Clock(controller_ID,interface,control_selector,data,size);
  1414. break;
  1415. default:
  1416. break;
  1417. }
  1418. return USB_OK;
  1419. }
  1420. #endif /* AUDIO_CLASS_2_0 */
  1421. /**************************************************************************//*!
  1422. *
  1423. * @name: USB_Set_Request_Interface
  1424. *
  1425. * @brief This function is called in response to Set Interface Requests
  1426. *
  1427. * @param controller_ID : Controller ID
  1428. * @param setup_packet : Pointer to setup packet
  1429. * @param data : Data to be send back
  1430. * @param size : Size to be returned
  1431. *
  1432. * @return status:
  1433. * USB_OK : When Successfull
  1434. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1435. * Interface is presented
  1436. *
  1437. ******************************************************************************
  1438. * The funtion set Feature unit and Terminal request. It is called in
  1439. * USB_Other_Request function
  1440. *****************************************************************************/
  1441. static uint_8 USB_Set_Request_Interface(
  1442. uint_8 controller_ID, /* [IN] Controller ID */
  1443. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  1444. uint_8_ptr *data, /* [IN] Pointer to Data */
  1445. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  1446. )
  1447. {
  1448. uint_8 i;
  1449. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1450. USB_AUDIO_UNITS *entity_desc_data;
  1451. USB_UT_STRUCT_PTR ut_struct;
  1452. *size = 0;
  1453. /* get the I/O Interface and Feature from the descriptor module */
  1454. entity_desc_data = (USB_AUDIO_UNITS *)USB_Desc_Get_Audio_Entities(controller_ID);
  1455. for(i=0; i<AUDIO_UNIT_COUNT; i++)
  1456. {
  1457. ut_struct=(USB_UT_STRUCT_PTR)&(entity_desc_data->et[i]);
  1458. /* wIndex H byte is Entity ID */
  1459. if((setup_packet->index>>8) == ut_struct->unit_id)
  1460. {
  1461. switch(ut_struct->type)
  1462. {
  1463. #if AUDIO_CLASS_2_0
  1464. case AUDIO_CONTROL_CLOCK_SOURCE:
  1465. status = USB_Audio_Set_Control_Clock(controller_ID,setup_packet,data,size);
  1466. break;
  1467. #endif /* AUDIO_CLASS_2_0 */
  1468. case AUDIO_CONTROL_INPUT_TERMINAL:
  1469. break;
  1470. case AUDIO_CONTROL_FEATURE_UNIT:
  1471. /* Select SET request Control Feature Unit Module */
  1472. status = USB_Audio_Set_Feature_Unit(controller_ID,setup_packet,data,size);
  1473. break;
  1474. case AUDIO_CONTROL_OUTPUT_TERMINAL:
  1475. /* Select SET request Output Terminal Module */
  1476. status = USB_Audio_Set_Control_Terminal(controller_ID,setup_packet,data,size);
  1477. break;
  1478. default:
  1479. break;
  1480. }
  1481. }
  1482. }
  1483. return status;
  1484. }
  1485. /**************************************************************************//*!
  1486. *
  1487. * @name: USB_Get_Request_Interface
  1488. *
  1489. * @brief This function is called in response to Get Interface Requests
  1490. *
  1491. * @param controller_ID : Controller ID
  1492. * @param setup_packet : Pointer to setup packet
  1493. * @param data : Data to be send back
  1494. * @param size : Size to be returned
  1495. *
  1496. * @return status:
  1497. * USB_OK : When Successfull
  1498. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1499. * Interface is presented
  1500. *
  1501. ******************************************************************************
  1502. * The funtion Get Feature unit and Terminal requests. It is called in
  1503. * USB_Other_Request function
  1504. *****************************************************************************/
  1505. static uint_8 USB_Get_Request_Interface(
  1506. uint_8 controller_ID, /* [IN] Controller ID */
  1507. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  1508. uint_8_ptr *data, /* [OUT] Pointer to Data */
  1509. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  1510. )
  1511. {
  1512. uint_8 i;
  1513. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1514. USB_AUDIO_UNITS *entity_desc_data;
  1515. USB_UT_STRUCT_PTR ut_struct;
  1516. /* get the I/O Interface and Feature from the descriptor module */
  1517. entity_desc_data = (USB_AUDIO_UNITS *)USB_Desc_Get_Audio_Entities(controller_ID);
  1518. for(i=0;i<AUDIO_UNIT_COUNT; i++)
  1519. {
  1520. ut_struct=(USB_UT_STRUCT_PTR)&(entity_desc_data->et[i]);
  1521. if((setup_packet->index >>8) == ut_struct->unit_id)
  1522. {
  1523. switch(ut_struct->type)
  1524. {
  1525. #if AUDIO_CLASS_2_0
  1526. case AUDIO_CONTROL_CLOCK_SOURCE:
  1527. status = USB_Audio_Get_Control_Clock(controller_ID,setup_packet,data,size);
  1528. break;
  1529. #endif /* AUDIO_CLASS_2_0 */
  1530. case AUDIO_CONTROL_INPUT_TERMINAL:
  1531. /*Select SET Request Control Input Terminal Module */
  1532. status = USB_Audio_Get_Control_Terminal(controller_ID,setup_packet,data,size);
  1533. break;
  1534. case AUDIO_CONTROL_FEATURE_UNIT:
  1535. /* Select SET request Control Feature Unit Module */
  1536. status = USB_Audio_Get_Feature_Unit(controller_ID,setup_packet,data,size);
  1537. break;
  1538. default:
  1539. break;
  1540. }
  1541. }
  1542. }
  1543. return status;
  1544. }
  1545. /**************************************************************************//*!
  1546. *
  1547. * @name: USB_Set_Request_Endpoint
  1548. *
  1549. * @brief This function is called in response to Set Endpoint Requests
  1550. *
  1551. * @param controller_ID : Controller ID
  1552. * @param setup_packet : Pointer to setup packet
  1553. * @param data : Data to be send back
  1554. * @param size : Size to be returned
  1555. *
  1556. * @return status:
  1557. * USB_OK : When Successfull
  1558. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1559. * Interface is presented
  1560. *
  1561. ******************************************************************************
  1562. ** This funtion is called by USB_Other_Request function
  1563. *****************************************************************************/
  1564. static uint_8 USB_Set_Request_Endpoint
  1565. (
  1566. uint_8 controller_ID, /* [IN] Controller ID */
  1567. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  1568. uint_8_ptr *data, /* [IN] Pointer to Data */
  1569. USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
  1570. )
  1571. {
  1572. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1573. uint_8 interface;
  1574. uint_8 control_selector;
  1575. uint_16 offset;
  1576. /* get current interface */
  1577. interface = (uint_8)setup_packet->index;
  1578. /* get control selector */
  1579. control_selector = (uint_8)(setup_packet->value>>8);
  1580. switch(setup_packet->request)
  1581. {
  1582. case SET_CUR:
  1583. {
  1584. *size = 0;
  1585. switch(control_selector)
  1586. {
  1587. #if !AUDIO_CLASS_2_0
  1588. /*
  1589. * Request Valid only in Audio 1.0, in Audio 2.0 it was moved
  1590. * into Interface Requests
  1591. */
  1592. case SAMPLING_FREQ_CONTROL:
  1593. status = USB_Desc_Set_Cur_Sampling_Frequency(controller_ID,interface,data,size);
  1594. break;
  1595. #endif /* AUDIO_CLASS_2_0 */
  1596. case PITCH_CONTROL:
  1597. status = USB_Desc_Set_Cur_Pitch(controller_ID,interface,data,size);
  1598. break;
  1599. default:
  1600. break;
  1601. }
  1602. }
  1603. break;
  1604. case SET_MIN:
  1605. {
  1606. *size = 0;
  1607. switch(control_selector)
  1608. {
  1609. #if !AUDIO_CLASS_2_0
  1610. case SAMPLING_FREQ_CONTROL:
  1611. status = USB_Desc_Set_Min_Sampling_Frequency(controller_ID,interface,data,size);
  1612. break;
  1613. #endif /* AUDIO_CLASS_2_0 */
  1614. default:
  1615. break;
  1616. }
  1617. }
  1618. break;
  1619. case SET_MAX:
  1620. {
  1621. *size = 0;
  1622. switch(control_selector)
  1623. {
  1624. #if !AUDIO_CLASS_2_0
  1625. case SAMPLING_FREQ_CONTROL:
  1626. status = USB_Desc_Set_Max_Sampling_Frequency(controller_ID,interface,data,size);
  1627. break;
  1628. #endif /* AUDIO_CLASS_2_0 */
  1629. default:
  1630. break;
  1631. }
  1632. }
  1633. break;
  1634. case SET_RES:
  1635. {
  1636. *size = 0;
  1637. switch(control_selector)
  1638. {
  1639. #if !AUDIO_CLASS_2_0
  1640. case SAMPLING_FREQ_CONTROL:
  1641. status = USB_Desc_Set_Res_Sampling_Frequency(controller_ID,interface,data,size);
  1642. break;
  1643. #endif /* AUDIO_CLASS_2_0 */
  1644. default:
  1645. break;
  1646. }
  1647. }
  1648. break;
  1649. case SET_MEM:
  1650. *size = setup_packet->length;
  1651. offset=setup_packet->value;
  1652. status = USB_Desc_Set_Mem_Endpoint(controller_ID,offset,interface,data,size);
  1653. break;
  1654. default:
  1655. break;
  1656. }
  1657. return status;
  1658. }
  1659. /**************************************************************************//*!
  1660. *
  1661. * @name: USB_Get_Request_Endpoint
  1662. *
  1663. * @brief This function is called in response to Get Endpoint Requests
  1664. *
  1665. * @param controller_ID : Controller ID
  1666. * @param setup_packet : Pointer to setup packet
  1667. * @param data : Data to be send back
  1668. * @param size : Size to be returned
  1669. *
  1670. * @return status:
  1671. * USB_OK : When Successfull
  1672. * USBERR_INVALID_REQ_TYPE : When request for invalid
  1673. * Interface is presented
  1674. *
  1675. ******************************************************************************
  1676. * This funtion is called by USB_Other_Request function
  1677. *****************************************************************************/
  1678. static uint_8 USB_Get_Request_Endpoint
  1679. (
  1680. uint_8 controller_ID, /* [IN] Controller ID */
  1681. USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
  1682. uint_8_ptr *data, /* [OUT] Pointer to Data */
  1683. USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
  1684. )
  1685. {
  1686. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1687. uint_8 interface;
  1688. uint_8 control_selector;
  1689. uint_16 offset;
  1690. /* get current interface */
  1691. interface = (uint_8)setup_packet->index;
  1692. /* get control selector */
  1693. control_selector = (uint_8)(setup_packet->value >>8);
  1694. switch(setup_packet->request)
  1695. {
  1696. case GET_CUR:
  1697. switch(control_selector)
  1698. {
  1699. case SAMPLING_FREQ_CONTROL:
  1700. status = USB_Desc_Get_Cur_Sampling_Frequency(controller_ID,interface,data,size);
  1701. break;
  1702. case PITCH_CONTROL:
  1703. status = USB_Desc_Get_Cur_Pitch(controller_ID,interface,data,size);
  1704. break;
  1705. default:
  1706. break;
  1707. }
  1708. break;
  1709. case GET_MIN:
  1710. switch(control_selector)
  1711. {
  1712. case SAMPLING_FREQ_CONTROL:
  1713. status = USB_Desc_Get_Min_Sampling_Frequency(controller_ID,interface,data,size);
  1714. break;
  1715. default:
  1716. break;
  1717. }
  1718. break;
  1719. case GET_MAX:
  1720. switch(control_selector)
  1721. {
  1722. case SAMPLING_FREQ_CONTROL:
  1723. status = USB_Desc_Get_Max_Sampling_Frequency(controller_ID,interface,data,size);
  1724. break;
  1725. default:
  1726. break;
  1727. }
  1728. break;
  1729. case GET_RES:
  1730. switch(control_selector)
  1731. {
  1732. case SAMPLING_FREQ_CONTROL:
  1733. status = USB_Desc_Get_Res_Sampling_Frequency(controller_ID,interface,data,size);
  1734. break;
  1735. default:
  1736. break;
  1737. }
  1738. break;
  1739. case GET_MEM:
  1740. *size = setup_packet->length;
  1741. offset=setup_packet->value;
  1742. status = USB_Desc_Get_Mem_Endpoint(controller_ID,offset,interface,data,size);
  1743. break;
  1744. default:
  1745. break;
  1746. }
  1747. return status;
  1748. }
  1749. /**************************************************************************//*!
  1750. *
  1751. * @name USB_Other_Requests
  1752. *
  1753. * @brief The funtion provides flexibilty to add class and vendor specific
  1754. * requests
  1755. *
  1756. * @param controller_ID : Controller ID
  1757. * @param setup_packet : Setup packet received
  1758. * @param data : Data to be send back
  1759. * @param size : Size to be returned
  1760. *
  1761. * @return status:
  1762. * USB_OK : When Successfull
  1763. * Others : When Error
  1764. *
  1765. ******************************************************************************
  1766. * Handles Audio Class requests and forwards vendor specific request to the
  1767. * application
  1768. *****************************************************************************/
  1769. #ifndef COMPOSITE_DEV
  1770. static uint_8 USB_Other_Requests
  1771. #else
  1772. uint_8 USB_Audio_Other_Requests
  1773. #endif
  1774. (
  1775. uint_8 controller_ID, /* [IN] Controller ID */
  1776. USB_SETUP_STRUCT * setup_packet, /*[IN] Setup packet received */
  1777. uint_8_ptr *data, /* [OUT] Data to be send back */
  1778. USB_PACKET_SIZE *size /* [OUT] Size to be returned*/
  1779. )
  1780. {
  1781. uint_8 status = USBERR_INVALID_REQ_TYPE;
  1782. /* point to the data which comes after the setup packet */
  1783. *data = ((uint_8*)setup_packet)+USB_SETUP_PKT_SIZE;
  1784. if (size == NULL)
  1785. {
  1786. return USBERR_GET_MEMORY_FAILED;
  1787. }
  1788. switch(setup_packet->request_type)
  1789. {
  1790. /* Set I/O Terminal and Feature Unit */
  1791. case SET_REQUEST_ITF:
  1792. status = USB_Set_Request_Interface(controller_ID,setup_packet,data,size);
  1793. break;
  1794. /*Get I/O Terminal and Feature Unit */
  1795. case GET_REQUEST_ITF:
  1796. status = USB_Get_Request_Interface(controller_ID,setup_packet,data,size);
  1797. break;
  1798. /* Set Endpoint Request */
  1799. case SET_REQUEST_EP:
  1800. status = USB_Set_Request_Endpoint(controller_ID,setup_packet,data,size);
  1801. break;
  1802. /* Get Endpoint Request */
  1803. case GET_REQUEST_EP:
  1804. status = USB_Get_Request_Endpoint(controller_ID,setup_packet,data,size);
  1805. break;
  1806. default:
  1807. break;
  1808. } /* end of switch */
  1809. return status;
  1810. }
  1811. /*****************************************************************************
  1812. * Global Functions
  1813. *****************************************************************************/
  1814. /**************************************************************************//*!
  1815. *
  1816. * @name USB_Class_Audio_Init
  1817. *
  1818. * @brief The funtion initializes the Device and Controller layer
  1819. *
  1820. * @param controller_ID : Controller ID
  1821. * @param audio_class_callback : Audio Class Callback
  1822. * @param vendor_req_callback : Vendor Request Callback
  1823. * @param param_callback : Class requests Callback
  1824. *
  1825. * @return status:
  1826. * USB_OK : When Successfull
  1827. * Others : When Error
  1828. *
  1829. ******************************************************************************
  1830. *This function initializes the Audio Class layer and layers it is dependent on
  1831. *****************************************************************************/
  1832. uint_8 USB_Class_Audio_Init (
  1833. uint_8 controller_ID, /* [IN] Controller ID */
  1834. USB_CLASS_CALLBACK audio_class_callback, /* [IN] Audio Class Callback */
  1835. USB_REQ_FUNC vendor_req_callback, /* [IN] Vendor Request Callback */
  1836. USB_CLASS_CALLBACK param_callback /* [ IN] Audio Class requests Callback */
  1837. )
  1838. {
  1839. uint_8 index;
  1840. uint_8 status = USB_OK;
  1841. USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *)
  1842. USB_Desc_Get_Endpoints(controller_ID);
  1843. #ifndef COMPOSITE_DEV
  1844. /* Initialize the device layer*/
  1845. status = _usb_device_init(controller_ID, NULL,
  1846. (uint_8)(ep_desc_data->count+1), TRUE);
  1847. if(status == USB_OK)
  1848. {
  1849. /* Initialize the generic class functions */
  1850. status = USB_Class_Init(controller_ID,USB_Class_Audio_Event,
  1851. USB_Other_Requests);
  1852. if(status == USB_OK)
  1853. {
  1854. #endif
  1855. g_audio_endpoint_data.count = ep_desc_data->count;
  1856. for(index = 0; index < ep_desc_data->count; index++)
  1857. {
  1858. g_audio_endpoint_data.ep[index].endpoint = ep_desc_data->ep[index].ep_num;
  1859. g_audio_endpoint_data.ep[index].type = ep_desc_data->ep[index].type;
  1860. g_audio_endpoint_data.ep[index].bin_consumer = 0x00;
  1861. g_audio_endpoint_data.ep[index].bin_producer = 0x00;
  1862. g_audio_endpoint_data.ep[index].queue_num = 0x00;
  1863. }
  1864. /* save the Audio class callback pointer */
  1865. g_audio_class_callback = audio_class_callback;
  1866. /* save the vendor request callback pointer */
  1867. g_vendor_req_callback = vendor_req_callback;
  1868. UNUSED(g_vendor_req_callback);
  1869. /* Save the callback to ask application for class specific params*/
  1870. g_param_callback = param_callback;
  1871. #ifndef COMPOSITE_DEV
  1872. }
  1873. }
  1874. #endif
  1875. return status;
  1876. }
  1877. /**************************************************************************//*!
  1878. *
  1879. * @name USB_Class_Audio_DeInit
  1880. *
  1881. * @brief The funtion de-initializes the Device and Controller layer
  1882. *
  1883. * @param controller_ID : Controller ID
  1884. *
  1885. * @return status:
  1886. * USB_OK : When Successfull
  1887. * Others : When Error
  1888. *
  1889. ******************************************************************************
  1890. *This function de-initializes the Audio Class layer
  1891. *****************************************************************************/
  1892. uint_8 USB_Class_Audio_DeInit
  1893. (
  1894. uint_8 controller_ID /* [IN] Controller ID */
  1895. )
  1896. {
  1897. uint_8 status = USB_OK;
  1898. #ifdef COMPOSITE_DEV
  1899. UNUSED(controller_ID)
  1900. #endif
  1901. /* free the Audio class callback pointer */
  1902. g_audio_class_callback = NULL;
  1903. /* free the vendor request callback pointer */
  1904. g_vendor_req_callback = NULL;
  1905. /* free the callback to ask application for class specific params*/
  1906. g_param_callback = NULL;
  1907. #ifndef COMPOSITE_DEV
  1908. /* Call common class deinit function */
  1909. status = USB_Class_DeInit(controller_ID);
  1910. if(status == USB_OK)
  1911. /* Call device deinit function */
  1912. status = _usb_device_deinit();
  1913. #endif
  1914. return status;
  1915. }
  1916. /**************************************************************************//*!
  1917. *
  1918. * @name USB_Class_Audio_Send_Data
  1919. *
  1920. * @brief This fucntion is used by Application to send data through Audio class
  1921. *
  1922. * @param controller_ID : Controller ID
  1923. * @param ep_num : Endpoint number
  1924. * @param app_buff : Buffer to send
  1925. * @param size : Length of the transfer
  1926. *
  1927. * @return status:
  1928. * USB_OK : When Successfull
  1929. * Others : When Error
  1930. *
  1931. ******************************************************************************
  1932. * This fucntion is used by Application to send data through Audio class
  1933. *****************************************************************************/
  1934. uint_8 USB_Class_Audio_Send_Data (
  1935. uint_8 controller_ID, /* [IN] Controller ID */
  1936. uint_8 ep_num, /* [IN] Endpoint Number */
  1937. uint_8_ptr app_buff, /* [IN] Buffer to Send */
  1938. USB_PACKET_SIZE size /* [IN] Length of the Transfer */
  1939. )
  1940. {
  1941. uint_8 status = USB_OK;
  1942. PTR_USB_CLASS_AUDIO_QUEUE queue_tmp;
  1943. #if IMPLEMENT_QUEUING
  1944. uint_8 index;
  1945. uint_8 producer, queue_num;
  1946. USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
  1947. USB_Desc_Get_Endpoints(controller_ID);
  1948. /* map the endpoint num to the index of the endpoint structure */
  1949. for(index = 0; index < usb_ep_data->count; index++)
  1950. {
  1951. if(usb_ep_data->ep[index].ep_num == ep_num)
  1952. break;
  1953. }
  1954. producer = g_audio_endpoint_data.ep[index].bin_producer;
  1955. queue_num = g_audio_endpoint_data.ep[index].queue_num;
  1956. UNUSED(producer);
  1957. if(MAX_QUEUE_ELEMS != queue_num)
  1958. {
  1959. /* the bin is not full*/
  1960. /* put all send request parameters in the endpoint data structure */
  1961. queue_tmp = &(g_audio_endpoint_data.ep[index].queue[producer]);
  1962. queue_tmp->controller_ID = controller_ID;
  1963. queue_tmp->channel = ep_num;
  1964. queue_tmp->app_buff = app_buff;
  1965. queue_tmp->size = size;
  1966. /* increment producer bin by 1*/
  1967. if (producer == (MAX_QUEUE_ELEMS - 1))
  1968. {
  1969. g_audio_endpoint_data.ep[index].bin_producer = 0;
  1970. }
  1971. else
  1972. {
  1973. g_audio_endpoint_data.ep[index].bin_producer++;
  1974. }
  1975. g_audio_endpoint_data.ep[index].queue_num++;
  1976. if(g_audio_endpoint_data.ep[index].queue_num == 1)
  1977. {
  1978. #endif
  1979. status = USB_Class_Send_Data(controller_ID, ep_num, app_buff,size);
  1980. #if IMPLEMENT_QUEUING
  1981. }
  1982. }
  1983. else /* bin is full */
  1984. {
  1985. status = USBERR_DEVICE_BUSY;
  1986. }
  1987. #endif
  1988. return status;
  1989. }
  1990. /**************************************************************************//*!
  1991. *
  1992. * @name USB_Class_Audio_Recv_Data
  1993. *
  1994. * @brief This function receives Data from Host.
  1995. *
  1996. * @param controller_ID : Controller ID
  1997. * @param ep_num : Endpoint number
  1998. * @param app_buff : Buffer to send
  1999. * @param size : Length of the transfer
  2000. *
  2001. * @return status
  2002. * USB_OK : When Successfull
  2003. * Others : Errors
  2004. ****************************************************************************
  2005. * This function called bye USB_App_Callback function
  2006. *****************************************************************************/
  2007. uint_8 USB_Class_Audio_Recv_Data
  2008. (
  2009. uint_8 controller_ID, /* [IN] Controller ID */
  2010. uint_8 ep_num, /* [IN] Endpoint Number */
  2011. uint_8_ptr app_buff, /* [IN] Buffer to Send */
  2012. USB_PACKET_SIZE size /* [IN] Length of the Transfer */
  2013. )
  2014. {
  2015. uint_8 status;
  2016. status = _usb_device_recv_data(&controller_ID,ep_num,app_buff,size);
  2017. return status;
  2018. }