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

📄 drvusb.h

📁 cortex-m0 LCD1602程序
💻 H
📖 第 1 页 / 共 2 页
字号:
#define USB_DATA_QUEUE_SIZE             16
#define USB_SRAM_ADDR g_UsbSramBase
#define USB_BUF_SETUP                   DrvUSB_GetSetupBuffer()

#define DRVUSB_EVENT_FLAG_ATTACH        0x00000001
#define DRVUSB_EVENT_FLAG_DETACH        0x00000002
#define DRVUSB_EVENT_FLAG_BUS_RESET     0x00000004
#define DRVUSB_EVENT_FLAG_BUS_SUSPEND   0x00000008
#define DRVUSB_EVENT_FLAG_BUS_RESUME    0x00000010
#define DRVUSB_EVENT_FLAG_SETUP         0x00000020
    
/*---------------------------------------------------------------------------------------------------------*/
/* USB Device state                                                                                        */
/*---------------------------------------------------------------------------------------------------------*/
typedef enum
{
    eDRVUSB_DETACHED    = 0,
    eDRVUSB_ATTACHED    = 0x00000001,
    eDRVUSB_POWERED     = eDRVUSB_ATTACHED + 0x00000002,
    eDRVUSB_DEFAULT     = eDRVUSB_POWERED  + 0x00000004,
    eDRVUSB_ADDRESS     = eDRVUSB_DEFAULT  + 0x00000008,
    eDRVUSB_CONFIGURED  = eDRVUSB_ADDRESS  + 0x00000010,
    eDRVUSB_SUSPENDED   = 0x00000020

} E_DRVUSB_STATE;


/*---------------------------------------------------------------------------------------------------------*/
/* USB Vender_info descriptor structure                                                                    */
/*---------------------------------------------------------------------------------------------------------*/
typedef struct
{
    uint8_t byLength;
    uint8_t byDescType;
    uint16_t au16UnicodeString[100];
    
} S_DRVUSB_STRING_DESC;

typedef S_DRVUSB_STRING_DESC    S_STRING_DESC;

typedef struct
{
    uint16_t u16VendorId;
    uint16_t u16ProductId;
    const S_DRVUSB_STRING_DESC *psVendorStringDesc;
    const S_DRVUSB_STRING_DESC *psProductStringDesc;

} S_DRVUSB_VENDOR_INFO;

typedef S_DRVUSB_VENDOR_INFO    S_VENDOR_INFO;


/*---------------------------------------------------------------------------------------------------------*/
/* Typedef USB Callback function                                                                           */
/*---------------------------------------------------------------------------------------------------------*/
typedef void (*PFN_DRVUSB_ATTACH_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_DETACH_CALLBACK)(void *);

typedef void (*PFN_DRVUSB_BUS_RESET_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_BUS_SUSPEND_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_BUS_RESUME_CALLBACK)(void *);

typedef void (*PFN_DRVUSB_SETUP_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_EP_IN_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_EP_OUT_CALLBACK)(void *);

typedef void (*PFN_DRVUSB_CTRL_SETUP_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_CTRL_DATA_IN_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_CTRL_DATA_OUT_CALLBACK)(void *);


/*---------------------------------------------------------------------------------------------------------*/
/* Typedef ISR USB Callback function                                                                       */
/*---------------------------------------------------------------------------------------------------------*/
typedef void (*PFN_DRVUSB_ISR_ATTACH_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_ISR_DETACH_CALLBACK)(void *);

typedef void (*PFN_DRVUSB_ISR_BUS_RESET_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_ISR_BUS_SUSPEND_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_ISR_BUS_RESUME_CALLBACK)(void *);

typedef void (*PFN_DRVUSB_ISR_SETUP_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_ISR_EP_IN_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_ISR_EP_OUT_CALLBACK)(void *);

typedef void (*PFN_DRVUSB_CALLBACK)(void *);
typedef void (*PFN_DRVUSB_INTCALLBACK)(void *);
typedef int32_t (*PFN_DRVUSB_COMPARE)(uint8_t);


/*---------------------------------------------------------------------------------------------------------*/
/* USB Control callback function structure                                                                 */
/*---------------------------------------------------------------------------------------------------------*/
typedef struct
{
    uint8_t u8RequestType;
    uint8_t u8Request;
    PFN_DRVUSB_CTRL_SETUP_CALLBACK      pfnCtrlSetupCallback;
    PFN_DRVUSB_CTRL_DATA_IN_CALLBACK    pfnCtrlDataInCallback;
    PFN_DRVUSB_CTRL_DATA_OUT_CALLBACK   pfnCtrlDataOutCallback;
    void *                              pVoid;
} S_DRVUSB_CTRL_CALLBACK_ENTRY;

typedef struct
{
    int32_t                             bReg;
    S_DRVUSB_CTRL_CALLBACK_ENTRY        sCtrlCallbackEntry;
} S_DRVUSB_CTRL_CALLBACK_ENTRY_REG;


/*---------------------------------------------------------------------------------------------------------*/
/* EP ctrl structure. USB class must implement this structure                                              */
/*---------------------------------------------------------------------------------------------------------*/
typedef struct
{
    uint32_t u32EpNum;
    uint32_t u32MaxPacketSize; 
    uint8_t *u8SramBuffer;
}S_DRVUSB_EP_CTRL;


/*---------------------------------------------------------------------------------------------------------*/
/* Misc and USB event call back function                                                                   */
/*---------------------------------------------------------------------------------------------------------*/
typedef struct
{
    PFN_DRVUSB_CALLBACK apfnCallback;
    void *              apCallbackArgu;
}S_DRVUSB_EVENT_PROCESS;


/*---------------------------------------------------------------------------------------------------------*/
/* The interface between USB class and USB driver                                                          */
/* USB class implement this structure and register to USB driver                                           */
/*---------------------------------------------------------------------------------------------------------*/
typedef struct
{
    void * device;
    PFN_DRVUSB_CALLBACK pfnStart;       /* The callback function when set configuration or set interface */
    PFN_DRVUSB_COMPARE  pfnCompare;
    void * pVoid;
}S_DRVUSB_CLASS;


/*---------------------------------------------------------------------------------------------------------*/
/* USB driver device                                                                                       */
/*---------------------------------------------------------------------------------------------------------*/
typedef struct
{
    uint32_t u32ATTR;
    uint32_t u32EPSTS;
    uint32_t u32FLDET;
    uint32_t u32INTSTS;

    int32_t  abData0[MAX_EP_ID];  /* Index is EP identity   */
    S_DRVUSB_EP_CTRL sEpCrl[MAX_EP_ID+1];
    int32_t  eUsbState;           /* E_DRVUSB_STATE */

    uint16_t u16MiscEventFlags;

    uint16_t u16EPEventFlags;

    S_DRVUSB_CTRL_CALLBACK_ENTRY    *pCtrlCallback;
    uint32_t CtrlCallbackSize;
    uint8_t  au8Setup[8];
    uint8_t  u8UsbAddress;
    uint8_t  u8UsbConfiguration;
        
    int32_t  bSelfPowered;  /* TRUE : Self-Powereded, FALSE : BUS-Powereded */
    int32_t  bRemoteWakeup; /* TRUE : Support RemoteWakeup, FALSE : no support */
    uint8_t  u8MaxPower;        /* Maximum MaxPower 0xFA (500mA), default is 0x32 (100mA) */
        
    S_DRVUSB_CLASS *psUsbClass;
} S_DRVUSB_DEVICE;


/* EP ctrl structure;descript EP */
extern S_DRVUSB_EP_CTRL sEpDescription[];
/* BUS event call back function; USB class must implement */
extern S_DRVUSB_EVENT_PROCESS g_sBusOps[];
/* USB event call back function; USB class must implement */
extern S_DRVUSB_EVENT_PROCESS g_sUsbOps[];
extern uint32_t CFG_EP_SETTING[6];  /* CFGx register setting value */
extern PFN_DRVUSB_INTCALLBACK g_FnIntCallBack;  /* Interrupt call back  */
extern S_DRVUSB_DEVICE gsUsbDevice;


/*---------------------------------------------------------------------------------------------------------*/
/* Get/Set USB device state                                                                                */
/*---------------------------------------------------------------------------------------------------------*/
/* DATA0 or DATA1 Out transaction when Data Out ACK happens */
int32_t DrvUSB_IsData0Out(uint32_t u32EpId);

/* Get USB device state. */
E_DRVUSB_STATE DrvUSB_GetUsbState(void);

/* Set USB device state. */
void DrvUSB_SetUsbState(E_DRVUSB_STATE eUsbState);


/*---------------------------------------------------------------------------------------------------------*/
/* Define DrvUSB READ/WRITE USB BUFFER                                                                     */
/*---------------------------------------------------------------------------------------------------------*/
#define _DRVUSB_READ_USB_BUF(UsbBuf, Mem, Len) \
    memcpy ((void *) (Mem), (void *) (UsbBuf), (Len))

#define _DRVUSB_WRITE_USB_BUF(UsbBuf, Mem, Len) \
    memcpy ((void *) (UsbBuf), (void *) (Mem), (Len))


/*---------------------------------------------------------------------------------------------------------*/
/* APIs declare                                                                                            */
/*---------------------------------------------------------------------------------------------------------*/
uint32_t DrvUSB_GetVersion(void);
int32_t  DrvUSB_Open(void * pVoid);
void     DrvUSB_PreDispatchEvent(void);
void     DrvUSB_DispatchEvent(void);
void     DrvUSB_Close(void);
void     DrvUSB_BusResetCallback(void * pVoid);
uint32_t DrvUSB_GetSetupBuffer(void);
void *   DrvUSB_InstallClassDevice(S_DRVUSB_CLASS *sUsbClass);
int32_t  DrvUSB_InstallCtrlHandler(void * *device, S_DRVUSB_CTRL_CALLBACK_ENTRY *psCtrlCallbackEntry, uint32_t u32RegCnt);
int32_t  DrvUSB_DataOutTrigger(uint32_t u32EpNum, uint32_t u32Size);
uint8_t* DrvUSB_GetOutData(uint32_t u32EpNum, uint32_t *u32Size);
int32_t  DrvUSB_DataIn(uint32_t u32EpNum, const uint8_t * u8Buffer, uint32_t u32Size);
void     DrvUSB_CtrlSetupAck(void * pArgu);
void     DrvUSB_CtrlDataInAck(void * pArgu);
void     DrvUSB_CtrlDataOutAck(void * pArgu);
void     DrvUSB_ClrCtrlReady(void);
void     DrvUSB_ClrCtrlReadyAndTrigStall(void);
void     DrvUSB_CtrlDataInDefault(void * pVoid);
void     DrvUSB_CtrlDataOutDefault(void * pVoid);
void     DrvUSB_Reset(uint32_t u32EpNum);
int32_t DrvUSB_GetEpId(uint32_t u32EpNum);
int32_t DrvUSB_GetEpIdentity(uint32_t u32EpNum, uint32_t u32EPAttr);
void     DrvUSB_EnableRemoteWakeup(void);
void     DrvUSB_DisableRemoteWakeup(void);
void     DrvUSB_EnableSelfPower (void);
void     DrvUSB_DisableSelfPower (void);
int32_t  DrvUSB_IsSelfPowerEnabled (void);          /* TRUE : Self-Powereded, FALSE : BUS-Powereded */
void     DrvUSB_EnableRemoteWakeup(void);
void     DrvUSB_DisableRemoteWakeup(void);
int32_t  DrvUSB_IsRemoteWakeupEnabled (void);       /* TRUE : Support RemoteWakeup, FALSE : not support */
int32_t  DrvUSB_SetMaxPower(uint32_t u32MaxPower);  /* Maximum MaxPower 0xFA (500mA), default is 0x32 (100mA) */
int32_t  DrvUSB_GetMaxPower(void);                  /* Maximum MaxPower 0xFA (500mA), default is 0x32 (100mA)   */

void DrvUSB_CtrlSetupSetAddress(void * pVoid);
void DrvUSB_CtrlSetupClearSetFeature(void * pVoid);
void DrvUSB_CtrlSetupGetConfiguration(void * pVoid);
void DrvUSB_CtrlSetupGetStatus(void * pVoid);
void DrvUSB_CtrlSetupGetInterface(void * pVoid);
void DrvUSB_CtrlSetupSetInterface(void * pVoid);
void DrvUSB_CtrlSetupSetConfiguration(void * pVoid);
void DrvUSB_CtrlDataInSetAddress(void * pVoid);

uint32_t DrvUSB_GetVersion(void);
int32_t DrvUSB_IsData0(uint32_t u32EpId);

void DrvUSB_EnableUsb(S_DRVUSB_DEVICE *psDevice);
void DrvUSB_DisableUsb(S_DRVUSB_DEVICE *psDevice);
void DrvUSB_PreDispatchWakeupEvent(S_DRVUSB_DEVICE *psDevice);
void DrvUSB_PreDispatchFDTEvent(S_DRVUSB_DEVICE *psDevice);
void DrvUSB_PreDispatchEPEvent(S_DRVUSB_DEVICE *psDevice);
void DrvUSB_PreDispatchBusEvent(S_DRVUSB_DEVICE *psDevice);
void DrvUSB_DispatchWakeupEvent(S_DRVUSB_DEVICE *psDevice);
void DrvUSB_DispatchMiscEvent(S_DRVUSB_DEVICE *psDevice);
void DrvUSB_DispatchEPEvent(S_DRVUSB_DEVICE *psDevice);
void DrvUSB_memcpy(uint8_t *pi8Dest, uint8_t *pi8Src, uint32_t u32Size);
uint32_t DrvUSB_GetFreeSRAM(void);
    
#ifdef __cplusplus
}
#endif

#endif 



⌨️ 快捷键说明

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