mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-07 16:01:10 +00:00
Create wrapper headers for platform specific hidapi modules
This commit is contained in:
parent
2a08bf6118
commit
22f22472a0
8 changed files with 228 additions and 72 deletions
|
@ -564,66 +564,16 @@ typedef struct PLATFORM_hid_device_ PLATFORM_hid_device;
|
||||||
#define read_thread PLATFORM_read_thread
|
#define read_thread PLATFORM_read_thread
|
||||||
#define return_data PLATFORM_return_data
|
#define return_data PLATFORM_return_data
|
||||||
|
|
||||||
/* Allow hidapi.h to be included in the platform implementation */
|
|
||||||
#undef HIDAPI_H__
|
|
||||||
|
|
||||||
#ifdef __LINUX__
|
#ifdef __LINUX__
|
||||||
|
#include "SDL_hidapi_linux.h"
|
||||||
#ifdef SDL_USE_LIBUDEV
|
|
||||||
static const SDL_UDEV_Symbols *udev_ctx = NULL;
|
|
||||||
|
|
||||||
#define udev_device_get_devnode udev_ctx->udev_device_get_devnode
|
|
||||||
#define udev_device_get_parent_with_subsystem_devtype udev_ctx->udev_device_get_parent_with_subsystem_devtype
|
|
||||||
#define udev_device_get_sysattr_value udev_ctx->udev_device_get_sysattr_value
|
|
||||||
#define udev_device_get_syspath udev_ctx->udev_device_get_syspath
|
|
||||||
#define udev_device_new_from_devnum udev_ctx->udev_device_new_from_devnum
|
|
||||||
#define udev_device_new_from_syspath udev_ctx->udev_device_new_from_syspath
|
|
||||||
#define udev_device_unref udev_ctx->udev_device_unref
|
|
||||||
#define udev_enumerate_add_match_subsystem udev_ctx->udev_enumerate_add_match_subsystem
|
|
||||||
#define udev_enumerate_get_list_entry udev_ctx->udev_enumerate_get_list_entry
|
|
||||||
#define udev_enumerate_new udev_ctx->udev_enumerate_new
|
|
||||||
#define udev_enumerate_scan_devices udev_ctx->udev_enumerate_scan_devices
|
|
||||||
#define udev_enumerate_unref udev_ctx->udev_enumerate_unref
|
|
||||||
#define udev_list_entry_get_name udev_ctx->udev_list_entry_get_name
|
|
||||||
#define udev_list_entry_get_next udev_ctx->udev_list_entry_get_next
|
|
||||||
#define udev_new udev_ctx->udev_new
|
|
||||||
#define udev_unref udev_ctx->udev_unref
|
|
||||||
|
|
||||||
#include "linux/hid.c"
|
|
||||||
#define HAVE_PLATFORM_BACKEND 1
|
|
||||||
#endif /* SDL_USE_LIBUDEV */
|
|
||||||
|
|
||||||
#elif defined(__MACOS__)
|
#elif defined(__MACOS__)
|
||||||
#include "mac/hid.c"
|
#include "SDL_hidapi_mac.h"
|
||||||
#define HAVE_PLATFORM_BACKEND 1
|
|
||||||
#define udev_ctx 1
|
|
||||||
#elif defined(__WINDOWS__) || defined(__WINGDK__)
|
#elif defined(__WINDOWS__) || defined(__WINGDK__)
|
||||||
/* Define standard library functions in terms of SDL */
|
#include "SDL_hidapi_windows.h"
|
||||||
#define calloc SDL_calloc
|
|
||||||
#define free SDL_free
|
|
||||||
#define malloc SDL_malloc
|
|
||||||
#define memcmp SDL_memcmp
|
|
||||||
#define swprintf SDL_swprintf
|
|
||||||
#define towupper SDL_toupper
|
|
||||||
#define wcscmp SDL_wcscmp
|
|
||||||
#define _wcsdup SDL_wcsdup
|
|
||||||
#define wcslen SDL_wcslen
|
|
||||||
#define wcsncpy SDL_wcslcpy
|
|
||||||
#define wcsstr SDL_wcsstr
|
|
||||||
#define wcstol SDL_wcstol
|
|
||||||
#include "windows/hid.c"
|
|
||||||
#define HAVE_PLATFORM_BACKEND 1
|
|
||||||
#define udev_ctx 1
|
|
||||||
#elif defined(__ANDROID__)
|
#elif defined(__ANDROID__)
|
||||||
/* The implementation for Android is in a separate .cpp file */
|
#include "SDL_hidapi_android.h"
|
||||||
#include "hidapi/hidapi.h"
|
|
||||||
#define HAVE_PLATFORM_BACKEND 1
|
|
||||||
#define udev_ctx 1
|
|
||||||
#elif defined(__IOS__) || defined(__TVOS__)
|
#elif defined(__IOS__) || defined(__TVOS__)
|
||||||
/* The implementation for iOS and tvOS is in a separate .m file */
|
#include "SDL_hidapi_ios.h"
|
||||||
#include "hidapi/hidapi.h"
|
|
||||||
#define HAVE_PLATFORM_BACKEND 1
|
|
||||||
#define udev_ctx 1
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#undef api_version
|
#undef api_version
|
||||||
|
@ -696,8 +646,7 @@ typedef struct DRIVER_hid_device_ DRIVER_hid_device;
|
||||||
#define hid_write DRIVER_hid_write
|
#define hid_write DRIVER_hid_write
|
||||||
|
|
||||||
#ifdef SDL_JOYSTICK_HIDAPI_STEAMXBOX
|
#ifdef SDL_JOYSTICK_HIDAPI_STEAMXBOX
|
||||||
#undef HIDAPI_H__
|
#include "SDL_hidapi_steamxbox.h"
|
||||||
#include "steamxbox/hid.c"
|
|
||||||
#else
|
#else
|
||||||
#error Need a driver hid.c for this platform!
|
#error Need a driver hid.c for this platform!
|
||||||
#endif
|
#endif
|
||||||
|
@ -857,21 +806,7 @@ typedef struct LIBUSB_hid_device_ LIBUSB_hid_device;
|
||||||
#define read_thread LIBUSB_read_thread
|
#define read_thread LIBUSB_read_thread
|
||||||
#define return_data LIBUSB_return_data
|
#define return_data LIBUSB_return_data
|
||||||
|
|
||||||
#ifndef __FreeBSD__
|
#include "SDL_hidapi_libusb.h"
|
||||||
/* this is awkwardly inlined, so we need to re-implement it here
|
|
||||||
* so we can override the libusb_control_transfer call */
|
|
||||||
static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
|
|
||||||
uint8_t descriptor_index, uint16_t lang_id,
|
|
||||||
unsigned char *data, int length)
|
|
||||||
{
|
|
||||||
return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | 0x0, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | descriptor_index, lang_id,
|
|
||||||
data, (uint16_t)length, 1000); /* Endpoint 0 IN */
|
|
||||||
}
|
|
||||||
#define libusb_get_string_descriptor SDL_libusb_get_string_descriptor
|
|
||||||
#endif /* __FreeBSD__ */
|
|
||||||
|
|
||||||
#undef HIDAPI_H__
|
|
||||||
#include "libusb/hid.c"
|
|
||||||
|
|
||||||
#undef libusb_init
|
#undef libusb_init
|
||||||
#undef libusb_exit
|
#undef libusb_exit
|
||||||
|
|
26
src/hidapi/SDL_hidapi_android.h
Normal file
26
src/hidapi/SDL_hidapi_android.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* The implementation for Android is in a separate .cpp file */
|
||||||
|
#undef HIDAPI_H__
|
||||||
|
#include "hidapi/hidapi.h"
|
||||||
|
#define HAVE_PLATFORM_BACKEND 1
|
||||||
|
#define udev_ctx 1
|
26
src/hidapi/SDL_hidapi_ios.h
Normal file
26
src/hidapi/SDL_hidapi_ios.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* The implementation for iOS and tvOS is in a separate .m file */
|
||||||
|
#undef HIDAPI_H__
|
||||||
|
#include "hidapi/hidapi.h"
|
||||||
|
#define HAVE_PLATFORM_BACKEND 1
|
||||||
|
#define udev_ctx 1
|
36
src/hidapi/SDL_hidapi_libusb.h
Normal file
36
src/hidapi/SDL_hidapi_libusb.h
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
/*
|
||||||
|
Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __FreeBSD__
|
||||||
|
/* this is awkwardly inlined, so we need to re-implement it here
|
||||||
|
* so we can override the libusb_control_transfer call */
|
||||||
|
static int SDL_libusb_get_string_descriptor(libusb_device_handle *dev,
|
||||||
|
uint8_t descriptor_index, uint16_t lang_id,
|
||||||
|
unsigned char *data, int length)
|
||||||
|
{
|
||||||
|
return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN | 0x0, LIBUSB_REQUEST_GET_DESCRIPTOR, (LIBUSB_DT_STRING << 8) | descriptor_index, lang_id,
|
||||||
|
data, (uint16_t)length, 1000); /* Endpoint 0 IN */
|
||||||
|
}
|
||||||
|
#define libusb_get_string_descriptor SDL_libusb_get_string_descriptor
|
||||||
|
#endif /* __FreeBSD__ */
|
||||||
|
|
||||||
|
#undef HIDAPI_H__
|
||||||
|
#include "libusb/hid.c"
|
46
src/hidapi/SDL_hidapi_linux.h
Normal file
46
src/hidapi/SDL_hidapi_linux.h
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef SDL_USE_LIBUDEV
|
||||||
|
static const SDL_UDEV_Symbols *udev_ctx = NULL;
|
||||||
|
|
||||||
|
#define udev_device_get_devnode udev_ctx->udev_device_get_devnode
|
||||||
|
#define udev_device_get_parent_with_subsystem_devtype udev_ctx->udev_device_get_parent_with_subsystem_devtype
|
||||||
|
#define udev_device_get_sysattr_value udev_ctx->udev_device_get_sysattr_value
|
||||||
|
#define udev_device_get_syspath udev_ctx->udev_device_get_syspath
|
||||||
|
#define udev_device_new_from_devnum udev_ctx->udev_device_new_from_devnum
|
||||||
|
#define udev_device_new_from_syspath udev_ctx->udev_device_new_from_syspath
|
||||||
|
#define udev_device_unref udev_ctx->udev_device_unref
|
||||||
|
#define udev_enumerate_add_match_subsystem udev_ctx->udev_enumerate_add_match_subsystem
|
||||||
|
#define udev_enumerate_get_list_entry udev_ctx->udev_enumerate_get_list_entry
|
||||||
|
#define udev_enumerate_new udev_ctx->udev_enumerate_new
|
||||||
|
#define udev_enumerate_scan_devices udev_ctx->udev_enumerate_scan_devices
|
||||||
|
#define udev_enumerate_unref udev_ctx->udev_enumerate_unref
|
||||||
|
#define udev_list_entry_get_name udev_ctx->udev_list_entry_get_name
|
||||||
|
#define udev_list_entry_get_next udev_ctx->udev_list_entry_get_next
|
||||||
|
#define udev_new udev_ctx->udev_new
|
||||||
|
#define udev_unref udev_ctx->udev_unref
|
||||||
|
|
||||||
|
#undef HIDAPI_H__
|
||||||
|
#include "linux/hid.c"
|
||||||
|
#define HAVE_PLATFORM_BACKEND 1
|
||||||
|
|
||||||
|
#endif /* SDL_USE_LIBUDEV */
|
25
src/hidapi/SDL_hidapi_mac.h
Normal file
25
src/hidapi/SDL_hidapi_mac.h
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#undef HIDAPI_H__
|
||||||
|
#include "mac/hid.c"
|
||||||
|
#define HAVE_PLATFORM_BACKEND 1
|
||||||
|
#define udev_ctx 1
|
23
src/hidapi/SDL_hidapi_steamxbox.h
Normal file
23
src/hidapi/SDL_hidapi_steamxbox.h
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#undef HIDAPI_H__
|
||||||
|
#include "steamxbox/hid.c"
|
39
src/hidapi/SDL_hidapi_windows.h
Normal file
39
src/hidapi/SDL_hidapi_windows.h
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
Simple DirectMedia Layer
|
||||||
|
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
|
||||||
|
|
||||||
|
This software is provided 'as-is', without any express or implied
|
||||||
|
warranty. In no event will the authors be held liable for any damages
|
||||||
|
arising from the use of this software.
|
||||||
|
|
||||||
|
Permission is granted to anyone to use this software for any purpose,
|
||||||
|
including commercial applications, and to alter it and redistribute it
|
||||||
|
freely, subject to the following restrictions:
|
||||||
|
|
||||||
|
1. The origin of this software must not be misrepresented; you must not
|
||||||
|
claim that you wrote the original software. If you use this software
|
||||||
|
in a product, an acknowledgment in the product documentation would be
|
||||||
|
appreciated but is not required.
|
||||||
|
2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
misrepresented as being the original software.
|
||||||
|
3. This notice may not be removed or altered from any source distribution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Define standard library functions in terms of SDL */
|
||||||
|
#define calloc SDL_calloc
|
||||||
|
#define free SDL_free
|
||||||
|
#define malloc SDL_malloc
|
||||||
|
#define memcmp SDL_memcmp
|
||||||
|
#define swprintf SDL_swprintf
|
||||||
|
#define towupper SDL_toupper
|
||||||
|
#define wcscmp SDL_wcscmp
|
||||||
|
#define _wcsdup SDL_wcsdup
|
||||||
|
#define wcslen SDL_wcslen
|
||||||
|
#define wcsncpy SDL_wcslcpy
|
||||||
|
#define wcsstr SDL_wcsstr
|
||||||
|
#define wcstol SDL_wcstol
|
||||||
|
|
||||||
|
#undef HIDAPI_H__
|
||||||
|
#include "windows/hid.c"
|
||||||
|
#define HAVE_PLATFORM_BACKEND 1
|
||||||
|
#define udev_ctx 1
|
Loading…
Add table
Add a link
Reference in a new issue