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

📄 obj_usbdesc.c

📁 AT91RM9200的引到程序
💻 C
📖 第 1 页 / 共 2 页
字号:
//*----------------------------------------------------------------------------
//*         ATMEL Microcontroller Software Support  -  ROUSSET  -
//*----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*----------------------------------------------------------------------------
//* File Name           : obj_udpdesc.c
//* Object              : USB peripheral library.
//*
//* 1.0 07/23/01 ODi    : Creation
//*----------------------------------------------------------------------------
#include "services/obj_usbdesc.h"



/* ************************************ */
/* AT91F_OpenUsbDesc                    */
/*                                      */
/* Arguments:                           */
/* Return:                              */
/*     Pointer toAT91PS_UsbDesc object  */
/* Description:                         */
/* ************************************ */
AT91PS_UsbDesc AT91F_OpenUsbDesc(
	AT91PS_UsbDesc  pUsbDesc,  /* pointer to a AT91S_UsbDesc structure */
	AT91PS_UDP      pUdp,      /* Uregister structure */
	char            epId)      /* endpoint number */
{
	pUsbDesc->DispatchRequest = AT91F_UsbDescDispatchRequest;
	//pUsbDesc->DispatchClassRequest  = (AT91PF_DispatchClassRequest)  0;
	//pUsbDesc->DispatchVendorRequest = (AT91PF_DispatchVendorRequest) 0;
	//pUsbDesc->ClearFeature          = (AT91PF_ClearFeature)          0;
	//pUsbDesc->GetConfiguration      = (AT91PF_GetConfiguration)      0;
	//pUsbDesc->GetDescriptor         = (AT91PF_GetDescriptor)         0;
	//pUsbDesc->GetInterface          = (AT91PF_GetInterface)          0;
	//pUsbDesc->GetStatus             = (AT91PF_GetStatus)             0;
	//pUsbDesc->SetAddress            = (AT91PF_SetAddress)            0;
	//pUsbDesc->SetConfiguration      = (AT91PF_SetConfiguration)      0;
	//pUsbDesc->SetDescriptor         = (AT91PF_SetDescriptor)         0;
	//pUsbDesc->SetFeature            = (AT91PF_SetFeature)            0;
	//pUsbDesc->SetInterface          = (AT91PF_SetInterface)          0;
	//pUsbDesc->SynchFrame            = (AT91PF_SynchFrame)            0;

	pUsbDesc->pUdp = pUdp;
	pUsbDesc->epId = epId;
	return pUsbDesc;
}

/* ************************************ */
/* usbDescDispatchRequest               */
/*                                      */
/* Arguments:                           */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request handle standard     */
/*     request or call                  */
/*     usbDescDispatchClassRequest      */
/*     usbDescDispatchVendorRequest     */
/* ************************************ */
void AT91F_UsbDescDispatchRequest(
	AT91PS_UsbDesc const pDesc,  /* pointer to a AT91S_UsbDesc structure */
	AT91PS_UsbSetup      pSetup) /* USB setup data Cf USB spec rev 1.1 */
{
	switch ((pSetup->bmRequestType & (0x60)) >> 5) {
	case 0: /* Standard request */
		switch (pSetup->bRequest) {
		case USB_CLEAR_FEATURE:     AT91F_UsbDescClearFeature    (pDesc, pSetup); break;
		case USB_GET_CONFIGURATION: AT91F_UsbDescGetConfiguration(pDesc, pSetup); break;
		case USB_GET_DESCRIPTOR:    AT91F_UsbDescGetDescriptor   (pDesc, pSetup); break;
		case USB_GET_INTERFACE:     AT91F_UsbDescGetInterface    (pDesc, pSetup); break;
		case USB_GET_STATUS:        AT91F_UsbDescGetStatus       (pDesc, pSetup); break;
		case USB_SET_ADDRESS:       AT91F_UsbDescSetAddress      (pDesc, pSetup); break;
		case USB_SET_CONFIGURATION: AT91F_UsbDescSetConfiguration(pDesc, pSetup); break;
		case USB_SET_DESCRIPTOR:    AT91F_UsbDescSetDescriptor   (pDesc, pSetup); break;
		case USB_SET_FEATURE:       AT91F_UsbDescSetFeature      (pDesc, pSetup); break;
		case USB_SET_INTERFACE:     AT91F_UsbDescSetInterface    (pDesc, pSetup); break;
		case USB_SYNCH_FRAME:       AT91F_UsbDescSynchFrame      (pDesc, pSetup); break;
		default:                    AT91F_UdpEpStall             (pDesc->pUdp, pDesc->epId);                                      break;
		}
		break;
	case 1: /* Class request */
		if (pDesc->DispatchClassRequest)
			pDesc->DispatchClassRequest(pSetup, pDesc->pPrivateClassData);
		break;
	case 2: /* Vendor request */
		if (pDesc->DispatchVendorRequest)
			pDesc->DispatchVendorRequest(pSetup, pDesc->pPrivateVendorData);
		break;
	default: /* Reserved */
		AT91F_UdpEpStall(pDesc->pUdp, pDesc->epId);
		break;
	}
	return;
}

/* ************************************ */
/* AT91F_UsbDescClearFeature            */
/*                                      */
/* Arguments:                           */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request is used to clear or */
/*     disable a specific feature       */
/* ************************************ */
void AT91F_UsbDescClearFeature(
	AT91PS_UsbDesc const pUsbDesc,  /* pointer to a AT91S_UsbDesc structure */
	AT91PS_UsbSetup      pSetup)    /* USB setup data Cf USB spec rev 1.1 */
{
	u_int usbState = AT91F_UdpGetState(pUsbDesc->pUdp);
	u_int recipient = (pSetup->bmRequestType & 0x1F);

	/* Check request arguments */
	if (recipient > 2 || pSetup->wLength != 0)
		/* Device behavior not specified */
		AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);

	/* ================ Configured state ================= */
	else if ( (usbState & UDP_CONFG) ) {
		/* If an application handler exists, transmit the request */
		if (pUsbDesc->ClearFeature)
			pUsbDesc->ClearFeature(recipient, pSetup->wIndex, pSetup->wValue, pUsbDesc->pPrivateStandardData);
		else
			AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
	}
	/* =================== Address state ================= */
	else if ( (usbState & UDP_FADDEN) ) {
		/* This request is valid in Address State only when reference endpoint 0 */
		if (recipient != 0 && pSetup->wIndex != 0)
			AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
		else {
		/* If an application handler exists, transmit the request */
			if (pUsbDesc->ClearFeature )
				pUsbDesc->ClearFeature(recipient, pSetup->wIndex, pSetup->wValue, pUsbDesc->pPrivateStandardData);
			else
				AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
		}
	}
	/* =================== Default state ================= */
	else
		/* Device behavior not specified */
		AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
}

/* ************************************ */
/* AT91F_UsbDescGetConfiguration        */
/*                                      */
/* Arguments:                           */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request returns the current */
/*     device configuration value       */
/* ************************************ */
void AT91F_UsbDescGetConfiguration(
	AT91PS_UsbDesc const pUsbDesc,  /* pointer to a AT91S_UsbDesc structure */
	AT91PS_UsbSetup      pSetup)    /* USB setup data Cf USB spec rev 1.1 */
{
	u_int usbState = AT91F_UdpGetState(pUsbDesc->pUdp);

	/* Check request arguments */
	if (pSetup->wValue != 0 || pSetup->wIndex != 0 || pSetup->wLength != 1)
		/* Device behavior not specified */
		AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);

	/* ================ Configured state ================= */
	else if ( (usbState & UDP_CONFG) ) {
		/* If an application handler exists, transmit the request */
		if (pUsbDesc->GetConfiguration )
			pUsbDesc->GetConfiguration(pUsbDesc->pPrivateStandardData);
		else
			AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
	}
	/* =================== Address state ================= */
	else if ( (usbState & UDP_FADDEN) ) {
		/* Return a 0 value */
		AT91F_UdpEpWrite(pUsbDesc->pUdp, pUsbDesc->epId, "\0x00", 1);
		AT91F_UdpEpEow(pUsbDesc->pUdp, pUsbDesc->epId);
	}
	/* =================== Default state ================= */
	else
		/* Device behavior not specified */
		AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
}

/* ************************************ */
/* AT91F_UsbDescGetDescriptor           */
/*                                      */
/* Arguments:                           */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request returns the         */
/*     specified descriptor if the      */
/*     descriptor exists                */
/* ************************************ */
void AT91F_UsbDescGetDescriptor(
	AT91PS_UsbDesc const pUsbDesc,  /* pointer to a AT91S_UsbDesc structure */
	AT91PS_UsbSetup      pSetup)    /* USB setup data Cf USB spec rev 1.1 */
{
	/* This request is valid in all states */
	if (pUsbDesc->GetDescriptor)
		pUsbDesc->GetDescriptor (
			((pSetup->wValue) >> 8),   /* Descriptor type */
			((pSetup->wValue) & 0xFF), /* Descriptor Index */
			pSetup->wIndex,            /* Language ID */
			pSetup->wLength,           /* Descripotr Length */
			pUsbDesc->pPrivateStandardData);
	else
		AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);

}

/* ************************************ */
/* AT91F_UsbDescGetInterface            */
/*                                      */
/* Arguments:                           */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request returns the         */
/*     selected alternate setting for   */
/*     the specified interface          */
/* ************************************ */
void AT91F_UsbDescGetInterface(
	AT91PS_UsbDesc const pUsbDesc,  /* pointer to a AT91S_UsbDesc structure */
	AT91PS_UsbSetup      pSetup)    /* USB setup data Cf USB spec rev 1.1 */
{
	u_int usbState = AT91F_UdpGetState(pUsbDesc->pUdp);

	/* Check request arguments */
	if (pSetup->wValue != 0 || pSetup->wLength != 1)
		/* Device behavior not specified */
		AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);

	/* ================ Configured state ================= */
	else if ( (usbState & UDP_CONFG) ) {
		/* If an application handler exists, transmit the request */
		if (pUsbDesc->GetInterface)
			pUsbDesc->GetInterface(pSetup->wIndex, pUsbDesc->pPrivateStandardData);
		else
			AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
	}
	/* =================== Address state ================= */
	else if ( (usbState & UDP_FADDEN) )
		AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
	/* =================== Default state ================= */
	else
		/* Device behavior not specified */
		AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
}

/* ************************************ */
/* AT91F_UsbDescGetStatus               */
/*                                      */
/* Arguments:                           */
/*     pSetup: pointer to setup datas   */
/* Return:                              */
/*     Nothing                          */
/* Description:                         */
/*     This request returns status for  */
/*     the specified endpoint           */
/* ************************************ */
void AT91F_UsbDescGetStatus(
	AT91PS_UsbDesc const pUsbDesc,  /* pointer to a AT91S_UsbDesc structure */
	AT91PS_UsbSetup      pSetup)    /* USB setup data Cf USB spec rev 1.1 */
{
	u_int usbState  = AT91F_UdpGetState(pUsbDesc->pUdp);
	u_int recipient = (pSetup->bmRequestType & 0x1F);

	/* Check request arguments */
	if (recipient > 2 || pSetup->wValue != 0 || pSetup->wLength != 2)
		/* Device behavior not specified */
		AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
	else if (recipient == 0 && pSetup->wIndex != 0)
		/* Device behavior not specified */
		AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);

	/* ================ Configured state ================= */
	else if ( (usbState & UDP_CONFG) ) {
		if (pUsbDesc->GetStatus)
			pUsbDesc->GetStatus(recipient, pSetup->wIndex, pUsbDesc->pPrivateStandardData);
		else
			AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);
	}
	/* =================== Address state ================= */
	else if ( (usbState & UDP_FADDEN) ) {
		if (pSetup->wIndex != 0 || !(pUsbDesc->GetStatus))
			AT91F_UdpEpStall(pUsbDesc->pUdp, pUsbDesc->epId);

⌨️ 快捷键说明

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