usbh_lib.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /**************************************************************************//**
  2. * @file usbh_lib.h
  3. * @version V1.10
  4. * @brief USB Host library exported header file.
  5. *
  6. * @note
  7. * SPDX-License-Identifier: Apache-2.0
  8. * Copyright (C) 2017 Nuvoton Technology Corp. All rights reserved.
  9. ******************************************************************************/
  10. #ifndef _USBH_LIB_H_
  11. #define _USBH_LIB_H_
  12. #include "NuMicro.h"
  13. #include "usb.h"
  14. #ifdef __cplusplus
  15. extern "C"
  16. {
  17. #endif
  18. /** @addtogroup LIBRARY Library
  19. @{
  20. */
  21. /** @addtogroup USBH_Library USB Host Library
  22. @{
  23. */
  24. /** @addtogroup USBH_EXPORTED_CONSTANTS USB Host Exported Constants
  25. @{
  26. */
  27. #define USBH_OK 0 /*!< No error. */
  28. #define USBH_ERR_MEMORY_OUT -10 /*!< Out of memory. */
  29. #define USBH_ERR_IF_ALT_LIMIT -11 /*!< Number of alternative interface > MAX_ALT_PER_IFACE */
  30. #define USBH_ERR_IF_EP_LIMIT -15 /*!< Number of endpoints > MAX_EP_PER_IFACE */
  31. #define USBH_ERR_NOT_SUPPORTED -101 /*!< Device/Class/Transfer not supported */
  32. #define USBH_ERR_NOT_MATCHED -103 /*!< Not macthed */
  33. #define USBH_ERR_NOT_EXPECTED -104 /*!< Unknown or unexpected */
  34. #define USBH_ERR_INVALID_PARAM -105 /*!< Invalid parameter */
  35. #define USBH_ERR_NOT_FOUND -106 /*!< Device or interface not found */
  36. #define USBH_ERR_EP_NOT_FOUND -107 /*!< Endpoint not found */
  37. #define USBH_ERR_DESCRIPTOR -137 /*!< Failed to parse USB descriptors */
  38. #define USBH_ERR_SET_DEV_ADDR -139 /*!< Failed to set device address */
  39. #define USBH_ERR_SET_CONFIG -151 /*!< Failed to set device configuration */
  40. #define USBH_ERR_TRANSFER -201 /*!< USB transfer error */
  41. #define USBH_ERR_TIMEOUT -203 /*!< USB transfer time-out */
  42. #define USBH_ERR_ABORT -205 /*!< USB transfer aborted due to disconnect or reset */
  43. #define USBH_ERR_PORT_RESET -255 /*!< Hub port reset failed */
  44. #define USBH_ERR_SCH_OVERRUN -257 /*!< USB isochronous schedule overrun */
  45. #define USBH_ERR_DISCONNECTED -259 /*!< USB device was disconnected */
  46. #define USBH_ERR_TRANSACTION -271 /*!< USB transaction timeout, CRC, Bad PID, etc. */
  47. #define USBH_ERR_BABBLE_DETECTED -272 /*!< A 'babble' is detected during the transaction */
  48. #define USBH_ERR_DATA_BUFF -274 /*!< Data buffer overrun or underrun */
  49. #define USBH_ERR_CC_NO_ERR -280 /*!< OHCI CC code - no error */
  50. #define USBH_ERR_CRC -281 /*!< USB trasfer CRC error */
  51. #define USBH_ERR_BIT_STUFF -282 /*!< USB transfer bit stuffing error */
  52. #define USBH_ERR_DATA_TOGGLE -283 /*!< USB trasfer data toggle error */
  53. #define USBH_ERR_STALL -284 /*!< USB trasfer STALL error */
  54. #define USBH_ERR_DEV_NO_RESP -285 /*!< USB trasfer device no response error */
  55. #define USBH_ERR_PID_CHECK -286 /*!< USB trasfer PID check failure */
  56. #define USBH_ERR_UNEXPECT_PID -287 /*!< USB trasfer unexpected PID error */
  57. #define USBH_ERR_DATA_OVERRUN -288 /*!< USB trasfer data overrun error */
  58. #define USBH_ERR_DATA_UNDERRUN -289 /*!< USB trasfer data underrun error */
  59. #define USBH_ERR_BUFF_OVERRUN -292 /*!< USB trasfer buffer overrun error */
  60. #define USBH_ERR_BUFF_UNDERRUN -293 /*!< USB trasfer buffer underrun error */
  61. #define USBH_ERR_NOT_ACCESS0 -294 /*!< USB trasfer not accessed error */
  62. #define USBH_ERR_NOT_ACCESS1 -295 /*!< USB trasfer not accessed error */
  63. #define USBH_ERR_OHCI_INIT -301 /*!< Failed to initialize OHIC controller. */
  64. #define USBH_ERR_OHCI_EP_BUSY -303 /*!< The endpoint is under transfer. */
  65. #define USBH_ERR_EHCI_INIT -501 /*!< Failed to initialize EHCI controller. */
  66. #define USBH_ERR_EHCI_QH_BUSY -503 /*!< the Queue Head is busy. */
  67. #define UMAS_OK 0 /*!< No error. */
  68. #define UMAS_ERR_NO_DEVICE -1031 /*!< No Mass Stroage Device found. */
  69. #define UMAS_ERR_IO -1033 /*!< Device read/write failed. */
  70. #define UMAS_ERR_INIT_DEVICE -1035 /*!< failed to init MSC device */
  71. #define UMAS_ERR_CMD_STATUS -1037 /*!< SCSI command status failed */
  72. #define UMAS_ERR_IVALID_PARM -1038 /*!< Invalid parameter. */
  73. #define UMAS_ERR_DRIVE_NOT_FOUND -1039 /*!< drive not found */
  74. #define HID_RET_OK 0 /*!< Return with no errors. */
  75. #define HID_RET_DEV_NOT_FOUND -1081 /*!< HID device not found or removed. */
  76. #define HID_RET_IO_ERR -1082 /*!< USB transfer failed. */
  77. #define HID_RET_INVALID_PARAMETER -1083 /*!< Invalid parameter. */
  78. #define HID_RET_OUT_OF_MEMORY -1084 /*!< Out of memory. */
  79. #define HID_RET_NOT_SUPPORTED -1085 /*!< Function not supported. */
  80. #define HID_RET_EP_NOT_FOUND -1086 /*!< Endpoint not found. */
  81. #define HID_RET_PARSING -1087 /*!< Failed to parse HID descriptor */
  82. #define HID_RET_XFER_IS_RUNNING -1089 /*!< The transfer has been enabled. */
  83. #define HID_RET_REPORT_NOT_FOUND -1090 /*!< The transfer has been enabled. */
  84. #define UAC_RET_OK 0 /*!< Return with no errors. */
  85. #define UAC_RET_DEV_NOT_FOUND -2001 /*!< Audio Class device not found or removed. */
  86. #define UAC_RET_FUNC_NOT_FOUND -2002 /*!< Audio device has no this function. */
  87. #define UAC_RET_IO_ERR -2003 /*!< USB transfer failed. */
  88. #define UAC_RET_DATA_LEN -2004 /*!< Unexpected transfer length */
  89. #define UAC_RET_INVALID -2005 /*!< Invalid parameter or usage. */
  90. #define UAC_RET_OUT_OF_MEMORY -2007 /*!< Out of memory. */
  91. #define UAC_RET_DRV_NOT_SUPPORTED -2009 /*!< Function not supported by this UAC driver. */
  92. #define UAC_RET_DEV_NOT_SUPPORTED -2011 /*!< Function not supported by the UAC device. */
  93. #define UAC_RET_PARSER -2013 /*!< Failed to parse UAC descriptor */
  94. #define UAC_RET_IS_STREAMING -2015 /*!< Audio pipe is on streaming. */
  95. /*@}*/ /* end of group USBH_EXPORTED_CONSTANTS */
  96. /** @addtogroup USBH_EXPORTED_TYPEDEF USB Host Typedef
  97. @{
  98. */
  99. struct udev_t;
  100. typedef void (CONN_FUNC)(struct udev_t *udev, int param);
  101. struct line_coding_t;
  102. struct cdc_dev_t;
  103. typedef void (CDC_CB_FUNC)(struct cdc_dev_t *cdev, uint8_t *rdata, int data_len);
  104. struct usbhid_dev;
  105. typedef void (HID_IR_FUNC)(struct usbhid_dev *hdev, uint16_t ep_addr, int status, uint8_t *rdata, uint32_t data_len); /*!< interrupt in callback function \hideinitializer */
  106. typedef void (HID_IW_FUNC)(struct usbhid_dev *hdev, uint16_t ep_addr, int status, uint8_t *wbuff, uint32_t *data_len); /*!< interrupt out callback function \hideinitializer */
  107. struct uac_dev_t;
  108. typedef int (UAC_CB_FUNC)(struct uac_dev_t *dev, uint8_t *data, int len); /*!< audio in callback function \hideinitializer */
  109. /*@}*/ /* end of group USBH_EXPORTED_STRUCT */
  110. /** @addtogroup USBH_EXPORTED_FUNCTIONS USB Host Exported Functions
  111. @{
  112. */
  113. /*------------------------------------------------------------------*/
  114. /* */
  115. /* USB Core Library APIs */
  116. /* */
  117. /*------------------------------------------------------------------*/
  118. extern void usbh_core_init(void);
  119. extern int usbh_polling_root_hubs(void);
  120. extern void usbh_install_conn_callback(CONN_FUNC *conn_func, CONN_FUNC *disconn_func);
  121. extern void usbh_suspend(void);
  122. extern void usbh_resume(void);
  123. extern struct udev_t *usbh_find_device(char *hub_id, int port);
  124. /**
  125. * @brief A function return current tick count.
  126. * @return Current tick.
  127. * @details User application must provide this function to return current tick.
  128. * The tick should increase by 1 for every 10 ms.
  129. */
  130. extern uint32_t usbh_get_ticks(void); /* This function must be provided by user application. */
  131. extern uint32_t usbh_tick_from_millisecond(uint32_t msec); /* This function must be provided by user application. */
  132. /// @cond HIDDEN_SYMBOLS
  133. //extern void dump_ohci_regs(void);
  134. //extern void dump_ehci_regs(void);
  135. //extern void dump_ohci_ports(void);
  136. //extern void dump_ehci_ports(void);
  137. //extern uint32_t usbh_memory_used(void);
  138. /// @endcond HIDDEN_SYMBOLS
  139. /*@}*/ /* end of group USBH_EXPORTED_FUNCTIONS */
  140. /*@}*/ /* end of group USBH_Library */
  141. /*@}*/ /* end of group LIBRARY */
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif /* _USBH_LIB_H_ */
  146. /*** (C) COPYRIGHT 2017 Nuvoton Technology Corp. ***/