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

📄 usbtargkbdlib.c

📁 This the compressed USB driver source code for vxworks5.6. It has device controller driver and other
💻 C
📖 第 1 页 / 共 3 页
字号:
/* usbTargKbdLib.c - USB keyboard target exerciser/demonstration *//* Copyright 1999-2004 Wind River Systems, Inc. *//*Modification history--------------------02e,02aug04,mta  Modification History Changes02d,23jul04,ami  Apigen Changes02c,19jul04,ami  Coding Convention Changes02b,30jun04,pdg  Bug fixes - isp1582 full speed testing02a,05apr04,pdg  modifications for USB 2.0 stack.01b,23nov99,rcb  Change #include ../xxx references to lower case.01a,18aug99,rcb  First.*//*DESCRIPTIONThis module contains code to exercise the usbTargLib by emulating a rudimentaryUSB keyboard.  This module will generally be invoked by usbTool or a similarUSB test/exerciser application.It is the caller's responsibility to initialize usbTargLib and attach a USB TCDto it.	When attaching a TCD to usbTargLib, the caller must pass a pointer to atable of callbacks required by usbTargLib.  The address of this table and the"callback parameter" required by these callbacks may be obtained by callingusbTargKbdCallbackInfo().  It is not necessary to initialize the usbTartKbdLib or to shut it down.  It performs all of its operations in response to callbacks from  usbTargLib.This module also exports a function called usbTargKbdInjectReport().  This function allows the caller to inject a "boot report" into the interrupt pipe.This allows for rudimentary emulation of keystrokes.INCLUDE FILES: usb/usbPlatform.h, string.h, usb/usb.h, usb/usbHid.h,               usb/usbDescrCopyLib.h, usb/target/usbTargLib.h,               drv/usb/target/usbTargKbdLib.h*//* includes */#include "usb/usbPlatform.h"               #include "string.h"                         #include "usb/usb.h"                        #include "usb/usbHid.h" 		    #include "usb/usbDescrCopyLib.h"            #include "usb/target/usbTargLib.h"	    #include "drv/usb/target/usbTargKbdLib.h"/* defines *//* string identifiers */#define UNICODE_ENGLISH		0x409		/* unicode */		#define ID_STR_MFG		1		/* manufacture's index */#define ID_STR_MFG_VAL		"Wind River Systems" /* manufacture's string */#define ID_STR_PROD		2		/* product id */#define ID_STR_PROD_VAL		"USB keyboard emulator" /* product name *//* keyboard device */#define KBD_USB10_VERSION	0x0100	/* full speed version */#define KBD_USB20_VERSION	0x0200	/* high speed version */#define KBD_NUM_CONFIG		1	/* number of configurations *//* keyboard configuration */#define KBD_CONFIG_VALUE	1	/* keyboard configuraion value */#define KBD_NUM_INTERFACES	1	/* number of interfaces *//* keyboard interface */#define KBD_INTERFACE_NUM		0	/* interface number */#define KBD_INTERFACE_ALT_SETTING	0	/* alternate setting Index */#define KBD_NUM_ENDPOINTS		1	/* number of endpoints *//* keyboard interrupt endpoint */#define KBD_INTERRUPT_ENDPOINT_NUM	0x81    /* interrupt endpoint index */#define KBD_INTERRUPT_ENDPOINT_INTERVAL 20      /* 20 milliseconds */#define KBD_HIGH_SPEED_POLLING_INTERVAL	6#define KBD_HIGH_SPEED_CONTROL_MAX_PACKET_SIZE  0x40 /* maximum packet size */						     /* for the default */                                                     /* control endpoint, if */						     /* the device is */                                                     /* operating at high */						     /* speed *//* locals */LOCAL	USB_TARG_CHANNEL	channel;	     /* target channel */LOCAL	UINT8			curConfiguration;    /* current configuration */LOCAL	UINT8			curAlternateSetting; /* current alternate */						     /* setting */LOCAL	USB_TARG_PIPE		intPipeHandle;	/* interrupt pipe handler*/LOCAL	USB_ERP			reportErp;	/* boot report erp */LOCAL	BOOL			reportInUse;	/* boot report in use */LOCAL	HID_KBD_BOOT_REPORT 	reportBfr;	/* HID class boot report */LOCAL	UINT32			uDeviceFeature = 0;  /* features supported by */						     /* device */LOCAL	UINT32			uEndpointNumberBitmap = 0;							/* bitmap to show the */						/* endpoints supported by */						/* the device. */LOCAL	UINT32			uSpeed = USB_TCD_FULL_SPEED;						/* operation speed */LOCAL	UINT8			uDeviceStatus = 0x01;	/* curent status */LOCAL	UINT8			uDeviceAddress = 0;	/* device address */LOCAL USB_LANGUAGE_DESCR langDescr = {sizeof (USB_LANGUAGE_DESCR),                                      USB_DESCR_STRING,                                      {TO_LITTLEW (UNICODE_ENGLISH)}};LOCAL	char	*pStrMfg  = ID_STR_MFG_VAL;	/* manufacturer id */LOCAL	char	*pStrProd = ID_STR_PROD_VAL;	/* product id */LOCAL	UCHAR	pKeyBoardBuf[2];LOCAL USB_DEVICE_DESCR devDescr =	/* Device Descriptor */    {    USB_DEVICE_DESCR_LEN,		/* bLength */    USB_DESCR_DEVICE,			/* bDescriptorType */    TO_LITTLEW (KBD_USB10_VERSION),	/* bcdUsb */    0,					/* bDeviceClass */    0,					/* bDeviceSubclass */    0,					/* bDeviceProtocol */    USB_MIN_CTRL_PACKET_SIZE,		/* maxPacketSize0 */    0,					/* idVendor */    0,					/* idProduct */    0,					/* bcdDevice */    ID_STR_MFG,				/* iManufacturer */    ID_STR_PROD,			/* iProduct */    0,					/* iSerialNumber */    KBD_NUM_CONFIG			/* bNumConfigurations */    };LOCAL USB_DEVICE_QUALIFIER_DESCR devQualifierDescr =	/* Device Qualifier */    {    USB_DEVICE_QUALIFIER_DESCR_LEN,	/* bLength */    USB_DESCR_DEVICE_QUALIFIER,		/* bDescriptorType */    TO_LITTLEW (KBD_USB20_VERSION),	/* bcdUsb */    0,					/* bDeviceClass */    0,					/* bDeviceSubclass */    0,					/* bDeviceProtocol */    USB_MIN_CTRL_PACKET_SIZE,		/* maxPacketSize0 */    KBD_NUM_CONFIG,			/* bNumConfigurations */    0					/* Reserved */    };LOCAL USB_CONFIG_DESCR configDescr =	/* Configuration Descriptor */    {    USB_CONFIG_DESCR_LEN,		/* bLength */    USB_DESCR_CONFIGURATION,		/* bDescriptorType */    TO_LITTLEW (USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN +                USB_ENDPOINT_DESCR_LEN),/* wTotalLength */    KBD_NUM_INTERFACES,			/* bNumInterfaces */    KBD_CONFIG_VALUE,			/* bConfigurationValue */    0,					/* iConfiguration */    USB_ATTR_SELF_POWERED,		/* bmAttributes */    0					/* MaxPower */    };LOCAL USB_CONFIG_DESCR otherSpeedConfigDescr =	/* Other Speed Descriptor */    {    USB_CONFIG_DESCR_LEN,		/* bLength */    USB_DESCR_OTHER_SPEED_CONFIGURATION,/* bDescriptorType */    TO_LITTLEW (USB_CONFIG_DESCR_LEN + USB_INTERFACE_DESCR_LEN +                USB_ENDPOINT_DESCR_LEN),/* wTotalLength */    KBD_NUM_INTERFACES,			/* bNumInterfaces */    KBD_CONFIG_VALUE,			/* bConfigurationValue */    0,					/* iConfiguration */    USB_ATTR_SELF_POWERED,		/* bmAttributes */    0					/* MaxPower */    };LOCAL USB_INTERFACE_DESCR ifDescr =	/* Interface Descriptor */    {    USB_INTERFACE_DESCR_LEN,		/* bLength */    USB_DESCR_INTERFACE,		/* bDescriptorType */    KBD_INTERFACE_NUM,			/* bInterfaceNumber */    KBD_INTERFACE_ALT_SETTING,		/* bAlternateSetting */    KBD_NUM_ENDPOINTS,			/* bNumEndpoints */    USB_CLASS_HID,			/* bInterfaceClass */    USB_SUBCLASS_HID_BOOT,		/* bInterfaceSubClass */    USB_PROTOCOL_HID_BOOT_KEYBOARD,	/* bInterfaceProtocol */    0					/* iInterface */    };LOCAL USB_ENDPOINT_DESCR epDescr =	/* Endpoint Descriptor */    {    USB_ENDPOINT_DESCR_LEN,		/* bLength */    USB_DESCR_ENDPOINT,			/* bDescriptorType */    (USB_ENDPOINT_DIR_MASK | KBD_INTERRUPT_ENDPOINT_NUM),					/* bEndpointAddress */    USB_ATTR_INTERRUPT,			/* bmAttributes */    TO_LITTLEW(sizeof (HID_KBD_BOOT_REPORT)),					/* maxPacketSize */    KBD_INTERRUPT_ENDPOINT_INTERVAL	/* bInterval */    };/* forward declarations */LOCAL STATUS mngmtFunc (pVOID param, USB_TARG_CHANNEL targChannel,                         UINT16 mngmtCode, pVOID pContext);LOCAL STATUS featureClear (pVOID param, USB_TARG_CHANNEL targChannel,                           UINT8 requestType, UINT16 feature, UINT16 index);LOCAL STATUS featureSet (pVOID param, USB_TARG_CHANNEL targChannel,                          UINT8 requestType, UINT16 feature, UINT16 index);LOCAL STATUS configurationGet (pVOID param, USB_TARG_CHANNEL targChannel,                               pUINT8 pConfiguration);LOCAL STATUS configurationSet (pVOID param, USB_TARG_CHANNEL targChannel,                               UINT8 configuration);LOCAL STATUS descriptorGet (pVOID param, USB_TARG_CHANNEL targChannel,                            UINT8 requestType, UINT8 descriptorType,                            UINT8 descriptorIndex, UINT16 languageId,                            UINT16 length, pUINT8 pBfr, pUINT16 pActLen);LOCAL STATUS interfaceGet (pVOID param, USB_TARG_CHANNEL targChannel,                           UINT16 interfaceIndex, pUINT8 pAlternateSetting);LOCAL STATUS interfaceSet (pVOID param, USB_TARG_CHANNEL targChannel,                           UINT16 interfaceIndex, UINT8 alternateSetting);LOCAL STATUS statusGet (pVOID param, USB_TARG_CHANNEL targChannel,                        UINT16 requestType, UINT16 index, UINT16 length,                        pUINT8 pBfr);LOCAL STATUS addressSet (pVOID param, USB_TARG_CHANNEL targChannel,                         UINT16 deviceAddress);LOCAL STATUS vendorSpecific (pVOID param, USB_TARG_CHANNEL targChannel,                             UINT8 requestType, UINT8 request, UINT16 value,                             UINT16 index, UINT16 length);LOCAL VOID usbkbdSetReportCallback (pVOID pErp);LOCAL USB_TARG_CALLBACK_TABLE usbTargKbdCallbackTable =	/* Callback Table */    {    mngmtFunc,		/* mngmtFunc */    featureClear,	/* featureClear */    featureSet, 	/* featureSet */    configurationGet,	/* configurationGet */    configurationSet,	/* configurationSet */    descriptorGet,	/* descriptorGet */    NULL,		/* descriptorSet */    interfaceGet,	/* interfaceGet */    interfaceSet,	/* interfaceSet */    statusGet,		/* statusGet */    addressSet,		/* addressSet */    NULL,		/* synchFrameGet */    vendorSpecific,	/* vendorSpecific */    };/******************************************************************************** usbTargKbdCallbackInfo - returns usbTargKbdLib callback table** This function is called by the initialization rountine. It returns the* callback table information.** RETURNS: N/A** ERRNO:*  none.*/VOID usbTargKbdCallbackInfo    (    struct usbTargCallbackTable ** ppCallbacks,  /* Callback table pointer */    pVOID *pCallbackParam                  /* target app-specific parameter */    )    {    if (ppCallbacks != NULL)	*ppCallbacks = &usbTargKbdCallbackTable;    if (pCallbackParam != NULL)	*pCallbackParam = NULL;    }/******************************************************************************** reportErpCallback - called when report ERP terminates** This callback is invoked when an Endpoint Request Packet terminates. It* states that no more ERP reports are pending.** RETURNS: N/A** ERRNO:*  none** \NOMANUAL*/LOCAL VOID reportErpCallback    (    pVOID p				/* pointer to ERP */    )    {    reportInUse = FALSE;    }/******************************************************************************** usbTargKbdInjectReport - injects a "boot report"** This function injects the boot report into the interrupt pipe. <pReport>* is the pointer to the boot report ot be injected. <reportErpCallback> is* called after the boot report is successfully sent to the host.** RETURNS: OK, or ERROR if unable to inject report** ERRNO:*  none.*/STATUS usbTargKbdInjectReport    (    pHID_KBD_BOOT_REPORT pReport,	/* Boot Report to be injected */    UINT16 reportLen			/* Length of the boot report */    )    {        /* If the report pipe isn't enabled, return an error. */    if (intPipeHandle == NULL)	return ERROR;    /* If a report is already queued, return an error. */    while (reportInUse)        OSS_THREAD_SLEEP(1);    reportInUse = TRUE;    /* Copy the report and set up the transfer. */    reportLen = min (sizeof (reportBfr), reportLen);    memcpy (&reportBfr, pReport, reportLen);    memset (&reportErp, 0, sizeof (reportErp));    reportErp.erpLen = sizeof (reportErp);    reportErp.userCallback = reportErpCallback;    reportErp.bfrCount = 1;    reportErp.bfrList [0].pid = USB_PID_IN;    reportErp.bfrList [0].pBfr = (pUINT8) &reportBfr;    reportErp.bfrList [0].bfrLen = reportLen;    return usbTargTransfer (intPipeHandle, &reportErp);    }/******************************************************************************** mngmtFunc - invoked by usbTargLib for connection management events** This function handles various management related events. <mngmtCode>* consist of the management event function code that is reported by the* TargLib layer. <pContext> is the argument sent for the management event to* be handled.** RETURNS: OK if able to handle event, or ERROR if unable to handle event** ERRNO:*  none.** \NOMANUAL*/LOCAL STATUS mngmtFunc    (    pVOID	param,			/* TCD specific parameter */    USB_TARG_CHANNEL	targChannel,	/* Target Channel */    UINT16	mngmtCode,		/* management code */

⌨️ 快捷键说明

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