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