csl_audioClassAux.h
Go to the documentation of this file.
00001 /*  ============================================================================
00002  *   Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005, 2008
00003  *
00004  *   Use of this software is controlled by the terms and conditions found in the
00005  *   license agreement under which this software has been supplied.
00006  *  ============================================================================
00007  */
00008 
00016 /* ============================================================================
00017  * Revision History
00018  * ================
00019  * 10-Dec-2008 Created
00020  * 21-Jan-2009 Modified for code review comments
00021  * ============================================================================
00022  */
00023 
00024 #ifndef _CSL_AUDIOCLASSAUX_H_
00025 #define _CSL_AUDIOCLASSAUX_H_
00026 
00027 #ifdef __cplusplus
00028 extern "C" {
00029 #endif
00030 
00031 #include "csl_usbAux.h"
00032 #include "csl_audioClass.h"
00033 
00091 static inline
00092 CSL_AcRequestRet AC_reqUnknown(CSL_UsbDevNum         devNum,
00093                                CSL_UsbSetupStruct    *usbSetup,
00094                                pUsbEpHandle          hInEp,
00095                                pUsbEpHandle          hOutEp,
00096                                void                  *pAcObj)
00097 {
00098     CSL_AcRequestRet    retStat;
00099 
00100     /* STALL the endpoint - the request is either not known or not supported */
00101     retStat = CSL_AC_REQUEST_STALL;
00102 
00103     return(retStat);
00104 }
00105 
00156 static inline
00157 fpAC_REQ_HANDLER AC_lookupReqHandler(Uint16                 request,
00158                                      CSL_AcRequestStruct    *pUSB_ReqTable)
00159 {
00160     Uint16    index;
00161 
00162     /* parse thru the end of request handler table */
00163     for(index = 0; pUSB_ReqTable[index].fpRequestHandler != NULL; index++)
00164     {
00165         /* if request handler exists return a pointer to the request handler routine */
00166         if(pUSB_ReqTable[index].request == request)
00167         {
00168             return(pUSB_ReqTable[index].fpRequestHandler);
00169         }
00170     }
00171 
00172     /* if request handler does not exist return a pointer to the USB_reqUnknown
00173     routine */
00174     return(AC_reqUnknown);
00175 }
00176 
00230 static inline
00231 CSL_AcRequestRet AC_reqSetAddress(CSL_UsbDevNum         devNum,
00232                                   CSL_UsbSetupStruct    *usbSetup,
00233                                   pUsbEpHandle          hInEp,
00234                                   pUsbEpHandle          hOutEp,
00235                                   void                  *pAcObj)
00236 {
00237     USB_setDevAddr(devNum, (Uint16)(usbSetup->wValue));
00238 
00239     return(CSL_AC_REQUEST_DONE);
00240 }
00241 
00296 static inline
00297 CSL_AcRequestRet AC_reqSetConfiguration(CSL_UsbDevNum         devNum,
00298                                         CSL_UsbSetupStruct    *usbSetup,
00299                                         pUsbEpHandle          hInEp,
00300                                         pUsbEpHandle          hOutEp,
00301                                         void                  *pAcObj)
00302 {
00303     CSL_AcRequestRet    retStat;
00304 
00305     pAcClassHandle      pAcClassHdl;
00306     CSL_AcCtrlObject    *pCtrlHandle;
00307 
00308     pAcClassHdl = (pAcClassHandle)(pAcObj);
00309     pCtrlHandle  = &pAcClassHdl->ctrlHandle;
00310 
00311     if((usbSetup->wValue == FALSE) || (usbSetup->wValue == TRUE))
00312     {
00313         pCtrlHandle->curConfigStat = usbSetup->wValue;
00314 
00315         USB_setConfiguration(devNum,usbSetup->wValue);
00316 
00317         retStat   = CSL_AC_REQUEST_SEND_ACK;
00318     }
00319     else
00320     {
00321         /* configuration not supported, STALL the endpoint */
00322         retStat = CSL_AC_REQUEST_STALL;
00323     }
00324 
00325     return(retStat);
00326 }
00327 
00382 static inline
00383 CSL_AcRequestRet AC_reqClearFeature(CSL_UsbDevNum         devNum,
00384                                     CSL_UsbSetupStruct    *usbSetup,
00385                                     pUsbEpHandle          hInEp,
00386                                     pUsbEpHandle          hOutEp,
00387                                     void                  *pAcObj)
00388 {
00389     CSL_AcRequestRet    retStat;
00390     pUsbEpHandle         hEPx;
00391     Uint16               endpt;  /* this is USB logical endpoint */
00392 
00393     retStat = CSL_AC_REQUEST_SEND_ACK;
00394 
00395     switch(usbSetup->wValue)
00396     {
00397         case CSL_USB_FEATURE_ENDPOINT_STALL:
00398             endpt = (usbSetup->wIndex) & CSL_AC_8BIT_MASK;
00399             hEPx = USB_epNumToHandle(devNum, endpt);
00400             USB_clearEndptStall(hEPx);
00401             break;
00402 
00403         case CSL_USB_FEATURE_REMOTE_WAKEUP:
00404             USB_setRemoteWakeup(devNum, (CSL_UsbBoolean)FALSE);
00405             break;
00406 
00407         default:
00408             /* Unsupported Feature. STALL the endpoint */
00409             retStat = CSL_AC_REQUEST_STALL;
00410             break;
00411     }
00412 
00413     return(retStat);
00414 }
00415 
00470 static inline
00471 CSL_AcRequestRet AC_reqGetStatus(CSL_UsbDevNum         devNum,
00472                                  CSL_UsbSetupStruct    *usbSetup,
00473                                  pUsbEpHandle          hInEp,
00474                                  pUsbEpHandle          hOutEp,
00475                                  void                  *pAcObj)
00476 {
00477     CSL_AcRequestRet     retStat;
00478     pAcClassHandle       pAcClassHdl;
00479     CSL_AcCtrlObject     *pCtrlHandle;
00480     pUsbEpHandle          hEPx;
00481     CSL_Status            status;
00482     Uint16                endpt;   /* this is USB logical endpoint */
00483 
00484     pAcClassHdl = (pAcClassHandle)(pAcObj);
00485     pCtrlHandle  = &pAcClassHdl->ctrlHandle;
00486     retStat      = CSL_AC_REQUEST_GET_ACK;
00487 
00488     switch(usbSetup->bmRequestType - CSL_AC_REQUEST_TYPE_BASE)
00489     {
00490         /* Device Status to be returned */
00491         case CSL_AC_REQUEST_TYPE_DEVICE_STATUS:
00492             pCtrlHandle->ctrlBuffer[1] =
00493             (((Uint16)USB_getRemoteWakeupStat(devNum))<<1) |
00494              CSL_AC_CURRDEV_STAT;
00495             USB_postTransaction(hInEp, 2, &pCtrlHandle->ctrlBuffer,
00496                                 CSL_USB_IOFLAG_NONE);
00497             break;
00498 
00499         /* Interface status is to be returned */
00500         case CSL_AC_REQUEST_TYPE_INTERFACE_STATUS:
00501             pCtrlHandle->ctrlBuffer[1] = CSL_AC_CURRDEV_STAT;
00502             USB_postTransaction(hInEp, 2, &pCtrlHandle->ctrlBuffer,
00503                                 CSL_USB_IOFLAG_NONE);
00504             break;
00505 
00506         /* Endpoint status to be returned */
00507         case CSL_AC_REQUEST_TYPE_EP_STATUS:
00508 
00509             endpt  =  usbSetup->wIndex & 0xFF;
00510             hEPx   =  USB_epNumToHandle(devNum, endpt);
00511             pCtrlHandle->ctrlBuffer[1] = (Uint16)USB_getEndptStall(hEPx,
00512                                                                    &status);
00513             USB_postTransaction(hInEp, 2, &pCtrlHandle->ctrlBuffer,
00514                                 CSL_USB_IOFLAG_NONE);
00515             break;
00516 
00517         default:
00518             /* STALL the endpoint */
00519             retStat = CSL_AC_REQUEST_STALL;
00520             break;
00521     }
00522 
00523     return(retStat);
00524 }
00525 
00580 static inline
00581 CSL_AcRequestRet AC_reqSetFeature(CSL_UsbDevNum         devNum,
00582                                   CSL_UsbSetupStruct    *usbSetup,
00583                                   pUsbEpHandle          hInEp,
00584                                   pUsbEpHandle          hOutEp,
00585                                   void                  *pAcObj)
00586 {
00587     CSL_AcRequestRet    retStat;
00588     pUsbEpHandle         hEPx;
00589     Uint16               endpt;        /* this is USB logical endpoint */
00590 
00591     retStat = CSL_AC_REQUEST_SEND_ACK;
00592 
00593     switch(usbSetup->wValue)
00594     {
00595         case CSL_USB_FEATURE_ENDPOINT_STALL:
00596             /* updated set and clear endpoint stall to work with logical endpoint num */
00597             endpt = (usbSetup->wIndex) & CSL_AC_8BIT_MASK;
00598             hEPx = USB_epNumToHandle(devNum, endpt);
00599             USB_stallEndpt(hEPx);
00600             break;
00601 
00602         case CSL_USB_FEATURE_REMOTE_WAKEUP:
00603             USB_setRemoteWakeup(devNum, (CSL_UsbBoolean)TRUE);
00604             break;
00605 
00606         default:
00607             /* Feature not supported, STALL the endpoint */
00608             retStat = CSL_AC_REQUEST_STALL;
00609             break;
00610     }
00611 
00612   return(retStat);
00613 }
00614 
00668 static inline
00669 CSL_AcRequestRet AC_reqGetConfiguration(CSL_UsbDevNum         devNum,
00670                                         CSL_UsbSetupStruct    *usbSetup,
00671                                         pUsbEpHandle          hInEp,
00672                                         pUsbEpHandle          hOutEp,
00673                                         void                  *pAcObj)
00674 {
00675     pAcClassHandle       pAcClassHdl;
00676     CSL_AcCtrlObject*    pCtrlHandle;
00677 
00678     pAcClassHdl = (pAcClassHandle)(pAcObj);
00679     pCtrlHandle  = &pAcClassHdl->ctrlHandle;
00680 
00681     /* Send the current Configuration Value */
00682     pCtrlHandle->ctrlBuffer[1] = pCtrlHandle->curConfigStat;
00683     USB_postTransaction(hInEp, 1, (void*)&pCtrlHandle->ctrlBuffer,
00684                         CSL_USB_IOFLAG_NONE | CSL_USB_IOFLAG_NOSHORT);
00685 
00686     return(CSL_AC_REQUEST_GET_ACK);
00687 }
00688 
00744 static inline
00745 CSL_AcRequestRet AC_reqGetMaxLUN(CSL_UsbDevNum         devNum,
00746                                  CSL_UsbSetupStruct    *usbSetup,
00747                                  pUsbEpHandle          hInEp,
00748                                  pUsbEpHandle          hOutEp,
00749                                  void                  *pAcObj)
00750 {
00751     pAcClassHandle       pAcClassHdl;
00752     CSL_AcCtrlObject*    pCtrlHandle;
00753     CSL_AcRequestRet     retStat;
00754 
00755     pAcClassHdl = (pAcClassHandle)(pAcObj);
00756     pCtrlHandle  = &pAcClassHdl->ctrlHandle;
00757     pCtrlHandle->ctrlBuffer[1] = pAcClassHdl->acHandle.noOfLun;
00758 
00759     if(pAcClassHdl->acHandle.noOfLun > 0)
00760     {
00761         USB_postTransaction(hInEp, 1, &pCtrlHandle->ctrlBuffer[0],
00762                             CSL_USB_IOFLAG_NONE);
00763 
00764         /*Receive a 0 length packet for acknowledgement */
00765         retStat = CSL_AC_REQUEST_GET_ACK;
00766     }
00767     else
00768     {
00769         retStat = CSL_AC_REQUEST_STALL;
00770     }
00771 
00772     return (retStat);
00773 }
00774 
00830 static inline
00831 CSL_AcRequestRet AC_reqGetInterface(CSL_UsbDevNum         devNum,
00832                                     CSL_UsbSetupStruct    *usbSetup,
00833                                     pUsbEpHandle          hInEp,
00834                                     pUsbEpHandle          hOutEp,
00835                                     void                  *pAcObj)
00836 {
00837     pAcClassHandle       pAcClassHdl;
00838     CSL_AcCtrlObject     *pCtrlHandle;
00839     CSL_AcRequestRet     retStat;
00840 
00841     pAcClassHdl = (pAcClassHandle)(pAcObj);
00842     pCtrlHandle  = &pAcClassHdl->ctrlHandle;
00843     retStat      = CSL_AC_REQUEST_GET_ACK;
00844 
00845     /* Compare the Interface with the bNumInterfaces byte of Configuration Descriptor */
00846     if(usbSetup->wIndex == 0)
00847     {
00848         /* Send the current Interface Value */
00849         pCtrlHandle->ctrlBuffer[1] = 0;
00850         USB_postTransaction(hInEp, 1, &pCtrlHandle->ctrlBuffer[0],
00851                             CSL_USB_IOFLAG_NONE);
00852     }
00853     else
00854     {
00855         /*  Interface specified doent exist, STALL the endpoint */
00856         retStat = CSL_AC_REQUEST_STALL;
00857     }
00858 
00859     return retStat;
00860 }
00861 
00865 #ifdef __cplusplus
00866 }
00867 #endif
00868 
00869 #endif    // _CSL_AUDIOCLASSAUX_H_
00870