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

📄 drvusb.c

📁 cortex-m0 LCD1602程序
💻 C
📖 第 1 页 / 共 5 页
字号:
        /* Pre-dispatch bus event. */
        DrvUSB_PreDispatchBusEvent(&gsUsbDevice);
    }
    else if (gsUsbDevice.u32INTSTS & INTSTS_USB)
    {
        gsUsbDevice.u32EPSTS = _DRVUSB_GET_EPSTS();
        
        /* Clear USB events individually instead of in total.
           Otherwise, incoming USB events may be cleared mistakenly.
           Pre-dispatch USB event. */
        DrvUSB_PreDispatchEPEvent(&gsUsbDevice);
    }
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_DispatchEvent                                                                          */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*      None                                                                                               */
/*                                                                                                         */
/* Returns:                                                                                                */
/*      None                                                                                               */
/*                                                                                                         */
/* Description:                                                                                            */
/*      Dispatch Misc and EP event                                                                         */
/*      Misc event include  attach/detach/bus reset/bus suspend/                                           */
/*      bus resume and setup ACK, Misc event'handler is g_sBusOps[]                                        */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUSB_DispatchEvent(void)
{
    DrvUSB_DispatchMiscEvent(&gsUsbDevice);
    DrvUSB_DispatchEPEvent(&gsUsbDevice);
}

/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_IsData0                                                                                */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*      u32EpId   [in]  EP Id. The hardware id of specified endpoint                                       */
/*                                                                                                         */
/* Returns:                                                                                                */
/*      None                                                                                               */
/*                                                                                                         */
/* Description:                                                                                            */
/*      To check if the current DATA is DATA0. If it is false, then it                                     */
/*      should be DATA1.                                                                                   */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvUSB_IsData0(uint32_t u32EpId)
{
    int32_t bData0 = 0;

    if (u32EpId >= MAX_EP_ID)
    {
        bData0 = 0;
    }
    else
    {
        bData0 = gsUsbDevice.abData0[u32EpId];
    }

    return bData0;
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_GetUsbState                                                                            */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*      None                                                                                               */
/*                                                                                                         */
/* Returns:                                                                                                */
/*      None                                                                                               */
/*                                                                                                         */
/* Description:                                                                                            */
/*      Get current USB state E_DRVUSB_STATE                                                               */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
E_DRVUSB_STATE DrvUSB_GetUsbState(void)
{
    return (E_DRVUSB_STATE)gsUsbDevice.eUsbState;
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_SetUsbState                                                                            */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*      eUsbState   [in]  The wanted state                                                                 */
/*                                                                                                         */
/* Returns:                                                                                                */
/*      None                                                                                               */
/*                                                                                                         */
/* Description:                                                                                            */
/*      Change current USB state                                                                           */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUSB_SetUsbState(E_DRVUSB_STATE eUsbState)
{
    gsUsbDevice.eUsbState = eUsbState;
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_Close                                                                                  */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*      None                                                                                               */
/*                                                                                                         */
/* Returns:                                                                                                */
/*      None                                                                                               */
/*                                                                                                         */
/* Description:                                                                                            */
/*      Close USB: uninstall interrupt handler, disable USB clock                                          */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
void DrvUSB_Close(void)
{    
    NVIC_DisableIRQ(USBD_IRQn);
    DrvUSB_UnInit();
}



/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_GetEpIdentity                                                                          */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*      u32EpNum   [in]   EP number                                                                        */
/*      u32EPAttr  [in]   EP_OUTPUT/EP_INPUT                                                               */
/*                                                                                                         */
/* Returns:                                                                                                */
/*      0~5         EP id                                                                                  */
/*      Otherwise   Error                                                                                  */
/*                                                                                                         */
/* Description:                                                                                            */
/*      Get endpoint id base on endpoint number and direction. The                                         */
/*      endpoint id is used to identify the hardware endpoint resource.                                    */
/*      The range of endpoint id could be 0 ~ 5. The endpoint number is                                    */
/*      assigned by software and it could be 0 ~ 15. Host will access                                      */
/*      the device through relative endpoint number.                                                       */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvUSB_GetEpIdentity(uint32_t u32EpNum, uint32_t u32EpAttr)
{
    uint32_t i;

    S_DRVUSB_DEVICE *psDevice =&gsUsbDevice;
    
    for ( i = 0; i < MAX_EP_ID; i++)
    {
        if (psDevice->sEpCrl[i].u32EpNum == (u32EpNum | u32EpAttr))
            return i;
    }
    
    return E_DRVUSB_INVALID_EP_NUM;

}


/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_GetEpId                                                                                */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*      u32EpNum     EP number. bit7 is used to define direction.                                          */
/*                   1 = IN endpoint, 0 = OUT endpoint.                                                    */
/*                                                                                                         */
/* Returns:                                                                                                */
/*      0~5         EP id                                                                                  */
/*      Otherwise   Error                                                                                  */
/*                                                                                                         */
/* Description:                                                                                            */
/*      Get EP id base on EP number                                                                        */
/*      This EP number is different from DrvUSB_GetEpIdentity's. Because                                   */
/*      its argument includes direction. eg: 0x81                                                          */
/*                                                                                                         */
/*---------------------------------------------------------------------------------------------------------*/
int32_t DrvUSB_GetEpId(uint32_t u32EpNum)
{
    uint32_t i;
    S_DRVUSB_DEVICE *psDevice =&gsUsbDevice;
    
    for ( i = 0; i < MAX_EP_ID; i++)
    {
        if (psDevice->sEpCrl[i].u32EpNum == u32EpNum)
            return i;
    }
    
    return E_DRVUSB_INVALID_EP_NUM; 
}


/*---------------------------------------------------------------------------------------------------------*/
/* Function: DrvUSB_DataOutTrigger                                                                         */
/*                                                                                                         */
/* Parameters:                                                                                             */
/*      u32EpNum      EP number                                                                            */
/*      u32Size       Max size want to receive from USB                                                    */
/*                                                                                                         */
/* Returns:                                                                                                */
/*      0           Success                                                                                */
/*      Otherwise   Error                                                                                  */
/*                                                                                                         */
/* Description:                                                                                            */
/*      Trigger data out ready flag by write MXPLD register                                                */

⌨️ 快捷键说明

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