/******************************************************************************* * Function Name : Standard_GetStatus. * Description : Copy the device request data to "StatusInfo buffer". * Input : - Length - How many bytes are needed. * Output : None. * Return : Return 0, if the request is at end of data block, * or is invalid when "Length" is 0. *******************************************************************************/ uint8_t *Standard_GetStatus(uint16_t Length) { if (Length == 0) { pInformation->Ctrl_Info.Usb_wLength = 2; return 0; } /* Reset Status Information */ StatusInfo.w = 0; if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT)) { /*Get Device Status */ uint8_t Feature = pInformation->Current_Feature; ///@note [JPN] Very f*****g ugly /* Remote Wakeup enabled */ if (ValBit(Feature, 5)) { SetBit(StatusInfo0, 1); } else { ClrBit(StatusInfo0, 1); } /* Bus-powered */ if (ValBit(Feature, 6)) { SetBit(StatusInfo0, 0); } /* Self-powered */ else { ClrBit(StatusInfo0, 0); } } /*Interface Status*/ else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT)) { return (uint8_t *)&StatusInfo; } /*Get EndPoint Status*/ else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) { uint8_t Related_Endpoint; uint8_t wIndex0 = pInformation->USBwIndex0; Related_Endpoint = (wIndex0 & 0x0f); if (ValBit(wIndex0, 7)) { /* IN endpoint */ if (_GetTxStallStatus(Related_Endpoint)) { SetBit(StatusInfo0, 0); /* IN Endpoint stalled */ } } else { /* OUT endpoint */ if (_GetRxStallStatus(Related_Endpoint)) { SetBit(StatusInfo0, 0); /* OUT Endpoint stalled */ } } } else { return NULL; } pUser_Standard_Requests->User_GetStatus(); return (uint8_t*)&StatusInfo; }
/******************************************************************************* * Function Name : Standard_ClearFeature. * Description : Clear or disable a specific feature. * Input : None. * Output : None. * Return : - Return USB_SUCCESS, if the request is performed. * - Return USB_UNSUPPORT, if the request is invalid. *******************************************************************************/ RESULT Standard_ClearFeature(void) { uint32_t Type_Rec = Type_Recipient; uint32_t Status; if (Type_Rec == (STANDARD_REQUEST | DEVICE_RECIPIENT)) {/*Device Clear Feature*/ ClrBit(pInformation->Current_Feature, 5); return USB_SUCCESS; } else if (Type_Rec == (STANDARD_REQUEST | ENDPOINT_RECIPIENT)) {/*EndPoint Clear Feature*/ DEVICE* pDev; uint32_t Related_Endpoint; uint32_t wIndex0; uint32_t rEP; if ((pInformation->USBwValue != ENDPOINT_STALL) || (pInformation->USBwIndex1 != 0)) { return USB_UNSUPPORT; } pDev = &Device_Table; wIndex0 = pInformation->USBwIndex0; rEP = wIndex0 & ~0x80; Related_Endpoint = ENDP0 + rEP; if (ValBit(pInformation->USBwIndex0, 7)) { /*Get Status of endpoint & stall the request if the related_ENdpoint is Disabled*/ Status = _GetEPTxStatus(Related_Endpoint); } else { Status = _GetEPRxStatus(Related_Endpoint); } if ((rEP >= pDev->Total_Endpoint) || (Status == 0) || (pInformation->Current_Configuration == 0)) { return USB_UNSUPPORT; } if (wIndex0 & 0x80) { /* IN endpoint */ if (_GetTxStallStatus(Related_Endpoint )) { #ifndef STM32F10X_CL ClearDTOG_TX(Related_Endpoint); #endif /* STM32F10X_CL */ SetEPTxStatus(Related_Endpoint, EP_TX_VALID); } } else { /* OUT endpoint */ if (_GetRxStallStatus(Related_Endpoint)) { if (Related_Endpoint == ENDP0) { /* After clear the STALL, enable the default endpoint receiver */ SetEPRxCount(Related_Endpoint, Device_Property.MaxPacketSize); _SetEPRxStatus(Related_Endpoint, EP_RX_VALID); } else { #ifndef STM32F10X_CL ClearDTOG_RX(Related_Endpoint); #endif /* STM32F10X_CL */ _SetEPRxStatus(Related_Endpoint, EP_RX_VALID); } } } pUser_Standard_Requests->User_ClearFeature(); return USB_SUCCESS; } return USB_UNSUPPORT; }