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

📄 usbmouselib.c

📁 T2.0 USB driver.rar T2.0 USB driver.rar
💻 C
📖 第 1 页 / 共 3 页
字号:
    }/***************************************************************************** initMseIrp - Initialize IRP to listen for input on interrupt pipe** RETURNS: TRUE if able to submit IRP successfully, else FALSE*/LOCAL BOOL initMseIrp    (    pUSB_MSE_SIO_CHAN pSioChan    )    {    pUSB_IRP pIrp = &pSioChan->irp;    /* Initialize IRP */    memset (pIrp, 0, sizeof (*pIrp));    pIrp->userPtr = pSioChan;    pIrp->irpLen = sizeof (*pIrp);    pIrp->userCallback = usbMouseIrpCallback;    pIrp->timeout = USB_TIMEOUT_NONE;    pIrp->transferLen = sizeof (HID_MSE_BOOT_REPORT);    pIrp->bfrCount = 1;    pIrp->bfrList [0].pid = USB_PID_IN;    pIrp->bfrList [0].pBfr = pSioChan->pIrpBfr;    pIrp->bfrList [0].bfrLen =     min (pSioChan->intMaxPacketSize, HID_BOOT_REPORT_MAX_LEN);    /* Submit IRP */    if (usbdTransfer (usbdHandle, pSioChan->pipeHandle, pIrp) != OK)    return FALSE;    pSioChan->irpInUse = TRUE;    return TRUE;    }/***************************************************************************** usbMouseIrpCallback - Invoked upon IRP completion/cancellation** Examines the cause of the IRP completion.  If completion was successful,* interprets the USB mouse's boot report and re-submits the IRP.** RETURNS: N/A*/LOCAL VOID usbMouseIrpCallback    (    pVOID p	    /* completed IRP */    )    {    pUSB_IRP pIrp = (pUSB_IRP) p;    pUSB_MSE_SIO_CHAN pSioChan = pIrp->userPtr;    OSS_MUTEX_TAKE (mseMutex, OSS_BLOCK);    /* Was the IRP successful? */    if (pIrp->result == OK)    {    /* Interpret the mouse report */    interpMseReport (pSioChan);    }    /* Re-submit the IRP unless it was canceled - which would happen only     * during pipe shutdown (e.g., the disappearance of the device).     */    pSioChan->irpInUse = FALSE;    if (pIrp->result != S_usbHcdLib_IRP_CANCELED)    initMseIrp (pSioChan);    OSS_MUTEX_RELEASE (mseMutex);    }/***************************************************************************** configureSioChan - configure USB mouse for operation** Selects the configuration/interface specified in the <pSioChan>* structure.  These values come from the USBD dynamic attach callback,* which in turn retrieved them from the configuration/interface* descriptors which reported the device to be a mouse.** RETURNS: TRUE if successful, else FALSE if failed to configure channel*/LOCAL BOOL configureSioChan    (    pUSB_MSE_SIO_CHAN pSioChan    )    {    pUSB_CONFIG_DESCR pCfgDescr;    pUSB_INTERFACE_DESCR pIfDescr;    pUSB_ENDPOINT_DESCR pEpDescr;    UINT8 bfr [USB_MAX_DESCR_LEN];    pUINT8 pBfr;    UINT16 actLen;    UINT16 ifNo;    /* Read the configuration descriptor to get the configuration selection     * value and to determine the device's power requirements.     */    if (usbdDescriptorGet (usbdHandle, pSioChan->nodeId,    USB_RT_STANDARD | USB_RT_DEVICE, USB_DESCR_CONFIGURATION, 0, 0,    sizeof (bfr), bfr, &actLen) != OK)    return FALSE;    if ((pCfgDescr = usbDescrParse (bfr, actLen, USB_DESCR_CONFIGURATION))     == NULL)    return FALSE;    /* Look for the interface indicated in the pSioChan structure. */    ifNo = 0;    pBfr = bfr;    while ((pIfDescr = usbDescrParseSkip (&pBfr, &actLen, USB_DESCR_INTERFACE))     != NULL)    {    if (ifNo == pSioChan->interface)	break;    ifNo++;    }    if (pIfDescr == NULL)    return FALSE;    /* Retrieve the endpoint descriptor following the identified interface     * descriptor.     */    if ((pEpDescr = usbDescrParseSkip (&pBfr, &actLen, USB_DESCR_ENDPOINT))    == NULL)    return FALSE;    /* Select the configuration. */    if (usbdConfigurationSet (usbdHandle, pSioChan->nodeId,    pCfgDescr->configurationValue,     pCfgDescr->maxPower * USB_POWER_MA_PER_UNIT) != OK)    return FALSE;    /* Select interface      *      * NOTE: Some devices may reject this command, and this does not represent     * a fatal error.  Therefore, we ignore the return status.     */    usbdInterfaceSet (usbdHandle, pSioChan->nodeId,    pSioChan->interface, pIfDescr->alternateSetting);    /* Select the mouse boot protocol. */    if (usbHidProtocolSet (usbdHandle, pSioChan->nodeId,    pSioChan->interface, USB_HID_PROTOCOL_BOOT) != OK)    return FALSE;    /* Set the mouse idle time to infinite. */    if (usbHidIdleSet (usbdHandle, pSioChan->nodeId,    pSioChan->interface, 0 /* no report ID */, 0 /* infinite */) != OK)    return FALSE;    /* Create a pipe to monitor input reports from the mouse. */    pSioChan->intMaxPacketSize = *((pUINT8) &pEpDescr->maxPacketSize) |    (*(((pUINT8) &pEpDescr->maxPacketSize) + 1) << 8);    if (usbdPipeCreate (usbdHandle, pSioChan->nodeId,     pEpDescr->endpointAddress, pCfgDescr->configurationValue,    pSioChan->interface, USB_XFRTYPE_INTERRUPT, USB_DIR_IN,    pSioChan->intMaxPacketSize, sizeof (HID_MSE_BOOT_REPORT),     pEpDescr->interval, &pSioChan->pipeHandle) != OK)    return FALSE;    /* Initiate IRP to listen for input on interrupt pipe */    if (!initMseIrp (pSioChan))    return FALSE;    return TRUE;    }/***************************************************************************** destroyAttachRequest - disposes of an ATTACH_REQUEST structure** RETURNS: N/A*/LOCAL VOID destroyAttachRequest    (    pATTACH_REQUEST pRequest    )    {    /* Unlink request */    usbListUnlink (&pRequest->reqLink);    /* Dispose of structure */    OSS_FREE (pRequest);    }/***************************************************************************** destroySioChan - disposes of a USB_MSE_SIO_CHAN structure** Unlinks the indicated USB_MSE_SIO_CHAN structure and de-allocates* resources associated with the channel.** RETURNS: N/A*/LOCAL VOID destroySioChan    (    pUSB_MSE_SIO_CHAN pSioChan    )    {    /* Unlink the structure. */    usbListUnlink (&pSioChan->sioLink);    /* Release pipe if one has been allocated.	Wait for the IRP to be     * cancelled if necessary.     */    if (pSioChan->pipeHandle != NULL)    usbdPipeDestroy (usbdHandle, pSioChan->pipeHandle);    while (pSioChan->irpInUse)    OSS_THREAD_SLEEP (1);    /* Release structure. */    if (pSioChan->pIrpBfr != NULL)    OSS_FREE (pSioChan->pIrpBfr);    OSS_FREE (pSioChan);    }/***************************************************************************** createSioChan - creates a new USB_MSE_SIO_CHAN structure** Creates a new USB_MSE_SIO_CHAN structure for the indicated <nodeId>.* If successful, the new structure is linked into the sioList upon * return.** <configuration> and <interface> identify the configuration/interface* that first reported itself as a mouse for this device.** RETURNS: pointer to newly created structure, or NULL if failure*/LOCAL pUSB_MSE_SIO_CHAN createSioChan    (    USBD_NODE_ID nodeId,    UINT16 configuration,    UINT16 interface    )    {    pUSB_MSE_SIO_CHAN pSioChan;    /* Try to allocate space for a new mouse struct */    if ((pSioChan = OSS_CALLOC (sizeof (*pSioChan))) == NULL)    return NULL;    if ((pSioChan->pIrpBfr = OSS_MALLOC_ALIGN (    (HID_BOOT_REPORT_MAX_LEN + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE,     CACHE_LINE_SIZE, TRUE)) == NULL)    {    OSS_FREE (pSioChan);    return NULL;    }    pSioChan->sioChan.pDrvFuncs = &usbMouseSioDrvFuncs;    pSioChan->nodeId = nodeId;    pSioChan->connected = TRUE;    pSioChan->mode = SIO_MODE_INT;    pSioChan->configuration = configuration;    pSioChan->interface = interface;    pSioChan->pReport = (pHID_MSE_BOOT_REPORT) pSioChan->pIrpBfr;    /* Try to configure the mouse. */    if (!configureSioChan (pSioChan))    {    destroySioChan (pSioChan);    return NULL;    }    /* Link the newly created structure. */    usbListLink (&sioList, pSioChan, &pSioChan->sioLink, LINK_TAIL);    return pSioChan;    }/***************************************************************************** findSioChan - Searches for a USB_MSE_SIO_CHAN for indicated node ID** RETURNS: pointer to matching USB_MSE_SIO_CHAN or NULL if not found*/LOCAL pUSB_MSE_SIO_CHAN findSioChan    (    USBD_NODE_ID nodeId    )    {    pUSB_MSE_SIO_CHAN pSioChan = usbListFirst (&sioList);    while (pSioChan != NULL)    {    if (pSioChan->nodeId == nodeId)	break;    pSioChan = usbListNext (&pSioChan->sioLink);    }    return pSioChan;    }/***************************************************************************** notifyAttach - Notifies registered callers of attachment/removal** RETURNS: N/A*/LOCAL VOID notifyAttach    (    pUSB_MSE_SIO_CHAN pSioChan,    UINT16 attachCode    )    {    pATTACH_REQUEST pRequest = usbListFirst (&reqList);    while (pRequest != NULL)    {    (*pRequest->callback) (pRequest->callbackArg, 	(SIO_CHAN *) pSioChan, attachCode);    pRequest = usbListNext (&pRequest->reqLink);    }    }/***************************************************************************** usbMouseAttachCallback - called by USBD when mouse attached/removed** The USBD will invoke this callback when a USB mouse is attached to or* removed from the system.  <nodeId> is the USBD_NODE_ID of the node being* attached or removed.	<attachAction> is USBD_DYNA_ATTACH or USBD_DYNA_REMOVE.* Mice generally report their class information at the interface level,* so <configuration> and <interface> will indicate the configuratin/interface* that reports itself as a mouse.  Finally, <deviceClass>, <deviceSubClass>,* and <deviceProtocol> will identify a HID/BOOT/KEYBOARD device.** NOTE: The USBD will invoke this function once for each configuration/* interface which reports itself as a mouse.  So, it is possible that* a single device insertion/removal may trigger multiple callbacks.  We* ignore all callbacks except the first for a given device.** RETURNS: N/A*/LOCAL VOID usbMouseAttachCallback    (    USBD_NODE_ID nodeId,     UINT16 attachAction,     UINT16 configuration,    UINT16 interface,    UINT16 deviceClass,     UINT16 deviceSubClass,     UINT16 deviceProtocol    )    {    pUSB_MSE_SIO_CHAN pSioChan;

⌨️ 快捷键说明

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