Atlas - SDL_hidapi_libusb.h

Home / ext / SDL / src / hidapi Lines: 1 | Size: 4918 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)]
[FILE BEGIN]
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2025 Sam Lantinga <[email protected]> 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/* Define standard library functions in terms of SDL */ 23 24/* #pragma push_macro/pop_macro works correctly only as of gcc >= 4.4.3 25 clang-3.0 _seems_ to be OK. */ 26#pragma push_macro("calloc") 27#pragma push_macro("malloc") 28#pragma push_macro("realloc") 29#pragma push_macro("free") 30#pragma push_macro("iconv_t") 31#pragma push_macro("iconv") 32#pragma push_macro("iconv_open") 33#pragma push_macro("iconv_close") 34#pragma push_macro("setlocale") 35#pragma push_macro("snprintf") 36#pragma push_macro("strcmp") 37#pragma push_macro("strdup") 38#pragma push_macro("strncpy") 39#pragma push_macro("tolower") 40#pragma push_macro("wcscmp") 41#pragma push_macro("wcsdup") 42#pragma push_macro("wcsncpy") 43 44#undef calloc 45#undef malloc 46#undef realloc 47#undef free 48#undef iconv_t 49#undef iconv 50#undef iconv_open 51#undef iconv_close 52#undef setlocale 53#undef snprintf 54#undef strcmp 55#undef strdup 56#undef strncpy 57#undef tolower 58#undef wcscmp 59#undef wcsdup 60#undef wcsncpy 61 62#define calloc SDL_calloc 63#define malloc SDL_malloc 64#define realloc SDL_realloc 65#define free SDL_free 66#define iconv_t SDL_iconv_t 67#ifndef ICONV_CONST 68#define ICONV_CONST 69#define UNDEF_ICONV_CONST 70#endif 71#define iconv(a,b,c,d,e) SDL_iconv(a, (const char **)b, c, d, e) 72#define iconv_open SDL_iconv_open 73#define iconv_close SDL_iconv_close 74#define setlocale(X, Y) NULL 75#define snprintf SDL_snprintf 76#define strcmp SDL_strcmp 77#define strdup SDL_strdup 78#define strncpy SDL_strlcpy 79#define tolower SDL_tolower 80#define wcscmp SDL_wcscmp 81#define wcsdup SDL_wcsdup 82#define wcsncpy SDL_wcslcpy 83 84 85/* this is awkwardly inlined, so we need to re-implement it here 86 * so we can override the libusb_control_transfer call */ 87static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev, 88 uint8_t descriptor_index, uint16_t lang_id, 89 unsigned char *data, int length) 90{ 91 return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | 0x0, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | descriptor_index, lang_id, 92 data, (uint16_t)length, 1000); /* Endpoint 0 IN */ 93} 94#define libusb_get_string_descriptor SDL_libusb_get_string_descriptor 95 96/* this is inlined, except on FreeBSD, so we need to re-implement it here */ 97static void SDL_libusb_fill_interrupt_transfer( 98 struct libusb_transfer *transfer, libusb_device_handle *dev_handle, 99 unsigned char endpoint, unsigned char *buffer, int length, 100 libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout) 101{ 102 transfer->dev_handle = dev_handle; 103 transfer->endpoint = endpoint; 104 transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT; 105 transfer->timeout = timeout; 106 transfer->buffer = buffer; 107 transfer->length = length; 108 transfer->user_data = user_data; 109 transfer->callback = callback; 110} 111#define libusb_fill_interrupt_transfer SDL_libusb_fill_interrupt_transfer 112 113#define HIDAPI_THREAD_MODEL_INCLUDE "hidapi_thread_sdl.h" 114#ifndef LIBUSB_API_VERSION 115#ifdef LIBUSBX_API_VERSION 116#define LIBUSB_API_VERSION LIBUSBX_API_VERSION 117#else 118#define LIBUSB_API_VERSION 0x0 119#endif 120#endif 121/* we need libusb >= 1.0.16 because of libusb_get_port_numbers */ 122/* we don't need libusb_wrap_sys_device: */ 123#define HIDAPI_TARGET_LIBUSB_API_VERSION 0x01000102 124 125#undef HIDAPI_H__ 126#include "libusb/hid.c" 127 128/* restore libc function macros */ 129#ifdef UNDEF_ICONV_CONST 130#undef ICONV_CONST 131#undef UNDEF_ICONV_CONST 132#endif 133#pragma pop_macro("calloc") 134#pragma pop_macro("malloc") 135#pragma pop_macro("realloc") 136#pragma pop_macro("free") 137#pragma pop_macro("iconv_t") 138#pragma pop_macro("iconv") 139#pragma pop_macro("iconv_open") 140#pragma pop_macro("iconv_close") 141#pragma pop_macro("setlocale") 142#pragma pop_macro("snprintf") 143#pragma pop_macro("strcmp") 144#pragma pop_macro("strdup") 145#pragma pop_macro("strncpy") 146#pragma pop_macro("tolower") 147#pragma pop_macro("wcscmp") 148#pragma pop_macro("wcsdup") 149#pragma pop_macro("wcsncpy") 150
[FILE END]
(C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.