/******************************************************************************* * Function Name: USBFS_1_HandleVendorRqst ******************************************************************************** * * Summary: * This routine provide users with a method to implement vendor specifc * 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. * * Parameters: * None. * * Return: * requestHandled. * * Reentrant: * No. * *******************************************************************************/ uint8 USBFS_1_HandleVendorRqst(void) { uint8 requestHandled = USBFS_1_FALSE; if ((CY_GET_REG8(USBFS_1_bmRequestType) & USBFS_1_RQST_DIR_MASK) == USBFS_1_RQST_DIR_D2H) { /* Control Read */ switch (CY_GET_REG8(USBFS_1_bRequest)) { case USBFS_1_GET_EXTENDED_CONFIG_DESCRIPTOR: #if defined(USBFS_1_ENABLE_MSOS_STRING) USBFS_1_currentTD.pData = &USBFS_1_MSOS_CONFIGURATION_DESCR[0u]; USBFS_1_currentTD.count = USBFS_1_MSOS_CONFIGURATION_DESCR[0u]; requestHandled = USBFS_1_InitControlRead(); #endif /* End USBFS_1_ENABLE_MSOS_STRING */ break; default: break; } } /* `#START VENDOR_SPECIFIC_CODE` Place your vendor specific request here */ /* `#END` */ return(requestHandled); }
/******************************************************************************* * Function Name: USBFS_1_DispatchCDCClassRqst ******************************************************************************** * * Summary: * This routine dispatches CDC class requests. * * Parameters: * None. * * Return: * requestHandled * * Global variables: * USBFS_1_lineCoding: 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. * USBFS_1_lineControlBitmap: 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. * USBFS_1_lineChanged: 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 USBFS_1_DispatchCDCClassRqst() { uint8 requestHandled = USBFS_1_FALSE; if ((CY_GET_REG8(USBFS_1_bmRequestType) & USBFS_1_RQST_DIR_MASK) == USBFS_1_RQST_DIR_D2H) { /* Control Read */ switch (CY_GET_REG8(USBFS_1_bRequest)) { case USBFS_1_CDC_GET_LINE_CODING: USBFS_1_currentTD.count = USBFS_1_LINE_CODING_SIZE; USBFS_1_currentTD.pData = USBFS_1_lineCoding; requestHandled = USBFS_1_InitControlRead(); break; /* `#START CDC_READ_REQUESTS` Place other request handler here */ /* `#END` */ default: /* requestHandled is initialezed as FALSE by default */ break; } } else if ((CY_GET_REG8(USBFS_1_bmRequestType) & USBFS_1_RQST_DIR_MASK) == \ USBFS_1_RQST_DIR_H2D) { /* Control Write */ switch (CY_GET_REG8(USBFS_1_bRequest)) { case USBFS_1_CDC_SET_LINE_CODING: USBFS_1_currentTD.count = USBFS_1_LINE_CODING_SIZE; USBFS_1_currentTD.pData = USBFS_1_lineCoding; USBFS_1_lineChanged |= USBFS_1_LINE_CODING_CHANGED; requestHandled = USBFS_1_InitControlWrite(); break; case USBFS_1_CDC_SET_CONTROL_LINE_STATE: USBFS_1_lineControlBitmap = CY_GET_REG8(USBFS_1_wValueLo); USBFS_1_lineChanged |= USBFS_1_LINE_CONTROL_CHANGED; requestHandled = USBFS_1_InitNoDataControlTransfer(); break; /* `#START CDC_WRITE_REQUESTS` Place other request handler here */ /* `#END` */ default: /* requestHandled is initialezed as FALSE by default */ break; } } else { /* requestHandled is initialezed as FALSE by default */ } return(requestHandled); }
/******************************************************************************* * Function Name: USBFS_1_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 USBFS_1_HandleVendorRqst(void) { uint8 requestHandled = USBFS_1_FALSE; /* Check request direction: D2H or H2D. */ if (0u != (USBFS_1_bmRequestTypeReg & USBFS_1_RQST_DIR_D2H)) { /* Handle direction from device to host. */ switch (USBFS_1_bRequestReg) { case USBFS_1_GET_EXTENDED_CONFIG_DESCRIPTOR: #if defined(USBFS_1_ENABLE_MSOS_STRING) USBFS_1_currentTD.pData = (volatile uint8 *) &USBFS_1_MSOS_CONFIGURATION_DESCR[0u]; USBFS_1_currentTD.count = USBFS_1_MSOS_CONFIGURATION_DESCR[0u]; requestHandled = USBFS_1_InitControlRead(); #endif /* (USBFS_1_ENABLE_MSOS_STRING) */ break; default: break; } } /* `#START VENDOR_SPECIFIC_CODE` Place your vendor specific request here */ /* `#END` */ #ifdef USBFS_1_HANDLE_VENDOR_RQST_CALLBACK if (USBFS_1_FALSE == requestHandled) { requestHandled = USBFS_1_HandleVendorRqst_Callback(); } #endif /* (USBFS_1_HANDLE_VENDOR_RQST_CALLBACK) */ return (requestHandled); }
/******************************************************************************* * Function Name: USBFS_1_DispatchAUDIOClassRqst ****************************************************************************//** * * This routine dispatches class requests * * \return * Results of Audio Class request handling: * - USBFS_1_TRUE - request was handled without errors * - USBFS_1_FALSE - error occurs during handling of request * * \globalvars * USBFS_1_currentSampleFrequency: Contains the current audio Sample * Frequency. It is set by the Host using SET_CUR request to the endpoint. * USBFS_1_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 * * USBFS_1_transferState variable is checked to be sure that transfer * completes. * USBFS_1_currentMute: Contains mute configuration set by Host. * USBFS_1_currentVolume: Contains volume level set by Host. * * \reentrant * No. * *******************************************************************************/ uint8 USBFS_1_DispatchAUDIOClassRqst(void) { uint8 requestHandled = USBFS_1_FALSE; uint8 RqstRcpt = (uint8)(USBFS_1_bmRequestTypeReg & USBFS_1_RQST_RCPT_MASK); #if defined(USBFS_1_ENABLE_AUDIO_STREAMING) uint8 wValueHi = (uint8) USBFS_1_wValueHiReg; uint8 epNumber = (uint8) USBFS_1_wIndexLoReg & USBFS_1_DIR_UNUSED; #endif /* (USBFS_1_ENABLE_AUDIO_STREAMING) */ /* Check request direction: D2H or H2D. */ if (0u != (USBFS_1_bmRequestTypeReg & USBFS_1_RQST_DIR_D2H)) { /* Handle direction from device to host. */ if (USBFS_1_RQST_RCPT_EP == RqstRcpt) { /* Request recipient is to endpoint. */ switch (USBFS_1_bRequestReg) { case USBFS_1_GET_CUR: #if defined(USBFS_1_ENABLE_AUDIO_STREAMING) if (wValueHi == USBFS_1_SAMPLING_FREQ_CONTROL) { /* point Control Selector is Sampling Frequency */ USBFS_1_currentTD.wCount = USBFS_1_SAMPLE_FREQ_LEN; USBFS_1_currentTD.pData = USBFS_1_currentSampleFrequency[epNumber]; requestHandled = USBFS_1_InitControlRead(); } #endif /* (USBFS_1_ENABLE_AUDIO_STREAMING) */ /* `#START AUDIO_READ_REQUESTS` Place other request handler here */ /* `#END` */ #ifdef USBFS_1_DISPATCH_AUDIO_CLASS_AUDIO_READ_REQUESTS_CALLBACK USBFS_1_DispatchAUDIOClass_AUDIO_READ_REQUESTS_Callback(); #endif /* (USBFS_1_DISPATCH_AUDIO_CLASS_AUDIO_READ_REQUESTS_CALLBACK) */ break; default: /* Do not handle this request unless callback is defined. */ break; } } else if (USBFS_1_RQST_RCPT_IFC == RqstRcpt) { /* Request recipient is interface or entity ID. */ switch (USBFS_1_bRequestReg) { case USBFS_1_GET_CUR: #if defined(USBFS_1_ENABLE_AUDIO_STREAMING) if (wValueHi == USBFS_1_MUTE_CONTROL) { /* `#START MUTE_CONTROL_GET_REQUEST` Place multi-channel handler here */ /* `#END` */ #ifdef USBFS_1_DISPATCH_AUDIO_CLASS_MUTE_CONTROL_GET_REQUEST_CALLBACK USBFS_1_DispatchAUDIOClass_MUTE_CONTROL_GET_REQUEST_Callback(); #endif /* (USBFS_1_DISPATCH_AUDIO_CLASS_MUTE_CONTROL_GET_REQUEST_CALLBACK) */ /* Entity ID Control Selector is MUTE */ USBFS_1_currentTD.wCount = 1u; USBFS_1_currentTD.pData = &USBFS_1_currentMute; requestHandled = USBFS_1_InitControlRead(); } else if (wValueHi == USBFS_1_VOLUME_CONTROL) { /* `#START VOLUME_CONTROL_GET_REQUEST` Place multi-channel handler here */ /* `#END` */ #ifdef USBFS_1_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_GET_REQUEST_CALLBACK USBFS_1_DispatchAUDIOClass_VOLUME_CONTROL_GET_REQUEST_Callback(); #endif /* (USBFS_1_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_GET_REQUEST_CALLBACK) */ /* Entity ID Control Selector is VOLUME, */ USBFS_1_currentTD.wCount = USBFS_1_VOLUME_LEN; USBFS_1_currentTD.pData = USBFS_1_currentVolume; requestHandled = USBFS_1_InitControlRead(); } else { /* `#START OTHER_GET_CUR_REQUESTS` Place other request handler here */ /* `#END` */ #ifdef USBFS_1_DISPATCH_AUDIO_CLASS_OTHER_GET_CUR_REQUESTS_CALLBACK USBFS_1_DispatchAUDIOClass_OTHER_GET_CUR_REQUESTS_Callback(); #endif /* (USBFS_1_DISPATCH_AUDIO_CLASS_OTHER_GET_CUR_REQUESTS_CALLBACK) */ } break; case USBFS_1_GET_MIN: if (wValueHi == USBFS_1_VOLUME_CONTROL) { /* Entity ID Control Selector is VOLUME, */ USBFS_1_currentTD.wCount = USBFS_1_VOLUME_LEN; USBFS_1_currentTD.pData = &USBFS_1_minimumVolume[0]; requestHandled = USBFS_1_InitControlRead(); } break; case USBFS_1_GET_MAX: if (wValueHi == USBFS_1_VOLUME_CONTROL) { /* Entity ID Control Selector is VOLUME, */ USBFS_1_currentTD.wCount = USBFS_1_VOLUME_LEN; USBFS_1_currentTD.pData = &USBFS_1_maximumVolume[0]; requestHandled = USBFS_1_InitControlRead(); } break; case USBFS_1_GET_RES: if (wValueHi == USBFS_1_VOLUME_CONTROL) { /* Entity ID Control Selector is VOLUME, */ USBFS_1_currentTD.wCount = USBFS_1_VOLUME_LEN; USBFS_1_currentTD.pData = &USBFS_1_resolutionVolume[0]; requestHandled = USBFS_1_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 USBFS_1_GET_STAT: USBFS_1_currentTD.wCount = 0u; requestHandled = USBFS_1_InitControlWrite(); #endif /* (USBFS_1_ENABLE_AUDIO_STREAMING) */ /* `#START AUDIO_WRITE_REQUESTS` Place other request handler here */ /* `#END` */ #ifdef USBFS_1_DISPATCH_AUDIO_CLASS_AUDIO_WRITE_REQUESTS_CALLBACK USBFS_1_DispatchAUDIOClass_AUDIO_WRITE_REQUESTS_Callback(); #endif /* (USBFS_1_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 (USBFS_1_RQST_RCPT_EP == RqstRcpt) { /* Request recipient is endpoint. */ switch (USBFS_1_bRequestReg) { case USBFS_1_SET_CUR: #if defined(USBFS_1_ENABLE_AUDIO_STREAMING) if (wValueHi == USBFS_1_SAMPLING_FREQ_CONTROL) { /* point Control Selector is Sampling Frequency */ USBFS_1_currentTD.wCount = USBFS_1_SAMPLE_FREQ_LEN; USBFS_1_currentTD.pData = USBFS_1_currentSampleFrequency[epNumber]; USBFS_1_frequencyChanged = (uint8) epNumber; requestHandled = USBFS_1_InitControlWrite(); } #endif /* (USBFS_1_ENABLE_AUDIO_STREAMING) */ /* `#START AUDIO_SAMPLING_FREQ_REQUESTS` Place other request handler here */ /* `#END` */ #ifdef USBFS_1_DISPATCH_AUDIO_CLASS_AUDIO_SAMPLING_FREQ_REQUESTS_CALLBACK USBFS_1_DispatchAUDIOClass_AUDIO_SAMPLING_FREQ_REQUESTS_Callback(); #endif /* (USBFS_1_DISPATCH_AUDIO_CLASS_AUDIO_SAMPLING_FREQ_REQUESTS_CALLBACK) */ break; default: /* Do not handle this request. */ break; } } else if(USBFS_1_RQST_RCPT_IFC == RqstRcpt) { /* Request recipient is interface or entity ID. */ switch (USBFS_1_bRequestReg) { case USBFS_1_SET_CUR: #if defined(USBFS_1_ENABLE_AUDIO_STREAMING) if (wValueHi == USBFS_1_MUTE_CONTROL) { /* `#START MUTE_SET_REQUEST` Place multi-channel handler here */ /* `#END` */ #ifdef USBFS_1_DISPATCH_AUDIO_CLASS_MUTE_SET_REQUEST_CALLBACK USBFS_1_DispatchAUDIOClass_MUTE_SET_REQUEST_Callback(); #endif /* (USBFS_1_DISPATCH_AUDIO_CLASS_MUTE_SET_REQUEST_CALLBACK) */ /* Entity ID Control Selector is MUTE */ USBFS_1_currentTD.wCount = 1u; USBFS_1_currentTD.pData = &USBFS_1_currentMute; requestHandled = USBFS_1_InitControlWrite(); } else if (wValueHi == USBFS_1_VOLUME_CONTROL) { /* `#START VOLUME_CONTROL_SET_REQUEST` Place multi-channel handler here */ /* `#END` */ #ifdef USBFS_1_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_SET_REQUEST_CALLBACK USBFS_1_DispatchAUDIOClass_VOLUME_CONTROL_SET_REQUEST_Callback(); #endif /* (USBFS_1_DISPATCH_AUDIO_CLASS_VOLUME_CONTROL_SET_REQUEST_CALLBACK) */ /* Entity ID Control Selector is VOLUME */ USBFS_1_currentTD.wCount = USBFS_1_VOLUME_LEN; USBFS_1_currentTD.pData = USBFS_1_currentVolume; requestHandled = USBFS_1_InitControlWrite(); } else { /* `#START OTHER_SET_CUR_REQUESTS` Place other request handler here */ /* `#END` */ #ifdef USBFS_1_DISPATCH_AUDIO_CLASS_OTHER_SET_CUR_REQUESTS_CALLBACK USBFS_1_DispatchAUDIOClass_OTHER_SET_CUR_REQUESTS_Callback(); #endif /* (USBFS_1_DISPATCH_AUDIO_CLASS_OTHER_SET_CUR_REQUESTS_CALLBACK) */ } #endif /* USBFS_1_ENABLE_AUDIO_STREAMING */ /* `#START AUDIO_CONTROL_SEL_REQUESTS` Place other request handler here */ /* `#END` */ #ifdef USBFS_1_DISPATCH_AUDIO_CLASS_AUDIO_CONTROL_SEL_REQUESTS_CALLBACK USBFS_1_DispatchAUDIOClass_AUDIO_CONTROL_SEL_REQUESTS_Callback(); #endif /* (USBFS_1_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); }
/******************************************************************************* * Function Name: USBFS_1_DispatchHIDClassRqst ******************************************************************************** * * Summary: * This routine dispatches class requests * * Parameters: * None. * * Return: * requestHandled * * Reentrant: * No. * *******************************************************************************/ uint8 USBFS_1_DispatchHIDClassRqst(void) { uint8 requestHandled = USBFS_1_FALSE; uint8 interfaceNumber; interfaceNumber = CY_GET_REG8(USBFS_1_wIndexLo); if ((CY_GET_REG8(USBFS_1_bmRequestType) & USBFS_1_RQST_DIR_MASK) == USBFS_1_RQST_DIR_D2H) { /* Control Read */ switch (CY_GET_REG8(USBFS_1_bRequest)) { case USBFS_1_GET_DESCRIPTOR: if (CY_GET_REG8(USBFS_1_wValueHi) == USBFS_1_DESCR_HID_CLASS) { USBFS_1_FindHidClassDecriptor(); if (USBFS_1_currentTD.count != 0u) { requestHandled = USBFS_1_InitControlRead(); } } else if (CY_GET_REG8(USBFS_1_wValueHi) == USBFS_1_DESCR_HID_REPORT) { USBFS_1_FindReportDescriptor(); if (USBFS_1_currentTD.count != 0u) { requestHandled = USBFS_1_InitControlRead(); } } else { /* requestHandled is initialezed as FALSE by default */ } break; case USBFS_1_HID_GET_REPORT: USBFS_1_FindReport(); if (USBFS_1_currentTD.count != 0u) { requestHandled = USBFS_1_InitControlRead(); } break; case USBFS_1_HID_GET_IDLE: /* This function does not support multiple reports per interface*/ /* Validate interfaceNumber and Report ID (should be 0) */ if( (interfaceNumber < USBFS_1_MAX_INTERFACES_NUMBER) && (CY_GET_REG8(USBFS_1_wValueLo) == 0u ) ) /* Do not support Idle per Report ID */ { USBFS_1_currentTD.count = 1u; USBFS_1_currentTD.pData = &USBFS_1_hidIdleRate[interfaceNumber]; requestHandled = USBFS_1_InitControlRead(); } break; case USBFS_1_HID_GET_PROTOCOL: /* Validate interfaceNumber */ if( interfaceNumber < USBFS_1_MAX_INTERFACES_NUMBER) { USBFS_1_currentTD.count = 1u; USBFS_1_currentTD.pData = &USBFS_1_hidProtocol[interfaceNumber]; requestHandled = USBFS_1_InitControlRead(); } break; default: /* requestHandled is initialized as FALSE by default */ break; } } else if ((CY_GET_REG8(USBFS_1_bmRequestType) & USBFS_1_RQST_DIR_MASK) == USBFS_1_RQST_DIR_H2D) { /* Control Write */ switch (CY_GET_REG8(USBFS_1_bRequest)) { case USBFS_1_HID_SET_REPORT: USBFS_1_FindReport(); if (USBFS_1_currentTD.count != 0u) { requestHandled = USBFS_1_InitControlWrite(); } break; case USBFS_1_HID_SET_IDLE: /* This function does not support multiple reports per interface */ /* Validate interfaceNumber and Report ID (should be 0) */ if( (interfaceNumber < USBFS_1_MAX_INTERFACES_NUMBER) && (CY_GET_REG8(USBFS_1_wValueLo) == 0u ) ) /* Do not support Idle per Report ID */ { USBFS_1_hidIdleRate[interfaceNumber] = CY_GET_REG8(USBFS_1_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(USBFS_1_hidIdleRate[interfaceNumber] < USBFS_1_hidIdleTimer[interfaceNumber]) { /* Set the timer to zero and let the UpdateHIDTimer() API return IDLE_TIMER_EXPIRED status*/ USBFS_1_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(USBFS_1_hidIdleTimer[interfaceNumber] <= 1u) { /* Do nothing. * Let the UpdateHIDTimer() API continue to work and * return IDLE_TIMER_EXPIRED status */ } else { /* Reload the timer*/ USBFS_1_hidIdleTimer[interfaceNumber] = USBFS_1_hidIdleRate[interfaceNumber]; } requestHandled = USBFS_1_InitNoDataControlTransfer(); } break; case USBFS_1_HID_SET_PROTOCOL: /* Validate interfaceNumber and protocol (must be 0 or 1) */ if( (interfaceNumber < USBFS_1_MAX_INTERFACES_NUMBER) && (CY_GET_REG8(USBFS_1_wValueLo) <= 1u) ) { USBFS_1_hidProtocol[interfaceNumber] = CY_GET_REG8(USBFS_1_wValueLo); requestHandled = USBFS_1_InitNoDataControlTransfer(); } break; default: /* requestHandled is initialized as FALSE by default */ break; } } else { /* requestHandled is initialized as FALSE by default */ } return(requestHandled); }