nu_hsusbd.h 18 KB

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