1 /**************************************************************************//**
2 * @file hsusbd.h
3 * @version V3.00
4 * @brief M460 series HSUSBD driver header file
5 *
6 * @copyright SPDX-License-Identifier: Apache-2.0
7 * @copyright Copyright (C) 2021 Nuvoton Technology Corp. All rights reserved.
8 ****************************************************************************/
9 #ifndef __HSUSBD_H__
10 #define __HSUSBD_H__
11
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16
17
18 /** @addtogroup Standard_Driver Standard Driver
19 @{
20 */
21
22 /** @addtogroup HSUSBD_Driver HSUSBD Driver
23 @{
24 */
25
26 /** @addtogroup HSUSBD_EXPORTED_CONSTANTS HSUSBD Exported Constants
27 @{
28 */
29 /** @cond HIDDEN_SYMBOLS */
30 #define HSUSBD_MAX_EP 12ul
31
32 #define Maximum(a,b) (a)>(b) ? (a) : (b)
33 #define Minimum(a,b) (((a)<(b)) ? (a) : (b))
34
35
36 #define CEP 0xfful /*!< Control Endpoint \hideinitializer */
37 #define EPA 0ul /*!< Endpoint A \hideinitializer */
38 #define EPB 1ul /*!< Endpoint B \hideinitializer */
39 #define EPC 2ul /*!< Endpoint C \hideinitializer */
40 #define EPD 3ul /*!< Endpoint D \hideinitializer */
41 #define EPE 4ul /*!< Endpoint E \hideinitializer */
42 #define EPF 5ul /*!< Endpoint F \hideinitializer */
43 #define EPG 6ul /*!< Endpoint G \hideinitializer */
44 #define EPH 7ul /*!< Endpoint H \hideinitializer */
45 #define EPI 8ul /*!< Endpoint I \hideinitializer */
46 #define EPJ 9ul /*!< Endpoint J \hideinitializer */
47 #define EPK 10ul /*!< Endpoint K \hideinitializer */
48 #define EPL 11ul /*!< Endpoint L \hideinitializer */
49
50 /** @endcond HIDDEN_SYMBOLS */
51 /********************* Bit definition of CEPCTL register **********************/
52 #define HSUSBD_CEPCTL_NAKCLR ((uint32_t)0x00000000ul) /*!<NAK clear \hideinitializer */
53 #define HSUSBD_CEPCTL_STALL ((uint32_t)0x00000002ul) /*!<Stall \hideinitializer */
54 #define HSUSBD_CEPCTL_ZEROLEN ((uint32_t)0x00000004ul) /*!<Zero length packet \hideinitializer */
55 #define HSUSBD_CEPCTL_FLUSH ((uint32_t)0x00000008ul) /*!<CEP flush \hideinitializer */
56
57 /********************* Bit definition of EPxRSPCTL register **********************/
58 #define HSUSBD_EP_RSPCTL_FLUSH ((uint32_t)0x00000001ul) /*!<Buffer Flush \hideinitializer */
59 #define HSUSBD_EP_RSPCTL_MODE_AUTO ((uint32_t)0x00000000ul) /*!<Auto-Validate Mode \hideinitializer */
60 #define HSUSBD_EP_RSPCTL_MODE_MANUAL ((uint32_t)0x00000002ul) /*!<Manual-Validate Mode \hideinitializer */
61 #define HSUSBD_EP_RSPCTL_MODE_FLY ((uint32_t)0x00000004ul) /*!<Fly Mode \hideinitializer */
62 #define HSUSBD_EP_RSPCTL_MODE_MASK ((uint32_t)0x00000006ul) /*!<Mode Mask \hideinitializer */
63 #define HSUSBD_EP_RSPCTL_TOGGLE ((uint32_t)0x00000008ul) /*!<Clear Toggle bit \hideinitializer */
64 #define HSUSBD_EP_RSPCTL_HALT ((uint32_t)0x00000010ul) /*!<Endpoint halt \hideinitializer */
65 #define HSUSBD_EP_RSPCTL_ZEROLEN ((uint32_t)0x00000020ul) /*!<Zero length packet IN \hideinitializer */
66 #define HSUSBD_EP_RSPCTL_SHORTTXEN ((uint32_t)0x00000040ul) /*!<Packet end \hideinitializer */
67 #define HSUSBD_EP_RSPCTL_DISBUF ((uint32_t)0x00000080ul) /*!<Disable buffer \hideinitializer */
68
69 /********************* Bit definition of EPxCFG register **********************/
70 #define HSUSBD_EP_CFG_VALID ((uint32_t)0x00000001ul) /*!<Endpoint Valid \hideinitializer */
71 #define HSUSBD_EP_CFG_TYPE_BULK ((uint32_t)0x00000002ul) /*!<Endpoint type - bulk \hideinitializer */
72 #define HSUSBD_EP_CFG_TYPE_INT ((uint32_t)0x00000004ul) /*!<Endpoint type - interrupt \hideinitializer */
73 #define HSUSBD_EP_CFG_TYPE_ISO ((uint32_t)0x00000006ul) /*!<Endpoint type - isochronous \hideinitializer */
74 #define HSUSBD_EP_CFG_TYPE_MASK ((uint32_t)0x00000006ul) /*!<Endpoint type mask \hideinitializer */
75 #define HSUSBD_EP_CFG_DIR_OUT ((uint32_t)0x00000000ul) /*!<OUT endpoint \hideinitializer */
76 #define HSUSBD_EP_CFG_DIR_IN ((uint32_t)0x00000008ul) /*!<IN endpoint \hideinitializer */
77
78 /********************* Bit definition of BCDC register **********************/
79 #define HSUSBD_BCDC_DETMOD_IDLE ((uint32_t)0x00000000ul) /*!<Idle \hideinitializer */
80 #define HSUSBD_BCDC_DETMOD_VBUS ((uint32_t)0x00000002ul) /*!<Vbus detect \hideinitializer */
81 #define HSUSBD_BCDC_DETMOD_DCD ((uint32_t)0x00000004ul) /*!<Data contact detect \hideinitializer */
82 #define HSUSBD_BCDC_DETMOD_PD ((uint32_t)0x00000006ul) /*!<Primary detect \hideinitializer */
83 #define HSUSBD_BCDC_DETMOD_SD ((uint32_t)0x00000008ul) /*!<Secondary detect \hideinitializer */
84 #define HSUSBD_BCDC_DETSTS_VBUS_UNREACH ((uint32_t)0x00000000ul) /*!<Vbus unreach \hideinitializer */
85 #define HSUSBD_BCDC_DETSTS_VBUS_REACH ((uint32_t)0x00000010ul) /*!<Vbus reach \hideinitializer */
86 #define HSUSBD_BCDC_DETSTS_DCD_DATA_UNCONTACT ((uint32_t)0x00000000ul) /*!<Data pin uncontact \hideinitializer */
87 #define HSUSBD_BCDC_DETSTS_DCD_DATA_CONTACT ((uint32_t)0x00000010ul) /*!<Data pin contact \hideinitializer */
88 #define HSUSBD_BCDC_DETSTS_PD_SDP_NUSP ((uint32_t)0x00000000ul) /*!<SDP or NUSP \hideinitializer */
89 #define HSUSBD_BCDC_DETSTS_PD_DCP_CDP ((uint32_t)0x00000010ul) /*!<DCP or CDP \hideinitializer */
90 #define HSUSBD_BCDC_DETSTS_SD_CDP ((uint32_t)0x00000000ul) /*!<CDP \hideinitializer */
91 #define HSUSBD_BCDC_DETSTS_SD_DCP ((uint32_t)0x00000010ul) /*!<DCP \hideinitializer */
92
93 /*---------------------------------------------------------------------------------------------------------*/
94 /* HSUSBD Define Error Code */
95 /*---------------------------------------------------------------------------------------------------------*/
96 #define HSUSBD_TIMEOUT SystemCoreClock /*!< HSUSBD time-out counter (1 second time-out) \hideinitializer */
97 #define HSUSBD_OK ( 0L) /*!< HSUSBD operation OK \hideinitializer */
98 #define HSUSBD_ERR_FAIL (-1L) /*!< HSUSBD operation failed \hideinitializer */
99 #define HSUSBD_ERR_TIMEOUT (-2L) /*!< HSUSBD operation abort due to timeout error \hideinitializer */
100
101 /*@}*/ /* end of group HSUSBD_EXPORTED_CONSTANTS */
102
103 /** @addtogroup HSUSBD_EXPORTED_STRUCT HSUSBD Exported Struct
104 @{
105 */
106
107
108 typedef struct HSUSBD_CMD_STRUCT
109 {
110 uint8_t bmRequestType;
111 uint8_t bRequest;
112 uint16_t wValue;
113 uint16_t wIndex;
114 uint16_t wLength;
115
116 } S_HSUSBD_CMD_T; /*!<USB Setup Packet Structure */
117
118
119
120
121 typedef struct s_hsusbd_info
122 {
123 uint8_t *gu8DevDesc; /*!< Device descriptor */
124 uint8_t *gu8ConfigDesc; /*!< Config descriptor */
125 uint8_t **gu8StringDesc; /*!< Pointer for USB String Descriptor pointers */
126 uint8_t *gu8QualDesc; /*!< Qualifier descriptor */
127 uint8_t *gu8FullConfigDesc; /*!< Full Speed Config descriptor */
128 uint8_t *gu8HSOtherConfigDesc; /*!< Other Speed Config descriptor */
129 uint8_t *gu8FSOtherConfigDesc; /*!< Other Speed Config descriptor */
130 uint8_t *gu8BosDesc; /*!< Pointer for USB BOS Descriptor */
131 uint8_t **gu8HidReportDesc; /*!< Pointer for HID Report descriptor */
132 uint32_t *gu32HidReportSize; /*!< Pointer for HID Report descriptor Size */
133 uint32_t *gu32ConfigHidDescIdx; /*!< Pointer for HID Descriptor start index */
134
135 } S_HSUSBD_INFO_T; /*!<USB Information Structure */
136
137
138 /*@}*/ /* end of group HSUSBD_EXPORTED_STRUCT */
139
140 /** @cond HIDDEN_SYMBOLS */
141 extern uint32_t g_u32HsEpStallLock;
142 extern uint8_t volatile g_hsusbd_Configured;
143 extern uint8_t g_hsusbd_ShortPacket;
144 extern uint8_t g_hsusbd_CtrlZero;
145 extern uint8_t g_hsusbd_UsbAddr;
146 extern uint32_t volatile g_hsusbd_DmaDone;
147 extern uint32_t g_hsusbd_CtrlInSize;
148 extern S_HSUSBD_INFO_T gsHSInfo;
149 extern S_HSUSBD_CMD_T gUsbCmd;
150 extern volatile uint8_t g_hsusbd_RemoteWakeupEn;
151 /** @endcond HIDDEN_SYMBOLS */
152
153
154 /** @addtogroup HSUSBD_EXPORTED_FUNCTIONS HSUSBD Exported Functions
155 @{
156 */
157
158 #define HSUSBD_ENABLE_USB() ((uint32_t)(HSUSBD->PHYCTL |= (HSUSBD_PHYCTL_PHYEN_Msk|HSUSBD_PHYCTL_DPPUEN_Msk))) /*!<Enable USB \hideinitializer */
159 #define HSUSBD_DISABLE_USB() ((uint32_t)(HSUSBD->PHYCTL &= ~HSUSBD_PHYCTL_DPPUEN_Msk)) /*!<Disable USB \hideinitializer */
160 #define HSUSBD_ENABLE_PHY() ((uint32_t)(HSUSBD->PHYCTL |= HSUSBD_PHYCTL_PHYEN_Msk)) /*!<Enable PHY \hideinitializer */
161 #define HSUSBD_DISABLE_PHY() ((uint32_t)(HSUSBD->PHYCTL &= ~HSUSBD_PHYCTL_PHYEN_Msk)) /*!<Disable PHY \hideinitializer */
162 #define HSUSBD_SET_SE0() ((uint32_t)(HSUSBD->PHYCTL &= ~HSUSBD_PHYCTL_DPPUEN_Msk)) /*!<Enable SE0, Force USB PHY Transceiver to Drive SE0 \hideinitializer */
163 #define HSUSBD_CLR_SE0() ((uint32_t)(HSUSBD->PHYCTL |= HSUSBD_PHYCTL_DPPUEN_Msk)) /*!<Disable SE0 \hideinitializer */
164 #define HSUSBD_SET_ADDR(addr) (HSUSBD->FADDR = (addr)) /*!<Set USB address \hideinitializer */
165 #define HSUSBD_GET_ADDR() ((uint32_t)(HSUSBD->FADDR)) /*!<Get USB address \hideinitializer */
166 #define HSUSBD_ENABLE_USB_INT(intr) (HSUSBD->GINTEN = (intr)) /*!<Enable USB Interrupt \hideinitializer */
167 #define HSUSBD_ENABLE_BUS_INT(intr) (HSUSBD->BUSINTEN = (intr)) /*!<Enable BUS Interrupt \hideinitializer */
168 #define HSUSBD_GET_BUS_INT_FLAG() (HSUSBD->BUSINTSTS) /*!<Get Bus interrupt flag \hideinitializer */
169 #define HSUSBD_CLR_BUS_INT_FLAG(flag) (HSUSBD->BUSINTSTS = (flag)) /*!<Clear Bus interrupt flag \hideinitializer */
170 #define HSUSBD_ENABLE_CEP_INT(intr) (HSUSBD->CEPINTEN = (intr)) /*!<Enable CEP Interrupt \hideinitializer */
171 #define HSUSBD_CLR_CEP_INT_FLAG(flag) (HSUSBD->CEPINTSTS = (flag)) /*!<Clear CEP interrupt flag \hideinitializer */
172 #define HSUSBD_SET_CEP_STATE(flag) (HSUSBD->CEPCTL = (flag)) /*!<Set CEP state \hideinitializer */
173 #define HSUSBD_START_CEP_IN(size) (HSUSBD->CEPTXCNT = (size)) /*!<Start CEP IN Transfer \hideinitializer */
174 #define HSUSBD_SET_MAX_PAYLOAD(ep, size) (HSUSBD->EP[(ep)].EPMPS = (size)) /*!<Set EPx Maximum Packet Size \hideinitializer */
175 #define HSUSBD_ENABLE_EP_INT(ep, intr) (HSUSBD->EP[(ep)].EPINTEN = (intr)) /*!<Enable EPx Interrupt \hideinitializer */
176 #define HSUSBD_GET_EP_INT_FLAG(ep) (HSUSBD->EP[(ep)].EPINTSTS) /*!<Get EPx interrupt flag \hideinitializer */
177 #define HSUSBD_CLR_EP_INT_FLAG(ep, flag) (HSUSBD->EP[(ep)].EPINTSTS = (flag)) /*!<Clear EPx interrupt flag \hideinitializer */
178 #define HSUSBD_SET_DMA_LEN(len) (HSUSBD->DMACNT = (len)) /*!<Set DMA transfer length \hideinitializer */
179 #define HSUSBD_SET_DMA_ADDR(addr) (HSUSBD->DMAADDR = (addr)) /*!<Set DMA transfer address \hideinitializer */
180 #define HSUSBD_SET_DMA_READ(epnum) (HSUSBD->DMACTL = (HSUSBD->DMACTL & ~HSUSBD_DMACTL_EPNUM_Msk) | HSUSBD_DMACTL_DMARD_Msk | (epnum) | 0x100) /*!<Set DMA transfer type to read \hideinitializer */
181 #define HSUSBD_SET_DMA_WRITE(epnum) (HSUSBD->DMACTL = (HSUSBD->DMACTL & ~(HSUSBD_DMACTL_EPNUM_Msk | HSUSBD_DMACTL_DMARD_Msk | 0x100)) | (epnum)) /*!<Set DMA transfer type to write \hideinitializer */
182 #define HSUSBD_ENABLE_DMA() (HSUSBD->DMACTL |= HSUSBD_DMACTL_DMAEN_Msk) /*!<Enable DMA transfer \hideinitializer */
183 #define HSUSBD_IS_ATTACHED() ((uint32_t)(HSUSBD->PHYCTL & HSUSBD_PHYCTL_VBUSDET_Msk)) /*!<Check cable connect state \hideinitializer */
184 #define HSUSBD_ENABLE_BCD() ((uint32_t)(HSUSBD->BCDC |= HSUSBD_BCDC_BCDEN_Msk)) /*!<Enable BCD \hideinitializer */
185 #define HSUSBD_DISABLE_BCD() ((uint32_t)(HSUSBD->BCDC &= ~HSUSBD_BCDC_BCDEN_Msk)) /*!<Disable BCD \hideinitializer */
186 #define HSUSBD_ENABLE_LPM() ((uint32_t)(HSUSBD->LPMCSR |= HSUSBD_LPMCSR_LPMEN_Msk)) /*!<Enable LPM \hideinitializer */
187 #define HSUSBD_DISABLE_LPM() ((uint32_t)(HSUSBD->LPMCSR &= ~HSUSBD_LPMCSR_LPMEN_Msk)) /*!<Disable LPM \hideinitializer */
188
189 /**
190 * @brief HSUSBD_memcpy, Copy bytes hardware limitation
191 * @param[in] u8Dst Destination pointer.
192 * @param[in] u8Src Source pointer.
193 * @param[in] u32Size Copy size.
194 * @retval None.
195 */
HSUSBD_MemCopy(uint8_t u8Dst[],uint8_t u8Src[],uint32_t u32Size)196 __STATIC_INLINE void HSUSBD_MemCopy(uint8_t u8Dst[], uint8_t u8Src[], uint32_t u32Size)
197 {
198 uint32_t i = 0ul;
199
200 while (u32Size--)
201 {
202 u8Dst[i] = u8Src[i];
203 i++;
204 }
205 }
206
207 /**
208 * @brief HSUSBD_ResetDMA
209 * @param None
210 * @retval None.
211 */
HSUSBD_ResetDMA(void)212 __STATIC_INLINE void HSUSBD_ResetDMA(void)
213 {
214 HSUSBD->DMACNT = 0ul;
215 HSUSBD->DMACTL = 0x80ul;
216 HSUSBD->DMACTL = 0x00ul;
217 }
218 /**
219 * @brief HSUSBD_SetEpBufAddr, Set Endpoint buffer address
220 * @param[in] u32Ep Endpoint Number
221 * @param[in] u32Base Buffer Start Address
222 * @param[in] u32Len Buffer length
223 * @retval None.
224 */
HSUSBD_SetEpBufAddr(uint32_t u32Ep,uint32_t u32Base,uint32_t u32Len)225 __STATIC_INLINE void HSUSBD_SetEpBufAddr(uint32_t u32Ep, uint32_t u32Base, uint32_t u32Len)
226 {
227 if (u32Ep == CEP)
228 {
229 HSUSBD->CEPBUFST = u32Base;
230 HSUSBD->CEPBUFEND = u32Base + u32Len - 1ul;
231 }
232 else
233 {
234 HSUSBD->EP[u32Ep].EPBUFST = u32Base;
235 HSUSBD->EP[u32Ep].EPBUFEND = u32Base + u32Len - 1ul;
236 }
237 }
238
239 /**
240 * @brief HSUSBD_ConfigEp, Config Endpoint
241 * @param[in] u32Ep USB endpoint
242 * @param[in] u32EpNum Endpoint number
243 * @param[in] u32EpType Endpoint type
244 * @param[in] u32EpDir Endpoint direction
245 * @retval None.
246 */
HSUSBD_ConfigEp(uint32_t u32Ep,uint32_t u32EpNum,uint32_t u32EpType,uint32_t u32EpDir)247 __STATIC_INLINE void HSUSBD_ConfigEp(uint32_t u32Ep, uint32_t u32EpNum, uint32_t u32EpType, uint32_t u32EpDir)
248 {
249 if (u32EpType == HSUSBD_EP_CFG_TYPE_BULK)
250 {
251 HSUSBD->EP[u32Ep].EPRSPCTL = (HSUSBD_EP_RSPCTL_FLUSH|HSUSBD_EP_RSPCTL_MODE_AUTO);
252 }
253 else if (u32EpType == HSUSBD_EP_CFG_TYPE_INT)
254 {
255 HSUSBD->EP[u32Ep].EPRSPCTL = (HSUSBD_EP_RSPCTL_FLUSH|HSUSBD_EP_RSPCTL_MODE_MANUAL);
256 }
257 else if (u32EpType == HSUSBD_EP_CFG_TYPE_ISO)
258 {
259 HSUSBD->EP[u32Ep].EPRSPCTL = (HSUSBD_EP_RSPCTL_FLUSH|HSUSBD_EP_RSPCTL_MODE_FLY);
260 }
261
262 HSUSBD->EP[u32Ep].EPCFG = (u32EpType|u32EpDir|HSUSBD_EP_CFG_VALID|(u32EpNum << 4));
263 }
264
265 /**
266 * @brief Set USB endpoint stall state
267 * @param[in] u32Ep The USB endpoint ID.
268 * @return None
269 * @details Set USB endpoint stall state for the specified endpoint ID. Endpoint will respond STALL token automatically.
270 */
HSUSBD_SetEpStall(uint32_t u32Ep)271 __STATIC_INLINE void HSUSBD_SetEpStall(uint32_t u32Ep)
272 {
273 if (u32Ep == CEP)
274 {
275 HSUSBD_SET_CEP_STATE(HSUSBD_CEPCTL_STALL);
276 }
277 else
278 {
279 HSUSBD->EP[u32Ep].EPRSPCTL = (HSUSBD->EP[u32Ep].EPRSPCTL & 0xf7ul) | HSUSBD_EP_RSPCTL_HALT;
280 }
281 }
282
283 /**
284 * @brief Set USB endpoint stall state
285 *
286 * @param[in] u32EpNum USB endpoint
287 * @return None
288 *
289 * @details Set USB endpoint stall state, endpoint will return STALL token.
290 */
HSUSBD_SetStall(uint32_t u32EpNum)291 __STATIC_INLINE void HSUSBD_SetStall(uint32_t u32EpNum)
292 {
293 uint32_t i;
294
295 if (u32EpNum == 0ul)
296 {
297 HSUSBD_SET_CEP_STATE(HSUSBD_CEPCTL_STALL);
298 }
299 else
300 {
301 for (i=0ul; i<HSUSBD_MAX_EP; i++)
302 {
303 if (((HSUSBD->EP[i].EPCFG & 0xf0ul) >> 4) == u32EpNum)
304 {
305 HSUSBD->EP[i].EPRSPCTL = (HSUSBD->EP[i].EPRSPCTL & 0xf7ul) | HSUSBD_EP_RSPCTL_HALT;
306 }
307 }
308 }
309 }
310
311 /**
312 * @brief Clear USB endpoint stall state
313 * @param[in] u32Ep The USB endpoint ID.
314 * @return None
315 * @details Clear USB endpoint stall state for the specified endpoint ID. Endpoint will respond ACK/NAK token.
316 */
HSUSBD_ClearEpStall(uint32_t u32Ep)317 __STATIC_INLINE void HSUSBD_ClearEpStall(uint32_t u32Ep)
318 {
319 HSUSBD->EP[u32Ep].EPRSPCTL = HSUSBD_EP_RSPCTL_TOGGLE;
320 }
321
322 /**
323 * @brief Clear USB endpoint stall state
324 *
325 * @param[in] u32EpNum USB endpoint
326 * @return None
327 *
328 * @details Clear USB endpoint stall state, endpoint will return ACK/NAK token.
329 */
HSUSBD_ClearStall(uint32_t u32EpNum)330 __STATIC_INLINE void HSUSBD_ClearStall(uint32_t u32EpNum)
331 {
332 uint32_t i;
333
334 for (i=0ul; i<HSUSBD_MAX_EP; i++)
335 {
336 if (((HSUSBD->EP[i].EPCFG & 0xf0ul) >> 4) == u32EpNum)
337 {
338 HSUSBD->EP[i].EPRSPCTL = HSUSBD_EP_RSPCTL_TOGGLE;
339 }
340 }
341 }
342
343 /**
344 * @brief Get USB endpoint stall state
345 * @param[in] u32Ep The USB endpoint ID.
346 * @retval 0 USB endpoint is not stalled.
347 * @retval Others USB endpoint is stalled.
348 * @details Get USB endpoint stall state of the specified endpoint ID.
349 */
HSUSBD_GetEpStall(uint32_t u32Ep)350 __STATIC_INLINE uint32_t HSUSBD_GetEpStall(uint32_t u32Ep)
351 {
352 return (HSUSBD->EP[u32Ep].EPRSPCTL & HSUSBD_EP_RSPCTL_HALT);
353 }
354
355 /**
356 * @brief Get USB endpoint stall state
357 *
358 * @param[in] u32EpNum USB endpoint
359 * @retval 0: USB endpoint is not stalled.
360 * @retval non-0: USB endpoint is stalled.
361 *
362 * @details Get USB endpoint stall state.
363 */
HSUSBD_GetStall(uint32_t u32EpNum)364 __STATIC_INLINE uint32_t HSUSBD_GetStall(uint32_t u32EpNum)
365 {
366 uint32_t i;
367 uint32_t val = 0ul;
368
369 for (i=0ul; i<HSUSBD_MAX_EP; i++)
370 {
371 if (((HSUSBD->EP[i].EPCFG & 0xf0ul) >> 4) == u32EpNum)
372 {
373 val = (HSUSBD->EP[i].EPRSPCTL & HSUSBD_EP_RSPCTL_HALT);
374 break;
375 }
376 }
377 return val;
378 }
379
380
381 /*-------------------------------------------------------------------------------------------*/
382 typedef void (*HSUSBD_VENDOR_REQ)(void); /*!<USB Vendor request callback function */
383 typedef void (*HSUSBD_CLASS_REQ)(void); /*!<USB Class request callback function */
384 typedef void (*HSUSBD_SET_INTERFACE_REQ)(uint32_t u32AltInterface); /*!<USB Standard request "Set Interface" callback function */
385
386 int32_t HSUSBD_Open(S_HSUSBD_INFO_T *param, HSUSBD_CLASS_REQ pfnClassReq, HSUSBD_SET_INTERFACE_REQ pfnSetInterface);
387 void HSUSBD_Start(void);
388 void HSUSBD_ProcessSetupPacket(void);
389 void HSUSBD_StandardRequest(void);
390 void HSUSBD_UpdateDeviceState(void);
391 void HSUSBD_PrepareCtrlIn(uint8_t pu8Buf[], uint32_t u32Size);
392 void HSUSBD_CtrlIn(void);
393 int32_t HSUSBD_CtrlOut(uint8_t pu8Buf[], uint32_t u32Size);
394 void HSUSBD_SwReset(void);
395 void HSUSBD_SetVendorRequest(HSUSBD_VENDOR_REQ pfnVendorReq);
396
397
398
399 /*@}*/ /* end of group HSUSBD_EXPORTED_FUNCTIONS */
400
401 /*@}*/ /* end of group HSUSBD_Driver */
402
403 /*@}*/ /* end of group Standard_Driver */
404
405 #ifdef __cplusplus
406 }
407 #endif
408
409 #endif /*__HSUSBD_H__ */
410