SDL_hidapi_libusb.h 3.6 KB

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