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

📄 usrusbtool.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	else	    {	    fprintf (fout, "Another channel already in use, ignored.\n");	    }	}    else	{	if (pChan == pKbdSioChan)	    {	    if (usbKeyboardSioChanUnlock (pChan) != OK)		fprintf (fout, "usbKeyboardSioChanUnlock() returned ERROR\n");	    pKbdSioChan = NULL;	    }	}    }/*************************************************************************** cmdKbdPoll - Polls keyboard SIO driver for input** RETURNS: RET_CONTINUE*/LOCAL UINT16 cmdKbdPoll    (    pVOID Param,		/* Generic parameter passed down */    char **ppCmd,		/* Ptr to remainder of cmd line */    FILE *fin,			/* stream for input (if any) */    FILE *fout			/* stream for output (if any) */    )    {    THREAD_HANDLE thread;    char inChar;    /* register for callbacks */    pKbdSioChan = NULL;    if (usbKeyboardDynamicAttachRegister (kbdAttachCallback, (pVOID) fout) != OK)	{	fprintf (fout, "usbKeyboardDynamicAttachRegister() returned ERROR\n");	return RET_CONTINUE;	}    /* Poll for input or until user presses CTRL-Z on USB keyboard or     * [enter] on main keyboard. */    /* Create thread to watch for keypress */    enterPressed = FALSE;    if (OSS_THREAD_CREATE (enterThread, (pVOID) fout, OSS_PRIORITY_INHERIT, "tEnter",	&thread) != OK)	goto pipe_done;    fprintf (fout, "Press CTRL-Z to terminate polling.\n");    while (!enterPressed)	{	if (pKbdSioChan != NULL)	    {	    if ((*pKbdSioChan->pDrvFuncs->pollInput) (pKbdSioChan, &inChar) == OK)		{		fprintf (fout, "ASCII %3d", inChar);		if (inChar >= 32)		    fprintf (fout, " '%c'", inChar);		fprintf (fout, "\n");		if (inChar == CTRL_Z)		    {		    fprintf (fout, "Stopped by CTRL-Z\n");		    break;		    }		}	    }	OSS_THREAD_SLEEP (1);	}    OSS_THREAD_DESTROY (thread);pipe_done:    /* unregister */    if (usbKeyboardDynamicAttachUnRegister (kbdAttachCallback, (pVOID) fout) != OK)	fprintf (fout, "usbKeyboardDynamicAttachUnRegister() returned ERROR\n");    return RET_CONTINUE;    }#endif	/*INCLUDE_USB_KEYBOARD*/#ifdef INCLUDE_USB_MOUSE/*************************************************************************** showMouseState** RETURNS: N/A*/LOCAL long mouseX;LOCAL long mouseY;LOCAL VOID showMouseState    (    FILE *fout,    UINT8 buttons    )    {    fprintf (fout, "\rx:%5ld  y:%5ld  B1:%3.3s B2:%3.3s B3:%3.3s",	mouseX, mouseY, 	(buttons & MOUSE_BUTTON_1) == 0 ? "UP " : "DWN",	(buttons & MOUSE_BUTTON_2) == 0 ? "UP " : "DWN",	(buttons & MOUSE_BUTTON_3) == 0 ? "UP " : "DWN");    }/*************************************************************************** signExtend - extends sign from char to long** RETURNS: sign-extended long value*/LOCAL long signExtend    (    char value    )    {    if ((value & 0x80) != 0)	return value | 0xffffff00;        return value;    }/*************************************************************************** mseRptCallback - invoked when reports received from mouse** RETURNS: OK*/LOCAL STATUS mseRptCallback    (    void *arg,    pHID_MSE_BOOT_REPORT pReport    )    {    FILE *fout = (FILE *) arg;    long xChange = signExtend (pReport->xDisplacement);    long yChange = signExtend (pReport->yDisplacement);    mouseX += xChange;    mouseY += yChange;    showMouseState (fout, pReport->buttonState);    return OK;    }/*************************************************************************** mseAttachCallback - receives callbacks from USB mouse SIO driver** RETURNS: N/A*/LOCAL SIO_CHAN *pMseSioChan;LOCAL VOID mseAttachCallback    (    pVOID arg,			    /* caller-defined argument */    SIO_CHAN *pChan,		    /* pointer to affected SIO_CHAN */    UINT16 attachCode		    /* defined as USB_KBD_xxxx */    )    {    FILE *fout = (FILE *) arg;    fprintf (fout, "pChan = %p, attach code = %s\n", pChan,	(attachCode == USB_MSE_ATTACH) ? "USB_MSE_ATTACH" : "USB_MSE_REMOVE");    if (attachCode == USB_MSE_ATTACH)	{	if (pMseSioChan == NULL)	    {	    if (usbMouseSioChanLock (pChan) != OK)		fprintf (fout, "usbMouseSioChanLock() returned ERROR\n");	    else		{		pMseSioChan = pChan;		/* Register for report callbacks */    		if (pMseSioChan != NULL)		    {		    if ((*pMseSioChan->pDrvFuncs->callbackInstall) (pMseSioChan,				SIO_CALLBACK_PUT_MOUSE_REPORT, 	 	 		(STATUS  (*) (void *, ...)) mseRptCallback, 				fout) != OK)			{			fprintf (fout, "callbackInstall() returned ERROR.\n");			}		    }		}	    }	else	    {	    fprintf (fout, "Another channel already in use, ignored.\n");	    }	}    else	{	if (pChan == pMseSioChan)	    {	    if (usbMouseSioChanUnlock (pChan) != OK)		fprintf (fout, "usbMouseSioChanUnlock() returned ERROR\n");	    pMseSioChan = NULL;	    }	}    }/*************************************************************************** cmdMouseTest - Tests mouse SIO driver for input** RETURNS: RET_CONTINUE*/LOCAL UINT16 cmdMouseTest    (    pVOID Param,		/* Generic parameter passed down */    char **ppCmd,		/* Ptr to remainder of cmd line */    FILE *fin,			/* stream for input (if any) */    FILE *fout			/* stream for output (if any) */    )    {    THREAD_HANDLE thread;    /* Initialize usbMouseLib. */    if (usbMouseDevInit () != OK)	{	fprintf (fout, "usbMouseDevInit() returned ERROR\n");	return RET_CONTINUE;	}    /* register for attach callbacks */    pMseSioChan = NULL;    mouseX = 0;    mouseY = 0;    if (usbMouseDynamicAttachRegister (mseAttachCallback, (pVOID) fout) != OK)	{	fprintf (fout, "usbMouseDynamicAttachRegister() returned ERROR\n");	goto mouseDown;	}    /* Wait for use to press [enter] to terminate test. */    /* Create thread to watch for keypress */    enterPressed = FALSE;    if (OSS_THREAD_CREATE (enterThread, (pVOID) fout, OSS_PRIORITY_INHERIT, "tEnter",	&thread) != OK)	{	fprintf (fout, "Failed to create tEnter thread.\n");	goto mouseUnreg;	}    /* Wait for mouse to be attached */    while (pMseSioChan == NULL)	{	if (enterPressed)	    goto threadDone;	OSS_THREAD_SLEEP (1);	}    /* Let background threads show mouse state */    showMouseState (fout, 0);    while (!enterPressed)	OSS_THREAD_SLEEP (1);    fprintf (fout, "\n");threadDone:    OSS_THREAD_DESTROY (thread);mouseUnreg:    /* unregister for attach callbacks */    if (usbMouseDynamicAttachUnRegister (mseAttachCallback, (pVOID) fout) != OK)	fprintf (fout, "usbMouseDynamicAttachUnRegister() returned ERROR\n");    /* Terminate report callbacks */    if (pMseSioChan != NULL)	if ((*pMseSioChan->pDrvFuncs->callbackInstall) (pMseSioChan, 	    SIO_CALLBACK_PUT_MOUSE_REPORT, NULL, NULL) != OK)	    {	    fprintf (fout, "callbackInstall() returned ERROR.\n");	    }mouseDown:    if (usbMouseDevShutdown () != OK)	fprintf (fout, "usbMouseDevShutdown() returned ERROR\n");    return RET_CONTINUE;    }#endif	/*INCLUDE_USB_KEYBOARD*/#ifdef INCLUDE_USB_PRINTER/*************************************************************************** closeTxFile - closes any open print tx file ** RETURNS: N/A*/LOCAL VOID closeTxFile (void)    {    txCharCount = 0;        if (txFile != NULL)	{	fclose (txFile);	txFile = NULL;	}    }/*************************************************************************** prnTxCallback - feeds characters to USB printer SIO driver** RETURNS: OK*/LOCAL STATUS prnTxCallback    (    void *callbackParam,    char *txChar    )    {    /* If no more chars to send, return an error */    if (txCharCount == 0)	return ERROR;    txCharCount--;    /* Check if running a pattern test or a file dump */    if (patternTest)	{	/* Running a pattern test.  Return the next pattern char */	if ((nextCharVal & 1) == 0)	    *txChar = nextCharVal >> 8;	else	    *txChar = nextCharVal & 0xff;	nextCharVal++;	}    else	{	/* Running a file dump test.  Return the next char from file */	if (txBfrCount == 0 && txCharCount > 0)	    {	    /* Read next buffer from file */	    txBfrCount = fread (txBfr, sizeof (char), sizeof (txBfr), txFile);	    txBfrIndex = 0;	    }	if (txCharCount == 0 || txBfrCount == 0)	    {	    closeTxFile ();	    txCharCount = 0;	    }	if (txBfrCount == 0)	    return ERROR;	*txChar = txBfr [txBfrIndex++];	--txBfrCount;	}    return OK;    }/*************************************************************************** prnAttachCallback - receives attach callbacks from printer SIO driver** RETURNS: N/A*/LOCAL SIO_CHAN *pPrnSioChan;LOCAL VOID prnAttachCallback    (    pVOID arg,			    /* caller-defined argument */    SIO_CHAN *pChan,		    /* pointer to affected SIO_CHAN */    UINT16 attachCode		    /* defined as USB_KBD_xxxx */    )    {    FILE *fout = (FILE *) arg;    fprintf (fout, "pChan = %p, attach code = %s\n", pChan,	(attachCode == USB_PRN_ATTACH) ? "USB_PRN_ATTACH" : "USB_PRN_REMOVE");    if (attachCode == USB_PRN_ATTACH)	{	if (pPrnSioChan == NULL)	    {	    if (usbPrinterSioChanLock (pChan) != OK)		fprintf (fout, "usbPrinterSioChanLock() returned ERROR\n");	    else		{		pPrnSioChan = pChan;		if ((*pPrnSioChan->pDrvFuncs->callbackInstall) (pPrnSioChan, 		    	SIO_CALLBACK_GET_TX_CHAR, 	 	 	(STATUS  (*) (void *, ...)) prnTxCallback, 			NULL) != OK)		    {		    fprintf (fout, "callbackInstall() returned ERROR.\n");		    }		}	    }	else	    {	    fprintf (fout, "Another channel already in use, ignored.\n");	    }	}    else	{	if (pChan == pPrnSioChan)	    {	    if (usbPrinterSioChanUnlock (pChan) != OK)		fprintf (fout, "usbPrinterSioChanUnlock() returned ERROR\n");	    pPrnSioChan = NULL;	    }	}    }/*************************************************************************** cmdPrnInit - initializes USB printer SIO driver** RETURNS: RET_CONTINUE*/LOCAL BOOL prnInitialized = FALSE;LOCAL UINT16 cmdPrnInit    (    pVOID Param,		/* Generic parameter passed down */    char **ppCmd,		/* Ptr to remainder of cmd line */    FILE *fin,			/* stream for input (if any) */    FILE *fout			/* stream for output (if any) */    )    {    if (prnInitialized)	{	fprintf (fout, "USB printer SIO driver already initialized.\n");	return RET_CONTINUE;	}    if (usbPrinterDevInit () == OK)	{	fprintf (fout, "usbPrinterDevInit() returned OK\n");	prnInitialized = TRUE;	/* Register for attach notification */	if (usbPrinterDynamicAttachRegister (prnAttachCallback, (pVOID) fout) != OK)	    {	    fprintf (fout, "usbPrinterDynamicAttachRegister() returned ERROR\n");	    return RET_CONTINUE;	    }	}    else	fprintf (fout, "usbPrinterDevInit() returned ERROR\n");    return RET_CONTINUE;    }/*************************************************************************** cmdPrnDown - shuts down USB printer SIO driver** RETURNS: RET_CONTINUE*/LOCAL UINT16 cmdPrnDown    (    pVOID Param,		/* Generic parameter passed down */    char **ppCmd,		/* Ptr to remainder of cmd line */    FILE *fin,			/* stream for input (if any) */    FILE *fout			/* stream for output (if any) */    )    {    if (!prnInitialized)	{	fprintf (fout, "USB printer SIO driver not initialized.\n");	return RET_CONTINUE;	}    prnInitialized = FALSE;    pPrnSioChan = NULL;    /* unregister */    if (usbPrinterDynamicAttachUnRegister (prnAttachCallback, (pVOID) fout) != OK)	fprintf (fout, "usbPrinterDynamicAttachUnRegister() returned ERROR\n");    if (usbPrinterDevShutdown () == OK)	fprintf (fout, "usbPrinterDevShutdown() returned OK\n");    else	fprintf (fout, "usbPrinterDevShutdown() returned ERROR\n");    return RET_CONTINUE;    }/*************************************************************************** waitForPrinter - waits for a printer to be connected** RETURNS: OK if printer connected, else ERROR*/LOCAL STATUS waitForPrinter     (    FILE *fout    )    {    THREAD_HANDLE thread;    UINT8 * pBfr;    USB_PRINTER_CAPABILITIES * pCaps;    UINT16 idLen;    UINT8 protocol;    UINT16 i;    /* Create thread to watch for keypress */

⌨️ 快捷键说明

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