early-access version 2835
This commit is contained in:
131
externals/SDL/src/hidapi/SDL_hidapi.c
vendored
131
externals/SDL/src/hidapi/SDL_hidapi.c
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -951,6 +951,7 @@ DeleteHIDDeviceWrapper(SDL_hid_device *device)
|
||||
}
|
||||
|
||||
#if !SDL_HIDAPI_DISABLED
|
||||
#if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC)
|
||||
|
||||
#define COPY_IF_EXISTS(var) \
|
||||
if (pSrc->var != NULL) { \
|
||||
@@ -987,6 +988,7 @@ CopyHIDDeviceInfo(struct SDL_hid_device_info *pSrc, struct SDL_hid_device_info *
|
||||
#undef COPY_IF_EXISTS
|
||||
#undef WCOPY_IF_EXISTS
|
||||
|
||||
#endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */
|
||||
#endif /* !SDL_HIDAPI_DISABLED */
|
||||
|
||||
static int SDL_hidapi_refcount = 0;
|
||||
@@ -1011,50 +1013,81 @@ int SDL_hid_init(void)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
++attempts;
|
||||
libusb_ctx.libhandle = SDL_LoadObject(SDL_LIBUSB_DYNAMIC);
|
||||
if (libusb_ctx.libhandle != NULL) {
|
||||
SDL_bool loaded = SDL_TRUE;
|
||||
#define LOAD_LIBUSB_SYMBOL(func) \
|
||||
if (!(libusb_ctx.func = SDL_LoadFunction(libusb_ctx.libhandle, "libusb_" #func))) {loaded = SDL_FALSE;}
|
||||
LOAD_LIBUSB_SYMBOL(init)
|
||||
LOAD_LIBUSB_SYMBOL(exit)
|
||||
LOAD_LIBUSB_SYMBOL(get_device_list)
|
||||
LOAD_LIBUSB_SYMBOL(free_device_list)
|
||||
LOAD_LIBUSB_SYMBOL(get_device_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(get_active_config_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(get_config_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(free_config_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(get_bus_number)
|
||||
LOAD_LIBUSB_SYMBOL(get_device_address)
|
||||
LOAD_LIBUSB_SYMBOL(open)
|
||||
LOAD_LIBUSB_SYMBOL(close)
|
||||
LOAD_LIBUSB_SYMBOL(claim_interface)
|
||||
LOAD_LIBUSB_SYMBOL(release_interface)
|
||||
LOAD_LIBUSB_SYMBOL(kernel_driver_active)
|
||||
LOAD_LIBUSB_SYMBOL(detach_kernel_driver)
|
||||
LOAD_LIBUSB_SYMBOL(attach_kernel_driver)
|
||||
LOAD_LIBUSB_SYMBOL(set_interface_alt_setting)
|
||||
LOAD_LIBUSB_SYMBOL(alloc_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(submit_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(cancel_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(free_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(control_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(interrupt_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(handle_events)
|
||||
LOAD_LIBUSB_SYMBOL(handle_events_completed)
|
||||
#undef LOAD_LIBUSB_SYMBOL
|
||||
#if defined(SDL_USE_LIBUDEV)
|
||||
if (SDL_getenv("SDL_HIDAPI_JOYSTICK_DISABLE_UDEV") != NULL) {
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"udev disabled by SDL_HIDAPI_JOYSTICK_DISABLE_UDEV");
|
||||
linux_enumeration_method = ENUMERATION_FALLBACK;
|
||||
} else if (access("/.flatpak-info", F_OK) == 0
|
||||
|| access("/run/host/container-manager", F_OK) == 0) {
|
||||
/* Explicitly check `/.flatpak-info` because, for old versions of
|
||||
* Flatpak, this was the only available way to tell if we were in
|
||||
* a Flatpak container. */
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"Container detected, disabling HIDAPI udev integration");
|
||||
linux_enumeration_method = ENUMERATION_FALLBACK;
|
||||
} else {
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"Using udev for HIDAPI joystick device discovery");
|
||||
linux_enumeration_method = ENUMERATION_LIBUDEV;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!loaded) {
|
||||
SDL_UnloadObject(libusb_ctx.libhandle);
|
||||
libusb_ctx.libhandle = NULL;
|
||||
/* SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, SDL_LIBUSB_DYNAMIC " found but could not load function"); */
|
||||
} else if (LIBUSB_hid_init() < 0) {
|
||||
SDL_UnloadObject(libusb_ctx.libhandle);
|
||||
libusb_ctx.libhandle = NULL;
|
||||
} else {
|
||||
++success;
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
if (SDL_getenv("SDL_HIDAPI_DISABLE_LIBUSB") != NULL) {
|
||||
SDL_LogDebug(SDL_LOG_CATEGORY_INPUT,
|
||||
"libusb disabled by SDL_HIDAPI_DISABLE_LIBUSB");
|
||||
libusb_ctx.libhandle = NULL;
|
||||
} else {
|
||||
++attempts;
|
||||
libusb_ctx.libhandle = SDL_LoadObject(SDL_LIBUSB_DYNAMIC);
|
||||
if (libusb_ctx.libhandle != NULL) {
|
||||
SDL_bool loaded = SDL_TRUE;
|
||||
#ifdef __OS2__
|
||||
#define LOAD_LIBUSB_SYMBOL(func) \
|
||||
if (!(libusb_ctx.func = SDL_LoadFunction(libusb_ctx.libhandle,"_libusb_" #func))) {loaded = SDL_FALSE;}
|
||||
#else
|
||||
#define LOAD_LIBUSB_SYMBOL(func) \
|
||||
if (!(libusb_ctx.func = SDL_LoadFunction(libusb_ctx.libhandle, "libusb_" #func))) {loaded = SDL_FALSE;}
|
||||
#endif
|
||||
LOAD_LIBUSB_SYMBOL(init)
|
||||
LOAD_LIBUSB_SYMBOL(exit)
|
||||
LOAD_LIBUSB_SYMBOL(get_device_list)
|
||||
LOAD_LIBUSB_SYMBOL(free_device_list)
|
||||
LOAD_LIBUSB_SYMBOL(get_device_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(get_active_config_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(get_config_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(free_config_descriptor)
|
||||
LOAD_LIBUSB_SYMBOL(get_bus_number)
|
||||
LOAD_LIBUSB_SYMBOL(get_device_address)
|
||||
LOAD_LIBUSB_SYMBOL(open)
|
||||
LOAD_LIBUSB_SYMBOL(close)
|
||||
LOAD_LIBUSB_SYMBOL(claim_interface)
|
||||
LOAD_LIBUSB_SYMBOL(release_interface)
|
||||
LOAD_LIBUSB_SYMBOL(kernel_driver_active)
|
||||
LOAD_LIBUSB_SYMBOL(detach_kernel_driver)
|
||||
LOAD_LIBUSB_SYMBOL(attach_kernel_driver)
|
||||
LOAD_LIBUSB_SYMBOL(set_interface_alt_setting)
|
||||
LOAD_LIBUSB_SYMBOL(alloc_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(submit_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(cancel_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(free_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(control_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(interrupt_transfer)
|
||||
LOAD_LIBUSB_SYMBOL(handle_events)
|
||||
LOAD_LIBUSB_SYMBOL(handle_events_completed)
|
||||
#undef LOAD_LIBUSB_SYMBOL
|
||||
|
||||
if (!loaded) {
|
||||
SDL_UnloadObject(libusb_ctx.libhandle);
|
||||
libusb_ctx.libhandle = NULL;
|
||||
/* SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, SDL_LIBUSB_DYNAMIC " found but could not load function"); */
|
||||
} else if (LIBUSB_hid_init() < 0) {
|
||||
SDL_UnloadObject(libusb_ctx.libhandle);
|
||||
libusb_ctx.libhandle = NULL;
|
||||
} else {
|
||||
++success;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* SDL_LIBUSB_DYNAMIC */
|
||||
@@ -1160,9 +1193,9 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
|
||||
#ifdef SDL_LIBUSB_DYNAMIC
|
||||
if (libusb_ctx.libhandle) {
|
||||
usb_devs = LIBUSB_hid_enumerate(vendor_id, product_id);
|
||||
#ifdef DEBUG_HIDAPI
|
||||
#ifdef DEBUG_HIDAPI
|
||||
SDL_Log("libusb devices found:");
|
||||
#endif
|
||||
#endif
|
||||
for (usb_dev = usb_devs; usb_dev; usb_dev = usb_dev->next) {
|
||||
new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info));
|
||||
if (!new_dev) {
|
||||
@@ -1172,11 +1205,11 @@ struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned
|
||||
return NULL;
|
||||
}
|
||||
CopyHIDDeviceInfo(usb_dev, new_dev);
|
||||
#ifdef DEBUG_HIDAPI
|
||||
#ifdef DEBUG_HIDAPI
|
||||
SDL_Log(" - %ls %ls 0x%.4hx 0x%.4hx",
|
||||
usb_dev->manufacturer_string, usb_dev->product_string,
|
||||
usb_dev->vendor_id, usb_dev->product_id);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (last != NULL) {
|
||||
last->next = new_dev;
|
||||
@@ -1497,7 +1530,7 @@ int SDL_hid_get_indexed_string(SDL_hid_device *device, int string_index, wchar_t
|
||||
|
||||
void SDL_hid_ble_scan(SDL_bool active)
|
||||
{
|
||||
#if __IPHONEOS__ || __TVOS__
|
||||
#if !SDL_HIDAPI_DISABLED && (__IPHONEOS__ || __TVOS__)
|
||||
hid_ble_scan(active);
|
||||
#endif
|
||||
}
|
||||
|
2
externals/SDL/src/hidapi/SDL_hidapi_c.h
vendored
2
externals/SDL/src/hidapi/SDL_hidapi_c.h
vendored
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2021 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
|
119
externals/SDL/src/hidapi/android/hid.cpp
vendored
119
externals/SDL/src/hidapi/android/hid.cpp
vendored
@@ -24,6 +24,30 @@
|
||||
//
|
||||
// This layer glues the hidapi API to Android's USB and BLE stack.
|
||||
|
||||
|
||||
// Common to stub version and non-stub version of functions
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#define TAG "hidapi"
|
||||
|
||||
// Have error log always available
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
|
||||
|
||||
#ifdef DEBUG
|
||||
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__)
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define LOGV(...)
|
||||
#define LOGD(...)
|
||||
#endif
|
||||
|
||||
#define SDL_JAVA_PREFIX org_libsdl_app
|
||||
#define CONCAT1(prefix, class, function) CONCAT2(prefix, class, function)
|
||||
#define CONCAT2(prefix, class, function) Java_ ## prefix ## _ ## class ## _ ## function
|
||||
#define HID_DEVICE_MANAGER_JAVA_INTERFACE(function) CONCAT1(SDL_JAVA_PREFIX, HIDDeviceManager, function)
|
||||
|
||||
|
||||
#if !SDL_HIDAPI_DISABLED
|
||||
|
||||
#include "SDL_hints.h"
|
||||
@@ -48,30 +72,10 @@
|
||||
#define hid_get_indexed_string PLATFORM_hid_get_indexed_string
|
||||
#define hid_error PLATFORM_hid_error
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h> // For ETIMEDOUT and ECONNRESET
|
||||
#include <stdlib.h> // For malloc() and free()
|
||||
|
||||
#define TAG "hidapi"
|
||||
|
||||
// Have error log always available
|
||||
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
|
||||
|
||||
#ifdef DEBUG
|
||||
#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, TAG, __VA_ARGS__)
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, TAG, __VA_ARGS__)
|
||||
#else
|
||||
#define LOGV(...)
|
||||
#define LOGD(...)
|
||||
#endif
|
||||
|
||||
#define SDL_JAVA_PREFIX org_libsdl_app
|
||||
#define CONCAT1(prefix, class, function) CONCAT2(prefix, class, function)
|
||||
#define CONCAT2(prefix, class, function) Java_ ## prefix ## _ ## class ## _ ## function
|
||||
#define HID_DEVICE_MANAGER_JAVA_INTERFACE(function) CONCAT1(SDL_JAVA_PREFIX, HIDDeviceManager, function)
|
||||
|
||||
#include "../hidapi/hidapi.h"
|
||||
|
||||
typedef uint32_t uint32;
|
||||
@@ -1336,4 +1340,79 @@ int hid_exit(void)
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz);
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallback)(JNIEnv *env, jobject thiz);
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNIEnv *env, jobject thiz, int nDeviceID, jstring sIdentifier, int nVendorId, int nProductId, jstring sSerialNumber, int nReleaseNumber, jstring sManufacturer, jstring sProduct, int nInterface, int nInterfaceClass, int nInterfaceSubclass, int nInterfaceProtocol );
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceOpenPending)(JNIEnv *env, jobject thiz, int nDeviceID);
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceOpenResult)(JNIEnv *env, jobject thiz, int nDeviceID, bool bOpened);
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceDisconnected)(JNIEnv *env, jobject thiz, int nDeviceID);
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceInputReport)(JNIEnv *env, jobject thiz, int nDeviceID, jbyteArray value);
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceFeatureReport)(JNIEnv *env, jobject thiz, int nDeviceID, jbyteArray value);
|
||||
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceRegisterCallback)(JNIEnv *env, jobject thiz )
|
||||
{
|
||||
LOGV("Stub HIDDeviceRegisterCallback()");
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceReleaseCallback)(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
LOGV("Stub HIDDeviceReleaseCallback()");
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceConnected)(JNIEnv *env, jobject thiz, int nDeviceID, jstring sIdentifier, int nVendorId, int nProductId, jstring sSerialNumber, int nReleaseNumber, jstring sManufacturer, jstring sProduct, int nInterface, int nInterfaceClass, int nInterfaceSubclass, int nInterfaceProtocol )
|
||||
{
|
||||
LOGV("Stub HIDDeviceConnected() id=%d VID/PID = %.4x/%.4x, interface %d\n", nDeviceID, nVendorId, nProductId, nInterface);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceOpenPending)(JNIEnv *env, jobject thiz, int nDeviceID)
|
||||
{
|
||||
LOGV("Stub HIDDeviceOpenPending() id=%d\n", nDeviceID);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceOpenResult)(JNIEnv *env, jobject thiz, int nDeviceID, bool bOpened)
|
||||
{
|
||||
LOGV("Stub HIDDeviceOpenResult() id=%d, result=%s\n", nDeviceID, bOpened ? "true" : "false");
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceDisconnected)(JNIEnv *env, jobject thiz, int nDeviceID)
|
||||
{
|
||||
LOGV("Stub HIDDeviceDisconnected() id=%d\n", nDeviceID);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceInputReport)(JNIEnv *env, jobject thiz, int nDeviceID, jbyteArray value)
|
||||
{
|
||||
LOGV("Stub HIDDeviceInput() id=%d len=%u\n", nDeviceID, nBufSize);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT void JNICALL HID_DEVICE_MANAGER_JAVA_INTERFACE(HIDDeviceFeatureReport)(JNIEnv *env, jobject thiz, int nDeviceID, jbyteArray value)
|
||||
{
|
||||
LOGV("Stub HIDDeviceFeatureReport() id=%d len=%u\n", nDeviceID, nBufSize);
|
||||
}
|
||||
|
||||
#endif /* SDL_HIDAPI_DISABLED */
|
||||
|
54
externals/SDL/src/hidapi/libusb/hid.c
vendored
54
externals/SDL/src/hidapi/libusb/hid.c
vendored
@@ -31,9 +31,24 @@
|
||||
#include "SDL_thread.h"
|
||||
#include "SDL_mutex.h"
|
||||
|
||||
#if defined(HAVE__WCSDUP) && !defined(HAVE_WCSDUP)
|
||||
#ifndef HAVE_WCSDUP
|
||||
#ifdef HAVE__WCSDUP
|
||||
#define wcsdup _wcsdup
|
||||
#else
|
||||
#define wcsdup _dupwcs
|
||||
static wchar_t *_dupwcs(const wchar_t *src)
|
||||
{
|
||||
wchar_t *dst = NULL;
|
||||
if (src) {
|
||||
size_t len = SDL_wcslen(src) + 1;
|
||||
len *= sizeof(wchar_t);
|
||||
dst = (wchar_t *) malloc(len);
|
||||
if (dst) memcpy(dst, src, len);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
#endif
|
||||
#endif /* HAVE_WCSDUP */
|
||||
|
||||
#include <libusb.h>
|
||||
#include <locale.h> /* setlocale */
|
||||
@@ -59,12 +74,8 @@ typedef struct _SDL_ThreadBarrier
|
||||
|
||||
static int SDL_CreateThreadBarrier(SDL_ThreadBarrier *barrier, Uint32 count)
|
||||
{
|
||||
if (barrier == NULL) {
|
||||
return SDL_SetError("barrier must be non-NULL");
|
||||
}
|
||||
if (count == 0) {
|
||||
return SDL_SetError("count must be > 0");
|
||||
}
|
||||
SDL_assert(barrier != NULL);
|
||||
SDL_assert(count != 0);
|
||||
|
||||
barrier->mutex = SDL_CreateMutex();
|
||||
if (barrier->mutex == NULL) {
|
||||
@@ -373,12 +384,16 @@ static int is_language_supported(libusb_device_handle *dev, uint16_t lang)
|
||||
/* This function returns a newly allocated wide string containing the USB
|
||||
device string numbered by the index. The returned string must be freed
|
||||
by using free(). */
|
||||
#if defined(__OS2__) /* don't use iconv on OS/2: no support for wchar_t. */
|
||||
#define NO_ICONV
|
||||
#endif
|
||||
static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
|
||||
{
|
||||
char buf[512];
|
||||
int len;
|
||||
wchar_t *str = NULL;
|
||||
|
||||
#if !defined(NO_ICONV)
|
||||
wchar_t wbuf[256];
|
||||
SDL_iconv_t ic;
|
||||
size_t inbytes;
|
||||
@@ -386,6 +401,9 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
|
||||
size_t res;
|
||||
const char *inptr;
|
||||
char *outptr;
|
||||
#else
|
||||
int i;
|
||||
#endif
|
||||
|
||||
/* Determine which language to use. */
|
||||
uint16_t lang;
|
||||
@@ -402,6 +420,23 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
|
||||
if (len < 0)
|
||||
return NULL;
|
||||
|
||||
#if defined(NO_ICONV) /* original hidapi code for NO_ICONV : */
|
||||
|
||||
/* Bionic does not have wchar_t iconv support, so it
|
||||
has to be done manually. The following code will only work for
|
||||
code points that can be represented as a single UTF-16 character,
|
||||
and will incorrectly convert any code points which require more
|
||||
than one UTF-16 character.
|
||||
|
||||
Skip over the first character (2-bytes). */
|
||||
len -= 2;
|
||||
str = (wchar_t*) malloc((len / 2 + 1) * sizeof(wchar_t));
|
||||
for (i = 0; i < len / 2; i++) {
|
||||
str[i] = buf[i * 2 + 2] | (buf[i * 2 + 3] << 8);
|
||||
}
|
||||
str[len / 2] = 0x00000000;
|
||||
|
||||
#else
|
||||
/* buf does not need to be explicitly NULL-terminated because
|
||||
it is only passed into iconv() which does not need it. */
|
||||
|
||||
@@ -434,6 +469,7 @@ static wchar_t *get_usb_string(libusb_device_handle *dev, uint8_t idx)
|
||||
|
||||
err:
|
||||
SDL_iconv_close(ic);
|
||||
#endif
|
||||
|
||||
return str;
|
||||
}
|
||||
@@ -599,6 +635,7 @@ static int is_xbox360(unsigned short vendor_id, const struct libusb_interface_de
|
||||
0x1bad, /* Harmonix */
|
||||
0x20d6, /* PowerA */
|
||||
0x24c6, /* PowerA */
|
||||
0x2c22, /* Qanba */
|
||||
};
|
||||
|
||||
if (intf_desc->bInterfaceClass == LIBUSB_CLASS_VENDOR_SPEC &&
|
||||
@@ -958,7 +995,7 @@ static void LIBUSB_CALL read_callback(struct libusb_transfer *transfer)
|
||||
}
|
||||
|
||||
|
||||
static int read_thread(void *param)
|
||||
static int SDLCALL read_thread(void *param)
|
||||
{
|
||||
hid_device *dev = (hid_device *)param;
|
||||
uint8_t *buf;
|
||||
@@ -1461,6 +1498,7 @@ void HID_API_EXPORT hid_close(hid_device *dev)
|
||||
|
||||
/* Clean up the Transfer objects allocated in read_thread(). */
|
||||
free(dev->transfer->buffer);
|
||||
dev->transfer->buffer = NULL;
|
||||
libusb_free_transfer(dev->transfer);
|
||||
|
||||
/* release the interface */
|
||||
|
33
externals/SDL/src/hidapi/mac/hid.c
vendored
33
externals/SDL/src/hidapi/mac/hid.c
vendored
@@ -259,7 +259,7 @@ static int get_string_property(IOHIDDeviceRef device, CFStringRef prop, wchar_t
|
||||
|
||||
buf[0] = 0;
|
||||
|
||||
if (str) {
|
||||
if (str && CFGetTypeID(str) == CFStringGetTypeID()) {
|
||||
len --;
|
||||
|
||||
CFIndex str_len = CFStringGetLength(str);
|
||||
@@ -298,7 +298,7 @@ static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, cha
|
||||
|
||||
buf[0] = 0;
|
||||
|
||||
if (str) {
|
||||
if (str && CFGetTypeID(str) == CFStringGetTypeID()) {
|
||||
len--;
|
||||
|
||||
CFIndex str_len = CFStringGetLength(str);
|
||||
@@ -326,10 +326,7 @@ static int get_string_property_utf8(IOHIDDeviceRef device, CFStringRef prop, cha
|
||||
|
||||
static int get_serial_number(IOHIDDeviceRef device, wchar_t *buf, size_t len)
|
||||
{
|
||||
// This crashes on M1 Macs, tracked by radar bug 79667729
|
||||
//return get_string_property(device, CFSTR(kIOHIDSerialNumberKey), buf, len);
|
||||
buf[0] = 0;
|
||||
return 0;
|
||||
return get_string_property(device, CFSTR(kIOHIDSerialNumberKey), buf, len);
|
||||
}
|
||||
|
||||
static int get_manufacturer_string(IOHIDDeviceRef device, wchar_t *buf, size_t len)
|
||||
@@ -557,6 +554,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
|
||||
continue;
|
||||
}
|
||||
|
||||
#if 0 // Prefer direct HID support as that has extended functionality
|
||||
#if defined(SDL_JOYSTICK_MFI)
|
||||
// We want to prefer Game Controller support where available,
|
||||
// as Apple will likely be requiring that for supported devices.
|
||||
@@ -564,6 +562,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
|
||||
if (IOS_SupportedHIDDevice(dev)) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
dev_vid = get_vendor_id(dev);
|
||||
@@ -573,8 +572,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
|
||||
if ((vendor_id == 0x0 && product_id == 0x0) ||
|
||||
(vendor_id == dev_vid && product_id == dev_pid)) {
|
||||
struct hid_device_info *tmp;
|
||||
size_t len;
|
||||
|
||||
|
||||
/* VID/PID match. Create the record. */
|
||||
tmp = (struct hid_device_info *)calloc(1, sizeof(struct hid_device_info));
|
||||
if (cur_dev) {
|
||||
@@ -591,7 +589,7 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
|
||||
|
||||
/* Fill out the record */
|
||||
cur_dev->next = NULL;
|
||||
len = make_path(dev, cbuf, sizeof(cbuf));
|
||||
make_path(dev, cbuf, sizeof(cbuf));
|
||||
cur_dev->path = strdup(cbuf);
|
||||
|
||||
/* Serial Number */
|
||||
@@ -818,10 +816,9 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
|
||||
CFSetGetValues(device_set, (const void **) device_array);
|
||||
for (i = 0; i < num_devices; i++) {
|
||||
char cbuf[BUF_LEN];
|
||||
size_t len;
|
||||
IOHIDDeviceRef os_dev = device_array[i];
|
||||
|
||||
len = make_path(os_dev, cbuf, sizeof(cbuf));
|
||||
make_path(os_dev, cbuf, sizeof(cbuf));
|
||||
if (!strcmp(cbuf, path)) {
|
||||
// Matched Paths. Open this Device.
|
||||
IOReturn ret = IOHIDDeviceOpen(os_dev, kIOHIDOptionsTypeNone);
|
||||
@@ -834,6 +831,7 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path, int bExclusive)
|
||||
|
||||
/* Create the buffers for receiving data */
|
||||
dev->max_input_report_len = (CFIndex) get_max_report_length(os_dev);
|
||||
SDL_assert(dev->max_input_report_len > 0);
|
||||
dev->input_report_buf = (uint8_t *)calloc(dev->max_input_report_len, sizeof(uint8_t));
|
||||
|
||||
/* Create the Run Loop Mode for this device.
|
||||
@@ -937,11 +935,14 @@ static int return_data(hid_device *dev, unsigned char *data, size_t length)
|
||||
/* Copy the data out of the linked list item (rpt) into the
|
||||
return buffer (data), and delete the liked list item. */
|
||||
struct input_report *rpt = dev->input_reports;
|
||||
size_t len = (length < rpt->len)? length: rpt->len;
|
||||
memcpy(data, rpt->data, len);
|
||||
dev->input_reports = rpt->next;
|
||||
free(rpt->data);
|
||||
free(rpt);
|
||||
size_t len = 0;
|
||||
if (rpt != NULL) {
|
||||
len = (length < rpt->len)? length: rpt->len;
|
||||
memcpy(data, rpt->data, len);
|
||||
dev->input_reports = rpt->next;
|
||||
free(rpt->data);
|
||||
free(rpt);
|
||||
}
|
||||
return (int)len;
|
||||
}
|
||||
|
||||
|
32
externals/SDL/src/hidapi/windows/hid.c
vendored
32
externals/SDL/src/hidapi/windows/hid.c
vendored
@@ -43,21 +43,6 @@
|
||||
typedef LONG NTSTATUS;
|
||||
#endif
|
||||
|
||||
/* SDL C runtime functions */
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#define calloc SDL_calloc
|
||||
#define free SDL_free
|
||||
#define malloc SDL_malloc
|
||||
#define memcpy SDL_memcpy
|
||||
#define memset SDL_memset
|
||||
#define strcmp SDL_strcmp
|
||||
#define strlen SDL_strlen
|
||||
#define strstr SDL_strstr
|
||||
#define strtol SDL_strtol
|
||||
#define wcscmp SDL_wcscmp
|
||||
#define _wcsdup SDL_wcsdup
|
||||
|
||||
/* The maximum number of characters that can be passed into the
|
||||
HidD_Get*String() functions without it failing.*/
|
||||
#define MAX_STRING_WCHARS 0xFFF
|
||||
@@ -94,11 +79,26 @@ extern "C" {
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#include "../hidapi/hidapi.h"
|
||||
|
||||
/*#include <stdio.h>*/
|
||||
/*#include <stdlib.h>*/
|
||||
|
||||
/* SDL C runtime functions */
|
||||
#include "SDL_stdinc.h"
|
||||
|
||||
#define calloc SDL_calloc
|
||||
#define free SDL_free
|
||||
#define malloc SDL_malloc
|
||||
#define memcpy SDL_memcpy
|
||||
#define memset SDL_memset
|
||||
#define strcmp SDL_strcmp
|
||||
#define strlen SDL_strlen
|
||||
#define strstr SDL_strstr
|
||||
#define strtol SDL_strtol
|
||||
#define wcscmp SDL_wcscmp
|
||||
#define _wcsdup SDL_wcsdup
|
||||
|
||||
#include "../hidapi/hidapi.h"
|
||||
|
||||
#undef MIN
|
||||
#define MIN(x,y) ((x) < (y)? (x): (y))
|
||||
|
Reference in New Issue
Block a user