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

📄 usbtargkbdlib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 3 页
字号:
    /*      * This request is invalid if received in a default state     * or the configuration value is not expected     */    if ((uDeviceAddress == 0) || (configuration > KBD_CONFIG_VALUE))        return ERROR;    /* Check if the configuration value is the expected value */    if (configuration == KBD_CONFIG_VALUE)    	{    	/* Create the interrupt pipe if it is not created */    	if (intPipeHandle == NULL)    	    {    	    /* Create a bulk OUT pipe */     	    if (usbTargPipeCreate (targChannel,                                   &epDescr,                                   configuration,                                   KBD_INTERFACE_NUM,                                   KBD_INTERFACE_ALT_SETTING,                                   &intPipeHandle) != OK)                return ERROR;       	    reportInUse = FALSE;    	    }    	curConfiguration = configuration;    	}    else    	{    	/* Delete the interrupt pipe if created */    	if (intPipeHandle != NULL)    	    {    	    usbTargPipeDestroy (intPipeHandle);    	    intPipeHandle = NULL;    	    }    	curConfiguration = configuration;    	}    return OK;    }/******************************************************************************** descriptorGet - invoked by usbTargLib for GET_DESCRIPTOR request** This function is used to get the descriptor value. The type of * descriptor to get is specified in <descriptorType>.** RETURNS: OK, or ERROR if unable to return requested descriptor** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS descriptorGet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT8	requestType,            /* request type */    UINT8	descriptorType,         /* type of descriptor */    UINT8	descriptorIndex,        /* descriptor index */    UINT16	languageId,		/* lang. ID for string descriptors */    UINT16	length,			/* length of the descriptor */    pUINT8	pBfr,			/* buffer send data */    pUINT16	pActLen			/* length of data copied */    )    {    UINT8	bfr [USB_MAX_DESCR_LEN];/* buffer to hold descriptor values */    UINT16	actLen;			/* total length */    /* Determine type of descriptor being requested. */    if (requestType == (USB_RT_DEV_TO_HOST | USB_RT_STANDARD | USB_RT_DEVICE))    	{    	switch (descriptorType)    	    {    	    case USB_DESCR_DEVICE:                usbDescrCopy (pBfr, &devDescr, length, pActLen);                break;    	    case USB_DESCR_DEVICE_QUALIFIER:                usbDescrCopy (pBfr, &devQualifierDescr, length, pActLen);                break;    	    case USB_DESCR_CONFIGURATION:                memcpy (bfr, &configDescr, USB_CONFIG_DESCR_LEN);                memcpy (&bfr [USB_CONFIG_DESCR_LEN], &ifDescr,        		USB_INTERFACE_DESCR_LEN);                memcpy (&bfr [USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN],                        &epDescr, USB_ENDPOINT_DESCR_LEN);                actLen = min (length, USB_CONFIG_DESCR_LEN +        		      USB_INTERFACE_DESCR_LEN + USB_ENDPOINT_DESCR_LEN);                memcpy (pBfr, bfr, actLen);                *pActLen = actLen;                break;    	    case USB_DESCR_OTHER_SPEED_CONFIGURATION:                memcpy (bfr, &otherSpeedConfigDescr, USB_CONFIG_DESCR_LEN);                memcpy (&bfr [USB_CONFIG_DESCR_LEN], &ifDescr,                        USB_INTERFACE_DESCR_LEN);                memcpy (&bfr [USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN],                        &epDescr, USB_ENDPOINT_DESCR_LEN);                actLen = min (length, USB_CONFIG_DESCR_LEN +                              USB_INTERFACE_DESCR_LEN + USB_ENDPOINT_DESCR_LEN);                                memcpy (pBfr, bfr, actLen);                *pActLen = actLen;    		break;    	    case USB_DESCR_STRING:                switch (descriptorIndex)                    {                    case 0: /* language descriptor */                        usbDescrCopy (pBfr, &langDescr, length, pActLen);        		break;                    case ID_STR_MFG:                        usbDescrStrCopy (pBfr, pStrMfg, length, pActLen);        		break;                    case ID_STR_PROD:                        usbDescrStrCopy (pBfr, pStrProd, length, pActLen);                        break;                     default:                        return ERROR;                    }                break;            default:                return ERROR;    	    }        }    else        {    	return ERROR;    	}    return OK;    }/******************************************************************************** interfaceGet - invoked by usbTargLib for GET_INTERFACE request** This function is used to get the selected alternate setting of the* specified interface.** RETURNS: OK, or ERROR if unable to return interface setting** ERRNO:*  none*/LOCAL STATUS interfaceGet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT16	interfaceIndex,		/* index of the specified interface */    pUINT8	pAlternateSetting	/* value of alternate setting*/    )    {    /*      * This is an invalid request if the device is in     * default or addressed state     */    if ((uDeviceAddress == 0) ||(curConfiguration == 0))        return ERROR;    *pAlternateSetting = KBD_INTERFACE_ALT_SETTING;    return OK;    }/******************************************************************************** interfaceSet - invoked by usbTargLib for SET_INTERFACE request** This function is used to select the alternate setting of he specified* interface.** RETURNS: OK, or ERROR if unable to set specified interface** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS interfaceSet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT16	interfaceIndex,		/* index of the specified interface */    UINT8	alternateSetting	/* alternate Setting to be set */    )    {        /*      * This is an invalid request if the device is in default/addressed state     * or if the alternate setting value does not match     */    if ((uDeviceAddress == 0) ||        (curConfiguration == 0) ||        (alternateSetting != KBD_INTERFACE_ALT_SETTING))        return ERROR;    curAlternateSetting = alternateSetting;    return OK;    }/******************************************************************************** statusGet - invoked by usbTargLib for GET_STATUS request** This function is used to get the status of the recipient specified in* <index>. The status is sent in <pBfr> to the host.** RETURNS: OK, or ERROR if unable to get the status of the recepient.** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS statusGet    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT16	requestType,		/* type of request */    UINT16	index,			/* recipient */    UINT16	length,			/* wlength */    pUINT8	pBfr			/* status of the specified recipient */    )    {    STATUS status = ERROR;    /* This is an invalid request if received in default state */    if (uDeviceAddress == 0)        return ERROR;    /* Switch based on the recipient value specified */    switch(requestType & USB_RT_RECIPIENT_MASK)        {        case USB_RT_DEVICE:            pBfr[0] = uDeviceStatus;            status = OK;            break;        case USB_RT_ENDPOINT:            if ((index == epDescr.endpointAddress) && (intPipeHandle != NULL))                status = usbTargPipeStatusGet(intPipeHandle, pBfr);            break;        default:            break;        }    return status;    }/******************************************************************************** addressSet - invoked by usbTargLib for SET_ADDRESS request** This function is used to set the address of the device. <deviceAddress>* consist of the address to set.** RETURNS: OK, or ERROR if unable to set the address** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS addressSet    (    pVOID	param,			/* TCD Specific Parameter */    USB_TARG_CHANNEL	targChannel,	/* Target Channel */    UINT16	deviceAddress		/* Device Address to Set */    )    {    /* The device cannot accept a set address request after configuration */    if (curConfiguration != 0)        return ERROR;    /* Copy the address to the global */    uDeviceAddress = deviceAddress;    return OK;    }/******************************************************************************** usbkbdSetReportCallback - invoked on  USB_REQ_HID_SET_REPORT request ** This function is invoked when USB_REQ_HID_SET_REPORT vendor specific* request is received from the host. It acts as a dummy.** RETURNS: N/A** ERRNO:*  none*/LOCAL VOID usbkbdSetReportCallback    (    pVOID	pErp			/* Pointer to ERP structure */    )    {    return;    }/******************************************************************************** vendorSpecific - invoked by usbTargLib for VENDOR_SPECIFIC request** This fucntion is called when any vendor specific request comes from host.** RETURNS: OK, or ERROR if unable to process vendor-specific request** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS vendorSpecific    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* target channel */    UINT8	requestType,		/* characteristics of request */    UINT8	request,		/* request type */    UINT16	value,                  /* wValue */    UINT16	index,                  /* wIndex */    UINT16	length                  /* length to transfer */    )    {    if (requestType == (USB_RT_HOST_TO_DEV | USB_RT_CLASS | USB_RT_INTERFACE))    	{    	switch (request)    	    {    	    case USB_REQ_HID_SET_PROTOCOL:    	    case USB_REQ_HID_SET_IDLE:                /*                  * This emulator simply acknowledges these HID requests...no        	 * processing is required.        	 */        	usbTargControlStatusSend (targChannel);        	return OK;    	    case USB_REQ_HID_SET_REPORT:                /* Send the request to receive the data from the host */        	usbTargControlPayloadRcv (targChannel, 1, pKeyBoardBuf,                                           usbkbdSetReportCallback);                return OK;    	    default:        	break;    	    }    	}    return ERROR;    }

⌨️ 快捷键说明

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