SDL_libusb.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #ifdef HAVE_LIBUSB
  20. // libusb HIDAPI Implementation
  21. // Include this now, for our dynamically-loaded libusb context
  22. #include <libusb.h>
  23. typedef struct SDL_LibUSBContext
  24. {
  25. /* *INDENT-OFF* */ // clang-format off
  26. int (LIBUSB_CALL *init)(libusb_context **ctx);
  27. void (LIBUSB_CALL *exit)(libusb_context *ctx);
  28. ssize_t (LIBUSB_CALL *get_device_list)(libusb_context *ctx, libusb_device ***list);
  29. void (LIBUSB_CALL *free_device_list)(libusb_device **list, int unref_devices);
  30. int (LIBUSB_CALL *get_device_descriptor)(libusb_device *dev, struct libusb_device_descriptor *desc);
  31. int (LIBUSB_CALL *get_active_config_descriptor)(libusb_device *dev, struct libusb_config_descriptor **config);
  32. int (LIBUSB_CALL *get_config_descriptor)(
  33. libusb_device *dev,
  34. uint8_t config_index,
  35. struct libusb_config_descriptor **config
  36. );
  37. void (LIBUSB_CALL *free_config_descriptor)(struct libusb_config_descriptor *config);
  38. uint8_t (LIBUSB_CALL *get_bus_number)(libusb_device *dev);
  39. #ifdef SDL_PLATFORM_FREEBSD
  40. int (LIBUSB_CALL *get_port_numbers)(libusb_device *dev, uint8_t *port_numbers, uint8_t port_numbers_len);
  41. #else
  42. int (LIBUSB_CALL *get_port_numbers)(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len);
  43. #endif
  44. uint8_t (LIBUSB_CALL *get_device_address)(libusb_device *dev);
  45. int (LIBUSB_CALL *open)(libusb_device *dev, libusb_device_handle **dev_handle);
  46. void (LIBUSB_CALL *close)(libusb_device_handle *dev_handle);
  47. libusb_device *(LIBUSB_CALL *get_device)(libusb_device_handle *dev_handle);
  48. int (LIBUSB_CALL *claim_interface)(libusb_device_handle *dev_handle, int interface_number);
  49. int (LIBUSB_CALL *release_interface)(libusb_device_handle *dev_handle, int interface_number);
  50. int (LIBUSB_CALL *kernel_driver_active)(libusb_device_handle *dev_handle, int interface_number);
  51. int (LIBUSB_CALL *detach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
  52. int (LIBUSB_CALL *attach_kernel_driver)(libusb_device_handle *dev_handle, int interface_number);
  53. int (LIBUSB_CALL *set_interface_alt_setting)(libusb_device_handle *dev, int interface_number, int alternate_setting);
  54. struct libusb_transfer * (LIBUSB_CALL *alloc_transfer)(int iso_packets);
  55. int (LIBUSB_CALL *submit_transfer)(struct libusb_transfer *transfer);
  56. int (LIBUSB_CALL *cancel_transfer)(struct libusb_transfer *transfer);
  57. void (LIBUSB_CALL *free_transfer)(struct libusb_transfer *transfer);
  58. int (LIBUSB_CALL *control_transfer)(
  59. libusb_device_handle *dev_handle,
  60. uint8_t request_type,
  61. uint8_t bRequest,
  62. uint16_t wValue,
  63. uint16_t wIndex,
  64. unsigned char *data,
  65. uint16_t wLength,
  66. unsigned int timeout
  67. );
  68. int (LIBUSB_CALL *interrupt_transfer)(
  69. libusb_device_handle *dev_handle,
  70. unsigned char endpoint,
  71. unsigned char *data,
  72. int length,
  73. int *actual_length,
  74. unsigned int timeout
  75. );
  76. int (LIBUSB_CALL *bulk_transfer)(
  77. libusb_device_handle *dev_handle,
  78. unsigned char endpoint,
  79. unsigned char *data,
  80. int length,
  81. int *transferred,
  82. unsigned int timeout
  83. );
  84. int (LIBUSB_CALL *handle_events)(libusb_context *ctx);
  85. int (LIBUSB_CALL *handle_events_completed)(libusb_context *ctx, int *completed);
  86. const char * (LIBUSB_CALL *error_name)(int errcode);
  87. /* *INDENT-ON* */ // clang-format on
  88. } SDL_LibUSBContext;
  89. extern bool SDL_InitLibUSB(SDL_LibUSBContext **ctx);
  90. extern void SDL_QuitLibUSB(void);
  91. #endif // HAVE_LIBUSB