usb_hc.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * Copyright (c) 2022, sakumisu
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #ifndef USB_HC_H
  7. #define USB_HC_H
  8. #include <stdint.h>
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef void (*usbh_complete_callback_t)(void *arg, int nbytes);
  13. struct usbh_bus;
  14. /**
  15. * @brief USB Iso Configuration.
  16. *
  17. * Structure containing the USB Iso configuration.
  18. */
  19. struct usbh_iso_frame_packet {
  20. uint8_t *transfer_buffer;
  21. uint32_t transfer_buffer_length;
  22. uint32_t actual_length;
  23. int errorcode;
  24. };
  25. /**
  26. * @brief USB Urb Configuration.
  27. *
  28. * Structure containing the USB Urb configuration.
  29. */
  30. struct usbh_urb {
  31. usb_slist_t list;
  32. void *hcpriv;
  33. struct usbh_hubport *hport;
  34. struct usb_endpoint_descriptor *ep;
  35. uint8_t data_toggle;
  36. uint8_t interval;
  37. struct usb_setup_packet *setup;
  38. uint8_t *transfer_buffer;
  39. uint32_t transfer_buffer_length;
  40. int transfer_flags;
  41. uint32_t actual_length;
  42. uint32_t timeout;
  43. int errorcode;
  44. uint32_t num_of_iso_packets;
  45. uint32_t start_frame;
  46. usbh_complete_callback_t complete;
  47. void *arg;
  48. #if defined(__ICCARM__) || defined(__ICCRISCV__) || defined(__ICCRX__)
  49. struct usbh_iso_frame_packet *iso_packet;
  50. #else
  51. struct usbh_iso_frame_packet iso_packet[0];
  52. #endif
  53. };
  54. /**
  55. * @brief usb host controller hardware init.
  56. *
  57. * @return On success will return 0, and others indicate fail.
  58. */
  59. int usb_hc_init(struct usbh_bus *bus);
  60. /**
  61. * @brief usb host controller hardware deinit.
  62. *
  63. * @return On success will return 0, and others indicate fail.
  64. */
  65. int usb_hc_deinit(struct usbh_bus *bus);
  66. /**
  67. * @brief Get frame number.
  68. *
  69. * @return frame number.
  70. */
  71. uint16_t usbh_get_frame_number(struct usbh_bus *bus);
  72. /**
  73. * @brief control roothub.
  74. *
  75. * @param setup setup request buffer.
  76. * @param buf buf for reading response or write data.
  77. * @return On success will return 0, and others indicate fail.
  78. */
  79. int usbh_roothub_control(struct usbh_bus *bus, struct usb_setup_packet *setup, uint8_t *buf);
  80. /**
  81. * @brief Submit a usb transfer request to an endpoint.
  82. *
  83. * If timeout is not zero, this function will be in poll transfer mode,
  84. * otherwise will be in async transfer mode.
  85. *
  86. * @param urb Usb request block.
  87. * @return On success will return 0, and others indicate fail.
  88. */
  89. int usbh_submit_urb(struct usbh_urb *urb);
  90. /**
  91. * @brief Cancel a transfer request.
  92. *
  93. * This function will call When calls usbh_submit_urb and return -USB_ERR_TIMEOUT or -USB_ERR_SHUTDOWN.
  94. *
  95. * @param urb Usb request block.
  96. * @return On success will return 0, and others indicate fail.
  97. */
  98. int usbh_kill_urb(struct usbh_urb *urb);
  99. /* called by user */
  100. void USBH_IRQHandler(uint8_t busid);
  101. #ifdef __cplusplus
  102. }
  103. #endif
  104. #endif /* USB_HC_H */