44#define USBD_BUF_BASE (USBD_BASE+0x100)
58#define REQ_STANDARD 0x00
60#define REQ_VENDOR 0x40
63#define GET_STATUS 0x00
64#define CLEAR_FEATURE 0x01
65#define SET_FEATURE 0x03
66#define SET_ADDRESS 0x05
67#define GET_DESCRIPTOR 0x06
68#define SET_DESCRIPTOR 0x07
69#define GET_CONFIGURATION 0x08
70#define SET_CONFIGURATION 0x09
71#define GET_INTERFACE 0x0A
72#define SET_INTERFACE 0x0B
73#define SYNC_FRAME 0x0C
76#define DESC_DEVICE 0x01
77#define DESC_CONFIG 0x02
78#define DESC_STRING 0x03
79#define DESC_INTERFACE 0x04
80#define DESC_ENDPOINT 0x05
81#define DESC_QUALIFIER 0x06
82#define DESC_OTHERSPEED 0x07
86#define DESC_HID_RPT 0x22
91#define LEN_INTERFACE 9
102#define EP_OUTPUT 0x00
105#define FEATURE_DEVICE_REMOTE_WAKEUP 0x01
106#define FEATURE_ENDPOINT_HALT 0x00
112#define USBD_WAKEUP_EN USBD_INTEN_WKEN_Msk
113#define USBD_DRVSE0 USBD_SE0_SE0_Msk
115#define USBD_DPPU_EN USBD_ATTR_DPPUEN_Msk
116#define USBD_PWRDN USBD_ATTR_PWRDN_Msk
117#define USBD_PHY_EN USBD_ATTR_PHYEN_Msk
118#define USBD_USB_EN USBD_ATTR_USBEN_Msk
120#define USBD_INT_BUS USBD_INTEN_BUSIEN_Msk
121#define USBD_INT_USB USBD_INTEN_USBIEN_Msk
122#define USBD_INT_FLDET USBD_INTEN_VBDETIEN_Msk
123#define USBD_INT_WAKEUP (USBD_INTEN_NEVWKIEN_Msk | USBD_INTEN_WKEN_Msk)
125#define USBD_INTSTS_WAKEUP USBD_INTSTS_NEVWKIF_Msk
126#define USBD_INTSTS_FLDET USBD_INTSTS_VBDETIF_Msk
127#define USBD_INTSTS_BUS USBD_INTSTS_BUSIF_Msk
128#define USBD_INTSTS_USB USBD_INTSTS_USBIF_Msk
129#define USBD_INTSTS_SETUP USBD_INTSTS_SETUP_Msk
130#define USBD_INTSTS_EP0 USBD_INTSTS_EPEVT0_Msk
131#define USBD_INTSTS_EP1 USBD_INTSTS_EPEVT1_Msk
132#define USBD_INTSTS_EP2 USBD_INTSTS_EPEVT2_Msk
133#define USBD_INTSTS_EP3 USBD_INTSTS_EPEVT3_Msk
134#define USBD_INTSTS_EP4 USBD_INTSTS_EPEVT4_Msk
135#define USBD_INTSTS_EP5 USBD_INTSTS_EPEVT5_Msk
136#define USBD_INTSTS_EP6 USBD_INTSTS_EPEVT6_Msk
137#define USBD_INTSTS_EP7 USBD_INTSTS_EPEVT7_Msk
139#define USBD_STATE_USBRST USBD_ATTR_USBRST_Msk
140#define USBD_STATE_SUSPEND USBD_ATTR_SUSPEND_Msk
141#define USBD_STATE_RESUME USBD_ATTR_RESUME_Msk
142#define USBD_STATE_TIMEOUT USBD_ATTR_TOUT_Msk
144#define USBD_CFGP_SSTALL USBD_CFGP_SSTALL_Msk
145#define USBD_CFG_CSTALL USBD_CFG_CSTALL_Msk
147#define USBD_CFG_EPMODE_DISABLE (0ul << USBD_CFG_STATE_Pos)
148#define USBD_CFG_EPMODE_OUT (1ul << USBD_CFG_STATE_Pos)
149#define USBD_CFG_EPMODE_IN (2ul << USBD_CFG_STATE_Pos)
150#define USBD_CFG_TYPE_ISO (1ul << USBD_CFG_ISOCH_Pos)
171#define Maximum(a,b) ((a)>(b) ? (a) : (b))
184#define Minimum(a,b) ((a)<(b) ? (a) : (b))
197#define USBD_ENABLE_USB() ((uint32_t)(USBD->ATTR |= (USBD_USB_EN|USBD_PHY_EN)))
209#define USBD_DISABLE_USB() ((uint32_t)(USBD->ATTR &= ~USBD_USB_EN))
221#define USBD_ENABLE_PHY() ((uint32_t)(USBD->ATTR |= USBD_PHY_EN))
233#define USBD_DISABLE_PHY() ((uint32_t)(USBD->ATTR &= ~USBD_PHY_EN))
245#define USBD_SET_SE0() ((uint32_t)(USBD->SE0 |= USBD_DRVSE0))
257#define USBD_CLR_SE0() ((uint32_t)(USBD->SE0 &= ~USBD_DRVSE0))
269#define USBD_SET_ADDR(addr) (USBD->FADDR = (addr))
281#define USBD_GET_ADDR() ((uint32_t)(USBD->FADDR))
296#define USBD_ENABLE_INT(intr) (USBD->INTEN |= (intr))
308#define USBD_GET_INT_FLAG() ((uint32_t)(USBD->INTSTS))
323#define USBD_CLR_INT_FLAG(flag) (USBD->INTSTS = (flag))
335#define USBD_GET_EP_FLAG() ((uint32_t)(USBD->EPSTS))
351#define USBD_GET_BUS_STATE() ((uint32_t)(USBD->ATTR & 0xf))
364#define USBD_IS_ATTACHED() ((uint32_t)(USBD->VBUSDET & USBD_VBUSDET_VBUSDET_Msk))
376#define USBD_STOP_TRANSACTION(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) |= USBD_CFGP_CLRRDY_Msk)
389#define USBD_SET_DATA1(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) |= USBD_CFG_DSQSYNC_Msk)
402#define USBD_SET_DATA0(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) &= (~USBD_CFG_DSQSYNC_Msk))
416#define USBD_SET_PAYLOAD_LEN(ep, size) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))) = (size))
428#define USBD_GET_PAYLOAD_LEN(ep) ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].MXPLD + (uint32_t)((ep) << 4))))
442#define USBD_CONFIG_EP(ep, config) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFG + (uint32_t)((ep) << 4))) = (config))
456#define USBD_SET_EP_BUF_ADDR(ep, offset) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))) = (offset))
468#define USBD_GET_EP_BUF_ADDR(ep) ((uint32_t)*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].BUFSEG + (uint32_t)((ep) << 4))))
480#define USBD_SET_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) |= USBD_CFGP_SSTALL_Msk)
491#define USBD_CLR_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) &= ~USBD_CFGP_SSTALL_Msk)
504#define USBD_GET_EP_STALL(ep) (*((__IO uint32_t *) ((uint32_t)&USBD->EP[0].CFGP + (uint32_t)((ep) << 4))) & USBD_CFGP_SSTALL_Msk)
520static __INLINE
void USBD_MemCopy(uint8_t *dest, uint8_t *src, int32_t size)
522 while(size--) *dest++ = *src++;
544 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&
USBD->EP[0].CFG;
545 u32Cfg = *((__IO uint32_t *)(u32CfgAddr));
547 if((u32Cfg & 0xf) == epnum)
549 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&
USBD->EP[0].CFGP;
550 u32Cfg = *((__IO uint32_t *)(u32CfgAddr));
575 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&
USBD->EP[0].CFG;
576 u32Cfg = *((__IO uint32_t *)(u32CfgAddr));
578 if((u32Cfg & 0xf) == epnum)
580 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&
USBD->EP[0].CFGP;
581 u32Cfg = *((__IO uint32_t *)(u32CfgAddr));
608 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&
USBD->EP[0].CFG;
609 u32Cfg = *((__IO uint32_t *)(u32CfgAddr));
611 if((u32Cfg & 0xf) == epnum)
613 u32CfgAddr = (uint32_t)(i << 4) + (uint32_t)&
USBD->EP[0].CFGP;
void USBD_Open(const S_USBD_INFO_T *param, CLASS_REQ pfnClassReq, SET_INTERFACE_REQ pfnSetInterface)
This function makes USBD module to be ready to use.
void USBD_LockEpStall(uint32_t u32EpBitmap)
EP stall lock function to avoid stall clear by USB SET FEATURE request.
void USBD_StandardRequest(void)
Process standard request.
const uint32_t * gu32ConfigHidDescIdx
volatile uint8_t g_usbd_RemoteWakeupEn
void USBD_PrepareCtrlOut(uint8_t *pu8Buf, uint32_t u32Size)
Prepare the first Control OUT pipe.
static __INLINE void USBD_SetStall(uint8_t epnum)
Set USB endpoint stall state.
static __INLINE uint32_t USBD_GetStall(uint8_t epnum)
Get USB endpoint stall state.
void USBD_GetSetupPacket(uint8_t *buf)
Get the received SETUP packet.
static __INLINE void USBD_ClearStall(uint8_t epnum)
Clear USB endpoint stall state.
void USBD_Start(void)
This function makes USB host to recognize the device.
void USBD_SwReset(void)
Reset software flags.
void USBD_PrepareCtrlIn(uint8_t *pu8Buf, uint32_t u32Size)
Prepare the first Control IN pipe.
void USBD_CtrlIn(void)
Repeat Control IN pipe.
void USBD_SetConfigCallback(SET_CONFIG_CB pfnSetConfigCallback)
The callback function which called when get SET CONFIGURATION request.
static __INLINE void USBD_MemCopy(uint8_t *dest, uint8_t *src, int32_t size)
To support byte access between USB SRAM and system SRAM.
void USBD_SetVendorRequest(VENDOR_REQ pfnVendorReq)
USBD Set Vendor Request.
void USBD_ProcessSetupPacket(void)
Process SETUP packet.
void(* SET_INTERFACE_REQ)(void)
const uint8_t * gu8ConfigDesc
const uint8_t * gu8DevDesc
const uint32_t * gu32HidReportSize
void(* SET_CONFIG_CB)(void)
const uint8_t ** gu8HidReportDesc
void USBD_CtrlOut(void)
Repeat Control OUT pipe.
const uint8_t ** gu8StringDesc
struct s_usbd_info S_USBD_INFO_T
const S_USBD_INFO_T gsInfo