SDL_hidapi_libusb.h 3.9 KB

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