/******************************************************************************* * 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); }
/******************************************************************************* * 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); }
/******************************************************************************* * 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); }