SDL_hidapi_libusb.h 4.2 KB

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