usb_hc.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. void *hcpriv;
  32. struct usbh_hubport *hport;
  33. struct usb_endpoint_descriptor *ep;
  34. uint8_t data_toggle;
  35. uint8_t interval;
  36. struct usb_setup_packet *setup;
  37. uint8_t *transfer_buffer;
  38. uint32_t transfer_buffer_length;
  39. int transfer_flags;
  40. uint32_t actual_length;
  41. uint32_t timeout;
  42. int errorcode;
  43. uint32_t num_of_iso_packets;
  44. uint32_t start_frame;
  45. usbh_complete_callback_t complete;
  46. void *arg;
  47. #if defined(__ICCARM__) || defined(__ICCRISCV__) || defined(__ICCRX__)
  48. struct usbh_iso_frame_packet *iso_packet;
  49. #else
  50. struct usbh_iso_frame_packet iso_packet[0];
  51. #endif
  52. };
  53. /**
  54. * @brief usb host controller hardware init.
  55. *
  56. * @return On success will return 0, and others indicate fail.
  57. */
  58. int usb_hc_init(struct usbh_bus *bus);
  59. /**
  60. * @brief usb host controller hardware deinit.
  61. *
  62. * @return On success will return 0, and others indicate fail.
  63. */
  64. int usb_hc_deinit(struct usbh_bus *bus);
  65. /**
  66. * @brief Get frame number.
  67. *
  68. * @return frame number.
  69. */
  70. uint16_t usbh_get_frame_number(struct usbh_bus *bus);
  71. /**
  72. * @brief control roothub.
  73. *
  74. * @param setup setup request buffer.
  75. * @param buf buf for reading response or write data.
  76. * @return On success will return 0, and others indicate fail.
  77. */
  78. int usbh_roothub_control(struct usbh_bus *bus, struct usb_setup_packet *setup, uint8_t *buf);
  79. /**
  80. * @brief Submit a usb transfer request to an endpoint.
  81. *
  82. * If timeout is not zero, this function will be in poll transfer mode,
  83. * otherwise will be in async transfer mode.
  84. *
  85. * @param urb Usb request block.
  86. * @return On success will return 0, and others indicate fail.
  87. */
  88. int usbh_submit_urb(struct usbh_urb *urb);
  89. /**
  90. * @brief Cancel a transfer request.
  91. *
  92. * This function will call When calls usbh_submit_urb and return -USB_ERR_TIMEOUT or -USB_ERR_SHUTDOWN.
  93. *
  94. * @param urb Usb request block.
  95. * @return On success will return 0, and others indicate fail.
  96. */
  97. int usbh_kill_urb(struct usbh_urb *urb);
  98. #ifdef __cplusplus
  99. }
  100. #endif
  101. #endif /* USB_HC_H */