SDL_hidapi_libusb.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 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. /* Define standard library functions in terms of SDL */
  19. /* #pragma push_macro/pop_macro works correctly only as of gcc >= 4.4.3
  20. clang-3.0 _seems_ to be OK. */
  21. #pragma push_macro("calloc")
  22. #pragma push_macro("malloc")
  23. #pragma push_macro("realloc")
  24. #pragma push_macro("free")
  25. #pragma push_macro("iconv_t")
  26. #pragma push_macro("iconv")
  27. #pragma push_macro("iconv_open")
  28. #pragma push_macro("iconv_close")
  29. #pragma push_macro("setlocale")
  30. #pragma push_macro("snprintf")
  31. #pragma push_macro("strcmp")
  32. #pragma push_macro("strdup")
  33. #pragma push_macro("strncpy")
  34. #pragma push_macro("tolower")
  35. #pragma push_macro("wcsdup")
  36. #undef calloc
  37. #undef malloc
  38. #undef realloc
  39. #undef free
  40. #undef iconv_t
  41. #undef iconv
  42. #undef iconv_open
  43. #undef iconv_close
  44. #undef setlocale
  45. #undef snprintf
  46. #undef strcmp
  47. #undef strdup
  48. #undef strncpy
  49. #undef tolower
  50. #undef wcsdup
  51. #define calloc SDL_calloc
  52. #define malloc SDL_malloc
  53. #define realloc SDL_realloc
  54. #define free SDL_free
  55. #define iconv_t SDL_iconv_t
  56. #ifndef ICONV_CONST
  57. #define ICONV_CONST
  58. #define UNDEF_ICONV_CONST
  59. #endif
  60. #define iconv(a,b,c,d,e) SDL_iconv(a, (const char **)b, c, d, e)
  61. #define iconv_open SDL_iconv_open
  62. #define iconv_close SDL_iconv_close
  63. #define setlocale(X, Y) NULL
  64. #define snprintf SDL_snprintf
  65. #define strcmp SDL_strcmp
  66. #define strdup SDL_strdup
  67. #define strncpy SDL_strlcpy
  68. #define tolower SDL_tolower
  69. #define wcsdup SDL_wcsdup
  70. #ifndef __FreeBSD__
  71. /* this is awkwardly inlined, so we need to re-implement it here
  72. * so we can override the libusb_control_transfer call */
  73. static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
  74. uint8_t descriptor_index, uint16_t lang_id,
  75. unsigned char *data, int length)
  76. {
  77. return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | 0x0, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | descriptor_index, lang_id,
  78. data, (uint16_t)length, 1000); /* Endpoint 0 IN */
  79. }
  80. #define libusb_get_string_descriptor SDL_libusb_get_string_descriptor
  81. #endif /* __FreeBSD__ */
  82. #define HIDAPI_THREAD_MODEL_INCLUDE "hidapi_thread_sdl.h"
  83. #ifndef LIBUSB_API_VERSION
  84. #ifdef LIBUSBX_API_VERSION
  85. #define LIBUSB_API_VERSION LIBUSBX_API_VERSION
  86. #else
  87. #define LIBUSB_API_VERSION 0x0
  88. #endif
  89. #endif
  90. /* we need libusb >= 1.0.16 because of libusb_get_port_numbers */
  91. /* we don't need libusb_wrap_sys_device: */
  92. #define HIDAPI_TARGET_LIBUSB_API_VERSION 0x01000102
  93. #undef HIDAPI_H__
  94. #include "libusb/hid.c"
  95. /* restore libc function macros */
  96. #ifdef UNDEF_ICONV_CONST
  97. #undef ICONV_CONST
  98. #undef UNDEF_ICONV_CONST
  99. #endif
  100. #pragma pop_macro("calloc")
  101. #pragma pop_macro("malloc")
  102. #pragma pop_macro("realloc")
  103. #pragma pop_macro("free")
  104. #pragma pop_macro("iconv_t")
  105. #pragma pop_macro("iconv")
  106. #pragma pop_macro("iconv_open")
  107. #pragma pop_macro("iconv_close")
  108. #pragma pop_macro("setlocale")
  109. #pragma pop_macro("snprintf")
  110. #pragma pop_macro("strcmp")
  111. #pragma pop_macro("strdup")
  112. #pragma pop_macro("strncpy")
  113. #pragma pop_macro("tolower")
  114. #pragma pop_macro("wcsdup")