Beispiel #1
0
/*******************************************************************************
* Function Name: USBUART_DispatchMSCClassRqst
****************************************************************************//**
*   
*  \internal 
*  This routine dispatches MSC class requests.
*
* \return
*  Status of request processing: handled or not handled.
*
* \globalvars
*  USBUART_lunCount - stores number of LUN (logical units).
*
* \reentrant
*  No.
*
*******************************************************************************/
uint8 USBUART_DispatchMSCClassRqst(void) 
{
    uint8 requestHandled = USBUART_FALSE;
    
    /* Get request data. */
    uint16 value  = USBUART_GET_UINT16(USBUART_wValueHiReg,  USBUART_wValueLoReg);
    uint16 dataLength = USBUART_GET_UINT16(USBUART_wLengthHiReg, USBUART_wLengthLoReg);
       
    /* Check request direction: D2H or H2D. */
    if (0u != (USBUART_bmRequestTypeReg & USBUART_RQST_DIR_D2H))
    {
        /* Handle direction from device to host. */
        
        if (USBUART_MSC_GET_MAX_LUN == USBUART_bRequestReg)
        {
            /* Check request fields. */
            if ((value  == USBUART_MSC_GET_MAX_LUN_WVALUE) &&
                (dataLength == USBUART_MSC_GET_MAX_LUN_WLENGTH))
            {
                /* Reply to Get Max LUN request: setup control read. */
                USBUART_currentTD.pData = &USBUART_lunCount;
                USBUART_currentTD.count =  USBUART_MSC_GET_MAX_LUN_WLENGTH;
                
                requestHandled  = USBUART_InitControlRead();
            }
        }
    }
    else
    {
        /* Handle direction from host to device. */
        
        if (USBUART_MSC_RESET == USBUART_bRequestReg)
        {
            /* Check request fields. */
            if ((value  == USBUART_MSC_RESET_WVALUE) &&
                (dataLength == USBUART_MSC_RESET_WLENGTH))
            {
                /* Handle to Bulk-Only Reset request: no data control transfer. */
                USBUART_currentTD.count = USBUART_MSC_RESET_WLENGTH;
                
            #ifdef USBUART_DISPATCH_MSC_CLASS_MSC_RESET_RQST_CALLBACK
                USBUART_DispatchMSCClass_MSC_RESET_RQST_Callback();
            #endif /* (USBUART_DISPATCH_MSC_CLASS_MSC_RESET_RQST_CALLBACK) */
                
                requestHandled = USBUART_InitNoDataControlTransfer();
            }
        }
    }
    
    return (requestHandled);
}
Beispiel #2
0
/*******************************************************************************
* Function Name: USBUART_HandleVendorRqst
****************************************************************************//**
*
*  This routine provide users with a method to implement vendor specific
*  requests.
*
*  To implement vendor specific requests, add your code in this function to
*  decode and disposition the request.  If the request is handled, your code
*  must set the variable "requestHandled" to TRUE, indicating that the
*  request has been handled.
*
* \return
*  requestHandled.
*
* \reentrant
*  No.
*
*******************************************************************************/
uint8 USBUART_HandleVendorRqst(void) 
{
    uint8 requestHandled = USBUART_FALSE;

    /* Check request direction: D2H or H2D. */
    if (0u != (USBUART_bmRequestTypeReg & USBUART_RQST_DIR_D2H))
    {
        /* Handle direction from device to host. */
        
        switch (USBUART_bRequestReg)
        {
            case USBUART_GET_EXTENDED_CONFIG_DESCRIPTOR:
            #if defined(USBUART_ENABLE_MSOS_STRING)
                USBUART_currentTD.pData = (volatile uint8 *) &USBUART_MSOS_CONFIGURATION_DESCR[0u];
                USBUART_currentTD.count = USBUART_MSOS_CONFIGURATION_DESCR[0u];
                requestHandled  = USBUART_InitControlRead();
            #endif /* (USBUART_ENABLE_MSOS_STRING) */
                break;
            
            default:
                break;
        }
    }

    /* `#START VENDOR_SPECIFIC_CODE` Place your vendor specific request here */

    /* `#END` */

#ifdef USBUART_HANDLE_VENDOR_RQST_CALLBACK
    if (USBUART_FALSE == requestHandled)
    {
        requestHandled = USBUART_HandleVendorRqst_Callback();
    }
#endif /* (USBUART_HANDLE_VENDOR_RQST_CALLBACK) */

    return (requestHandled);
}
/*******************************************************************************
* Function Name: USBUART_DispatchHIDClassRqst
********************************************************************************
*
* Summary:
*  This routine dispatches class requests
*
* Parameters:
*  None.
*
* Return:
*  requestHandled
*
* Reentrant:
*  No.
*
*******************************************************************************/
uint8 USBUART_DispatchHIDClassRqst(void) 
{
    uint8 requestHandled = USBUART_FALSE;
    uint8 interfaceNumber;

    interfaceNumber = CY_GET_REG8(USBUART_wIndexLo);
    if ((CY_GET_REG8(USBUART_bmRequestType) & USBUART_RQST_DIR_MASK) == USBUART_RQST_DIR_D2H)
    {   /* Control Read */
        switch (CY_GET_REG8(USBUART_bRequest))
        {
            case USBUART_GET_DESCRIPTOR:
                if (CY_GET_REG8(USBUART_wValueHi) == USBUART_DESCR_HID_CLASS)
                {
                    USBUART_FindHidClassDecriptor();
                    if (USBUART_currentTD.count != 0u)
                    {
                        requestHandled = USBUART_InitControlRead();
                    }
                }
                else if (CY_GET_REG8(USBUART_wValueHi) == USBUART_DESCR_HID_REPORT)
                {
                    USBUART_FindReportDescriptor();
                    if (USBUART_currentTD.count != 0u)
                    {
                        requestHandled = USBUART_InitControlRead();
                    }
                }
                else
                {   /* requestHandled is initialezed as FALSE by default */
                }
                break;
            case USBUART_HID_GET_REPORT:
                USBUART_FindReport();
                if (USBUART_currentTD.count != 0u)
                {
                    requestHandled = USBUART_InitControlRead();
                }
                break;

            case USBUART_HID_GET_IDLE:
                /* This function does not support multiple reports per interface*/
                /* Validate interfaceNumber and Report ID (should be 0) */
                if( (interfaceNumber < USBUART_MAX_INTERFACES_NUMBER) &&
                    (CY_GET_REG8(USBUART_wValueLo) == 0u ) ) /* Do not support Idle per Report ID */
                {
                    USBUART_currentTD.count = 1u;
                    USBUART_currentTD.pData = &USBUART_hidIdleRate[interfaceNumber];
                    requestHandled  = USBUART_InitControlRead();
                }
                break;
            case USBUART_HID_GET_PROTOCOL:
                /* Validate interfaceNumber */
                if( interfaceNumber < USBUART_MAX_INTERFACES_NUMBER)
                {
                    USBUART_currentTD.count = 1u;
                    USBUART_currentTD.pData = &USBUART_hidProtocol[interfaceNumber];
                    requestHandled  = USBUART_InitControlRead();
                }
                break;
            default:    /* requestHandled is initialized as FALSE by default */
                break;
        }
    }
    else if ((CY_GET_REG8(USBUART_bmRequestType) & USBUART_RQST_DIR_MASK) ==
                                                                            USBUART_RQST_DIR_H2D)
    {   /* Control Write */
        switch (CY_GET_REG8(USBUART_bRequest))
        {
            case USBUART_HID_SET_REPORT:
                USBUART_FindReport();
                if (USBUART_currentTD.count != 0u)
                {
                    requestHandled = USBUART_InitControlWrite();
                }
                break;
            case USBUART_HID_SET_IDLE:
                /* This function does not support multiple reports per interface */
                /* Validate interfaceNumber and Report ID (should be 0) */
                if( (interfaceNumber < USBUART_MAX_INTERFACES_NUMBER) &&
                    (CY_GET_REG8(USBUART_wValueLo) == 0u ) ) /* Do not support Idle per Report ID */
                {
                    USBUART_hidIdleRate[interfaceNumber] = CY_GET_REG8(USBUART_wValueHi);
                    /* With regards to HID spec: "7.2.4 Set_Idle Request"
                    *  Latency. If the current period has gone past the
                    *  newly proscribed time duration, then a report
                    *  will be generated immediately.
                    */
                    if(USBUART_hidIdleRate[interfaceNumber] <
                       USBUART_hidIdleTimer[interfaceNumber])
                    {
                        /* Set the timer to zero and let the UpdateHIDTimer() API return IDLE_TIMER_EXPIRED status*/
                        USBUART_hidIdleTimer[interfaceNumber] = 0u;
                    }
                    /* If the new request is received within 4 milliseconds
                    *  (1 count) of the end of the current period, then the
                    *  new request will have no effect until after the report.
                    */
                    else if(USBUART_hidIdleTimer[interfaceNumber] <= 1u)
                    {
                        /* Do nothing.
                        *  Let the UpdateHIDTimer() API continue to work and
                        *  return IDLE_TIMER_EXPIRED status
                        */
                    }
                    else
                    {   /* Reload the timer*/
                        USBUART_hidIdleTimer[interfaceNumber] =
                        USBUART_hidIdleRate[interfaceNumber];
                    }
                    requestHandled = USBUART_InitNoDataControlTransfer();
                }
                break;

            case USBUART_HID_SET_PROTOCOL:
                /* Validate interfaceNumber and protocol (must be 0 or 1) */
                if( (interfaceNumber < USBUART_MAX_INTERFACES_NUMBER) &&
                    (CY_GET_REG8(USBUART_wValueLo) <= 1u) )
                {
                    USBUART_hidProtocol[interfaceNumber] = CY_GET_REG8(USBUART_wValueLo);
                    requestHandled = USBUART_InitNoDataControlTransfer();
                }
                break;
            default:    /* requestHandled is initialized as FALSE by default */
                break;
        }
    }
    else
    {   /* requestHandled is initialized as FALSE by default */
    }

    return(requestHandled);
}
Beispiel #4
0
/*******************************************************************************
* Function Name: USBUART_DispatchAUDIOClassRqst
****************************************************************************//**
*
*  This routine dispatches class requests
*
* \return
*  Results of Audio Class request handling: 
*  - USBUART_TRUE  - request was handled without errors
*  - USBUART_FALSE - error occurs during handling of request     
*
* \globalvars
*   USBUART_currentSampleFrequency: Contains the current audio Sample
*       Frequency. It is set by the Host using SET_CUR request to the endpoint.
*   USBUART_frequencyChanged: This variable is used as a flag for the
*       user code, to be aware that Host has been sent request for changing
*       Sample Frequency. Sample frequency will be sent on the next OUT
*       transaction. It is contains endpoint address when set. The following
*       code is recommended for detecting new Sample Frequency in main code:
*       
*  \snippet  /USBFS_sut_02.cydsn/main.c Detecting new Sample Frequency
*      
*   USBUART_transferState variable is checked to be sure that transfer
*              completes.
*   USBUART_currentMute: Contains mute configuration set by Host.
*   USBUART_currentVolume: Contains volume level set by Host.
*
* \reentrant
*  No.
*
*******************************************************************************/
uint8 USBUART_DispatchAUDIOClassRqst(void) 
{
    uint8 requestHandled = USBUART_FALSE;
    
    uint8 RqstRcpt = (uint8)(USBUART_bmRequestTypeReg & USBUART_RQST_RCPT_MASK);
#if defined(USBUART_ENABLE_AUDIO_STREAMING)
    uint8 wValueHi = (uint8) USBUART_wValueHiReg;
    uint8 epNumber = (uint8) USBUART_wIndexLoReg & USBUART_DIR_UNUSED;
#endif /* (USBUART_ENABLE_AUDIO_STREAMING) */
    
    /* Check request direction: D2H or H2D. */
    if (0u != (USBUART_bmRequestTypeReg & USBUART_RQST_DIR_D2H))
    {
        /* Handle direction from device to host. */
        
        if (USBUART_RQST_RCPT_EP == RqstRcpt)
        {
            /* Request recipient is to endpoint. */
            switch (USBUART_bRequestReg)
            {
                case USBUART_GET_CUR:
                #if defined(USBUART_ENABLE_AUDIO_STREAMING)
                    if (wValueHi == USBUART_SAMPLING_FREQ_CONTROL)
                    {
                         /* point Control Selector is Sampling Frequency */
                        USBUART_currentTD.wCount = USBUART_SAMPLE_FREQ_LEN;
                        USBUART_currentTD.pData  = USBUART_currentSampleFrequency[epNumber];
                        
                        requestHandled   = USBUART_InitControlRead();
                    }
                #endif /* (USBUART_ENABLE_AUDIO_STREAMING) */
                
                    /* `#START AUDIO_READ_REQUESTS` Place other request handler here */

                    /* `#END` */
                
                #ifdef USBUART_DISPATCH_AUDIO_CLASS_AUDIO_READ_REQUESTS_CALLBACK    
                    USBUART_DispatchAUDIOClass_AUDIO_READ_REQUESTS_Callback();
                #endif /* (USBUART_DISPATCH_AUDIO_CLASS_AUDIO_READ_REQUESTS_CALLBACK) */                   
                break;
                
                default:
                    /* Do not handle this request unless callback is defined. */
                    break;
            }
        
        }
        else if (USBUART_RQST_RCPT_IFC == RqstRcpt)
        {
            /* Request recipient is interface or entity ID. */
            switch (USBUART_bRequestReg)
            {
                case USBUART_GET_CUR:
                #if defined(USBUART_ENABLE_AUDIO_STREAMING)
                    if (wValueHi == USBUART_MUTE_CONTROL)
                    {
                        /* `#START MUTE_CONTROL_GET_REQUEST` Place multi-channel handler here */

                        /* `#END` */

                    #ifdef USBUART_DISPATCH_AUDIO_CLASS_MUTE_CONTROL_GET_REQUEST_CALLBACK
                        USBUART_DispatchAUDIOClass_MUTE_CONTROL_GET_REQUEST_Callback();
                    #endif /* (USBUART_DISPATCH_AUDIO_CLASS_MUTE_CONTROL_GET_REQUEST_CALLBACK) */

                        /* Entity ID Control Selector is MUTE */
                        USBUART_currentTD.wCount = 1u;
                        USBUART_currentTD.pData  = &USBUART_currentMute;
                        
                        requestHandled = USBUART_InitControlRead();
                    }
                    else if (wValueHi == USBUART_VOLUME_CONTROL)
                    {
                        /* `#START VOLUME_CONTROL_GET_REQUEST` Place multi-channel handler here */

                        /* `#END` */

                    #ifdef USBUART_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_GET_REQUEST_CALLBACK
                        USBUART_DispatchAUDIOClass_VOLUME_CONTROL_GET_REQUEST_Callback();
                    #endif /* (USBUART_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_GET_REQUEST_CALLBACK) */

                        /* Entity ID Control Selector is VOLUME, */
                        USBUART_currentTD.wCount = USBUART_VOLUME_LEN;
                        USBUART_currentTD.pData  = USBUART_currentVolume;
                        
                        requestHandled = USBUART_InitControlRead();
                    }
                    else
                    {
                        /* `#START OTHER_GET_CUR_REQUESTS` Place other request handler here */

                        /* `#END` */

                    #ifdef USBUART_DISPATCH_AUDIO_CLASS_OTHER_GET_CUR_REQUESTS_CALLBACK
                        USBUART_DispatchAUDIOClass_OTHER_GET_CUR_REQUESTS_Callback();
                    #endif /* (USBUART_DISPATCH_AUDIO_CLASS_OTHER_GET_CUR_REQUESTS_CALLBACK) */
                    }
                    break;
                    
                case USBUART_GET_MIN:
                    if (wValueHi == USBUART_VOLUME_CONTROL)
                    {
                        /* Entity ID Control Selector is VOLUME, */
                        USBUART_currentTD.wCount = USBUART_VOLUME_LEN;
                        USBUART_currentTD.pData  = &USBUART_minimumVolume[0];
                        
                        requestHandled = USBUART_InitControlRead();
                    }
                    break;
                    
                case USBUART_GET_MAX:
                    if (wValueHi == USBUART_VOLUME_CONTROL)
                    {
                        /* Entity ID Control Selector is VOLUME, */
                        USBUART_currentTD.wCount = USBUART_VOLUME_LEN;
                        USBUART_currentTD.pData  = &USBUART_maximumVolume[0];
                        
                        requestHandled = USBUART_InitControlRead();
                    }
                    break;
                    
                case USBUART_GET_RES:
                    if (wValueHi == USBUART_VOLUME_CONTROL)
                    {
                         /* Entity ID Control Selector is VOLUME, */
                        USBUART_currentTD.wCount = USBUART_VOLUME_LEN;
                        USBUART_currentTD.pData  = &USBUART_resolutionVolume[0];
                        
                        requestHandled   = USBUART_InitControlRead();
                    }
                    break;
                    
                /* The contents of the status message is reserved for future use.
                * For the time being, a null packet should be returned in the data stage of the
                * control transfer, and the received null packet should be ACKed.
                */
                case USBUART_GET_STAT:
                    USBUART_currentTD.wCount = 0u;    
                    
                    requestHandled = USBUART_InitControlWrite();

                #endif /* (USBUART_ENABLE_AUDIO_STREAMING) */
                
                    /* `#START AUDIO_WRITE_REQUESTS` Place other request handler here */

                    /* `#END` */
                
                #ifdef USBUART_DISPATCH_AUDIO_CLASS_AUDIO_WRITE_REQUESTS_CALLBACK
                    USBUART_DispatchAUDIOClass_AUDIO_WRITE_REQUESTS_Callback();
                #endif /* (USBUART_DISPATCH_AUDIO_CLASS_AUDIO_WRITE_REQUESTS_CALLBACK) */
                    break;
                
                default:
                    /* Do not handle this request. */
                    break;
            }
        }
        else
        {   
            /* Do not handle other requests recipients. */
        }
    }
    else
    {
        /* Handle direction from host to device. */
        
        if (USBUART_RQST_RCPT_EP == RqstRcpt)
        {
            /* Request recipient is endpoint. */
            switch (USBUART_bRequestReg)
            {
                case USBUART_SET_CUR:
                #if defined(USBUART_ENABLE_AUDIO_STREAMING)
                    if (wValueHi == USBUART_SAMPLING_FREQ_CONTROL)
                    {
                         /* point Control Selector is Sampling Frequency */
                        USBUART_currentTD.wCount = USBUART_SAMPLE_FREQ_LEN;
                        USBUART_currentTD.pData  = USBUART_currentSampleFrequency[epNumber];
                        USBUART_frequencyChanged = (uint8) epNumber;
                        
                        requestHandled   = USBUART_InitControlWrite();
                    }
                #endif /* (USBUART_ENABLE_AUDIO_STREAMING) */

                    /* `#START AUDIO_SAMPLING_FREQ_REQUESTS` Place other request handler here */

                    /* `#END` */

                #ifdef USBUART_DISPATCH_AUDIO_CLASS_AUDIO_SAMPLING_FREQ_REQUESTS_CALLBACK
                    USBUART_DispatchAUDIOClass_AUDIO_SAMPLING_FREQ_REQUESTS_Callback();
                #endif /* (USBUART_DISPATCH_AUDIO_CLASS_AUDIO_SAMPLING_FREQ_REQUESTS_CALLBACK) */
                    break;
                
                default:
                    /* Do not handle this request. */
                    break;
            }
        }
        else if(USBUART_RQST_RCPT_IFC == RqstRcpt)
        {
            /* Request recipient is interface or entity ID. */
            switch (USBUART_bRequestReg)
            {
                case USBUART_SET_CUR:
                #if defined(USBUART_ENABLE_AUDIO_STREAMING)
                    if (wValueHi == USBUART_MUTE_CONTROL)
                    {
                        /* `#START MUTE_SET_REQUEST` Place multi-channel handler here */

                        /* `#END` */

                    #ifdef USBUART_DISPATCH_AUDIO_CLASS_MUTE_SET_REQUEST_CALLBACK
                        USBUART_DispatchAUDIOClass_MUTE_SET_REQUEST_Callback();
                    #endif /* (USBUART_DISPATCH_AUDIO_CLASS_MUTE_SET_REQUEST_CALLBACK) */

                        /* Entity ID Control Selector is MUTE */
                        USBUART_currentTD.wCount = 1u;
                        USBUART_currentTD.pData  = &USBUART_currentMute;
                        
                        requestHandled = USBUART_InitControlWrite();
                    }
                    else if (wValueHi == USBUART_VOLUME_CONTROL)
                    {
                        /* `#START VOLUME_CONTROL_SET_REQUEST` Place multi-channel handler here */

                        /* `#END` */

                    #ifdef USBUART_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_SET_REQUEST_CALLBACK
                        USBUART_DispatchAUDIOClass_VOLUME_CONTROL_SET_REQUEST_Callback();
                    #endif /* (USBUART_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_SET_REQUEST_CALLBACK) */

                        /* Entity ID Control Selector is VOLUME */
                        USBUART_currentTD.wCount = USBUART_VOLUME_LEN;
                        USBUART_currentTD.pData  = USBUART_currentVolume;
                        
                        requestHandled = USBUART_InitControlWrite();
                    }
                    else
                    {
                        /* `#START OTHER_SET_CUR_REQUESTS` Place other request handler here */

                        /* `#END` */

                    #ifdef USBUART_DISPATCH_AUDIO_CLASS_OTHER_SET_CUR_REQUESTS_CALLBACK
                        USBUART_DispatchAUDIOClass_OTHER_SET_CUR_REQUESTS_Callback();
                    #endif /* (USBUART_DISPATCH_AUDIO_CLASS_OTHER_SET_CUR_REQUESTS_CALLBACK) */
                    }
                #endif /*  USBUART_ENABLE_AUDIO_STREAMING */
                
                
                    /* `#START AUDIO_CONTROL_SEL_REQUESTS` Place other request handler here */

                    /* `#END` */
                    
                #ifdef USBUART_DISPATCH_AUDIO_CLASS_AUDIO_CONTROL_SEL_REQUESTS_CALLBACK
                    USBUART_DispatchAUDIOClass_AUDIO_CONTROL_SEL_REQUESTS_Callback();
                #endif /* (USBUART_DISPATCH_AUDIO_CLASS_AUDIO_CONTROL_SEL_REQUESTS_CALLBACK) */
                break;

                default:
                    /* Do not handle this request. */
                break;
            }
        }
        else
        {
            /* Do not handle other requests recipients. */
        }
    }

    return (requestHandled);
}
Beispiel #5
0
/*******************************************************************************
* Function Name: USBUART_DispatchCDCClassRqst
****************************************************************************//**
*
*  This routine dispatches CDC class requests.
*
* \return
*  requestHandled
*
* \globalvars
*   USBUART_linesCoding: Contains the current line coding structure.
*     It is set by the Host using SET_LINE_CODING request and returned to the
*     user code by the USBFS_GetDTERate(), USBFS_GetCharFormat(),
*     USBFS_GetParityType(), USBFS_GetDataBits() APIs.
*   USBUART_linesControlBitmap: Contains the current control signal
*     bitmap. It is set by the Host using SET_CONTROL_LINE request and returned
*     to the user code by the USBFS_GetLineControl() API.
*   USBUART_linesChanged: This variable is used as a flag for the
*     USBFS_IsLineChanged() API, to be aware that Host has been sent request
*     for changing Line Coding or Control Bitmap.
*
* \reentrant
*  No.
*
*******************************************************************************/
uint8 USBUART_DispatchCDCClassRqst(void) 
{
    uint8 requestHandled = USBUART_FALSE;
    uint8 comPort;

    comPort = USBUART_GetInterfaceComPort((uint8)USBUART_wIndexLoReg);

    /* Check request direction: D2H or H2D. */
    if (0u != (USBUART_bmRequestTypeReg & USBUART_RQST_DIR_D2H))
    {
        /* Handle direction from device to host. */

        switch (USBUART_bRequestReg)
        {
            case USBUART_CDC_GET_LINE_CODING:
                USBUART_currentTD.count = USBUART_LINE_CODING_SIZE;
                USBUART_currentTD.pData = USBUART_linesCoding[comPort];
                requestHandled  = USBUART_InitControlRead();
                break;

            /* `#START CDC_READ_REQUESTS` Place other request handler here */

            /* `#END` */

            default:
            /* Do not handle this request unless callback is defined. */
            #ifdef USBUART_DISPATCH_CDC_CLASS_CDC_READ_REQUESTS_CALLBACK
                requestHandled = USBUART_DispatchCDCClass_CDC_READ_REQUESTS_Callback();
            #endif /* (USBUART_DISPATCH_CDC_CLASS_CDC_READ_REQUESTS_CALLBACK) */
                break;
        }
    }
    else
    {
        /* Handle direction from host to device. */

        switch (USBUART_bRequestReg)
        {
            case USBUART_CDC_SET_LINE_CODING:
                USBUART_currentTD.count  = USBUART_LINE_CODING_SIZE;
                USBUART_currentTD.pData  = USBUART_linesCoding[comPort];
                USBUART_linesChanged[comPort] |= USBUART_LINE_CODING_CHANGED;

                requestHandled = USBUART_InitControlWrite();
                break;

            case USBUART_CDC_SET_CONTROL_LINE_STATE:
                USBUART_linesControlBitmap[comPort] = (uint8) USBUART_wValueLoReg;
                USBUART_linesChanged[comPort]      |= USBUART_LINE_CONTROL_CHANGED;

                requestHandled = USBUART_InitNoDataControlTransfer();
                break;

            /* `#START CDC_WRITE_REQUESTS` Place other request handler here */

            /* `#END` */

            default:
                /* Do not handle this request unless callback is defined. */
            #ifdef USBUART_DISPATCH_CDC_CLASS_CDC_WRITE_REQUESTS_CALLBACK
                requestHandled = USBUART_DispatchCDCClass_CDC_WRITE_REQUESTS_Callback();
            #endif /* (USBUART_DISPATCH_CDC_CLASS_CDC_WRITE_REQUESTS_CALLBACK) */
                break;
        }
    }

    return(requestHandled);
}
/*******************************************************************************
* Function Name: USBUART_DispatchAUDIOClassRqst
********************************************************************************
*
* Summary:
*  This routine dispatches class requests
*
* Parameters:
*  None.
*
* Return:
*  requestHandled
*
* Global variables:
*   USBUART_currentSampleFrequency: Contains the current audio Sample
*       Frequency. It is set by the Host using SET_CUR request to the endpoint.
*   USBUART_frequencyChanged: This variable is used as a flag for the
*       user code, to be aware that Host has been sent request for changing
*       Sample Frequency. Sample frequency will be sent on the next OUT
*       transaction. It is contains endpoint address when set. The following
*       code is recommended for detecting new Sample Frequency in main code:
*       if((USBUART_frequencyChanged != 0) &&
*       (USBUART_transferState == USBUART_TRANS_STATE_IDLE))
*       {
*          USBUART_frequencyChanged = 0;
*       }
*       USBUART_transferState variable is checked to be sure that
*             transfer completes.
*   USBUART_currentMute: Contains mute configuration set by Host.
*   USBUART_currentVolume: Contains volume level set by Host.
*
* Reentrant:
*  No.
*
*******************************************************************************/
uint8 USBUART_DispatchAUDIOClassRqst(void) 
{
    uint8 requestHandled = USBUART_FALSE;
    uint8 bmRequestType  = CY_GET_REG8(USBUART_bmRequestType);

    #if defined(USBUART_ENABLE_AUDIO_STREAMING)
        uint8 epNumber;
        epNumber = CY_GET_REG8(USBUART_wIndexLo) & USBUART_DIR_UNUSED;
    #endif /*  USBUART_ENABLE_AUDIO_STREAMING */


    if ((bmRequestType & USBUART_RQST_DIR_MASK) == USBUART_RQST_DIR_D2H)
    {
        /* Control Read */
        if((bmRequestType & USBUART_RQST_RCPT_MASK) == USBUART_RQST_RCPT_EP)
        {
            /* Endpoint */
            switch (CY_GET_REG8(USBUART_bRequest))
            {
                case USBUART_GET_CUR:
                #if defined(USBUART_ENABLE_AUDIO_STREAMING)
                    if(CY_GET_REG8(USBUART_wValueHi) == USBUART_SAMPLING_FREQ_CONTROL)
                    {
                         /* point Control Selector is Sampling Frequency */
                        USBUART_currentTD.wCount = USBUART_SAMPLE_FREQ_LEN;
                        USBUART_currentTD.pData  = USBUART_currentSampleFrequency[epNumber];
                        requestHandled   = USBUART_InitControlRead();
                    }
                #endif /*  USBUART_ENABLE_AUDIO_STREAMING */

                /* `#START AUDIO_READ_REQUESTS` Place other request handler here */

                /* `#END` */
                
                #ifdef USBUART_DISPATCH_AUDIO_CLASS_AUDIO_READ_REQUESTS_CALLBACK
                    USBUART_DispatchAUDIOClass_AUDIO_READ_REQUESTS_Callback();
                #endif /* USBUART_DISPATCH_AUDIO_CLASS_AUDIO_READ_REQUESTS_CALLBACK */

                    break;
                default:
                    break;
            }
        }
        else if((bmRequestType & USBUART_RQST_RCPT_MASK) == USBUART_RQST_RCPT_IFC)
        {
            /* Interface or Entity ID */
            switch (CY_GET_REG8(USBUART_bRequest))
            {
                case USBUART_GET_CUR:
                #if defined(USBUART_ENABLE_AUDIO_STREAMING)
                    if(CY_GET_REG8(USBUART_wValueHi) == USBUART_MUTE_CONTROL)
                    {
                        /* `#START MUTE_CONTROL_GET_REQUEST` Place multi-channel handler here */

                        /* `#END` */

                        #ifdef USBUART_DISPATCH_AUDIO_CLASS_MUTE_CONTROL_GET_REQUEST_CALLBACK
                            USBUART_DispatchAUDIOClass_MUTE_CONTROL_GET_REQUEST_Callback();
                        #endif /* USBUART_DISPATCH_AUDIO_CLASS_MUTE_CONTROL_GET_REQUEST_CALLBACK */

                        /* Entity ID Control Selector is MUTE */
                        USBUART_currentTD.wCount = 1u;
                        USBUART_currentTD.pData  = &USBUART_currentMute;
                        requestHandled   = USBUART_InitControlRead();
                    }
                    else if(CY_GET_REG8(USBUART_wValueHi) == USBUART_VOLUME_CONTROL)
                    {
                        /* `#START VOLUME_CONTROL_GET_REQUEST` Place multi-channel handler here */

                        /* `#END` */

                        #ifdef USBUART_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_GET_REQUEST_CALLBACK
                            USBUART_DispatchAUDIOClass_VOLUME_CONTROL_GET_REQUEST_Callback();
                        #endif /* USBUART_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_GET_REQUEST_CALLBACK */

                        /* Entity ID Control Selector is VOLUME, */
                        USBUART_currentTD.wCount = USBUART_VOLUME_LEN;
                        USBUART_currentTD.pData  = USBUART_currentVolume;
                        requestHandled   = USBUART_InitControlRead();
                    }
                    else
                    {
                        /* `#START OTHER_GET_CUR_REQUESTS` Place other request handler here */

                        /* `#END` */

                        #ifdef USBUART_DISPATCH_AUDIO_CLASS_OTHER_GET_CUR_REQUESTS_CALLBACK
                            USBUART_DispatchAUDIOClass_OTHER_GET_CUR_REQUESTS_Callback();
                        #endif /* USBUART_DISPATCH_AUDIO_CLASS_OTHER_GET_CUR_REQUESTS_CALLBACK */
                    }
                    break;
                case USBUART_GET_MIN:    /* GET_MIN */
                    if(CY_GET_REG8(USBUART_wValueHi) == USBUART_VOLUME_CONTROL)
                    {
                        /* Entity ID Control Selector is VOLUME, */
                        USBUART_currentTD.wCount = USBUART_VOLUME_LEN;
                        USBUART_currentTD.pData  = &USBUART_minimumVolume[0];
                        requestHandled   = USBUART_InitControlRead();
                    }
                    break;
                case USBUART_GET_MAX:    /* GET_MAX */
                    if(CY_GET_REG8(USBUART_wValueHi) == USBUART_VOLUME_CONTROL)
                    {
                        /* Entity ID Control Selector is VOLUME, */
                        USBUART_currentTD.wCount = USBUART_VOLUME_LEN;
                        USBUART_currentTD.pData  = &USBUART_maximumVolume[0];
                        requestHandled   = USBUART_InitControlRead();
                    }
                    break;
                case USBUART_GET_RES:    /* GET_RES */
                    if(CY_GET_REG8(USBUART_wValueHi) == USBUART_VOLUME_CONTROL)
                    {
                         /* Entity ID Control Selector is VOLUME, */
                        USBUART_currentTD.wCount = USBUART_VOLUME_LEN;
                        USBUART_currentTD.pData  = &USBUART_resolutionVolume[0];
                        requestHandled   = USBUART_InitControlRead();
                    }
                    break;
                /* The contents of the status message is reserved for future use.
                *  For the time being, a null packet should be returned in the data stage of the
                *  control transfer, and the received null packet should be ACKed.
                */
                case USBUART_GET_STAT:
                        USBUART_currentTD.wCount = 0u;
                        requestHandled   = USBUART_InitControlWrite();

                #endif /*  USBUART_ENABLE_AUDIO_STREAMING */

                /* `#START AUDIO_WRITE_REQUESTS` Place other request handler here */

                /* `#END` */

                #ifdef USBUART_DISPATCH_AUDIO_CLASS_AUDIO_WRITE_REQUESTS_CALLBACK
                    USBUART_DispatchAUDIOClass_AUDIO_WRITE_REQUESTS_Callback();
                #endif /* USBUART_DISPATCH_AUDIO_CLASS_AUDIO_WRITE_REQUESTS_CALLBACK */

                    break;
                default:
                    break;
            }
        }
        else
        {   /* USBUART_RQST_RCPT_OTHER */
        }
    }
    else
    {
        /* Control Write */
        if((bmRequestType & USBUART_RQST_RCPT_MASK) == USBUART_RQST_RCPT_EP)
        {
            /* point */
            switch (CY_GET_REG8(USBUART_bRequest))
            {
                case USBUART_SET_CUR:
                #if defined(USBUART_ENABLE_AUDIO_STREAMING)
                    if(CY_GET_REG8(USBUART_wValueHi) == USBUART_SAMPLING_FREQ_CONTROL)
                    {
                         /* point Control Selector is Sampling Frequency */
                        USBUART_currentTD.wCount = USBUART_SAMPLE_FREQ_LEN;
                        USBUART_currentTD.pData  = USBUART_currentSampleFrequency[epNumber];
                        requestHandled   = USBUART_InitControlWrite();
                        USBUART_frequencyChanged = epNumber;
                    }
                #endif /*  USBUART_ENABLE_AUDIO_STREAMING */

                /* `#START AUDIO_SAMPLING_FREQ_REQUESTS` Place other request handler here */

                /* `#END` */

                #ifdef USBUART_DISPATCH_AUDIO_CLASS_AUDIO_SAMPLING_FREQ_REQUESTS_CALLBACK
                    USBUART_DispatchAUDIOClass_AUDIO_SAMPLING_FREQ_REQUESTS_Callback();
                #endif /* USBUART_DISPATCH_AUDIO_CLASS_AUDIO_SAMPLING_FREQ_REQUESTS_CALLBACK */

                    break;
                default:
                    break;
            }
        }
        else if((bmRequestType & USBUART_RQST_RCPT_MASK) == USBUART_RQST_RCPT_IFC)
        {
            /* Interface or Entity ID */
            switch (CY_GET_REG8(USBUART_bRequest))
            {
                case USBUART_SET_CUR:
                #if defined(USBUART_ENABLE_AUDIO_STREAMING)
                    if(CY_GET_REG8(USBUART_wValueHi) == USBUART_MUTE_CONTROL)
                    {
                        /* `#START MUTE_SET_REQUEST` Place multi-channel handler here */

                        /* `#END` */

                        #ifdef USBUART_DISPATCH_AUDIO_CLASS_MUTE_SET_REQUEST_CALLBACK
                            USBUART_DispatchAUDIOClass_MUTE_SET_REQUEST_Callback();
                        #endif /* USBUART_DISPATCH_AUDIO_CLASS_MUTE_SET_REQUEST_CALLBACK */

                        /* Entity ID Control Selector is MUTE */
                        USBUART_currentTD.wCount = 1u;
                        USBUART_currentTD.pData  = &USBUART_currentMute;
                        requestHandled   = USBUART_InitControlWrite();
                    }
                    else if(CY_GET_REG8(USBUART_wValueHi) == USBUART_VOLUME_CONTROL)
                    {
                        /* `#START VOLUME_CONTROL_SET_REQUEST` Place multi-channel handler here */

                        /* `#END` */

                        #ifdef USBUART_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_SET_REQUEST_CALLBACK
                            USBUART_DispatchAUDIOClass_VOLUME_CONTROL_SET_REQUEST_Callback();
                        #endif /* USBUART_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_SET_REQUEST_CALLBACK */

                        /* Entity ID Control Selector is VOLUME */
                        USBUART_currentTD.wCount = USBUART_VOLUME_LEN;
                        USBUART_currentTD.pData  = USBUART_currentVolume;
                        requestHandled   = USBUART_InitControlWrite();
                    }
                    else
                    {
                        /* `#START OTHER_SET_CUR_REQUESTS` Place other request handler here */

                        /* `#END` */

                        #ifdef USBUART_DISPATCH_AUDIO_CLASS_OTHER_SET_CUR_REQUESTS_CALLBACK
                            USBUART_DispatchAUDIOClass_OTHER_SET_CUR_REQUESTS_Callback();
                        #endif /* USBUART_DISPATCH_AUDIO_CLASS_OTHER_SET_CUR_REQUESTS_CALLBACK */
                    }
                #endif /*  USBUART_ENABLE_AUDIO_STREAMING */

                /* `#START AUDIO_CONTROL_SEL_REQUESTS` Place other request handler here */

                /* `#END` */

                #ifdef USBUART_DISPATCH_AUDIO_CLASS_AUDIO_CONTROL_SEL_REQUESTS_CALLBACK
                    USBUART_DispatchAUDIOClass_AUDIO_CONTROL_SEL_REQUESTS_Callback();
                #endif /* USBUART_DISPATCH_AUDIO_CLASS_AUDIO_CONTROL_SEL_REQUESTS_CALLBACK */

                    break;
                default:
                    break;
            }
        }
        else
        {
            /* USBUART_RQST_RCPT_OTHER */
        }
    }

    return(requestHandled);
}