⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbd_func.c

📁 epson usb2.0 控制芯片 S1R72V05 固件程序。
💻 C
📖 第 1 页 / 共 5 页
字号:
	while (1) {
		/* Delete the callback function */
		retValue = PrvDelCallbackInf(PRV_CBINF_WAKEUP,PRV_ID_NONE,PRV_PORT_NONE,pfnCallback);
	break;};

	return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncRegisterCBRResume
// description	: Register the callback function of notification when USB resume has occurred
// argument		: pfnCallback			[in]	Address of callback function
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_UNABLE_TO_REGISTER	Unable to register the callback function
// =============================================================================
*/
LONG USBD_FuncRegisterCBRResume(CALLBACK_PROC pfnCallback)
{
	LONG retValue;

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Register the callback function */
		retValue = PrvAddCallbackInf(PRV_CBINF_RESUME,PRV_ID_NONE,PRV_PORT_NONE,pfnCallback);

	break;};

	return retValue;

}
/* =============================================================================
// Function_Name: USBD_FuncUnregisterCBRResume
// description	: Delet the callback function of notification when USB resume has occurred
// argument		: pfnCallback			[in]	Address of callback function
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_UNREGISTERED			Unable to delete the callback function
// =============================================================================
*/
LONG USBD_FuncUnregisterCBRResume(CALLBACK_PROC pfnCallback)
{
	LONG retValue;

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Delete the callback function */
		retValue = PrvDelCallbackInf(PRV_CBINF_RESUME,PRV_ID_NONE,PRV_PORT_NONE,pfnCallback);
	break;};

	return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncRegisterCBRChangeUSBAddress
// description	: Register the callback function of notification that means USB Address's setting has completed
// argument		: pfnCallback			[in]	Address of callback function
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_UNABLE_TO_REGISTER	Unable to register the callback function
// =============================================================================
*/
LONG USBD_FuncRegisterCBRChangeUSBAddress(CALLBACK_PROC pfnCallback)
{
	LONG retValue;

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Register the callback function */
		retValue = PrvAddCallbackInf(PRV_CBINF_USBADR,PRV_ID_NONE,PRV_PORT_NONE,pfnCallback);

	break;};

	return retValue;

}
/* =============================================================================
// Function_Name: USBD_FuncUnregisterCBRChangeUSBAddress
// description	: Delete the callback function of notification that means USB Address's setting has completed
// argument		: pfnCallback			[in]	Address of callback function
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_UNREGISTERED			Unable to delete the callback function
// =============================================================================
*/
LONG USBD_FuncUnregisterCBRChangeUSBAddress(CALLBACK_PROC pfnCallback)
{
	LONG retValue;

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Delete the callback function */
		retValue = PrvDelCallbackInf(PRV_CBINF_USBADR,PRV_ID_NONE,PRV_PORT_NONE,pfnCallback);

	break;};

	return retValue;

}
/* =============================================================================
// Function_Name: USBD_FuncRegisterCBREnterTestMode
// description	: Register the callback function for notifying that system has entered TestMode
// argument		: pfnCallback			[in]	Address of callback function
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_UNABLE_TO_REGISTER	Unable to register the callback function
// =============================================================================
*/
LONG USBD_FuncRegisterCBREnterTestMode(CALLBACK_PROC pfnCallback)
{
	LONG retValue;

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Register the callback function */
		retValue = PrvAddCallbackInf(PRV_CBINF_TESTMODE,PRV_ID_NONE,PRV_PORT_NONE,pfnCallback);

	break;};

	return retValue;

}
/* =============================================================================
// Function_Name: USBD_FuncUnregisterCBREnterTestMode
// description	: Delete the callback function for notifying that system has entered TestMode
// argument		: pfnCallback			[in]	Address of callback function
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_UNREGISTERED			Unable to delete the callback function
// =============================================================================
*/
LONG USBD_FuncUnregisterCBREnterTestMode(CALLBACK_PROC pfnCallback)
{
	LONG retValue;

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Delete the callback function */
		retValue = PrvDelCallbackInf(PRV_CBINF_TESTMODE,PRV_ID_NONE,PRV_PORT_NONE,pfnCallback);

	break;};

	return retValue;

}
/* =============================================================================
// Function_Name: USBD_FuncSetConfigureEndpoint
// description	: Set the Endpoint that relates to the specified configuration value, and make it possible to be used
// argument		: config_num			[in]	Configuration number
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_UNSUCCESSFUL			Finished abnormally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_INVALID_PARAMETER	Parameter error
// =============================================================================
*/
LONG USBD_FuncSetConfigureEndpoint(UCHAR config_num)
{
	LONG retValue;
	UCHAR *tempPtr;
	USHORT tempSize;
	USB_DESC_CONFIG *config;
	PRV_DESCINFOPTR descInfoPtr;

	memset(&descInfoPtr, 0, sizeof(descInfoPtr));	// Countermeasure against warning of optimizing
	retValue = STATUS_SUCCESS;

	while (1) {
		/* Check if ReserveControlTransfer() has been called */
		if (IS_BIT(PrvStatusInfo.dwInternalStatus,PRV_IS_EP0TRNDIS) == TRUE) {
			/* Assume it as error when ReserveControlTransfer() has not been done */
			retValue = STATUS_UNSUCCESSFUL;
			break;
		}

		/* Initialize the information of Configuration Descriptor */
		memset(&PrvConfigInfo,0x00,sizeof (PRV_CONFIG_INFO));
		/* Set all of Endpoints to Disable */
		PrvDisableEndpoints();
		if (config_num > 0) {
			/* Configured State */
			/* Get address of Configuration Descriptor of current action speed */
			if (IS_BIT(PrvStatusInfo.dwBusStatus,USBD_FUNC_BS_HSMODE) == TRUE) {
				/* HS */
				retValue = PrvGetDescriptorInfoAddress((UCHAR)USBD_FUNC_SPEEDHS,(UCHAR)USBD_FUNC_DT_CONFIG,(UCHAR)(config_num - 1),&descInfoPtr);
			} else {
				/* FS */
				retValue = PrvGetDescriptorInfoAddress((UCHAR)USBD_FUNC_SPEEDFS,(UCHAR)USBD_FUNC_DT_CONFIG,(UCHAR)(config_num - 1),&descInfoPtr);
			}
			tempPtr = *descInfoPtr.ptr;
			if (retValue != STATUS_SUCCESS || tempPtr == NULL) {
				/* When Configuration Descriptor can not be gotten */
				retValue = STATUS_UNSUCCESSFUL;
				break;
			}

			/* Get the size of Descriptor */
			config = (USB_DESC_CONFIG *)tempPtr;
			tempSize = MAKEWORD(config->wTotalLength[0],config->wTotalLength[1]);

			/* Analyze the Configuration Descriptor */
			retValue = PrvParseConfig(tempPtr,tempSize);
			if (retValue != STATUS_SUCCESS) {
				/* When there is error in Descriptor */
				retValue = STATUS_UNSUCCESSFUL;
				break;
			}
			/* Set endpoints except for EP0, and enable them */
			retValue = PrvEnableEndpoints();
			if (retValue != STATUS_SUCCESS) {
				/* Unable to set Endpoint */
				retValue = STATUS_UNSUCCESSFUL;
				break;
			}
			/* Save the Configuration number which has been set */
			PrvConfigInfo.selectConfig = config_num;
		}
	break;};
	return retValue;
}
/* =============================================================================
// Function_Name: USBD_FuncSetAlternateEndpoint
// description	: Set the bandwidth of Endpoint that relates to the specified Alternate Setting value
// argument		: config_num			[in]	Configuration number
// argument		: interface_num		[in]	Interface number
// argument		: alternate_num		[in]	Alternate number
// return		: STATUS_SUCCESS			Finished normally
// return		: STATUS_UNSUCCESSFUL		Finished abnormally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_INVALID_PARAMETER	Parameter error
// =============================================================================
*/
LONG USBD_FuncSetAlternateEndpoint(UCHAR config_num,UCHAR interface_num,UCHAR alternate_num)
{
	LONG retValue;
	UCHAR *tempPtr;
//	USB_DESC_CONFIG *config;
	PRV_DESCINFOPTR descInfoPtr;
//	USHORT tempSize;

	memset(&descInfoPtr, 0, sizeof(descInfoPtr));	// Countermeasure against warning of optimizing
	retValue = STATUS_SUCCESS;

	while (1) {

		if (config_num == 0) {
			/* Assume it as error, because it is enabled only in Configureed state */
			retValue = STATUS_UNSUCCESSFUL;
			break;
		}
		if (interface_num >= PrvConfigInfo.interfaceNum || alternate_num >= PrvConfigInfo.alternateNum[interface_num]) {
			/* When parameter is wrong */
			retValue = STATUS_INVALID_PARAMETER;
			break;
		}

		/* Get address of Configuration Descriptor of current action speed */
		if (IS_BIT(PrvStatusInfo.dwBusStatus,USBD_FUNC_BS_HSMODE) == TRUE) {
			/* HS */
			retValue = PrvGetDescriptorInfoAddress(USBD_FUNC_SPEEDHS,USBD_FUNC_DT_CONFIG,(config_num - 1),&descInfoPtr);
		} else {
			/* FS */
			retValue = PrvGetDescriptorInfoAddress(USBD_FUNC_SPEEDFS,USBD_FUNC_DT_CONFIG,(config_num - 1),&descInfoPtr);
		}

		tempPtr = *descInfoPtr.ptr;
		if (retValue != STATUS_SUCCESS || tempPtr == NULL) {
			/* When Configuration Descriptor can not be gotten */
			retValue = STATUS_UNSUCCESSFUL;
			break;
		}


		/* Get the size of Descriptor */
//		config = (USB_DESC_CONFIG *)tempPtr;
//		tempSize = MAKEWORD(config->wTotalLength[0],config->wTotalLength[1]);

		/* Set Endpoint which is in existence in specified Interface to unused state */
		retValue = PrvSetUnuseInterfaceEndpoints(interface_num);

		/* Alternate setting */
		PrvConfigInfo.alternateList[interface_num] = alternate_num;

		/* Set Endpoint base on Configuration Infomation */
		retValue = PrvEnableEndpoints();
		if (retValue != STATUS_SUCCESS) {
			/* Unable to set Endpoint */
			retValue = STATUS_UNSUCCESSFUL;
			break;
		}
	break;};

	return retValue;
}
#if 1
/* =============================================================================
// Function_Name: PrvSetUnuseInterfaceEndpoints
// description	: Set Endpoint which is in existence in specified Interface to unused state
// argument		: interface			[IN]	Interface number
// return		: STATUS_SUCCESS				Finished normally
// return		: STATUS_INVALID_PARAMETER	Parameter error
// =============================================================================
*/
static LONG PrvSetUnuseInterfaceEndpoints(UCHAR interface)
{
	LONG retValue,retIFValue;
	USB_DESC_ENDPOINT *endpoint;
	UCHAR i,j;

	retValue = STATUS_SUCCESS;
	while (1) {
		for (i = 0;i < PrvConfigInfo.endpointListNum;i++) {
			if (PrvConfigInfo.endpointList[i].bInterface == interface) {
				/* Get the Endpoint Descriptor */
				endpoint = (USB_DESC_ENDPOINT *)PrvConfigInfo.endpointList[i].endpoint;
				for (j = 1;j < MAX_ENDPOINT;j++) {
					if (IS_BIT(PrvEPxInfo[j].flag,PRV_EPXINFO_USED) == TRUE
						&& PrvEPxInfo[j].epAddress == endpoint->bEndpointAddress) {
						/* Set to unused state */
						CLR_BIT(PrvEPxInfo[j].flag,PRV_EPXINFO_USED);
						CLR_BIT(PrvEPxInfo[j].flag,PRV_EPXINFO_ENABLED);
						retIFValue = USBD_IFEPxEnable(j,0);
						retValue = IFRET_TO_FUNCRET(retIFValue);
						break;
					}
				}
				if (retValue != STATUS_SUCCESS) {
					break;
				}
			}
		}
	break;};

	return retValue;
}
#endif
/* =============================================================================
// Function_Name: USBD_FuncInitEndpoint
// description	: Initialize the specified Endpoint
// argument		: endpoint_num		[in]	Address of Endpoint
// return		: STATUS_SUCCESS			Finished normally
// return		: STATUS_NOT_OPENED			Not be opened yet
// return		: STATUS_INVALID_PARAMETER	Parameter error
// =============================================================================
*/
LONG USBD_FuncInitEndpoint(UCHAR endpoint_num)
{
	LONG retValue;
	UCHAR epn;

	retValue = STATUS_SUCCESS;
	while (1) {
		/* Get Endpoint number which is used in I/F layer */
		epn = PrvEPAdrToEPx(endpoint_num);
		if (epn == 0xFF) {
			retValue = STATUS_INVALID_PARAMETER;
			break;
		}
		if (IS_EP0(endpoint_num) == TRUE && IS_EPX_DIRIN(endpoint_num) == TRUE) {
			/* EP0 uses IN(0x

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -