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

📄 usbtargkbdlib.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* usbTargKbdLib.c - USB keyboard target exerciser/demonstration *//* Copyright 2000 Wind River Systems, Inc. *//*Modification history--------------------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 similar USBtest/exerciser application.It is the caller's responsibility to initialize usbTargLib and attach a USB TCD to 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 orto shut it down.  It performs all of its operations in response to callbacks fromusbTargLib.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.*//* includes */#include "usb/usbPlatform.h"#include "string.h"#include "usb/usb.h"#include "usb/usbHid.h" 		    /* USB HID definitions */#include "usb/usbDescrCopyLib.h"			/* USB utility functions */#include "usb/target/usbTargLib.h"	    /* USB target functions */#include "drv/usb/target/usbTargKbdLib.h"   /* our API *//* defines *//* string identifiers */#define UNICODE_ENGLISH     0x409#define ID_STR_MFG	    1#define ID_STR_MFG_VAL	    "Wind River Systems"#define ID_STR_PROD	    2#define ID_STR_PROD_VAL     "USB keyboard emulator"/* keyboard device */#define KBD_USB_VERSION 		0x0100#define KBD_NUM_CONFIG			1/* keyboard configuration */#define KBD_CONFIG_VALUE		1#define KBD_NUM_INTERFACES		1/* keyboard interface */#define KBD_INTERFACE_NUM		0#define KBD_INTERFACE_ALT_SETTING	1#define KBD_NUM_ENDPOINTS		1/* keyboard interrupt endpoint */#define KBD_INTERRUPT_ENDPOINT_NUM	0x01#define KBD_INTERRUPT_ENDPOINT_INTERVAL 20	/* 20 milliseconds *//* typedefs *//* forward declarations */LOCAL STATUS mngmtFunc    (    pVOID param,    USB_TARG_CHANNEL targChannel,    UINT16 mngmtCode    );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 vendorSpecific    (    pVOID param,    USB_TARG_CHANNEL targChannel,    UINT8 requestType,    UINT8 request,    UINT16 value,    UINT16 index,    UINT16 length    );/* locals */LOCAL USB_TARG_CALLBACK_TABLE usbTargKbdCallbackTable =    {    mngmtFunc,		/* mngmtFunc */    featureClear,	/* featureClear */    featureSet, 	/* featureSet */    configurationGet,	/* configurationGet */    configurationSet,	/* configurationSet */    descriptorGet,	/* descriptorGet */    NULL,		/* descriptorSet */    interfaceGet,	/* interfaceGet */    interfaceSet,	/* interfaceSet */    NULL,		/* statusGet */    NULL,		/* addressSet */    NULL,		/* synchFrameGet */    vendorSpecific,	/* vendorSpecific */    };LOCAL USB_TARG_CHANNEL channel;LOCAL UINT16 numEndpoints;LOCAL pUSB_TARG_ENDPOINT_INFO pEndpoints;LOCAL UINT8 curConfiguration;LOCAL UINT8 curAlternateSetting;LOCAL USB_TARG_PIPE intPipeHandle;LOCAL USB_ERP reportErp;LOCAL BOOL reportInUse;LOCAL HID_KBD_BOOT_REPORT reportBfr;LOCAL USB_LANGUAGE_DESCR langDescr =    {sizeof (USB_LANGUAGE_DESCR), USB_DESCR_STRING, 	{TO_LITTLEW (UNICODE_ENGLISH)}};LOCAL char *pStrMfg = ID_STR_MFG_VAL;LOCAL char *pStrProd = ID_STR_PROD_VAL;LOCAL USB_DEVICE_DESCR devDescr =    {    USB_DEVICE_DESCR_LEN,	    /* bLength */    USB_DESCR_DEVICE,		    /* bDescriptorType */    TO_LITTLEW (KBD_USB_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_CONFIG_DESCR configDescr =    {    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_INTERFACE_DESCR ifDescr =    {    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 =    {    USB_ENDPOINT_DESCR_LEN,	    /* bLength */    USB_DESCR_ENDPOINT, 	    /* bDescriptorType */    KBD_INTERRUPT_ENDPOINT_NUM,     /* bEndpointAddress */    USB_ATTR_INTERRUPT, 	    /* bmAttributes */    sizeof (HID_KBD_BOOT_REPORT),   /* maxPacketSize */    KBD_INTERRUPT_ENDPOINT_INTERVAL /* bInterval */    };/* functions *//***************************************************************************** usbTargKbdCallbackInfo - returns usbTargKbdLib callback table** RETURNS: N/A*/VOID usbTargKbdCallbackInfo    (    pUSB_TARG_CALLBACK_TABLE *ppCallbacks,    pVOID *pCallbackParam    )    {    if (ppCallbacks != NULL)	*ppCallbacks = &usbTargKbdCallbackTable;    if (pCallbackParam != NULL)	*pCallbackParam = NULL;    }/***************************************************************************** reportErpCallback - called when report ERP terminates** RETURNS: N/A*/LOCAL VOID reportErpCallback    (    pVOID p			/* pointer to ERP */    )    {    reportInUse = FALSE;    }/***************************************************************************** usbTargKbdInjectReport - injects a "boot report" into the interrupt pipe** RETURNS: OK, or ERROR if unable to inject report*/STATUS usbTargKbdInjectReport    (    pHID_KBD_BOOT_REPORT pReport,    UINT16 reportLen    )    {    /* If the report pipe isn't enabled, return an error. */    if (intPipeHandle == NULL)	return ERROR;    /* If a report is already queued, return an error. */    if (reportInUse)	return ERROR;    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** RETURNS: OK if able to handle event, or ERROR if unable to handle event*/

⌨️ 快捷键说明

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