| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145 |
- /******************************************************************************
- *
- * Freescale Semiconductor Inc.
- * (c) Copyright 2004-2010 Freescale Semiconductor, Inc.
- * ALL RIGHTS RESERVED.
- *
- ******************************************************************************
- *
- * THIS SOFTWARE IS PROVIDED BY FREESCALE "AS IS" AND ANY EXPRESSED OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL FREESCALE OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
- * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- *
- **************************************************************************//*!
- *
- * @file usb_audio.c
- *
- * @author
- *
- * @version
- *
- * @date
- *
- * @brief The file contains USB stack Audio layer implementation.
- *
- *****************************************************************************/
- /******************************************************************************
- * Includes
- *****************************************************************************/
- #include "usb_audio.h" /* USB Audio Class Header File */
- #include "usb_devapi.h" /* USB device Header File */
- #include "usb_framework.h" /* USB device Header File */
- /*****************************************************************************
- * Constant and Macro's
- *****************************************************************************/
- /****************************************************************************
- * Global Variables
- ****************************************************************************/
- /* Audio endpoint info array */
- static USB_CLASS_AUDIO_ENDPOINT_DATA g_audio_endpoint_data;
- /* Audio Class Callback Function Pointer */
- static USB_CLASS_CALLBACK g_audio_class_callback=NULL;
- /* Audio Class Vendor Callback Function Pointer */
- static USB_REQ_FUNC g_vendor_req_callback=NULL;
- /* Audio Class requests Callback Function Pointer */
- static USB_CLASS_CALLBACK g_param_callback = NULL;
- /*****************************************************************************
- * Local Types - None
- *****************************************************************************/
- /*****************************************************************************
- * Local Functions Prototypes
- *****************************************************************************/
- #ifndef COMPOSITE_DEV
- static uint_8 USB_Other_Requests(uint_8 controller_ID,
- USB_SETUP_STRUCT * setup_packet,
- uint_8_ptr *data,
- USB_PACKET_SIZE *size);
- #endif
- /*****************************************************************************
- * Local Variables
- *****************************************************************************/
- #ifdef USE_FEEDBACK_ENDPOINT
- uint_32 feedback_data = 0;
- uint_32 gNrSamples = 0;
- #endif
- /*****************************************************************************
- * Local Functions
- *****************************************************************************/
- /**************************************************************************//*!
- *
- * @name USB_Service_Audio_Status_Interrupt
- *
- * @brief The funtion is callback function of Audio Status Interrupt endpoint
- *
- * @param event
- *
- * @return None
- *
- ****************************************************************************
- * This function is called in response to Status Interrupt Service
- ****************************************************************************/
- void USB_Service_Audio_Status_Interrupt(PTR_USB_DEV_EVENT_STRUCT event)
- {
- #if IMPLEMENT_QUEUING
- uint_8 index;
- uint_8 producer, consumer;
- USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
- USB_Desc_Get_Endpoints(event->controller_ID);
- /* map the endpoint num to the index of the endpoint structure */
- for(index = 0; index < usb_ep_data->count; index++)
- {
- if(usb_ep_data->ep[index].ep_num == event->ep_num)
- break;
- }
- producer = g_audio_endpoint_data.ep[index].bin_producer;
- consumer = g_audio_endpoint_data.ep[index].bin_consumer;
- UNUSED(producer);
-
- /* if there are no errors de-queue the queue and decrement the no. of
- transfers left, else send the same data again */
- if (event->errors == 0)
- {
- /* de-queue if the send is complete without an error */
- if((MAX_QUEUE_ELEMS-1) == consumer)
- {
- g_audio_endpoint_data.ep[index].bin_consumer = 0;
- }
- else
- {
- g_audio_endpoint_data.ep[index].bin_consumer++;
- }
- }
- consumer = g_audio_endpoint_data.ep[index].bin_consumer;
- g_audio_endpoint_data.ep[index].queue_num--;
- if(0 == g_audio_endpoint_data.ep[index].queue_num)
- {
- /*if bin is not empty */
- USB_CLASS_AUDIO_QUEUE queue;
- /* send the next packet in queue */
- queue = g_audio_endpoint_data.ep[index].queue[consumer];
- (void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
- queue.app_buff, queue.size);
- }
- #endif
- if(g_param_callback != NULL)
- {
- uint_8 event_type = USB_APP_SEND_COMPLETE;
- if(event->errors != 0)
- {
- event_type = USB_APP_ERROR;
- }
- g_param_callback(event->controller_ID, event_type,
- (uint_8*)(&(event->errors)));
- }
- }
- /**************************************************************************//*!
- *
- * @name USB_Service_Audio_Isochronous_IN
- *
- * @brief The funtion ic callback function of Audio Isochronous IN endpoint
- *
- * @param event
- *
- * @return None
- *
- ****************************************************************************
- * The function is called in response to Isochronous IN Service
- ******************************************************************************/
- void USB_Service_Audio_Isochronous_IN(PTR_USB_DEV_EVENT_STRUCT event)
- {
- #if IMPLEMENT_QUEUING
- uint_8 index;
- uint_8 producer, consumer;
- APP_DATA_STRUCT iso_in_recv;
- USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
- USB_Desc_Get_Endpoints(event->controller_ID);
-
- iso_in_recv.data_ptr = event->buffer_ptr;
- iso_in_recv.data_size = event->len;
- /* map the endpoint num to the index of the endpoint structure */
- for(index = 0; index < usb_ep_data->count; index++)
- {
- if(usb_ep_data->ep[index].ep_num ==event->ep_num)
- break;
- }
- producer = g_audio_endpoint_data.ep[index].bin_producer;
- UNUSED(producer);
- /* if there are no errors de-queue the queue and decrement the no. of
- transfers left, else send the same data again */
- if(event->errors == 0)
- {
- /* de-queue if the send is complete without an error */
- if ((MAX_QUEUE_ELEMS-1) == g_audio_endpoint_data.ep[index].bin_consumer)
- {
- g_audio_endpoint_data.ep[index].bin_consumer = 0;
- } else {
- g_audio_endpoint_data.ep[index].bin_consumer++;
- }
- g_audio_endpoint_data.ep[index].queue_num--;
- }
- consumer = g_audio_endpoint_data.ep[index].bin_consumer;
- if(0 != g_audio_endpoint_data.ep[index].queue_num)
- {
- /*if bin is not empty */
- USB_CLASS_AUDIO_QUEUE queue;
- /* send the next packet in queue */
- queue = g_audio_endpoint_data.ep[index].queue[consumer];
- (void)USB_Class_Send_Data(queue.controller_ID, queue.channel,
- queue.app_buff, queue.size);
- }
- #endif
- if(g_audio_class_callback != NULL)
- {
- uint_8 event_type = USB_APP_SEND_COMPLETE;
- if(event->errors != 0)
- {
- event_type = USB_APP_ERROR;
- }
- g_audio_class_callback(event->controller_ID, event_type,
- (uint_8*)(&iso_in_recv));
- }
- }
- /**************************************************************************//*!
- *
- * @name USB_Service_Audio_Isochronous_OUT
- *
- * @brief The funtion is callback function of Isochronous Out Endpoint
- *
- * @param event
- *
- * @return None
- *
- ****************************************************************************
- * The function is called in response to Isochronous OUT Service
- *****************************************************************************/
- void USB_Service_Audio_Isochronous_OUT(PTR_USB_DEV_EVENT_STRUCT event)
- {
- APP_DATA_STRUCT iso_out_recv;
- if(g_audio_class_callback != NULL)
- {
- if(event->errors != 0)
- {
- g_audio_class_callback(event->controller_ID, USB_APP_ERROR,
- (uint_8*)(&(event->errors)));
- } else {
- iso_out_recv.data_ptr = event->buffer_ptr;
- iso_out_recv.data_size = event->len;
- g_audio_class_callback(event->controller_ID, USB_APP_DATA_RECEIVED,
- (uint_8*)(&(iso_out_recv)));
- }
- }
- }
- /**************************************************************************//*!
- *
- * @name USB_Class_Audio_Event
- *
- * @brief The funtion initializes Audio endpoint
- *
- * @param controller_ID : Controller ID
- * @param event : Event Type
- * @param val : Pointer to configuration Value
- *
- * @return None
- *
- ******************************************************************************
- * The funtion initializes the Audio endpoints when event of comleted enumeration is
- * received
- *****************************************************************************/
- void USB_Class_Audio_Event (
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 event, /* [IN] Event Type */
- void* val /* [IN] Pointer to configuration Value */
- )
- {
- uint_8 index;
- if(event == USB_APP_ENUM_COMPLETE)
- {
- uint_8 index_num = 0;
- uint_8 count = 0,ep_count = 0;
- USB_ENDPOINTS *ep_desc_data;
- #ifdef COMPOSITE_DEV
- DEV_ARCHITECTURE_STRUCT_PTR dev_arc_ptr;
- CLASS_ARC_STRUCT_PTR dev_class_ptr;
- dev_arc_ptr = (DEV_ARCHITECTURE_STRUCT *)USB_Desc_Get_Class_Architecture(controller_ID);
- for(count = 0; count < dev_arc_ptr->cl_count; count++)
- {
- dev_class_ptr = (CLASS_ARC_STRUCT_PTR)dev_arc_ptr->value[count];
- /* Initializes sub_classes */
- ep_count = dev_class_ptr->value[0];
- if(dev_class_ptr->class_type == 0x01/*AUDIO_CC*/)
- break;
- index_num +=dev_class_ptr->value[0];
- }
- /* get the endpoints from the descriptor module */
- ep_desc_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID);
- #else
- /* get the endpoints from the descriptor module */
- ep_desc_data = (USB_ENDPOINTS *)USB_Desc_Get_Endpoints(controller_ID);
- ep_count = ep_desc_data->count;
- #endif
- /* deinitialize all endpoints in case they were initialized */
- for(count=index_num; count<ep_count+index_num; count++)
- {
- USB_EP_STRUCT_PTR ep_struct_ptr=
- (USB_EP_STRUCT_PTR) (&ep_desc_data->ep[count]);
- (void)_usb_device_deinit_endpoint(&controller_ID,
- ep_struct_ptr->ep_num, ep_struct_ptr->direction);
- }
- /* intialize all non control endpoints */
- for(count=index_num; count<ep_count+index_num; count++)
- {
- USB_EP_STRUCT_PTR ep_struct=
- (USB_EP_STRUCT_PTR)&ep_desc_data->ep[count];
- (void)_usb_device_init_endpoint(&controller_ID, ep_struct->ep_num,
- ep_struct->size, ep_struct->direction, ep_struct->type, FALSE);
- /* register callback service for the endpoint */
- switch(ep_struct->type)
- {
- case USB_INTERRUPT_PIPE:
- (void)_usb_device_register_service(controller_ID,
- (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
- USB_Service_Audio_Status_Interrupt);
- break;
- case USB_ISOCHRONOUS_PIPE:
- if (ep_struct->direction == USB_RECV)
- {
- (void)_usb_device_register_service(controller_ID,
- (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
- USB_Service_Audio_Isochronous_OUT);
- }
- else
- {
- (void)_usb_device_register_service(controller_ID,
- (uint_8)(USB_SERVICE_EP0+ep_struct->ep_num),
- USB_Service_Audio_Isochronous_IN);
- }
- break;
- default:
- break;
- }
- /* set the EndPoint Status as Idle in the device layer */
- (void)_usb_device_set_status(&controller_ID,
- (uint_8)(USB_STATUS_ENDPOINT | 1|
- (ep_struct->direction << USB_COMPONENT_DIRECTION_SHIFT)),
- USB_STATUS_IDLE);
- }
- }
- else if(event == USB_APP_BUS_RESET)
- {
- /* clear producer and consumer on reset */
- for(index = 0; index < g_audio_endpoint_data.count; index++)
- {
- g_audio_endpoint_data.ep[index].bin_consumer = 0x00;
- g_audio_endpoint_data.ep[index].bin_producer = 0x00;
- g_audio_endpoint_data.ep[index].queue_num = 0x00;
- }
- }
- if(g_audio_class_callback != NULL)
- {
- /* notify the event to the application */
- g_audio_class_callback(controller_ID, event, val);
- }
- }
- #if AUDIO_CLASS_2_0
- /**************************************************************************
- *
- * @name: USB_Set_Cur_Audio_Clock
- *
- * @brief The function sets current attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Set_Control_Clock function
- *****************************************************************************/
- static uint_8 USB_Set_Cur_Audio_Clock(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case CS_SAM_FREQ_CONTROL:
- status = USB_Desc_Set_Cur_Sampling_Frequency(controller_ID,interface,data, size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************
- *
- * @name: USB_Set_Min_Audio_Clock
- *
- * @brief The function sets current attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Set_Control_Clock function
- *****************************************************************************/
- static uint_8 USB_Set_Min_Audio_Clock(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case CS_SAM_FREQ_CONTROL:
- status = USB_Desc_Set_Min_Sampling_Frequency(controller_ID,interface,data, size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************
- *
- * @name: USB_Set_Max_Audio_Clock
- *
- * @brief The function sets current attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Set_Control_Clock function
- *****************************************************************************/
- static uint_8 USB_Set_Max_Audio_Clock(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case CS_SAM_FREQ_CONTROL:
- status = USB_Desc_Set_Max_Sampling_Frequency(controller_ID,interface,data, size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************
- *
- * @name: USB_Set_Res_Audio_Clock
- *
- * @brief The function sets current attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Set_Control_Clock function
- *****************************************************************************/
- static uint_8 USB_Set_Res_Audio_Clock(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case CS_SAM_FREQ_CONTROL:
- status = USB_Desc_Set_Res_Sampling_Frequency(controller_ID,interface,data, size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Get_Cur_Audio_Clock
- *
- * @brief The function gets Current attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Get_Control_Clock function
- *****************************************************************************/
- static uint_8 USB_Get_Cur_Audio_Clock(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- /* check control selector */
- switch(control_selector)
- {
- case CS_SAM_FREQ_CONTROL:
- status = USB_Desc_Get_Cur_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- case CS_CLOCK_VALID_CONTROL:
- status = USB_Desc_Get_Cur_Clock_Validity(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Get_Min_Audio_Clock
- *
- * @brief The function gets Min attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Get_Control_Clock function
- *****************************************************************************/
- static uint_8 USB_Get_Min_Audio_Clock(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case CS_SAM_FREQ_CONTROL:
- status = USB_Desc_Get_Min_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Get_Max_Audio_Clock
- *
- * @brief The function gets Max attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Get_Control_Clock function
- *****************************************************************************/
- static uint_8 USB_Get_Max_Audio_Clock(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case CS_SAM_FREQ_CONTROL:
- status = USB_Desc_Get_Max_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Get_Res_Audio_Clock
- *
- * @brief The function gets Resolution attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Get_Control_Clock function
- *****************************************************************************/
- static uint_8 USB_Get_Res_Audio_Clock(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case CS_SAM_FREQ_CONTROL:
- status = USB_Desc_Get_Res_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- #endif /* AUDIO_CLASS_2_0 */
- /**************************************************************************//*!
- *
- * @name: USB_Set_Cur_Audio_Feature_Unit
- *
- * @brief The function sets current attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Set_Feature_Unit function
- *****************************************************************************/
- static uint_8 USB_Set_Cur_Audio_Feature_Unit(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case MUTE_CONTROL:
- status = USB_Desc_Set_Cur_Mute(controller_ID,interface,data, size);
- break;
- case VOLUME_CONTROL:
- status = USB_Desc_Set_Cur_Volume(controller_ID,interface,data,size);
- break;
- case BASS_CONTROL:
- status = USB_Desc_Set_Cur_Bass(controller_ID,interface,data,size);
- break;
- case MID_CONTROL:
- status = USB_Desc_Set_Cur_Mid(controller_ID,interface,data,size);
- break;
- case TREBLE_CONTROL:
- status = USB_Desc_Set_Cur_Treble(controller_ID,interface,data,size);
- break;
- case GRAPHIC_EQUALIZER_CONTROL:
- status=USB_Desc_Set_Cur_Graphic_Equalizer(controller_ID,interface,data,size);
- break;
- case AUTOMATIC_GAIN_CONTROL:
- status = USB_Desc_Set_Cur_Automatic_Gain(controller_ID,interface,data,size);
- break;
- case DELAY_CONTROL:
- status = USB_Desc_Set_Cur_Delay(controller_ID,interface,data,size);
- break;
- case BASS_BOOST_CONTROL:
- status = USB_Desc_Set_Cur_Bass_Boost(controller_ID,interface,data,size);
- break;
- case LOUDNESS_CONTROL:
- status = USB_Desc_Set_Cur_Loudness(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Set_Min_Audio_Feature_Unit
- *
- * @brief The function sets Min attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Set_Feature_Unit function
- *****************************************************************************/
- static uint_8 USB_Set_Min_Audio_Feature_Unit(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case VOLUME_CONTROL:
- status = USB_Desc_Set_Min_Volume(controller_ID,interface,data,size);
- break;
- case BASS_CONTROL:
- status = USB_Desc_Set_Min_Bass(controller_ID,interface,data,size);
- break;
- case MID_CONTROL:
- status = USB_Desc_Set_Min_Mid(controller_ID,interface,data,size);
- break;
- case TREBLE_CONTROL:
- status = USB_Desc_Set_Min_Treble(controller_ID,interface,data,size);
- break;
- case GRAPHIC_EQUALIZER_CONTROL:
- status = USB_Desc_Set_Min_Graphic_Equalizer(controller_ID,interface,data,size);
- break;
- case DELAY_CONTROL:
- status = USB_Desc_Set_Min_Delay(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Set_Max_Audio_Feature_Unit
- *
- * @brief The function sets Max attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Set_Feature_Unit function
- *****************************************************************************/
- static uint_8 USB_Set_Max_Audio_Feature_Unit(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case VOLUME_CONTROL:
- status = USB_Desc_Set_Max_Volume(controller_ID,interface,data,size);
- break;
- case BASS_CONTROL:
- status = USB_Desc_Set_Max_Bass(controller_ID,interface,data,size);
- break;
- case MID_CONTROL:
- status = USB_Desc_Set_Max_Mid(controller_ID,interface,data,size);
- break;
- case TREBLE_CONTROL:
- status = USB_Desc_Set_Max_Treble(controller_ID,interface,data,size);
- break;
- case GRAPHIC_EQUALIZER_CONTROL:
- status =USB_Desc_Set_Max_Graphic_Equalizer(controller_ID,interface,data,size);
- break;
- case DELAY_CONTROL:
- status = USB_Desc_Set_Max_Delay(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Set_Res_Audio_Feature_Unit
- *
- * @brief The function sets Resolution attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Set_Feature_Unit function
- *****************************************************************************/
- static uint_8 USB_Set_Res_Audio_Feature_Unit(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case VOLUME_CONTROL:
- status = USB_Desc_Set_Res_Volume(controller_ID,interface,data,size);
- break;
- case BASS_CONTROL:
- status = USB_Desc_Set_Res_Bass(controller_ID,interface,data,size);
- break;
- case MID_CONTROL:
- status = USB_Desc_Set_Res_Mid(controller_ID,interface,data,size);
- break;
- case TREBLE_CONTROL:
- status = USB_Desc_Set_Res_Treble(controller_ID,interface,data,size);
- break;
- case GRAPHIC_EQUALIZER_CONTROL:
- status = USB_Desc_Set_Res_Graphic_Equalizer(controller_ID,interface,data,size);
- break;
- case DELAY_CONTROL:
- status = USB_Desc_Set_Res_Delay(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Get_Cur_Audio_Feature_Unit
- *
- * @brief The function gets Current attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Get_Feature_Unit function
- *****************************************************************************/
- static uint_8 USB_Get_Cur_Audio_Feature_Unit(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- /* check control selector */
- switch(control_selector)
- {
- case MUTE_CONTROL:
- status = USB_Desc_Get_Cur_Mute(controller_ID,interface,data,size);
- break;
- case VOLUME_CONTROL:
- status = USB_Desc_Get_Cur_Volume(controller_ID,interface,data,size);
- break;
- case BASS_CONTROL:
- status = USB_Desc_Get_Cur_Bass(controller_ID,interface,data,size);
- break;
- case MID_CONTROL:
- status = USB_Desc_Get_Cur_Mid(controller_ID,interface,data,size);
- break;
- case TREBLE_CONTROL:
- status = USB_Desc_Get_Cur_Treble(controller_ID,interface,data,size);
- break;
- case GRAPHIC_EQUALIZER_CONTROL:
- status = USB_Desc_Get_Cur_Graphic_Equalizer(controller_ID,interface,data,size);
- break;
- case AUTOMATIC_GAIN_CONTROL:
- status = USB_Desc_Get_Cur_Automatic_Gain(controller_ID,interface,data,size);
- break;
- case DELAY_CONTROL:
- status = USB_Desc_Get_Cur_Delay(controller_ID,interface,data,size);
- break;
- case BASS_BOOST_CONTROL:
- status = USB_Desc_Get_Cur_Bass_Boost(controller_ID,interface,data,size);
- break;
- case LOUDNESS_CONTROL:
- status = USB_Desc_Get_Cur_Loudness(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Get_Min_Audio_Feature_Unit
- *
- * @brief The function gets Min attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Get_Feature_Unit function
- *****************************************************************************/
- static uint_8 USB_Get_Min_Audio_Feature_Unit(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case VOLUME_CONTROL:
- status = USB_Desc_Get_Min_Volume(controller_ID,interface,data,size);
- break;
- case BASS_CONTROL:
- status = USB_Desc_Get_Min_Bass(controller_ID,interface,data,size);
- break;
- case MID_CONTROL:
- status = USB_Desc_Get_Min_Mid(controller_ID,interface,data,size);
- break;
- case TREBLE_CONTROL:
- status = USB_Desc_Get_Min_Treble(controller_ID,interface,data,size);
- break;
- case GRAPHIC_EQUALIZER_CONTROL:
- status = USB_Desc_Get_Min_Graphic_Equalizer(controller_ID,interface,data,size);
- break;
- case DELAY_CONTROL:
- status = USB_Desc_Get_Min_Delay(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Get_Max_Audio_Feature_Unit
- *
- * @brief The function gets Max attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Get_Feature_Unit function
- *****************************************************************************/
- static uint_8 USB_Get_Max_Audio_Feature_Unit(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case VOLUME_CONTROL:
- status = USB_Desc_Get_Max_Volume(controller_ID,interface,data,size);
- break;
- case BASS_CONTROL:
- status = USB_Desc_Get_Max_Bass(controller_ID,interface,data,size);
- break;
- case MID_CONTROL:
- status = USB_Desc_Get_Max_Mid(controller_ID,interface,data,size);
- break;
- case TREBLE_CONTROL:
- status = USB_Desc_Get_Max_Treble(controller_ID,interface,data,size);
- break;
- case GRAPHIC_EQUALIZER_CONTROL:
- status = USB_Desc_Get_Max_Graphic_Equalizer(controller_ID,interface,data,size);
- break;
- case DELAY_CONTROL:
- status = USB_Desc_Get_Max_Delay(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Get_Res_Audio_Feature_Unit
- *
- * @brief The function gets Resolution attributes of Feature Unit
- *
- * @param controller_ID : Controller ID
- * @param interface : Interface number
- * @param control_selector : Control Selector of Request
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called by USB_Audio_Get_Feature_Unit function
- *****************************************************************************/
- static uint_8 USB_Get_Res_Audio_Feature_Unit(
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 interface, /* [IN] interface */
- uint_8 control_selector, /* [IN] control selector */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(control_selector)
- {
- case VOLUME_CONTROL:
- status = USB_Desc_Get_Res_Volume(controller_ID,interface,data,size);
- break;
- case BASS_CONTROL:
- status = USB_Desc_Get_Res_Bass(controller_ID,interface,data,size);
- break;
- case MID_CONTROL:
- status = USB_Desc_Get_Res_Mid(controller_ID,interface,data,size);
- break;
- case TREBLE_CONTROL:
- status = USB_Desc_Get_Res_Treble(controller_ID,interface,data,size);
- break;
- case GRAPHIC_EQUALIZER_CONTROL:
- status = USB_Desc_Get_Res_Graphic_Equalizer(controller_ID,interface,data,size);
- break;
- case DELAY_CONTROL:
- status=USB_Desc_Get_Res_Delay(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Audio_Set_Control_Terminal
- *
- * @brief The function sets Copy protect level for I/O Terminal
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Pointer to setup packet
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This funtion is called in USB_Set_Request_Interface function
- *****************************************************************************/
- static uint_8 USB_Audio_Set_Control_Terminal(
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(setup_packet -> request)
- {
- /*Copy Protect Control only supports the CUR attribute! */
- case SET_CUR:
- if((setup_packet->value >>8) == COPY_PROTECT_CONTROL )
- {
- status = USB_Desc_Set_Copy_Protect(controller_ID,(uint_8)setup_packet->index,data,size);
- }
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Audio_Get_Control_Terminal
- *
- * @brief The function gets Copy protect level for I/O Terminal
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Pointer to setup packet
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This funtion is called in USB_Get_Request_Interface function
- *****************************************************************************/
- static uint_8 USB_Audio_Get_Control_Terminal(
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- switch(setup_packet -> request)
- {
- /* Copy Protect Control only supports the CUR attribute!*/
- case GET_CUR:
- if((setup_packet ->value >>8) == COPY_PROTECT_CONTROL )
- {
- status = USB_Desc_Get_Copy_Protect(controller_ID,(uint_8)setup_packet->index,data,size);
- }
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Audio_Set_Feature_Unit
- *
- * @brief The function sets Feature Unit requests
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Pointer to setup packet
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This funtion is called in Set_Request_Interface function
- *****************************************************************************/
- static uint_8 USB_Audio_Set_Feature_Unit(
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 interface, control_selector;
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- /* get current interface */
- interface = (uint_8)setup_packet->index;
- /* get control selector */
- control_selector = (uint_8)(setup_packet->value>>8);
- /* Select SET request Control Feature Unit Module */
- switch(setup_packet->request)
- {
- case SET_CUR:
- /*Set current attributes of Feature Unit*/
- status = USB_Set_Cur_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
- break;
- case SET_MIN:
- /*Set Min attributes of Feature Unit*/
- status = USB_Set_Min_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
- break;
- case SET_MAX:
- /*Set Max attributes of Feature Unit*/
- status = USB_Set_Max_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
- break;
- case SET_RES:
- /*Set Resolution attributes of Feature Unit*/
- status = USB_Set_Res_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Audio_Get_Feature_Unit
- *
- * @brief The function gets Feature Unit requests
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Pointer to setup packet
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This funtion is called in the Get_Request_Interface function
- *****************************************************************************/
- static uint_8 USB_Audio_Get_Feature_Unit(
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 interface, control_selector;
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- interface = (uint_8)setup_packet->index;
- control_selector = (uint_8)(setup_packet->value>>8);
- /* Select SET request Control Feature Unit Module */
- switch(setup_packet->request)
- {
- case GET_CUR:
- status = USB_Get_Cur_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
- break;
- case GET_MIN:
- status = USB_Get_Min_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
- break;
- case GET_MAX:
- status = USB_Get_Max_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
- break;
- case GET_RES:
- status = USB_Get_Res_Audio_Feature_Unit(controller_ID,interface,control_selector,data,size);
- break;
- default:
- break;
- }
- UNUSED(status);
- return USB_OK;
- }
- #if AUDIO_CLASS_2_0
- /**************************************************************************//*!
- *
- * @name: USB_Audio_Set_Control_Clock
- *
- * @brief The function sets Clock requests
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Pointer to setup packet
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called in Set_Request_Interface function
- *****************************************************************************/
- static uint_8 USB_Audio_Set_Control_Clock(
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 interface, control_selector;
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- /* get current interface */
- interface = (uint_8)setup_packet->index;
- /* get control selector */
- control_selector = (uint_8)(setup_packet->value>>8);
- /* Select SET request Control Clock Control Module */
- switch(setup_packet->request)
- {
- case SET_CUR:
- /*Set current attributes for Clock Control*/
- status = USB_Set_Cur_Audio_Clock(controller_ID,interface,control_selector,data,size);
- break;
- case SET_MIN:
- /*Set Min attributes of Clock Control */
- status = USB_Set_Min_Audio_Clock(controller_ID,interface,control_selector,data,size);
- break;
- case SET_MAX:
- /*Set Max attributes of Clock Control */
- status = USB_Set_Max_Audio_Clock(controller_ID,interface,control_selector,data,size);
- break;
- case SET_RES:
- /*Set Resolution attributes of Clock Control */
- status = USB_Set_Res_Audio_Clock(controller_ID,interface,control_selector,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Audio_Get_Control_Clock
- *
- * @brief The function gets Clock requests
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Pointer to setup packet
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This function is called in the Get_Request_Interface function
- *****************************************************************************/
- static uint_8 USB_Audio_Get_Control_Clock(
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 interface, control_selector;
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- interface = (uint_8)setup_packet->index;
- control_selector = (uint_8)(setup_packet->value>>8);
- /* Select GET request Control Feature Unit Module */
- switch(setup_packet->request)
- {
- case GET_CUR:
- status = USB_Get_Cur_Audio_Clock(controller_ID,interface,control_selector,data,size);
- break;
- case GET_MIN:
- status = USB_Get_Min_Audio_Clock(controller_ID,interface,control_selector,data,size);
- break;
- case GET_MAX:
- status = USB_Get_Max_Audio_Clock(controller_ID,interface,control_selector,data,size);
- break;
- case GET_RES:
- status = USB_Get_Res_Audio_Clock(controller_ID,interface,control_selector,data,size);
- break;
- default:
- break;
- }
- return USB_OK;
- }
- #endif /* AUDIO_CLASS_2_0 */
- /**************************************************************************//*!
- *
- * @name: USB_Set_Request_Interface
- *
- * @brief This function is called in response to Set Interface Requests
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Pointer to setup packet
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * The funtion set Feature unit and Terminal request. It is called in
- * USB_Other_Request function
- *****************************************************************************/
- static uint_8 USB_Set_Request_Interface(
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 i;
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- USB_AUDIO_UNITS *entity_desc_data;
- USB_UT_STRUCT_PTR ut_struct;
- *size = 0;
- /* get the I/O Interface and Feature from the descriptor module */
- entity_desc_data = (USB_AUDIO_UNITS *)USB_Desc_Get_Audio_Entities(controller_ID);
- for(i=0; i<AUDIO_UNIT_COUNT; i++)
- {
- ut_struct=(USB_UT_STRUCT_PTR)&(entity_desc_data->et[i]);
- /* wIndex H byte is Entity ID */
- if((setup_packet->index>>8) == ut_struct->unit_id)
- {
- switch(ut_struct->type)
- {
- #if AUDIO_CLASS_2_0
- case AUDIO_CONTROL_CLOCK_SOURCE:
- status = USB_Audio_Set_Control_Clock(controller_ID,setup_packet,data,size);
- break;
- #endif /* AUDIO_CLASS_2_0 */
- case AUDIO_CONTROL_INPUT_TERMINAL:
- break;
- case AUDIO_CONTROL_FEATURE_UNIT:
- /* Select SET request Control Feature Unit Module */
- status = USB_Audio_Set_Feature_Unit(controller_ID,setup_packet,data,size);
- break;
- case AUDIO_CONTROL_OUTPUT_TERMINAL:
- /* Select SET request Output Terminal Module */
- status = USB_Audio_Set_Control_Terminal(controller_ID,setup_packet,data,size);
- break;
- default:
- break;
- }
- }
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Get_Request_Interface
- *
- * @brief This function is called in response to Get Interface Requests
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Pointer to setup packet
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * The funtion Get Feature unit and Terminal requests. It is called in
- * USB_Other_Request function
- *****************************************************************************/
- static uint_8 USB_Get_Request_Interface(
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 i;
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- USB_AUDIO_UNITS *entity_desc_data;
- USB_UT_STRUCT_PTR ut_struct;
- /* get the I/O Interface and Feature from the descriptor module */
- entity_desc_data = (USB_AUDIO_UNITS *)USB_Desc_Get_Audio_Entities(controller_ID);
- for(i=0;i<AUDIO_UNIT_COUNT; i++)
- {
- ut_struct=(USB_UT_STRUCT_PTR)&(entity_desc_data->et[i]);
- if((setup_packet->index >>8) == ut_struct->unit_id)
- {
- switch(ut_struct->type)
- {
- #if AUDIO_CLASS_2_0
- case AUDIO_CONTROL_CLOCK_SOURCE:
- status = USB_Audio_Get_Control_Clock(controller_ID,setup_packet,data,size);
- break;
- #endif /* AUDIO_CLASS_2_0 */
- case AUDIO_CONTROL_INPUT_TERMINAL:
- /*Select SET Request Control Input Terminal Module */
- status = USB_Audio_Get_Control_Terminal(controller_ID,setup_packet,data,size);
- break;
- case AUDIO_CONTROL_FEATURE_UNIT:
- /* Select SET request Control Feature Unit Module */
- status = USB_Audio_Get_Feature_Unit(controller_ID,setup_packet,data,size);
- break;
- default:
- break;
- }
- }
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Set_Request_Endpoint
- *
- * @brief This function is called in response to Set Endpoint Requests
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Pointer to setup packet
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- ** This funtion is called by USB_Other_Request function
- *****************************************************************************/
- static uint_8 USB_Set_Request_Endpoint
- (
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
- uint_8_ptr *data, /* [IN] Pointer to Data */
- USB_PACKET_SIZE *size /* [IN] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- uint_8 interface;
- uint_8 control_selector;
- uint_16 offset;
- /* get current interface */
- interface = (uint_8)setup_packet->index;
- /* get control selector */
- control_selector = (uint_8)(setup_packet->value>>8);
- switch(setup_packet->request)
- {
- case SET_CUR:
- {
- *size = 0;
- switch(control_selector)
- {
- #if !AUDIO_CLASS_2_0
- /*
- * Request Valid only in Audio 1.0, in Audio 2.0 it was moved
- * into Interface Requests
- */
- case SAMPLING_FREQ_CONTROL:
- status = USB_Desc_Set_Cur_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- #endif /* AUDIO_CLASS_2_0 */
- case PITCH_CONTROL:
- status = USB_Desc_Set_Cur_Pitch(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- }
- break;
- case SET_MIN:
- {
- *size = 0;
- switch(control_selector)
- {
- #if !AUDIO_CLASS_2_0
- case SAMPLING_FREQ_CONTROL:
- status = USB_Desc_Set_Min_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- #endif /* AUDIO_CLASS_2_0 */
- default:
- break;
- }
- }
- break;
-
- case SET_MAX:
- {
- *size = 0;
- switch(control_selector)
- {
- #if !AUDIO_CLASS_2_0
- case SAMPLING_FREQ_CONTROL:
- status = USB_Desc_Set_Max_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- #endif /* AUDIO_CLASS_2_0 */
- default:
- break;
- }
- }
- break;
- case SET_RES:
- {
- *size = 0;
- switch(control_selector)
- {
- #if !AUDIO_CLASS_2_0
- case SAMPLING_FREQ_CONTROL:
- status = USB_Desc_Set_Res_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- #endif /* AUDIO_CLASS_2_0 */
- default:
- break;
- }
- }
- break;
- case SET_MEM:
- *size = setup_packet->length;
- offset=setup_packet->value;
- status = USB_Desc_Set_Mem_Endpoint(controller_ID,offset,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name: USB_Get_Request_Endpoint
- *
- * @brief This function is called in response to Get Endpoint Requests
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Pointer to setup packet
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * USBERR_INVALID_REQ_TYPE : When request for invalid
- * Interface is presented
- *
- ******************************************************************************
- * This funtion is called by USB_Other_Request function
- *****************************************************************************/
- static uint_8 USB_Get_Request_Endpoint
- (
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /* [IN] Pointer to setup packet */
- uint_8_ptr *data, /* [OUT] Pointer to Data */
- USB_PACKET_SIZE *size /* [OUT] Pointer to Size of Data */
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- uint_8 interface;
- uint_8 control_selector;
- uint_16 offset;
- /* get current interface */
- interface = (uint_8)setup_packet->index;
- /* get control selector */
- control_selector = (uint_8)(setup_packet->value >>8);
- switch(setup_packet->request)
- {
- case GET_CUR:
- switch(control_selector)
- {
- case SAMPLING_FREQ_CONTROL:
- status = USB_Desc_Get_Cur_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- case PITCH_CONTROL:
- status = USB_Desc_Get_Cur_Pitch(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- break;
- case GET_MIN:
- switch(control_selector)
- {
- case SAMPLING_FREQ_CONTROL:
- status = USB_Desc_Get_Min_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- break;
- case GET_MAX:
- switch(control_selector)
- {
- case SAMPLING_FREQ_CONTROL:
- status = USB_Desc_Get_Max_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- break;
- case GET_RES:
- switch(control_selector)
- {
- case SAMPLING_FREQ_CONTROL:
- status = USB_Desc_Get_Res_Sampling_Frequency(controller_ID,interface,data,size);
- break;
- default:
- break;
- }
- break;
- case GET_MEM:
- *size = setup_packet->length;
- offset=setup_packet->value;
- status = USB_Desc_Get_Mem_Endpoint(controller_ID,offset,interface,data,size);
- break;
- default:
- break;
- }
- return status;
- }
- /**************************************************************************//*!
- *
- * @name USB_Other_Requests
- *
- * @brief The funtion provides flexibilty to add class and vendor specific
- * requests
- *
- * @param controller_ID : Controller ID
- * @param setup_packet : Setup packet received
- * @param data : Data to be send back
- * @param size : Size to be returned
- *
- * @return status:
- * USB_OK : When Successfull
- * Others : When Error
- *
- ******************************************************************************
- * Handles Audio Class requests and forwards vendor specific request to the
- * application
- *****************************************************************************/
- #ifndef COMPOSITE_DEV
- static uint_8 USB_Other_Requests
- #else
- uint_8 USB_Audio_Other_Requests
- #endif
- (
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_SETUP_STRUCT * setup_packet, /*[IN] Setup packet received */
- uint_8_ptr *data, /* [OUT] Data to be send back */
- USB_PACKET_SIZE *size /* [OUT] Size to be returned*/
- )
- {
- uint_8 status = USBERR_INVALID_REQ_TYPE;
- /* point to the data which comes after the setup packet */
- *data = ((uint_8*)setup_packet)+USB_SETUP_PKT_SIZE;
- if (size == NULL)
- {
- return USBERR_GET_MEMORY_FAILED;
- }
- switch(setup_packet->request_type)
- {
- /* Set I/O Terminal and Feature Unit */
- case SET_REQUEST_ITF:
- status = USB_Set_Request_Interface(controller_ID,setup_packet,data,size);
- break;
- /*Get I/O Terminal and Feature Unit */
- case GET_REQUEST_ITF:
- status = USB_Get_Request_Interface(controller_ID,setup_packet,data,size);
- break;
- /* Set Endpoint Request */
- case SET_REQUEST_EP:
- status = USB_Set_Request_Endpoint(controller_ID,setup_packet,data,size);
- break;
- /* Get Endpoint Request */
- case GET_REQUEST_EP:
- status = USB_Get_Request_Endpoint(controller_ID,setup_packet,data,size);
- break;
- default:
- break;
- } /* end of switch */
- return status;
- }
- /*****************************************************************************
- * Global Functions
- *****************************************************************************/
- /**************************************************************************//*!
- *
- * @name USB_Class_Audio_Init
- *
- * @brief The funtion initializes the Device and Controller layer
- *
- * @param controller_ID : Controller ID
- * @param audio_class_callback : Audio Class Callback
- * @param vendor_req_callback : Vendor Request Callback
- * @param param_callback : Class requests Callback
- *
- * @return status:
- * USB_OK : When Successfull
- * Others : When Error
- *
- ******************************************************************************
- *This function initializes the Audio Class layer and layers it is dependent on
- *****************************************************************************/
- uint_8 USB_Class_Audio_Init (
- uint_8 controller_ID, /* [IN] Controller ID */
- USB_CLASS_CALLBACK audio_class_callback, /* [IN] Audio Class Callback */
- USB_REQ_FUNC vendor_req_callback, /* [IN] Vendor Request Callback */
- USB_CLASS_CALLBACK param_callback /* [ IN] Audio Class requests Callback */
- )
- {
- uint_8 index;
- uint_8 status = USB_OK;
- USB_ENDPOINTS *ep_desc_data = (USB_ENDPOINTS *)
- USB_Desc_Get_Endpoints(controller_ID);
- #ifndef COMPOSITE_DEV
- /* Initialize the device layer*/
- status = _usb_device_init(controller_ID, NULL,
- (uint_8)(ep_desc_data->count+1), TRUE);
- if(status == USB_OK)
- {
- /* Initialize the generic class functions */
- status = USB_Class_Init(controller_ID,USB_Class_Audio_Event,
- USB_Other_Requests);
- if(status == USB_OK)
- {
- #endif
- g_audio_endpoint_data.count = ep_desc_data->count;
- for(index = 0; index < ep_desc_data->count; index++)
- {
- g_audio_endpoint_data.ep[index].endpoint = ep_desc_data->ep[index].ep_num;
- g_audio_endpoint_data.ep[index].type = ep_desc_data->ep[index].type;
- g_audio_endpoint_data.ep[index].bin_consumer = 0x00;
- g_audio_endpoint_data.ep[index].bin_producer = 0x00;
- g_audio_endpoint_data.ep[index].queue_num = 0x00;
- }
- /* save the Audio class callback pointer */
- g_audio_class_callback = audio_class_callback;
- /* save the vendor request callback pointer */
- g_vendor_req_callback = vendor_req_callback;
-
- UNUSED(g_vendor_req_callback);
- /* Save the callback to ask application for class specific params*/
- g_param_callback = param_callback;
- #ifndef COMPOSITE_DEV
- }
- }
- #endif
- return status;
- }
- /**************************************************************************//*!
- *
- * @name USB_Class_Audio_DeInit
- *
- * @brief The funtion de-initializes the Device and Controller layer
- *
- * @param controller_ID : Controller ID
- *
- * @return status:
- * USB_OK : When Successfull
- * Others : When Error
- *
- ******************************************************************************
- *This function de-initializes the Audio Class layer
- *****************************************************************************/
- uint_8 USB_Class_Audio_DeInit
- (
- uint_8 controller_ID /* [IN] Controller ID */
- )
- {
- uint_8 status = USB_OK;
- #ifdef COMPOSITE_DEV
- UNUSED(controller_ID)
- #endif
- /* free the Audio class callback pointer */
- g_audio_class_callback = NULL;
- /* free the vendor request callback pointer */
- g_vendor_req_callback = NULL;
- /* free the callback to ask application for class specific params*/
- g_param_callback = NULL;
- #ifndef COMPOSITE_DEV
- /* Call common class deinit function */
- status = USB_Class_DeInit(controller_ID);
- if(status == USB_OK)
- /* Call device deinit function */
- status = _usb_device_deinit();
- #endif
- return status;
- }
- /**************************************************************************//*!
- *
- * @name USB_Class_Audio_Send_Data
- *
- * @brief This fucntion is used by Application to send data through Audio class
- *
- * @param controller_ID : Controller ID
- * @param ep_num : Endpoint number
- * @param app_buff : Buffer to send
- * @param size : Length of the transfer
- *
- * @return status:
- * USB_OK : When Successfull
- * Others : When Error
- *
- ******************************************************************************
- * This fucntion is used by Application to send data through Audio class
- *****************************************************************************/
- uint_8 USB_Class_Audio_Send_Data (
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 ep_num, /* [IN] Endpoint Number */
- uint_8_ptr app_buff, /* [IN] Buffer to Send */
- USB_PACKET_SIZE size /* [IN] Length of the Transfer */
- )
- {
- uint_8 status = USB_OK;
- PTR_USB_CLASS_AUDIO_QUEUE queue_tmp;
- #if IMPLEMENT_QUEUING
- uint_8 index;
- uint_8 producer, queue_num;
- USB_ENDPOINTS *usb_ep_data = (USB_ENDPOINTS *)
- USB_Desc_Get_Endpoints(controller_ID);
- /* map the endpoint num to the index of the endpoint structure */
- for(index = 0; index < usb_ep_data->count; index++)
- {
- if(usb_ep_data->ep[index].ep_num == ep_num)
- break;
- }
- producer = g_audio_endpoint_data.ep[index].bin_producer;
- queue_num = g_audio_endpoint_data.ep[index].queue_num;
-
- UNUSED(producer);
- if(MAX_QUEUE_ELEMS != queue_num)
- {
- /* the bin is not full*/
- /* put all send request parameters in the endpoint data structure */
- queue_tmp = &(g_audio_endpoint_data.ep[index].queue[producer]);
- queue_tmp->controller_ID = controller_ID;
- queue_tmp->channel = ep_num;
- queue_tmp->app_buff = app_buff;
- queue_tmp->size = size;
- /* increment producer bin by 1*/
- if (producer == (MAX_QUEUE_ELEMS - 1))
- {
- g_audio_endpoint_data.ep[index].bin_producer = 0;
- }
- else
- {
- g_audio_endpoint_data.ep[index].bin_producer++;
- }
- g_audio_endpoint_data.ep[index].queue_num++;
- if(g_audio_endpoint_data.ep[index].queue_num == 1)
- {
- #endif
- status = USB_Class_Send_Data(controller_ID, ep_num, app_buff,size);
- #if IMPLEMENT_QUEUING
- }
- }
- else /* bin is full */
- {
- status = USBERR_DEVICE_BUSY;
- }
- #endif
- return status;
- }
- /**************************************************************************//*!
- *
- * @name USB_Class_Audio_Recv_Data
- *
- * @brief This function receives Data from Host.
- *
- * @param controller_ID : Controller ID
- * @param ep_num : Endpoint number
- * @param app_buff : Buffer to send
- * @param size : Length of the transfer
- *
- * @return status
- * USB_OK : When Successfull
- * Others : Errors
- ****************************************************************************
- * This function called bye USB_App_Callback function
- *****************************************************************************/
- uint_8 USB_Class_Audio_Recv_Data
- (
- uint_8 controller_ID, /* [IN] Controller ID */
- uint_8 ep_num, /* [IN] Endpoint Number */
- uint_8_ptr app_buff, /* [IN] Buffer to Send */
- USB_PACKET_SIZE size /* [IN] Length of the Transfer */
- )
- {
- uint_8 status;
- status = _usb_device_recv_data(&controller_ID,ep_num,app_buff,size);
- return status;
- }
|