Example #1
0
/*******************************************************************************
* 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.
*******************************************************************************/
u8 *Standard_GetStatus(u16 Length)
{
	if (Length == 0)
	{
		pInformation->Ctrl_Info.Usb_wLength = 2;
		return 0;
	}

	StatusInfo.w = 0;
	/* Reset Status Information */

	if (Type_Recipient == (STANDARD_REQUEST | DEVICE_RECIPIENT))
	{
		u8 Feature = pInformation->Current_Feature;	/*Get Device Status */

		if (ValBit(Feature, 5))		/* Remote Wakeup enabled */
		{
			SetBit(StatusInfo0, 1);
		}

		if (ValBit(Feature, 6))		/* Bus-powered */
		{
			ClrBit(StatusInfo0, 0);
		}
		else
		{
			SetBit(StatusInfo0, 0);	/* Self-powered */
		}
	}
	else if (Type_Recipient == (STANDARD_REQUEST | INTERFACE_RECIPIENT))
	{	/*Interface Status*/
		return (u8 *)&StatusInfo;
	}
	else if (Type_Recipient == (STANDARD_REQUEST | ENDPOINT_RECIPIENT))
	{	/*Get EndPoint Status*/
		u8 Related_Endpoint;
		u8 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 (u8 *)&StatusInfo;
}
Example #2
0
/*******************************************************************************
* 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;
}