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