35#define Maximum(a,b) (a)>(b) ? (a) : (b)
36#define Minimum(a,b) (a)<(b) ? (a) : (b)
54#define REQ_STANDARD 0x00
56#define REQ_VENDOR 0x40
59#define GET_STATUS 0x00
60#define CLEAR_FEATURE 0x01
61#define SET_FEATURE 0x03
62#define SET_ADDRESS 0x05
63#define GET_DESCRIPTOR 0x06
64#define SET_DESCRIPTOR 0x07
65#define GET_CONFIGURATION 0x08
66#define SET_CONFIGURATION 0x09
67#define GET_INTERFACE 0x0A
68#define SET_INTERFACE 0x0B
69#define SYNC_FRAME 0x0C
72#define DESC_DEVICE 0x01
73#define DESC_CONFIG 0x02
74#define DESC_STRING 0x03
75#define DESC_INTERFACE 0x04
76#define DESC_ENDPOINT 0x05
77#define DESC_QUALIFIER 0x06
78#define DESC_OTHERSPEED 0x07
79#define DESC_IFPOWER 0x08
84#define DESC_HID_RPT 0x22
88#define LEN_QUALIFIER 10
90#define LEN_INTERFACE 9
101#define EP_OUTPUT 0x00
104#define FEATURE_DEVICE_REMOTE_WAKEUP 0x01
105#define FEATURE_ENDPOINT_HALT 0x00
108#define USB_CEPCTL_NAKCLR ((uint32_t)0x00000000)
109#define USB_CEPCTL_STALL ((uint32_t)0x00000002)
110#define USB_CEPCTL_ZEROLEN ((uint32_t)0x00000004)
111#define USB_CEPCTL_FLUSH ((uint32_t)0x00000008)
114#define USB_EP_RSPCTL_FLUSH ((uint32_t)0x00000001)
115#define USB_EP_RSPCTL_MODE_AUTO ((uint32_t)0x00000000)
116#define USB_EP_RSPCTL_MODE_MANUAL ((uint32_t)0x00000002)
117#define USB_EP_RSPCTL_MODE_FLY ((uint32_t)0x00000004)
118#define USB_EP_RSPCTL_MODE_MASK ((uint32_t)0x00000006)
119#define USB_EP_RSPCTL_TOGGLE ((uint32_t)0x00000008)
120#define USB_EP_RSPCTL_HALT ((uint32_t)0x00000010)
121#define USB_EP_RSPCTL_ZEROLEN ((uint32_t)0x00000020)
122#define USB_EP_RSPCTL_SHORTTXEN ((uint32_t)0x00000040)
123#define USB_EP_RSPCTL_DISBUF ((uint32_t)0x00000080)
126#define USB_EP_CFG_VALID ((uint32_t)0x00000001)
127#define USB_EP_CFG_TYPE_BULK ((uint32_t)0x00000002)
128#define USB_EP_CFG_TYPE_INT ((uint32_t)0x00000004)
129#define USB_EP_CFG_TYPE_ISO ((uint32_t)0x00000006)
130#define USB_EP_CFG_TYPE_MASK ((uint32_t)0x00000006)
131#define USB_EP_CFG_DIR_OUT ((uint32_t)0x00000000)
132#define USB_EP_CFG_DIR_IN ((uint32_t)0x00000008)
171extern uint32_t g_u32EpStallLock;
172extern uint8_t g_usbd_Configured;
173extern uint8_t g_usbd_ShortPacket;
174extern uint8_t g_usbd_CtrlZero;
175extern uint8_t g_usbd_UsbAddr;
176extern uint8_t g_usbd_EpHalt[];
177extern uint32_t
volatile g_usbd_DmaDone;
178extern uint32_t g_usbd_CtrlInSize;
187#define USBD_ENABLE_USB() ((uint32_t)(USBD->PHYCTL |= (USBD_PHYCTL_PHYEN_Msk|USBD_PHYCTL_DPPUEN_Msk)))
188#define USBD_DISABLE_USB() ((uint32_t)(USBD->PHYCTL &= ~USBD_PHYCTL_DPPUEN_Msk))
189#define USBD_ENABLE_PHY() ((uint32_t)(USBD->PHYCTL |= (USBD_PHYCTL_PHYEN_Msk|USBD_PHYCTL_DPPUEN_Msk)))
190#define USBD_DISABLE_PHY() ((uint32_t)(USBD->PHYCTL &= ~USBD_PHYCTL_PHYEN_Msk))
191#define USBD_SET_SE0() ((uint32_t)(USBD->PHYCTL &= ~USBD_PHYCTL_DPPUEN_Msk))
192#define USBD_CLR_SE0() ((uint32_t)(USBD->PHYCTL |= USBD_PHYCTL_DPPUEN_Msk))
193#define USBD_SET_ADDR(addr) (USBD->FADDR = (addr))
194#define USBD_GET_ADDR() ((uint32_t)(USBD->FADDR))
195#define USBD_ENABLE_USB_INT(intr) (USBD->GINTEN = (intr))
196#define USBD_ENABLE_BUS_INT(intr) (USBD->BUSINTEN = (intr))
197#define USBD_GET_BUS_INT_FLAG() (USBD->BUSINTSTS)
198#define USBD_CLR_BUS_INT_FLAG(flag) (USBD->BUSINTSTS = flag)
199#define USBD_ENABLE_CEP_INT(intr) (USBD->CEPINTEN = (intr))
200#define USBD_CLR_CEP_INT_FLAG(flag) (USBD->CEPINTSTS = flag)
201#define USBD_SET_CEP_STATE(flag) (USBD->CEPCTL = flag)
202#define USBD_START_CEP_IN(size) (USBD->CEPTXCNT = size)
203#define USBD_SET_MAX_PAYLOAD(ep, size) (USBD->EP[ep].EPMPS = (size))
204#define USBD_ENABLE_EP_INT(ep, intr) (USBD->EP[ep].EPINTEN = (intr))
205#define USBD_GET_EP_INT_FLAG(ep) (USBD->EP[ep].EPINTSTS)
206#define USBD_CLR_EP_INT_FLAG(ep, flag) (USBD->EP[ep].EPINTSTS = (flag))
207#define USBD_SET_DMA_LEN(len) (USBD->DMACNT = len)
208#define USBD_SET_DMA_ADDR(addr) (USBD->DMAADDR = addr)
209#define USBD_SET_DMA_READ(epnum) (USBD->DMACTL = (USBD->DMACTL & ~USBD_DMACTL_EPNUM_Msk) | USBD_DMACTL_DMARD_Msk | epnum)
210#define USBD_SET_DMA_WRITE(epnum) (USBD->DMACTL = (USBD->DMACTL & ~(USBD_DMACTL_EPNUM_Msk | USBD_DMACTL_DMARD_Msk)) | epnum)
211#define USBD_ENABLE_DMA() (USBD->DMACTL |= USBD_DMACTL_DMAEN_Msk)
212#define USBD_IS_ATTACHED() ((uint32_t)(USBD->PHYCTL & USBD_PHYCTL_VBUSDET_Msk))
226static __INLINE
void USBD_MemCopy(uint8_t *u8Dst, uint8_t *u8Src, int32_t i32Size)
228 while (i32Size--) *u8Dst++ = *u8Src++;
253 USBD->CEPBUFSTART = u32Base;
254 USBD->CEPBUFEND = u32Base + u32Len - 1;
258 USBD->EP[u32Ep].EPBUFSTART = u32Base;
259 USBD->EP[u32Ep].EPBUFEND = u32Base + u32Len - 1;
271static __INLINE
void USBD_ConfigEp(uint32_t u32Ep, uint32_t u32EpNum, uint32_t u32EpType, uint32_t u32EpDir)
315 for (i=0; i<USBD_MAX_EP; i++)
317 if (((
USBD->EP[i].EPCFG & 0xf0) >> 4) == u32EpNum)
348 for (i=0; i<USBD_MAX_EP; i++)
350 if (((
USBD->EP[i].EPCFG & 0xf0) >> 4) == u32EpNum)
382 for (i=0; i<USBD_MAX_EP; i++)
384 if (((
USBD->EP[i].EPCFG & 0xf0) >> 4) == u32EpNum)
#define USB_EP_RSPCTL_TOGGLE
#define USB_EP_RSPCTL_FLUSH
#define USB_EP_RSPCTL_HALT
#define USB_EP_CFG_TYPE_BULK
#define USB_EP_RSPCTL_MODE_FLY
#define USB_EP_CFG_TYPE_ISO
#define USB_EP_RSPCTL_MODE_MANUAL
#define USB_EP_RSPCTL_MODE_AUTO
#define USB_EP_CFG_TYPE_INT
static __INLINE void USBD_ClearStall(uint32_t u32EpNum)
Clear USB endpoint stall state.
static __INLINE uint32_t USBD_GetEpStall(uint32_t u32Ep)
Get USB endpoint stall state.
static __INLINE void USBD_SetEpBufAddr(uint32_t u32Ep, uint32_t u32Base, uint32_t u32Len)
USBD_SetEpBufAddr, Set Endpoint buffer address.
void USBD_StandardRequest(void)
Process USB standard request.
static __INLINE void USBD_ResetDMA(void)
USBD_ResetDMA.
void USBD_UpdateDeviceState(void)
Update Device State.
uint8_t ** gu8HidReportDesc
uint32_t * gu32HidReportSize
static __INLINE uint32_t USBD_GetStall(uint32_t u32EpNum)
Get USB endpoint stall state.
uint8_t * gu8OtherConfigDesc
void USBD_Start(void)
USBD Start.
void USBD_SwReset(void)
Clear all software flags.
static __INLINE void USBD_MemCopy(uint8_t *u8Dst, uint8_t *u8Src, int32_t i32Size)
USBD_memcpy, Copy bytes hardware limitation.
void USBD_PrepareCtrlIn(uint8_t *pu8Buf, uint32_t u32Size)
Prepare Control IN transaction.
static __INLINE void USBD_SetEpStall(uint32_t u32Ep)
Set USB endpoint stall state.
void USBD_CtrlIn(void)
Start Control IN transfer.
static __INLINE void USBD_SetStall(uint32_t u32EpNum)
Set USB endpoint stall state.
void USBD_SetVendorRequest(VENDOR_REQ pfnVendorReq)
USBD Set Vendor Request.
void USBD_ProcessSetupPacket(void)
Process Setup Packet.
static __INLINE void USBD_ConfigEp(uint32_t u32Ep, uint32_t u32EpNum, uint32_t u32EpType, uint32_t u32EpDir)
USBD_ConfigEp, Config Endpoint.
void USBD_Open(S_USBD_INFO_T *param, CLASS_REQ pfnClassReq, SET_INTERFACE_REQ pfnSetInterface)
USBD Initial.
static __INLINE void USBD_ClearEpStall(uint32_t u32Ep)
Clear USB endpoint stall state.
void USBD_CtrlOut(uint8_t *pu8Buf, uint32_t u32Size)
Start Control OUT transaction.
void(* SET_INTERFACE_REQ)(uint32_t u32AltInterface)
#define USBD_SET_CEP_STATE(flag)
struct s_usbd_info S_USBD_INFO_T
struct USBD_CMD_STRUCT S_USBD_CMD_T