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

📄 usrusbmseinit.c

📁 T2.0 USB driver.rar T2.0 USB driver.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
	{	if (usbMouseSioChanLock (pChan) != OK)	    {	    printf("usbMouseSioChanLock () returned ERROR\n");	    }	else	    {	    sprintf (mseName, "%s%d", USB_MSE_NAME, mseCount);	    if (usbMseDevCreate (mseName, pChan) != OK)		{		printf("usbMseDevCreate() returned ERROR\n");		}	    /* now we can increment the counter */	    mseCount++;	    if (usbMseDevFind (pChan, (USB_MSE_DEV *) &usbMseDev) != OK)		{		printf("usbMseDevFind() returned ERROR\n");		return;		}	    if ((*pChan->pDrvFuncs->callbackInstall) 									(pChan, 					SIO_CALLBACK_PUT_MOUSE_REPORT,					usbMseRptCallback, 					/*(void *) usbMseDev*/NULL) 				!= OK)		{		printf("usbMseRptCallback () failed to install\n");		}	    printf("USB Mouse attached as %s\n", mseName);	    }	}    else if (attachCode == USB_MSE_REMOVE)	{	/* find the related device */	if (usbMseDevFind (pChan, (USB_MSE_DEV *) &usbMseDev) != OK)	    {	    printf ("usbMseDevFind could not find channel 0x%d", pChan);	    return;	    }		/* delete the device */	usbMseDevDelete ((USB_MSE_DEV *) usbMseDev);	if (usbMouseSioChanUnlock (pChan) != OK)	    {	    printf("usbMouseSioChanUnlock () returned ERROR\n");	    return;	    }	}    }/********************************************************************************* usbMseOpen - open a usbMseDrv serial device.** Increments a counter that holds the number of open paths to device. */LOCAL int usbMseOpen    (    USB_MSE_DEV	* pUsbMseDev,  /* mouse device to read from */    char     *	name,		/* device name */    int		flags,		/* flags */    int        	mode		/* mode selected */    )    {    pUsbMseDev->numOpen++;  /* increment number of open paths */        sioIoctl (pUsbMseDev->pSioChan, SIO_OPEN, NULL);    return ((int) pUsbMseDev);    }/********************************************************************************* usbMseDrvUnInit - shuts down an I/O USB mouse driver*** This is supplied to for the user, but it should be noted that iosDrvRemove()* may cause unpredictable results.**/STATUS usbMseDrvUnInit (void)    {    if (!usbMseDrvNum)	return (OK);    /* remove the driver */    if (iosDrvRemove (usbMseDrvNum, TRUE) != OK)	{	printf("iosDrvRemove () returned ERROR\n");	return (ERROR);	}    /* HELP */    usbMseDrvNum = 0;    /* delete the mutex semaphores */     if (semDelete (usbMseMutex) == ERROR)	{	printf("semDelete (usbMseMutex) returned ERROR\n");	return (ERROR);	}    if (semDelete (usbMseListMutex) == ERROR)	{	printf("semDelete (usbMseListMutex) returned ERROR\n");	return (ERROR);	}    /* unregister */     if (usbMouseDynamicAttachUnRegister (mseAttachCallback, 					 NULL) 					!= OK)	{	printf("usbMouseDynamicAttachUnRegister () returned ERROR\n");	return (ERROR);	}     /* shutdown */    if (usbMouseDevShutdown () != OK)	{	printf("usbMouseDynamicAttachUnRegister () returned ERROR\n");	return (ERROR);	}    return (OK);    }/********************************************************************************* usbMseClose - close a usbMseDrv serial device.** Decrements the counter of open paths to device and alerts the driver * with an ioctl call when the count reaches zero. This scheme is used to* implement the HUPCL(hang up on last close).      */LOCAL int usbMseClose    (    USB_MSE_DEV	* pUsbMseDev          /* mouse device to read from */    )    {    /* if there are no open channels */    if (!(--pUsbMseDev->numOpen))	{	sioIoctl (pUsbMseDev->pSioChan, SIO_HUP, NULL);	}    return ((int) pUsbMseDev);    }/********************************************************************************* usbMseIoctl - issue device control commands** This routine issues device control commands to an USB mouse device.** RETURNS: depends on the function invoked.*/LOCAL int usbMseIoctl    (    USB_MSE_DEV	* pUsbMseDev,	/* mouse device to read from */    int		request,	/* request code */    void *	arg		/* some argument */    )    {    return (sioIoctl (pUsbMseDev->pSioChan, request, arg));    }/********************************************************************************* usbMseRead - read from the USB mouse** This routines is a no-op for a read from the USB mouse.** RETURNS: OK, always.*/LOCAL int usbMseRead    (    USB_MSE_DEV	* pUsbMseDev,           /* mouse device to read from */    UCHAR *buffer,     UINT32 nBytes        )    {    int		status = OK;		/* holder for the return value */    memcpy(buffer, pReportlocal, nBytes);/*    This shows the mouse coordinate    logMsg("\rx:%5ld  y:%5ld  button:%d   "             pReportlocal->xDisplacement, pReportlocal->xDisplacement,             pReportlocal->buttonState            ,0,0,0);*/    return (sizeof(HID_MSE_BOOT_REPORT));    }/********************************************************************************* usbMseWrite - write to the USB mouse** * USB mice don't like to be written to.  The don't support this feature.** RETURNS: ENOSYS*/int usbMseWrite    (    USB_MSE_DEV	* pUsbMseDev,		/* mouse device to read from */    UCHAR	* buffer,		/* buffer of data to write  */    UINT32	  nBytes		/* number of bytes in buffer */    )    {    return (ENOSYS);    }/*************************************************************************** usbMseTxCallback - feeds characters to USB mouse SIO driver** USB mice don't like to be written to.  The don't support this feature.** RETURNS: OK*/LOCAL STATUS usbMseTxCallback    (    void *callbackParam,    char *txChar    )    {    return ENOSYS;    }/*************************************************************************** usbMseRptCallback - invoked when reports received from mouse** The mouse returns 3 bytes.  The first two describe its x, y displacement * from its previous position.  The third describes the button state * of its 3 buttons.** In the third byte the first 3 bits represent the state of the buttons as * follows:  bit 1 = the middle button, bit 2 = the left button and bit 3 =* the right button.* * These three bytes are containied in a HID_MSE_BOOT_REPORT structure.  * this fucntion copys these 3 bytes into a local copy that can be accessed* with the mouse read routine.  *** RETURNS: OK*/LOCAL STATUS usbMseRptCallback	(	void *putReportArg,	pHID_MSE_BOOT_REPORT pReport	)	{	memcpy(pReportlocal, pReport, sizeof(HID_MSE_BOOT_REPORT));	return OK;	}/******************************************************************************* usrUsbMseInit - initialize the USB mouse driver** This function initializes the USB mouse driver and registers for attach * callbacks.  ** RETURNS: Nothing */void usrUsbMseInit (void)     {    /* Check if driver already installed */    if (usbMseDrvNum > 0)	{	printf ("Mouse already initilaized.\n");	}    if (usbMouseDevInit () == OK)	{        printf ("usbMouseDevInit() returned OK\n");		if (usbMouseDynamicAttachRegister (mseAttachCallback, 					   (void *) NULL) 					  != OK)	    {	    printf ("usbMouseDynamicAttachRegister() returned ERROR\n");	    }	}    else        printf ("usbMouseDevInit() returned ERROR\n");    }

⌨️ 快捷键说明

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