usb_private.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #pragma once
  7. #include <stddef.h>
  8. #include <stdbool.h>
  9. #include <stdint.h>
  10. #include <sys/queue.h>
  11. #include "usb/usb_types_ch9.h"
  12. #include "usb/usb_types_stack.h"
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. // ------------------------------------------------------ Types --------------------------------------------------------
  17. typedef struct {
  18. uint8_t *data_buffer;
  19. size_t data_buffer_size;
  20. int num_bytes;
  21. int actual_num_bytes;
  22. uint32_t flags;
  23. usb_device_handle_t device_handle;
  24. uint8_t bEndpointAddress;
  25. usb_transfer_status_t status;
  26. uint32_t timeout;
  27. usb_transfer_cb_t callback;
  28. void *context;
  29. int num_isoc_packets;
  30. usb_isoc_packet_desc_t isoc_packet_desc[0];
  31. } usb_transfer_dummy_t;
  32. _Static_assert(sizeof(usb_transfer_dummy_t) == sizeof(usb_transfer_t), "usb_transfer_dummy_t does not match usb_transfer_t");
  33. struct urb_s{
  34. TAILQ_ENTRY(urb_s) tailq_entry;
  35. //HCD handler pointer and variables. Must be initialized to NULL and 0 respectively
  36. void *hcd_ptr;
  37. uint32_t hcd_var;
  38. //Host Driver layer handler
  39. void *usb_host_client; //Currently only used when submitted to shared pipes (i.e., Device default pipes)
  40. size_t usb_host_header_size; //USB Host may need the data buffer to have a transparent header
  41. //Public transfer structure. Must be last due to variable length array
  42. usb_transfer_t transfer;
  43. };
  44. typedef struct urb_s urb_t;
  45. typedef enum {
  46. USB_NOTIF_SOURCE_USBH = 0x01,
  47. USB_NOTIF_SOURCE_HUB = 0x02,
  48. } usb_notif_source_t;
  49. typedef bool (*usb_notif_cb_t)(usb_notif_source_t source, bool in_isr, void *context);
  50. // --------------------------------------------------- Allocation ------------------------------------------------------
  51. /**
  52. * @brief Allocate a URB
  53. *
  54. * - Data buffer is allocated in DMA capable memory
  55. * - The constant fields of the URB are also set
  56. * - The data_buffer field of the URB is set to point to start of the allocated data buffer AFTER the header. To access
  57. * the header, users need a negative offset from data_buffer.
  58. *
  59. * @param data_buffer_size Size of the URB's data buffer
  60. * @param header_size Size of header to put in front of URB's data buffer
  61. * @param num_isoc_packets Number of isochronous packet descriptors
  62. * @return urb_t* URB object
  63. */
  64. urb_t *urb_alloc(size_t data_buffer_size, size_t header_size, int num_isoc_packets);
  65. /**
  66. * @brief Free a URB
  67. *
  68. * @param urb URB object
  69. */
  70. void urb_free(urb_t *urb);
  71. #ifdef __cplusplus
  72. }
  73. #endif