From 5b646cd19e36e02c658fcbf792721b5bdce8491f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sun, 7 Nov 2021 22:58:44 -0800 Subject: [PATCH] Build hidapi code into SDL as a new public API This prevents conflicts with hidapi linked with applications, as well as allowing applications to make use of HIDAPI on Android and other platforms that might not normally have an implementation available. --- Android.mk | 22 +- Makefile.os2 | 4 +- VisualC-WinRT/SDL-UWP.vcxproj | 4 +- VisualC-WinRT/SDL-UWP.vcxproj.filters | 6 + VisualC/SDL/SDL.vcxproj | 3 +- VisualC/SDL/SDL.vcxproj.filters | 3 + Xcode/SDL/SDL.xcodeproj/project.pbxproj | 406 +++---------------- include/SDL.h | 1 + include/SDL_hidapi.h | 415 ++++++++++++++++++++ include/SDL_stdinc.h | 1 + src/dynapi/SDL_dynapi_overrides.h | 15 + src/dynapi/SDL_dynapi_procs.h | 15 + src/hidapi/SDL_hidapi.c | 290 +++++++------- src/hidapi/{SDL_hidapi.h => SDL_hidapi_c.h} | 0 src/hidapi/android/hid.cpp | 23 ++ src/hidapi/hidapi/hidapi.h | 11 +- src/hidapi/ios/hid.m | 40 +- src/hidapi/libusb/hid.c | 4 - src/hidapi/linux/hid.c | 4 - src/hidapi/mac/hid.c | 4 - src/hidapi/windows/hid.c | 4 - src/joystick/hidapi/SDL_hidapi_gamecube.c | 14 +- src/joystick/hidapi/SDL_hidapi_luna.c | 6 +- src/joystick/hidapi/SDL_hidapi_ps4.c | 14 +- src/joystick/hidapi/SDL_hidapi_ps5.c | 16 +- src/joystick/hidapi/SDL_hidapi_rumble.c | 2 +- src/joystick/hidapi/SDL_hidapi_stadia.c | 6 +- src/joystick/hidapi/SDL_hidapi_steam.c | 26 +- src/joystick/hidapi/SDL_hidapi_switch.c | 10 +- src/joystick/hidapi/SDL_hidapi_xbox360.c | 10 +- src/joystick/hidapi/SDL_hidapi_xbox360w.c | 14 +- src/joystick/hidapi/SDL_hidapi_xboxone.c | 6 +- src/joystick/hidapi/SDL_hidapijoystick.c | 23 +- src/joystick/hidapi/SDL_hidapijoystick_c.h | 4 +- src/stdlib/SDL_iconv.c | 5 + 35 files changed, 798 insertions(+), 633 deletions(-) create mode 100644 include/SDL_hidapi.h rename src/hidapi/{SDL_hidapi.h => SDL_hidapi_c.h} (100%) diff --git a/Android.mk b/Android.mk index 99c0d13de..f3e65262b 100644 --- a/Android.mk +++ b/Android.mk @@ -31,6 +31,8 @@ LOCAL_SRC_FILES := \ $(wildcard $(LOCAL_PATH)/src/file/*.c) \ $(wildcard $(LOCAL_PATH)/src/haptic/*.c) \ $(wildcard $(LOCAL_PATH)/src/haptic/android/*.c) \ + $(wildcard $(LOCAL_PATH)/src/hidapi/*.c) \ + $(wildcard $(LOCAL_PATH)/src/hidapi/android/*.cpp) \ $(wildcard $(LOCAL_PATH)/src/joystick/*.c) \ $(wildcard $(LOCAL_PATH)/src/joystick/android/*.c) \ $(wildcard $(LOCAL_PATH)/src/joystick/hidapi/*.c) \ @@ -57,8 +59,6 @@ LOCAL_SRC_FILES := \ $(wildcard $(LOCAL_PATH)/src/video/yuv2rgb/*.c) \ $(wildcard $(LOCAL_PATH)/src/test/*.c)) -LOCAL_SHARED_LIBRARIES := hidapi - LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES LOCAL_CFLAGS += \ -Wall -Wextra \ @@ -121,22 +121,4 @@ LOCAL_MODULE_FILENAME := libSDL2main include $(BUILD_STATIC_LIBRARY) -########################### -# -# hidapi library -# -########################### - -include $(CLEAR_VARS) - -LOCAL_CPPFLAGS += -std=c++11 - -LOCAL_SRC_FILES := src/hidapi/android/hid.cpp - -LOCAL_MODULE := libhidapi -LOCAL_LDLIBS := -llog - -include $(BUILD_SHARED_LIBRARY) - $(call import-module,android/cpufeatures) - diff --git a/Makefile.os2 b/Makefile.os2 index 560eccfa3..2cbe65910 100644 --- a/Makefile.os2 +++ b/Makefile.os2 @@ -47,7 +47,7 @@ SRCS+= SDL_audio.c SDL_audiocvt.c SDL_audiodev.c SDL_audiotypecvt.c SDL_mixer.c SRCS+= SDL_events.c SDL_quit.c SDL_keyboard.c SDL_mouse.c SDL_windowevents.c & SDL_clipboardevents.c SDL_dropevents.c SDL_displayevents.c SDL_gesture.c & SDL_sensor.c SDL_touch.c -SRCS+= SDL_haptic.c SDL_gamecontroller.c SDL_joystick.c +SRCS+= SDL_haptic.c SDL_hidapi.c SDL_gamecontroller.c SDL_joystick.c SRCS+= SDL_render.c yuv_rgb.c SDL_yuv.c SDL_yuv_sw.c SDL_blendfillrect.c & SDL_blendline.c SDL_blendpoint.c SDL_drawline.c SDL_drawpoint.c & SDL_render_sw.c SDL_rotate.c SDL_triangle.c @@ -83,7 +83,7 @@ MOBJS= $(MSRCS:.c=.obj) .extensions: .extensions: .lib .dll .obj .c .asm -.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/atomic;./src/audio/disk; +.c: ./src;./src/dynapi;./src/audio;./src/cpuinfo;./src/events;./src/file;./src/haptic;./src/hidapi;./src/joystick;./src/power;./src/render;./src/render/software;./src/sensor;./src/stdlib;./src/thread;./src/timer;./src/video;./src/video/yuv2rgb;./src/atomic;./src/audio/disk; .c: ./src/haptic/dummy;./src/joystick/dummy;./src/joystick/virtual;./src/audio/dummy;./src/video/dummy;./src/sensor/dummy; .c: ./src/core/os2;./src/core/os2/geniconv;./src/audio/os2;./src/loadso/os2;./src/filesystem/os2;./src/joystick/os2;./src/thread/os2;./src/timer/os2;./src/video/os2; .c: ./src/locale/;./src/locale/unix;./src/misc;./src/misc/dummy;./src/joystick/hidapi;./src/hidapi diff --git a/VisualC-WinRT/SDL-UWP.vcxproj b/VisualC-WinRT/SDL-UWP.vcxproj index fcb2cd383..bc130f437 100644 --- a/VisualC-WinRT/SDL-UWP.vcxproj +++ b/VisualC-WinRT/SDL-UWP.vcxproj @@ -47,6 +47,7 @@ + @@ -113,6 +114,7 @@ + @@ -592,4 +594,4 @@ - \ No newline at end of file + diff --git a/VisualC-WinRT/SDL-UWP.vcxproj.filters b/VisualC-WinRT/SDL-UWP.vcxproj.filters index f61199c81..1260e9ef5 100644 --- a/VisualC-WinRT/SDL-UWP.vcxproj.filters +++ b/VisualC-WinRT/SDL-UWP.vcxproj.filters @@ -69,6 +69,9 @@ Header Files + + Header Files + Header Files @@ -539,6 +542,9 @@ Source Files + + Source Files + Source Files diff --git a/VisualC/SDL/SDL.vcxproj b/VisualC/SDL/SDL.vcxproj index 5cb8b0388..becaead56 100644 --- a/VisualC/SDL/SDL.vcxproj +++ b/VisualC/SDL/SDL.vcxproj @@ -236,6 +236,7 @@ + @@ -327,7 +328,7 @@ - + diff --git a/VisualC/SDL/SDL.vcxproj.filters b/VisualC/SDL/SDL.vcxproj.filters index bf82d502c..d317135ac 100644 --- a/VisualC/SDL/SDL.vcxproj.filters +++ b/VisualC/SDL/SDL.vcxproj.filters @@ -237,6 +237,9 @@ API Headers + + API Headers + API Headers diff --git a/Xcode/SDL/SDL.xcodeproj/project.pbxproj b/Xcode/SDL/SDL.xcodeproj/project.pbxproj index c77d1fd85..7b16f0d41 100644 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj @@ -881,8 +881,6 @@ A75FDAF923E35ED500529352 /* SDL_config_iphoneos.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDAF523E35EC400529352 /* SDL_config_iphoneos.h */; }; A75FDAFA23E35ED600529352 /* SDL_config_iphoneos.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDAF523E35EC400529352 /* SDL_config_iphoneos.h */; }; A75FDAFB23E35ED700529352 /* SDL_config_iphoneos.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDAF523E35EC400529352 /* SDL_config_iphoneos.h */; }; - A75FDB5323E39D1C00529352 /* hid.m in Sources */ = {isa = PBXBuildFile; fileRef = A75FDAA523E2792500529352 /* hid.m */; }; - A75FDB5523E39DAC00529352 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDAC323E28BA700529352 /* CoreBluetooth.framework */; }; A75FDB5823E39E6100529352 /* hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDB5723E39E6100529352 /* hidapi.h */; }; A75FDB5923E39E6100529352 /* hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDB5723E39E6100529352 /* hidapi.h */; }; A75FDB5A23E39E6100529352 /* hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDB5723E39E6100529352 /* hidapi.h */; }; @@ -892,33 +890,6 @@ A75FDB5E23E39E6100529352 /* hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDB5723E39E6100529352 /* hidapi.h */; }; A75FDB5F23E39E6100529352 /* hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDB5723E39E6100529352 /* hidapi.h */; }; A75FDB6023E39E6100529352 /* hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDB5723E39E6100529352 /* hidapi.h */; }; - A75FDB6123E39E6100529352 /* hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDB5723E39E6100529352 /* hidapi.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A75FDB6423E3A2C900529352 /* hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDB5723E39E6100529352 /* hidapi.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A75FDB6623E3A2C900529352 /* hid.m in Sources */ = {isa = PBXBuildFile; fileRef = A75FDAA523E2792500529352 /* hid.m */; }; - A75FDB6823E3A2C900529352 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDAC323E28BA700529352 /* CoreBluetooth.framework */; }; - A75FDB8223E4C74400529352 /* hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = A75FDB5723E39E6100529352 /* hidapi.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A75FDB9323E4C8DB00529352 /* hid.c in Sources */ = {isa = PBXBuildFile; fileRef = A75FDB9223E4C8DB00529352 /* hid.c */; }; - A75FDB9423E4C91300529352 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0073179F0858DECD00B2BC32 /* IOKit.framework */; }; - A75FDB9523E4C93600529352 /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00D0D08310675DD9004B05EF /* CoreFoundation.framework */; }; - A75FDB9A23E4CAEF00529352 /* hidapi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDB8C23E4C74400529352 /* hidapi.framework */; }; - A75FDB9B23E4CAEF00529352 /* hidapi.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDB8C23E4C74400529352 /* hidapi.framework */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; - A75FDB9D23E4CAFA00529352 /* hidapi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDB4923E399AC00529352 /* hidapi.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; - A75FDBA023E4CAFF00529352 /* hidapi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDB6E23E3A2C900529352 /* hidapi.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; - A75FDBA823E4CB7000529352 /* LICENSE-bsd.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA323E4CB6F00529352 /* LICENSE-bsd.txt */; }; - A75FDBA923E4CB7000529352 /* LICENSE-bsd.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA323E4CB6F00529352 /* LICENSE-bsd.txt */; }; - A75FDBAA23E4CB7000529352 /* LICENSE-bsd.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA323E4CB6F00529352 /* LICENSE-bsd.txt */; }; - A75FDBAB23E4CB7000529352 /* AUTHORS.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA423E4CB6F00529352 /* AUTHORS.txt */; }; - A75FDBAC23E4CB7000529352 /* AUTHORS.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA423E4CB6F00529352 /* AUTHORS.txt */; }; - A75FDBAD23E4CB7000529352 /* AUTHORS.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA423E4CB6F00529352 /* AUTHORS.txt */; }; - A75FDBAE23E4CB7000529352 /* LICENSE-orig.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA523E4CB6F00529352 /* LICENSE-orig.txt */; }; - A75FDBAF23E4CB7000529352 /* LICENSE-orig.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA523E4CB6F00529352 /* LICENSE-orig.txt */; }; - A75FDBB023E4CB7000529352 /* LICENSE-orig.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA523E4CB6F00529352 /* LICENSE-orig.txt */; }; - A75FDBB123E4CB7000529352 /* LICENSE-gpl3.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA623E4CB6F00529352 /* LICENSE-gpl3.txt */; }; - A75FDBB223E4CB7000529352 /* LICENSE-gpl3.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA623E4CB6F00529352 /* LICENSE-gpl3.txt */; }; - A75FDBB323E4CB7000529352 /* LICENSE-gpl3.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA623E4CB6F00529352 /* LICENSE-gpl3.txt */; }; - A75FDBB423E4CB7000529352 /* LICENSE.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA723E4CB6F00529352 /* LICENSE.txt */; }; - A75FDBB523E4CB7000529352 /* LICENSE.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA723E4CB6F00529352 /* LICENSE.txt */; }; - A75FDBB623E4CB7000529352 /* LICENSE.txt in Resources */ = {isa = PBXBuildFile; fileRef = A75FDBA723E4CB6F00529352 /* LICENSE.txt */; }; A75FDBB723E4CBC700529352 /* License.txt in Resources */ = {isa = PBXBuildFile; fileRef = 00794D3F09D0C461003FC8A1 /* License.txt */; }; A75FDBB823E4CBC700529352 /* ReadMe.txt in Resources */ = {isa = PBXBuildFile; fileRef = F59C710300D5CB5801000001 /* ReadMe.txt */; }; A75FDBB923E4CBC700529352 /* License.txt in Resources */ = {isa = PBXBuildFile; fileRef = 00794D3F09D0C461003FC8A1 /* License.txt */; }; @@ -3397,7 +3368,6 @@ F3631C652488534E004F28EA /* SDL_locale.h in Headers */ = {isa = PBXBuildFile; fileRef = 566E26792462701100718109 /* SDL_locale.h */; settings = {ATTRIBUTES = (Public, ); }; }; F376F6192559B29300CFC0BC /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6182559B29300CFC0BC /* OpenGLES.framework */; platformFilter = ios; }; F376F61B2559B2AF00CFC0BC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F61A2559B2AF00CFC0BC /* UIKit.framework */; }; - F376F6262559B30000CFC0BC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F61A2559B2AF00CFC0BC /* UIKit.framework */; }; F376F6322559B31D00CFC0BC /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6312559B31D00CFC0BC /* GameController.framework */; }; F376F6332559B33D00CFC0BC /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A7381E931D8B69C300B177DD /* AudioToolbox.framework */; }; F376F63E2559B35200CFC0BC /* CoreMotion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDABF23E28B8000529352 /* CoreMotion.framework */; }; @@ -3406,17 +3376,14 @@ F376F6552559B4E300CFC0BC /* SDL_hidapi.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A81423E2513F00DCD162 /* SDL_hidapi.c */; }; F376F6762559B4E500CFC0BC /* SDL_hidapi.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A81423E2513F00DCD162 /* SDL_hidapi.c */; }; F376F68D2559B4E900CFC0BC /* SDL_hidapi.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A81423E2513F00DCD162 /* SDL_hidapi.c */; }; - F376F6CD2559B54500CFC0BC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6CC2559B54500CFC0BC /* UIKit.framework */; }; F376F6D92559B59600CFC0BC /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6D82559B59600CFC0BC /* AudioToolbox.framework */; }; F376F6DB2559B5A000CFC0BC /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6DA2559B5A000CFC0BC /* AVFoundation.framework */; }; F376F6DD2559B5A900CFC0BC /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6DC2559B5A900CFC0BC /* OpenGLES.framework */; }; F376F6DF2559B5BA00CFC0BC /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6DE2559B5BA00CFC0BC /* GameController.framework */; }; F376F6EC2559B5DA00CFC0BC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6CC2559B54500CFC0BC /* UIKit.framework */; }; F376F6F82559B5EC00CFC0BC /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6F72559B5EC00CFC0BC /* CoreGraphics.framework */; }; - F376F70D2559B6A000CFC0BC /* hidapi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDB4923E399AC00529352 /* hidapi.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; F376F70E2559B6B800CFC0BC /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6182559B29300CFC0BC /* OpenGLES.framework */; }; F376F70F2559B6BF00CFC0BC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F61A2559B2AF00CFC0BC /* UIKit.framework */; }; - F376F71A2559B70B00CFC0BC /* hidapi.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDB6E23E3A2C900529352 /* hidapi.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; F376F71B2559B71C00CFC0BC /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6D82559B59600CFC0BC /* AudioToolbox.framework */; }; F376F71C2559B72900CFC0BC /* AVFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6DA2559B5A000CFC0BC /* AVFoundation.framework */; }; F376F71D2559B73200CFC0BC /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6CC2559B54500CFC0BC /* UIKit.framework */; }; @@ -3430,6 +3397,27 @@ F376F7332559B79B00CFC0BC /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F376F6DE2559B5BA00CFC0BC /* GameController.framework */; }; F37DC5F325350EBC0002E6F7 /* CoreHaptics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F37DC5F225350EBC0002E6F7 /* CoreHaptics.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; F37DC5F525350ECC0002E6F7 /* CoreHaptics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F37DC5F425350ECC0002E6F7 /* CoreHaptics.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; + F38233852738EB8600F7F527 /* SDL_hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = F38233842738EB8600F7F527 /* SDL_hidapi.h */; }; + F38233862738EB8600F7F527 /* SDL_hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = F38233842738EB8600F7F527 /* SDL_hidapi.h */; }; + F38233872738EB8600F7F527 /* SDL_hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = F38233842738EB8600F7F527 /* SDL_hidapi.h */; }; + F382338B2738EB8600F7F527 /* SDL_hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = F38233842738EB8600F7F527 /* SDL_hidapi.h */; }; + F382338C2738EB8600F7F527 /* SDL_hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = F38233842738EB8600F7F527 /* SDL_hidapi.h */; }; + F382338D2738EB8600F7F527 /* SDL_hidapi.h in Headers */ = {isa = PBXBuildFile; fileRef = F38233842738EB8600F7F527 /* SDL_hidapi.h */; }; + F382338E2738EBEC00F7F527 /* SDL_hidapi.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A81423E2513F00DCD162 /* SDL_hidapi.c */; }; + F382338F2738EBEF00F7F527 /* SDL_hidapi.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A81423E2513F00DCD162 /* SDL_hidapi.c */; }; + F38233902738EBF000F7F527 /* SDL_hidapi.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A81423E2513F00DCD162 /* SDL_hidapi.c */; }; + F38233912738EBF100F7F527 /* SDL_hidapi.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A81423E2513F00DCD162 /* SDL_hidapi.c */; }; + F38233922738EBF300F7F527 /* SDL_hidapi.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A81423E2513F00DCD162 /* SDL_hidapi.c */; }; + F38233932738EBF300F7F527 /* SDL_hidapi.c in Sources */ = {isa = PBXBuildFile; fileRef = A7D8A81423E2513F00DCD162 /* SDL_hidapi.c */; }; + F38233942738EC1400F7F527 /* hid.m in Sources */ = {isa = PBXBuildFile; fileRef = A75FDAA523E2792500529352 /* hid.m */; }; + F38233952738EC1500F7F527 /* hid.m in Sources */ = {isa = PBXBuildFile; fileRef = A75FDAA523E2792500529352 /* hid.m */; }; + F38233962738EC1600F7F527 /* hid.m in Sources */ = {isa = PBXBuildFile; fileRef = A75FDAA523E2792500529352 /* hid.m */; }; + F38233972738EC1600F7F527 /* hid.m in Sources */ = {isa = PBXBuildFile; fileRef = A75FDAA523E2792500529352 /* hid.m */; }; + F38233982738EC1800F7F527 /* hid.m in Sources */ = {isa = PBXBuildFile; fileRef = A75FDAA523E2792500529352 /* hid.m */; }; + F38233992738EC1800F7F527 /* hid.m in Sources */ = {isa = PBXBuildFile; fileRef = A75FDAA523E2792500529352 /* hid.m */; }; + F382339A2738ED5600F7F527 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDAC323E28BA700529352 /* CoreBluetooth.framework */; }; + F382339C2738ED6600F7F527 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F382339B2738ED6600F7F527 /* CoreBluetooth.framework */; }; + F382339D2738EE3F00F7F527 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F382339B2738ED6600F7F527 /* CoreBluetooth.framework */; }; F3928194258603F1003191A7 /* SDL_misc.h in Headers */ = {isa = PBXBuildFile; fileRef = 5616CA4F252BB2BE005D5928 /* SDL_misc.h */; settings = {ATTRIBUTES = (Public, ); }; }; F392819F25860422003191A7 /* SDL_misc.h in Headers */ = {isa = PBXBuildFile; fileRef = 5616CA4F252BB2BE005D5928 /* SDL_misc.h */; settings = {ATTRIBUTES = (Public, ); }; }; F3942659253579B400B03694 /* CoreHaptics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F37DC5F225350EBC0002E6F7 /* CoreHaptics.framework */; settings = {ATTRIBUTES = (Weak, ); }; }; @@ -3529,13 +3517,6 @@ remoteGlobalIDString = BECDF5FE0761BA81005FE872; remoteInfo = "Framework (Upgraded)"; }; - F3190016240CA3BA00ED104F /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 0867D690FE84028FC02AAC07 /* Project object */; - proxyType = 1; - remoteGlobalIDString = A75FDB8023E4C74400529352; - remoteInfo = hidapi; - }; /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -3545,7 +3526,6 @@ dstPath = ""; dstSubfolderSpec = 10; files = ( - A75FDB9B23E4CAEF00529352 /* hidapi.framework in Embed Frameworks */, ); name = "Embed Frameworks"; runOnlyForDeploymentPostprocessing = 0; @@ -3608,11 +3588,8 @@ A75FDAC123E28B9600529352 /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; A75FDAC323E28BA700529352 /* CoreBluetooth.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreBluetooth.framework; path = System/Library/Frameworks/CoreBluetooth.framework; sourceTree = SDKROOT; }; A75FDAF523E35EC400529352 /* SDL_config_iphoneos.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_config_iphoneos.h; sourceTree = ""; }; - A75FDB4923E399AC00529352 /* hidapi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = hidapi.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A75FDB4C23E399AC00529352 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; A75FDB5723E39E6100529352 /* hidapi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = hidapi.h; path = hidapi/hidapi.h; sourceTree = ""; }; - A75FDB6E23E3A2C900529352 /* hidapi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = hidapi.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - A75FDB8C23E4C74400529352 /* hidapi.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = hidapi.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A75FDB9223E4C8DB00529352 /* hid.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = hid.c; sourceTree = ""; }; A75FDBA323E4CB6F00529352 /* LICENSE-bsd.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "LICENSE-bsd.txt"; sourceTree = ""; }; A75FDBA423E4CB6F00529352 /* AUTHORS.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = AUTHORS.txt; sourceTree = ""; }; @@ -4019,6 +3996,8 @@ F376F7272559B77100CFC0BC /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS14.0.sdk/System/Library/Frameworks/CoreAudio.framework; sourceTree = DEVELOPER_DIR; }; F37DC5F225350EBC0002E6F7 /* CoreHaptics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreHaptics.framework; path = System/Library/Frameworks/CoreHaptics.framework; sourceTree = SDKROOT; }; F37DC5F425350ECC0002E6F7 /* CoreHaptics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreHaptics.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS14.0.sdk/System/Library/Frameworks/CoreHaptics.framework; sourceTree = DEVELOPER_DIR; }; + F38233842738EB8600F7F527 /* SDL_hidapi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_hidapi.h; sourceTree = ""; }; + F382339B2738ED6600F7F527 /* CoreBluetooth.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreBluetooth.framework; path = Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS15.0.sdk/System/Library/Frameworks/CoreBluetooth.framework; sourceTree = DEVELOPER_DIR; }; F3950CD7212BC88D00F51292 /* SDL_sensor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_sensor.h; sourceTree = ""; }; F395BF6425633B2400942BFF /* SDL_crc32.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_crc32.c; sourceTree = ""; }; F395C1912569C68E00942BFF /* SDL_iokitjoystick_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_iokitjoystick_c.h; sourceTree = ""; }; @@ -4043,7 +4022,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - F376F70D2559B6A000CFC0BC /* hidapi.framework in Frameworks */, A75FCEAE23E25AB700529352 /* AudioToolbox.framework in Frameworks */, A75FDABA23E28A7A00529352 /* AVFoundation.framework in Frameworks */, A75FCEA723E25AB700529352 /* CoreAudio.framework in Frameworks */, @@ -4066,10 +4044,10 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - F376F71A2559B70B00CFC0BC /* hidapi.framework in Frameworks */, F376F71B2559B71C00CFC0BC /* AudioToolbox.framework in Frameworks */, F376F71C2559B72900CFC0BC /* AVFoundation.framework in Frameworks */, F376F7282559B77100CFC0BC /* CoreAudio.framework in Frameworks */, + F382339D2738EE3F00F7F527 /* CoreBluetooth.framework in Frameworks */, F376F7262559B76800CFC0BC /* CoreFoundation.framework in Frameworks */, F376F7242559B76100CFC0BC /* CoreGraphics.framework in Frameworks */, F394265A253579D200B03694 /* CoreHaptics.framework in Frameworks */, @@ -4082,33 +4060,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - A75FDB4623E399AC00529352 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDB5523E39DAC00529352 /* CoreBluetooth.framework in Frameworks */, - F376F6262559B30000CFC0BC /* UIKit.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A75FDB6723E3A2C900529352 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDB6823E3A2C900529352 /* CoreBluetooth.framework in Frameworks */, - F376F6CD2559B54500CFC0BC /* UIKit.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A75FDB8523E4C74400529352 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDB9523E4C93600529352 /* CoreFoundation.framework in Frameworks */, - A75FDB9423E4C91300529352 /* IOKit.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; A769B22E23E259AE00872273 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -4120,10 +4071,10 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - A75FDB9D23E4CAFA00529352 /* hidapi.framework in Frameworks */, F376F6332559B33D00CFC0BC /* AudioToolbox.framework in Frameworks */, F376F6402559B38A00CFC0BC /* AVFoundation.framework in Frameworks */, A7D88B4C23E2437C00DCD162 /* CoreAudio.framework in Frameworks */, + F382339A2738ED5600F7F527 /* CoreBluetooth.framework in Frameworks */, A7D88B4D23E2437C00DCD162 /* CoreFoundation.framework in Frameworks */, F376F63F2559B37300CFC0BC /* CoreGraphics.framework in Frameworks */, F37DC5F325350EBC0002E6F7 /* CoreHaptics.framework in Frameworks */, @@ -4142,10 +4093,10 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - A75FDBA023E4CAFF00529352 /* hidapi.framework in Frameworks */, F376F6DB2559B5A000CFC0BC /* AVFoundation.framework in Frameworks */, F376F6D92559B59600CFC0BC /* AudioToolbox.framework in Frameworks */, A7D88D0723E24BED00DCD162 /* CoreAudio.framework in Frameworks */, + F382339C2738ED6600F7F527 /* CoreBluetooth.framework in Frameworks */, A7D88D0823E24BED00DCD162 /* CoreFoundation.framework in Frameworks */, F376F6F82559B5EC00CFC0BC /* CoreGraphics.framework in Frameworks */, F37DC5F525350ECC0002E6F7 /* CoreHaptics.framework in Frameworks */, @@ -4174,7 +4125,6 @@ 564624381FF821DA0074AC87 /* Metal.framework in Frameworks */, 564624361FF821C20074AC87 /* QuartzCore.framework in Frameworks */, A7381E971D8B6A0300B177DD /* AudioToolbox.framework in Frameworks */, - A75FDB9A23E4CAEF00529352 /* hidapi.framework in Frameworks */, 00D0D0D810675E46004B05EF /* Carbon.framework in Frameworks */, 007317A40858DECD00B2BC32 /* Cocoa.framework in Frameworks */, A7381E961D8B69D600B177DD /* CoreAudio.framework in Frameworks */, @@ -4252,6 +4202,7 @@ A77E6EB3167AB0A90010E40B /* SDL_gamecontroller.h */, AA7557D51595D4D800BBD41B /* SDL_gesture.h */, AA7557D61595D4D800BBD41B /* SDL_haptic.h */, + F38233842738EB8600F7F527 /* SDL_hidapi.h */, AA7557D71595D4D800BBD41B /* SDL_hints.h */, AA7557D91595D4D800BBD41B /* SDL_joystick.h */, AA7557DA1595D4D800BBD41B /* SDL_keyboard.h */, @@ -4315,9 +4266,6 @@ A769B23D23E259AE00872273 /* libSDL2.a */, A75FCEB323E25AB700529352 /* libSDL2.dylib */, A75FD06C23E25AC700529352 /* libSDL2.dylib */, - A75FDB4923E399AC00529352 /* hidapi.framework */, - A75FDB6E23E3A2C900529352 /* hidapi.framework */, - A75FDB8C23E4C74400529352 /* hidapi.framework */, F3CB94BA26B5E0A400B9C980 /* libSDLmain.a */, F3CB963826B5E0A600B9C980 /* libSDLmain.a */, ); @@ -4406,6 +4354,7 @@ 564624341FF821B70074AC87 /* Frameworks */ = { isa = PBXGroup; children = ( + F382339B2738ED6600F7F527 /* CoreBluetooth.framework */, F376F7272559B77100CFC0BC /* CoreAudio.framework */, F376F7252559B76800CFC0BC /* CoreFoundation.framework */, F376F7212559B74900CFC0BC /* Metal.framework */, @@ -5328,6 +5277,7 @@ A75FCD2023E25AB700529352 /* SDL_copying.h in Headers */, A75FCD2123E25AB700529352 /* yuv_rgb.h in Headers */, A75FCD2223E25AB700529352 /* SDL_dummyaudio.h in Headers */, + F382338C2738EB8600F7F527 /* SDL_hidapi.h in Headers */, A75FCD2323E25AB700529352 /* SDL_uikitmessagebox.h in Headers */, A75FCD2523E25AB700529352 /* SDL_thread_c.h in Headers */, A75FCD2623E25AB700529352 /* SDL_cocoamessagebox.h in Headers */, @@ -5552,6 +5502,7 @@ A75FCED923E25AC700529352 /* SDL_copying.h in Headers */, A75FCEDA23E25AC700529352 /* yuv_rgb.h in Headers */, A75FCEDB23E25AC700529352 /* SDL_dummyaudio.h in Headers */, + F382338D2738EB8600F7F527 /* SDL_hidapi.h in Headers */, A75FCEDC23E25AC700529352 /* SDL_uikitmessagebox.h in Headers */, A75FCEDE23E25AC700529352 /* SDL_thread_c.h in Headers */, A75FCEDF23E25AC700529352 /* SDL_cocoamessagebox.h in Headers */, @@ -5739,30 +5690,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - A75FDB4423E399AC00529352 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDB6123E39E6100529352 /* hidapi.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A75FDB6323E3A2C900529352 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDB6423E3A2C900529352 /* hidapi.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A75FDB8123E4C74400529352 /* Headers */ = { - isa = PBXHeadersBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDB8223E4C74400529352 /* hidapi.h in Headers */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; A769B08323E259AE00872273 /* Headers */ = { isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; @@ -6021,6 +5948,7 @@ F3928194258603F1003191A7 /* SDL_misc.h in Headers */, A7D88A3A23E2437C00DCD162 /* SDL_mouse.h in Headers */, A7D8BB1C23E2514500DCD162 /* SDL_mouse_c.h in Headers */, + F38233862738EB8600F7F527 /* SDL_hidapi.h in Headers */, A7D88A3B23E2437C00DCD162 /* SDL_mutex.h in Headers */, A7D88A3C23E2437C00DCD162 /* SDL_name.h in Headers */, A7D8ABFE23E2514100DCD162 /* SDL_nullevents_c.h in Headers */, @@ -6250,6 +6178,7 @@ F392819F25860422003191A7 /* SDL_misc.h in Headers */, A7D88BF323E24BED00DCD162 /* SDL_mouse.h in Headers */, A7D8BB1D23E2514500DCD162 /* SDL_mouse_c.h in Headers */, + F38233872738EB8600F7F527 /* SDL_hidapi.h in Headers */, A7D88BF423E24BED00DCD162 /* SDL_mutex.h in Headers */, A7D88BF523E24BED00DCD162 /* SDL_name.h in Headers */, A7D8ABFF23E2514100DCD162 /* SDL_nullevents_c.h in Headers */, @@ -6644,6 +6573,7 @@ 5616CA50252BB2BE005D5928 /* SDL_misc.h in Headers */, AA75582A1595D4D800BBD41B /* SDL_mouse.h in Headers */, A7D8BB1B23E2514500DCD162 /* SDL_mouse_c.h in Headers */, + F38233852738EB8600F7F527 /* SDL_hidapi.h in Headers */, AA75582C1595D4D800BBD41B /* SDL_mutex.h in Headers */, AA75582E1595D4D800BBD41B /* SDL_name.h in Headers */, A7D8ABFD23E2514100DCD162 /* SDL_nullevents_c.h in Headers */, @@ -6981,6 +6911,7 @@ DB313FCF17554B71006C0E22 /* SDL_config_macosx.h in Headers */, A7D8ABDE23E2514100DCD162 /* SDL_egl_c.h in Headers */, DB313FD117554B71006C0E22 /* SDL_copying.h in Headers */, + F382338B2738EB8600F7F527 /* SDL_hidapi.h in Headers */, A7D8B3D923E2514300DCD162 /* yuv_rgb.h in Headers */, A7D8B79923E2514400DCD162 /* SDL_dummyaudio.h in Headers */, A7D8AC9823E2514100DCD162 /* SDL_uikitmessagebox.h in Headers */, @@ -7225,60 +7156,6 @@ productReference = A75FD06C23E25AC700529352 /* libSDL2.dylib */; productType = "com.apple.product-type.library.dynamic"; }; - A75FDB4823E399AC00529352 /* hidapi-iOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = A75FDB5023E399AC00529352 /* Build configuration list for PBXNativeTarget "hidapi-iOS" */; - buildPhases = ( - A75FDB4423E399AC00529352 /* Headers */, - A75FDB4523E399AC00529352 /* Sources */, - A75FDB4623E399AC00529352 /* Frameworks */, - A75FDB4723E399AC00529352 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "hidapi-iOS"; - productName = hidapi; - productReference = A75FDB4923E399AC00529352 /* hidapi.framework */; - productType = "com.apple.product-type.framework"; - }; - A75FDB6223E3A2C900529352 /* hidapi-tvOS */ = { - isa = PBXNativeTarget; - buildConfigurationList = A75FDB6B23E3A2C900529352 /* Build configuration list for PBXNativeTarget "hidapi-tvOS" */; - buildPhases = ( - A75FDB6323E3A2C900529352 /* Headers */, - A75FDB6523E3A2C900529352 /* Sources */, - A75FDB6723E3A2C900529352 /* Frameworks */, - A75FDB6A23E3A2C900529352 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = "hidapi-tvOS"; - productName = hidapi; - productReference = A75FDB6E23E3A2C900529352 /* hidapi.framework */; - productType = "com.apple.product-type.framework"; - }; - A75FDB8023E4C74400529352 /* hidapi */ = { - isa = PBXNativeTarget; - buildConfigurationList = A75FDB8923E4C74400529352 /* Build configuration list for PBXNativeTarget "hidapi" */; - buildPhases = ( - A75FDB8123E4C74400529352 /* Headers */, - A75FDB8323E4C74400529352 /* Sources */, - A75FDB8523E4C74400529352 /* Frameworks */, - A75FDB8823E4C74400529352 /* Resources */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = hidapi; - productName = hidapi; - productReference = A75FDB8C23E4C74400529352 /* hidapi.framework */; - productType = "com.apple.product-type.framework"; - }; A769B08223E259AE00872273 /* Static Library-tvOS */ = { isa = PBXNativeTarget; buildConfigurationList = A769B23A23E259AE00872273 /* Build configuration list for PBXNativeTarget "Static Library-tvOS" */; @@ -7411,7 +7288,6 @@ buildRules = ( ); dependencies = ( - F3190017240CA3BA00ED104F /* PBXTargetDependency */, BECDF6C60761BA81005FE872 /* PBXTargetDependency */, ); name = "Standard DMG"; @@ -7487,11 +7363,6 @@ isa = PBXProject; attributes = { LastUpgradeCheck = 1130; - TargetAttributes = { - A75FDB4823E399AC00529352 = { - CreatedOnToolsVersion = 11.3.1; - }; - }; }; buildConfigurationList = 0073178E0858DB0500B2BC32 /* Build configuration list for PBXProject "SDL" */; compatibilityVersion = "Xcode 3.2"; @@ -7519,50 +7390,11 @@ A75FCCFB23E25AB700529352 /* Shared Library-iOS */, A75FCEB423E25AC700529352 /* Shared Library-tvOS */, BECDF6BB0761BA81005FE872 /* Standard DMG */, - A75FDB8023E4C74400529352 /* hidapi */, - A75FDB4823E399AC00529352 /* hidapi-iOS */, - A75FDB6223E3A2C900529352 /* hidapi-tvOS */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ - A75FDB4723E399AC00529352 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDBB223E4CB7000529352 /* LICENSE-gpl3.txt in Resources */, - A75FDBA923E4CB7000529352 /* LICENSE-bsd.txt in Resources */, - A75FDBAC23E4CB7000529352 /* AUTHORS.txt in Resources */, - A75FDBB523E4CB7000529352 /* LICENSE.txt in Resources */, - A75FDBAF23E4CB7000529352 /* LICENSE-orig.txt in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A75FDB6A23E3A2C900529352 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDBB323E4CB7000529352 /* LICENSE-gpl3.txt in Resources */, - A75FDBAA23E4CB7000529352 /* LICENSE-bsd.txt in Resources */, - A75FDBAD23E4CB7000529352 /* AUTHORS.txt in Resources */, - A75FDBB623E4CB7000529352 /* LICENSE.txt in Resources */, - A75FDBB023E4CB7000529352 /* LICENSE-orig.txt in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A75FDB8823E4C74400529352 /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDBB123E4CB7000529352 /* LICENSE-gpl3.txt in Resources */, - A75FDBA823E4CB7000529352 /* LICENSE-bsd.txt in Resources */, - A75FDBAB23E4CB7000529352 /* AUTHORS.txt in Resources */, - A75FDBB423E4CB7000529352 /* LICENSE.txt in Resources */, - A75FDBAE23E4CB7000529352 /* LICENSE-orig.txt in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; A7D88ABE23E2437C00DCD162 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -7713,6 +7545,7 @@ A75FCE1223E25AB700529352 /* SDL_hidapi_xbox360.c in Sources */, A75FCE1323E25AB700529352 /* SDL_coreaudio.m in Sources */, A75FCE1423E25AB700529352 /* SDL_blendline.c in Sources */, + F38233982738EC1800F7F527 /* hid.m in Sources */, A75FCE1523E25AB700529352 /* SDL_blit_A.c in Sources */, A75FCE1623E25AB700529352 /* SDL_d3dmath.c in Sources */, A75FCE1823E25AB700529352 /* SDL_nullvideo.c in Sources */, @@ -7749,6 +7582,7 @@ A75FCE3523E25AB700529352 /* SDL_error.c in Sources */, A75FCE3623E25AB700529352 /* SDL_blit.c in Sources */, A75FCE3723E25AB700529352 /* SDL_rwops.c in Sources */, + F38233922738EBF300F7F527 /* SDL_hidapi.c in Sources */, A75FCE3823E25AB700529352 /* SDL_uikitviewcontroller.m in Sources */, A75FCE3923E25AB700529352 /* s_cos.c in Sources */, A75FCE3A23E25AB700529352 /* SDL_yuv_sw.c in Sources */, @@ -7898,6 +7732,7 @@ A75FCFCB23E25AC700529352 /* SDL_hidapi_xbox360.c in Sources */, A75FCFCC23E25AC700529352 /* SDL_coreaudio.m in Sources */, A75FCFCD23E25AC700529352 /* SDL_blendline.c in Sources */, + F38233992738EC1800F7F527 /* hid.m in Sources */, A75FCFCE23E25AC700529352 /* SDL_blit_A.c in Sources */, A75FCFCF23E25AC700529352 /* SDL_d3dmath.c in Sources */, A75FCFD123E25AC700529352 /* SDL_nullvideo.c in Sources */, @@ -7934,6 +7769,7 @@ A75FCFEE23E25AC700529352 /* SDL_error.c in Sources */, A75FCFEF23E25AC700529352 /* SDL_blit.c in Sources */, A75FCFF023E25AC700529352 /* SDL_rwops.c in Sources */, + F38233932738EBF300F7F527 /* SDL_hidapi.c in Sources */, A75FCFF123E25AC700529352 /* SDL_uikitviewcontroller.m in Sources */, A75FCFF223E25AC700529352 /* s_cos.c in Sources */, A75FCFF323E25AC700529352 /* SDL_yuv_sw.c in Sources */, @@ -8034,30 +7870,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - A75FDB4523E399AC00529352 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDB5323E39D1C00529352 /* hid.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A75FDB6523E3A2C900529352 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDB6623E3A2C900529352 /* hid.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; - A75FDB8323E4C74400529352 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - A75FDB9323E4C8DB00529352 /* hid.c in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; A769B17023E259AE00872273 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -8128,6 +7940,7 @@ A769B1B523E259AE00872273 /* SDL_cocoakeyboard.m in Sources */, A769B1B623E259AE00872273 /* SDL_dynapi.c in Sources */, A769B1B723E259AE00872273 /* SDL_shaders_gl.c in Sources */, + F38233912738EBF100F7F527 /* SDL_hidapi.c in Sources */, A769B1B823E259AE00872273 /* e_log.c in Sources */, A769B1B923E259AE00872273 /* SDL_cocoamessagebox.m in Sources */, A769B1BA23E259AE00872273 /* SDL_blendfillrect.c in Sources */, @@ -8221,6 +8034,7 @@ A769B21523E259AE00872273 /* SDL_rwopsbundlesupport.m in Sources */, A769B21623E259AE00872273 /* SDL_video.c in Sources */, A769B21723E259AE00872273 /* SDL_offscreenopengl.c in Sources */, + F38233972738EC1600F7F527 /* hid.m in Sources */, A769B21823E259AE00872273 /* SDL_uikitmetalview.m in Sources */, A769B21923E259AE00872273 /* SDL_shaders_gles2.c in Sources */, A769B21A23E259AE00872273 /* SDL_blit_1.c in Sources */, @@ -8293,6 +8107,7 @@ A7D8BA2023E2514400DCD162 /* SDL_blendline.c in Sources */, A7D8ADF323E2514100DCD162 /* SDL_blit_A.c in Sources */, A7D8BA3823E2514400DCD162 /* SDL_d3dmath.c in Sources */, + F38233942738EC1400F7F527 /* hid.m in Sources */, A7D8ABEC23E2514100DCD162 /* SDL_nullvideo.c in Sources */, A7D8AB6823E2514100DCD162 /* SDL_offscreenevents.c in Sources */, A7D8ACA623E2514100DCD162 /* SDL_uikitview.m in Sources */, @@ -8329,6 +8144,7 @@ A7D8BA9223E2514400DCD162 /* s_cos.c in Sources */, A7D8B4D123E2514300DCD162 /* SDL_steamcontroller.c in Sources */, A7D8B9D223E2514400DCD162 /* SDL_yuv_sw.c in Sources */, + F382338E2738EBEC00F7F527 /* SDL_hidapi.c in Sources */, A7D8B76B23E2514300DCD162 /* SDL_wave.c in Sources */, A7D8BAD423E2514500DCD162 /* s_tan.c in Sources */, A7D8AA6623E2514000DCD162 /* SDL_hints.c in Sources */, @@ -8478,6 +8294,7 @@ A7D8BA2123E2514400DCD162 /* SDL_blendline.c in Sources */, A7D8ADF423E2514100DCD162 /* SDL_blit_A.c in Sources */, A7D8BA3923E2514400DCD162 /* SDL_d3dmath.c in Sources */, + F38233952738EC1500F7F527 /* hid.m in Sources */, A7D8ABED23E2514100DCD162 /* SDL_nullvideo.c in Sources */, A7D8AB6923E2514100DCD162 /* SDL_offscreenevents.c in Sources */, A7D8ACA723E2514100DCD162 /* SDL_uikitview.m in Sources */, @@ -8514,6 +8331,7 @@ A7D8BA9323E2514400DCD162 /* s_cos.c in Sources */, A7D8B4D223E2514300DCD162 /* SDL_steamcontroller.c in Sources */, A7D8B9D323E2514400DCD162 /* SDL_yuv_sw.c in Sources */, + F382338F2738EBEF00F7F527 /* SDL_hidapi.c in Sources */, A7D8B76C23E2514300DCD162 /* SDL_wave.c in Sources */, A7D8BAD523E2514500DCD162 /* s_tan.c in Sources */, A7D8AA6723E2514000DCD162 /* SDL_hints.c in Sources */, @@ -8684,6 +8502,7 @@ A7D8AEDA23E2514100DCD162 /* SDL_cocoakeyboard.m in Sources */, A7D8AB1A23E2514100DCD162 /* SDL_dynapi.c in Sources */, A7D8BA8923E2514400DCD162 /* SDL_shaders_gl.c in Sources */, + F38233902738EBF000F7F527 /* SDL_hidapi.c in Sources */, A7D8BAF523E2514500DCD162 /* e_log.c in Sources */, A7D8AED423E2514100DCD162 /* SDL_cocoamessagebox.m in Sources */, A7D8BA2F23E2514400DCD162 /* SDL_blendfillrect.c in Sources */, @@ -8777,6 +8596,7 @@ A7D8B5CD23E2514300DCD162 /* SDL_rwopsbundlesupport.m in Sources */, A7D8AC1323E2514100DCD162 /* SDL_video.c in Sources */, A7D8AB5923E2514100DCD162 /* SDL_offscreenopengl.c in Sources */, + F38233962738EC1600F7F527 /* hid.m in Sources */, A7D8ACC723E2514100DCD162 /* SDL_uikitmetalview.m in Sources */, A7D8BA5F23E2514400DCD162 /* SDL_shaders_gles2.c in Sources */, A7D8B14423E2514200DCD162 /* SDL_blit_1.c in Sources */, @@ -9379,11 +9199,6 @@ target = BECDF5FE0761BA81005FE872 /* Framework */; targetProxy = BECDF6C50761BA81005FE872 /* PBXContainerItemProxy */; }; - F3190017240CA3BA00ED104F /* PBXTargetDependency */ = { - isa = PBXTargetDependency; - target = A75FDB8023E4C74400529352 /* hidapi */; - targetProxy = F3190016240CA3BA00ED104F /* PBXContainerItemProxy */; - }; /* End PBXTargetDependency section */ /* Begin XCBuildConfiguration section */ @@ -9611,108 +9426,6 @@ }; name = Release; }; - A75FDB4E23E399AC00529352 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CURRENT_PROJECT_VERSION = 1.0; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(SDKROOT)/System/iOSSupport/System/Library/Frameworks", - ); - GCC_PREPROCESSOR_DEFINITIONS = "HID_API_EXPORT=\"__attribute__ ((visibility(\\\"default\\\")))\""; - INFOPLIST_FILE = hidapi/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = org.libsdl.hidapi; - PRODUCT_NAME = hidapi; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2,6"; - }; - name = Debug; - }; - A75FDB4F23E399AC00529352 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CURRENT_PROJECT_VERSION = 1.0; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(SDKROOT)/System/iOSSupport/System/Library/Frameworks", - ); - GCC_PREPROCESSOR_DEFINITIONS = "HID_API_EXPORT=\"__attribute__ ((visibility(\\\"default\\\")))\""; - INFOPLIST_FILE = hidapi/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = org.libsdl.hidapi; - PRODUCT_NAME = hidapi; - SDKROOT = iphoneos; - TARGETED_DEVICE_FAMILY = "1,2,6"; - }; - name = Release; - }; - A75FDB6C23E3A2C900529352 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CURRENT_PROJECT_VERSION = 1.0; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - GCC_PREPROCESSOR_DEFINITIONS = "HID_API_EXPORT=\"__attribute__ ((visibility(\\\"default\\\")))\""; - INFOPLIST_FILE = hidapi/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = org.libsdl.hidapi; - PRODUCT_NAME = hidapi; - SDKROOT = appletvos; - }; - name = Debug; - }; - A75FDB6D23E3A2C900529352 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_ENABLE_OBJC_WEAK = YES; - CURRENT_PROJECT_VERSION = 1.0; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - GCC_PREPROCESSOR_DEFINITIONS = "HID_API_EXPORT=\"__attribute__ ((visibility(\\\"default\\\")))\""; - INFOPLIST_FILE = hidapi/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = org.libsdl.hidapi; - PRODUCT_NAME = hidapi; - SDKROOT = appletvos; - }; - name = Release; - }; - A75FDB8A23E4C74400529352 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = YES; - CURRENT_PROJECT_VERSION = 1.0; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - GCC_PREPROCESSOR_DEFINITIONS = "HID_API_EXPORT=\"__attribute__ ((visibility(\\\"default\\\")))\""; - INFOPLIST_FILE = hidapi/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = org.libsdl.hidapi; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - A75FDB8B23E4C74400529352 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - CLANG_ENABLE_OBJC_ARC = YES; - CURRENT_PROJECT_VERSION = 1.0; - DYLIB_COMPATIBILITY_VERSION = 1; - DYLIB_CURRENT_VERSION = 1; - GCC_PREPROCESSOR_DEFINITIONS = "HID_API_EXPORT=\"__attribute__ ((visibility(\\\"default\\\")))\""; - INFOPLIST_FILE = hidapi/Info.plist; - PRODUCT_BUNDLE_IDENTIFIER = org.libsdl.hidapi; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; A769B23B23E259AE00872273 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -9930,33 +9643,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Debug; }; - A75FDB5023E399AC00529352 /* Build configuration list for PBXNativeTarget "hidapi-iOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - A75FDB4E23E399AC00529352 /* Debug */, - A75FDB4F23E399AC00529352 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Debug; - }; - A75FDB6B23E3A2C900529352 /* Build configuration list for PBXNativeTarget "hidapi-tvOS" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - A75FDB6C23E3A2C900529352 /* Debug */, - A75FDB6D23E3A2C900529352 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Debug; - }; - A75FDB8923E4C74400529352 /* Build configuration list for PBXNativeTarget "hidapi" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - A75FDB8A23E4C74400529352 /* Debug */, - A75FDB8B23E4C74400529352 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Debug; - }; A769B23A23E259AE00872273 /* Build configuration list for PBXNativeTarget "Static Library-tvOS" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/include/SDL.h b/include/SDL.h index 07d3356bf..dcb6d20fb 100644 --- a/include/SDL.h +++ b/include/SDL.h @@ -42,6 +42,7 @@ #include "SDL_filesystem.h" #include "SDL_gamecontroller.h" #include "SDL_haptic.h" +#include "SDL_hidapi.h" #include "SDL_hints.h" #include "SDL_joystick.h" #include "SDL_loadso.h" diff --git a/include/SDL_hidapi.h b/include/SDL_hidapi.h new file mode 100644 index 000000000..374eb5819 --- /dev/null +++ b/include/SDL_hidapi.h @@ -0,0 +1,415 @@ +/* + Simple DirectMedia Layer + Copyright (C) 1997-2021 Sam Lantinga + + 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. +*/ + +/** + * \file SDL_hidapi.h + * + * Header file for SDL HIDAPI functions. + * + * This is an adaptation of the original HIDAPI interface by Alan Ott, + * and includes source code licensed under the following BSD license: + * + Copyright (c) 2010, Alan Ott, Signal 11 Software + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of Signal 11 Software nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. + * + * If you would like a version of SDL without this code, you can build SDL + * with SDL_DISABLE_HIDAPI defined. You might want to do this for example on + * iOS or tvOS to avoid a dependency on the CoreBluetooth framework. + */ + +#ifndef SDL_hidapi_h_ +#define SDL_hidapi_h_ + +/** + * \brief A handle representing an open HID device + */ +struct SDL_hid_device_; +typedef struct SDL_hid_device_ SDL_hid_device; /**< opaque hidapi structure */ + +/** hidapi info structure */ +/** + * \brief Information about a connected HID device + */ +typedef struct SDL_hid_device_info +{ + /** Platform-specific device path */ + char *path; + /** Device Vendor ID */ + unsigned short vendor_id; + /** Device Product ID */ + unsigned short product_id; + /** Serial Number */ + wchar_t *serial_number; + /** Device Release Number in binary-coded decimal, + also known as Device Version Number */ + unsigned short release_number; + /** Manufacturer String */ + wchar_t *manufacturer_string; + /** Product string */ + wchar_t *product_string; + /** Usage Page for this Device/Interface + (Windows/Mac only). */ + unsigned short usage_page; + /** Usage for this Device/Interface + (Windows/Mac only).*/ + unsigned short usage; + /** The USB interface which this logical device + represents. + + * Valid on both Linux implementations in all cases. + * Valid on the Windows implementation only if the device + contains more than one interface. */ + int interface_number; + + /** Additional information about the USB interface. + Valid on libusb and Android implementations. */ + int interface_class; + int interface_subclass; + int interface_protocol; + + /** Pointer to the next device */ + struct SDL_hid_device_info *next; +} SDL_hid_device_info; + +/** + * Initialize the HIDAPI library. + * + * This function initializes the HIDAPI library. Calling it is not + * strictly necessary, as it will be called automatically by + * SDL_hid_enumerate() and any of the SDL_hid_open_*() functions + * if it is needed. This function should be called at the beginning + * of execution however, if there is a chance of HIDAPI handles + * being opened by different threads simultaneously. + * + * \returns 0 on success and -1 on error. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_init(void); + +/** + * Finalize the HIDAPI library. + * + * This function frees all of the static data associated with + * HIDAPI. It should be called at the end of execution to avoid + * memory leaks. + * + * \returns 0 on success and -1 on error. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_exit(void); + +/** + * Enumerate the HID Devices. + * + * This function returns a linked list of all the HID devices + * attached to the system which match vendor_id and product_id. + * If `vendor_id` is set to 0 then any vendor matches. + * If `product_id` is set to 0 then any product matches. + * If `vendor_id` and `product_id` are both set to 0, then + * all HID devices will be returned. + * + * \param vendor_id The Vendor ID (VID) of the types of device to open. + * \param product_id The Product ID (PID) of the types of device to open. + * + * \returns a pointer to a linked list of type SDL_hid_device_info, + * containing information about the HID devices attached to the + * system, or NULL in the case of failure. Free this linked list + * by calling SDL_hid_free_enumeration(). + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC SDL_hid_device_info * SDLCALL SDL_hid_enumerate(unsigned short vendor_id, unsigned short product_id); + +/** + * Free an enumeration Linked List + * + * This function frees a linked list created by SDL_hid_enumerate(). + * + * \param devs Pointer to a list of struct_device returned from + * SDL_hid_enumerate(). + */ +extern DECLSPEC void SDLCALL SDL_hid_free_enumeration(SDL_hid_device_info *devs); + +/** + * Open a HID device using a Vendor ID (VID), Product ID + * (PID) and optionally a serial number. + * + * If `serial_number` is NULL, the first device with the + * specified VID and PID is opened. + * + * \param vendor_id The Vendor ID (VID) of the device to open. + * \param product_id The Product ID (PID) of the device to open. + * \param serial_number The Serial Number of the device to open + * (Optionally NULL). + * + * \returns a pointer to a SDL_hid_device object on success or NULL on failure. + * + * \since This function is available since SDL 2.0.18. + */ +SDL_hid_device * SDL_hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number); + +/** + * Open a HID device by its path name. + * + * The path name be determined by calling SDL_hid_enumerate(), or a + * platform-specific path name can be used (eg: /dev/hidraw0 on + * Linux). + * + * \param path The path name of the device to open + * + * \returns a pointer to a SDL_hid_device object on success or NULL on failure. + * + * \since This function is available since SDL 2.0.18. + */ +SDL_hid_device * SDL_hid_open_path(const char *path, int bExclusive /* = false */); + +/** + * Write an Output report to a HID device. + * + * The first byte of `data` must contain the Report ID. For + * devices which only support a single report, this must be set + * to 0x0. The remaining bytes contain the report data. Since + * the Report ID is mandatory, calls to SDL_hid_write() will always + * contain one more byte than the report contains. For example, + * if a hid report is 16 bytes long, 17 bytes must be passed to + * SDL_hid_write(), the Report ID (or 0x0, for devices with a + * single report), followed by the report data (16 bytes). In + * this example, the length passed in would be 17. + * + * SDL_hid_write() will send the data on the first OUT endpoint, if + * one exists. If it does not, it will send the data through + * the Control Endpoint (Endpoint 0). + * + * \param dev A device handle returned from SDL_hid_open(). + * \param data The data to send, including the report number as + * the first byte. + * \param length The length in bytes of the data to send. + * + * \returns the actual number of bytes written and -1 on error. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_write(SDL_hid_device *dev, const unsigned char *data, size_t length); + +/** + * Read an Input report from a HID device with timeout. + * + * Input reports are returned + * to the host through the INTERRUPT IN endpoint. The first byte will + * contain the Report number if the device uses numbered reports. + * + * \param dev A device handle returned from SDL_hid_open(). + * \param data A buffer to put the read data into. + * \param length The number of bytes to read. For devices with + * multiple reports, make sure to read an extra byte for + * the report number. + * \param milliseconds timeout in milliseconds or -1 for blocking wait. + * + * \returns the actual number of bytes read and -1 on error. + If no packet was available to be read within the timeout period, this function returns 0. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_read_timeout(SDL_hid_device *dev, unsigned char *data, size_t length, int milliseconds); + +/** + * Read an Input report from a HID device. + * + * Input reports are returned + * to the host through the INTERRUPT IN endpoint. The first byte will + * contain the Report number if the device uses numbered reports. + * + * \param dev A device handle returned from SDL_hid_open(). + * \param data A buffer to put the read data into. + * \param length The number of bytes to read. For devices with + * multiple reports, make sure to read an extra byte for + * the report number. + * + * \returns the actual number of bytes read and -1 on error. + * If no packet was available to be read and the handle is in non-blocking mode, this function returns 0. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_read(SDL_hid_device *dev, unsigned char *data, size_t length); + +/** + * Set the device handle to be non-blocking. + * + * In non-blocking mode calls to SDL_hid_read() will return + * immediately with a value of 0 if there is no data to be + * read. In blocking mode, SDL_hid_read() will wait (block) until + * there is data to read before returning. + * + * Nonblocking can be turned on and off at any time. + * + * \param dev A device handle returned from SDL_hid_open(). + * \param nonblock enable or not the nonblocking reads + * - 1 to enable nonblocking + * - 0 to disable nonblocking. + * + * \returns 0 on success and -1 on error. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_set_nonblocking(SDL_hid_device *dev, int nonblock); + +/** + * Send a Feature report to the device. + * + * Feature reports are sent over the Control endpoint as a + * Set_Report transfer. The first byte of `data` must + * contain the Report ID. For devices which only support a + * single report, this must be set to 0x0. The remaining bytes + * contain the report data. Since the Report ID is mandatory, + * calls to SDL_hid_send_feature_report() will always contain one + * more byte than the report contains. For example, if a hid + * report is 16 bytes long, 17 bytes must be passed to + * SDL_hid_send_feature_report(): the Report ID (or 0x0, for + * devices which do not use numbered reports), followed by the + * report data (16 bytes). In this example, the length passed + * in would be 17. + * + * \param dev A device handle returned from SDL_hid_open(). + * \param data The data to send, including the report number as + * the first byte. + * \param length The length in bytes of the data to send, including + * the report number. + * + * \returns the actual number of bytes written and -1 on error. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_send_feature_report(SDL_hid_device *dev, const unsigned char *data, size_t length); + +/** + * Get a feature report from a HID device. + * + * Set the first byte of `data` to the Report ID of the + * report to be read. Make sure to allow space for this + * extra byte in `data`. Upon return, the first byte will + * still contain the Report ID, and the report data will + * start in data[1]. + * + * \param dev A device handle returned from SDL_hid_open(). + * \param data A buffer to put the read data into, including + * the Report ID. Set the first byte of `data` to the + * Report ID of the report to be read, or set it to zero + * if your device does not use numbered reports. + * \param length The number of bytes to read, including an + * extra byte for the report ID. The buffer can be longer + * than the actual report. + * + * \returns the number of bytes read plus one for the report ID + * (which is still in the first byte), or -1 on error. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_get_feature_report(SDL_hid_device *dev, unsigned char *data, size_t length); + +/** + * Close a HID device. + * + * \param dev A device handle returned from SDL_hid_open(). + */ +extern DECLSPEC void SDLCALL SDL_hid_close(SDL_hid_device *dev); + +/** + * Get The Manufacturer String from a HID device. + * + * \param dev A device handle returned from SDL_hid_open(). + * \param string A wide string buffer to put the data into. + * \param maxlen The length of the buffer in multiples of wchar_t. + * + * \returns 0 on success and -1 on error. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_get_manufacturer_string(SDL_hid_device *dev, wchar_t *string, size_t maxlen); + +/** + * Get The Product String from a HID device. + * + * \param dev A device handle returned from SDL_hid_open(). + * \param string A wide string buffer to put the data into. + * \param maxlen The length of the buffer in multiples of wchar_t. + * + * \returns 0 on success and -1 on error. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_get_product_string(SDL_hid_device *dev, wchar_t *string, size_t maxlen); + +/** + * Get The Serial Number String from a HID device. + * + * \param dev A device handle returned from SDL_hid_open(). + * \param string A wide string buffer to put the data into. + * \param maxlen The length of the buffer in multiples of wchar_t. + * + * \returns 0 on success and -1 on error. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_get_serial_number_string(SDL_hid_device *dev, wchar_t *string, size_t maxlen); + +/** + * Get a string from a HID device, based on its string index. + * + * \param dev A device handle returned from SDL_hid_open(). + * \param string_index The index of the string to get. + * \param string A wide string buffer to put the data into. + * \param maxlen The length of the buffer in multiples of wchar_t. + * + * \returns 0 on success and -1 on error. + * + * \since This function is available since SDL 2.0.18. + */ +extern DECLSPEC int SDLCALL SDL_hid_get_indexed_string(SDL_hid_device *dev, int string_index, wchar_t *string, size_t maxlen); + +#endif /* SDL_hidapi_h_ */ + +/* vi: set sts=4 ts=4 sw=4 expandtab: */ diff --git a/include/SDL_stdinc.h b/include/SDL_stdinc.h index 8a32eb229..c00374d12 100644 --- a/include/SDL_stdinc.h +++ b/include/SDL_stdinc.h @@ -666,6 +666,7 @@ extern DECLSPEC char *SDLCALL SDL_iconv_string(const char *tocode, #define SDL_iconv_utf8_locale(S) SDL_iconv_string("", "UTF-8", S, SDL_strlen(S)+1) #define SDL_iconv_utf8_ucs2(S) (Uint16 *)SDL_iconv_string("UCS-2-INTERNAL", "UTF-8", S, SDL_strlen(S)+1) #define SDL_iconv_utf8_ucs4(S) (Uint32 *)SDL_iconv_string("UCS-4-INTERNAL", "UTF-8", S, SDL_strlen(S)+1) +#define SDL_iconv_wchar_utf8(S) SDL_iconv_string("UTF-8", "WCHAR_T", (char *)S, (SDL_wcslen(S)+1)*sizeof(wchar_t)) /* force builds using Clang's static analysis tools to use literal C runtime here, since there are possibly tests that are ineffective otherwise. */ diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h index 657bfee26..ee071e8da 100644 --- a/src/dynapi/SDL_dynapi_overrides.h +++ b/src/dynapi/SDL_dynapi_overrides.h @@ -827,3 +827,18 @@ #define SDL_LinuxSetThreadPriorityAndPolicy SDL_LinuxSetThreadPriorityAndPolicy_REAL #define SDL_GameControllerGetAppleSFSymbolsNameForButton SDL_GameControllerGetAppleSFSymbolsNameForButton_REAL #define SDL_GameControllerGetAppleSFSymbolsNameForAxis SDL_GameControllerGetAppleSFSymbolsNameForAxis_REAL +#define SDL_hid_init SDL_hid_init_REAL +#define SDL_hid_exit SDL_hid_exit_REAL +#define SDL_hid_enumerate SDL_hid_enumerate_REAL +#define SDL_hid_free_enumeration SDL_hid_free_enumeration_REAL +#define SDL_hid_write SDL_hid_write_REAL +#define SDL_hid_read_timeout SDL_hid_read_timeout_REAL +#define SDL_hid_read SDL_hid_read_REAL +#define SDL_hid_set_nonblocking SDL_hid_set_nonblocking_REAL +#define SDL_hid_send_feature_report SDL_hid_send_feature_report_REAL +#define SDL_hid_get_feature_report SDL_hid_get_feature_report_REAL +#define SDL_hid_close SDL_hid_close_REAL +#define SDL_hid_get_manufacturer_string SDL_hid_get_manufacturer_string_REAL +#define SDL_hid_get_product_string SDL_hid_get_product_string_REAL +#define SDL_hid_get_serial_number_string SDL_hid_get_serial_number_string_REAL +#define SDL_hid_get_indexed_string SDL_hid_get_indexed_string_REAL diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 0ac166994..8a732bb20 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -896,3 +896,18 @@ SDL_DYNAPI_PROC(int,SDL_LinuxSetThreadPriorityAndPolicy,(Sint64 a, int b, int c) #endif SDL_DYNAPI_PROC(const char*,SDL_GameControllerGetAppleSFSymbolsNameForButton,(SDL_GameController *a, SDL_GameControllerButton b),(a,b),return) SDL_DYNAPI_PROC(const char*,SDL_GameControllerGetAppleSFSymbolsNameForAxis,(SDL_GameController *a, SDL_GameControllerAxis b),(a,b),return) +SDL_DYNAPI_PROC(int,SDL_hid_init,(void),(),return) +SDL_DYNAPI_PROC(int,SDL_hid_exit,(void),(),return) +SDL_DYNAPI_PROC(SDL_hid_device_info*,SDL_hid_enumerate,(unsigned short a, unsigned short b),(a,b),return) +SDL_DYNAPI_PROC(void,SDL_hid_free_enumeration,(SDL_hid_device_info *a),(a),) +SDL_DYNAPI_PROC(int,SDL_hid_write,(SDL_hid_device *a, const unsigned char *b, size_t c),(a,b,c),return) +SDL_DYNAPI_PROC(int,SDL_hid_read_timeout,(SDL_hid_device *a, unsigned char *b, size_t c, int d),(a,b,c,d),return) +SDL_DYNAPI_PROC(int,SDL_hid_read,(SDL_hid_device *a, unsigned char *b, size_t c),(a,b,c),return) +SDL_DYNAPI_PROC(int,SDL_hid_set_nonblocking,(SDL_hid_device *a, int b),(a,b),return) +SDL_DYNAPI_PROC(int,SDL_hid_send_feature_report,(SDL_hid_device *a, const unsigned char *b, size_t c),(a,b,c),return) +SDL_DYNAPI_PROC(int,SDL_hid_get_feature_report,(SDL_hid_device *a, unsigned char *b, size_t c),(a,b,c),return) +SDL_DYNAPI_PROC(void,SDL_hid_close,(SDL_hid_device *a),(a),) +SDL_DYNAPI_PROC(int,SDL_hid_get_manufacturer_string,(SDL_hid_device *a, wchar_t *b, size_t c),(a,b,c),return) +SDL_DYNAPI_PROC(int,SDL_hid_get_product_string,(SDL_hid_device *a, wchar_t *b, size_t c),(a,b,c),return) +SDL_DYNAPI_PROC(int,SDL_hid_get_serial_number_string,(SDL_hid_device *a, wchar_t *b, size_t c),(a,b,c),return) +SDL_DYNAPI_PROC(int,SDL_hid_get_indexed_string,(SDL_hid_device *a, int b, wchar_t *c, size_t d),(a,b,c,d),return) diff --git a/src/hidapi/SDL_hidapi.c b/src/hidapi/SDL_hidapi.c index d8a330728..aeeb317aa 100644 --- a/src/hidapi/SDL_hidapi.c +++ b/src/hidapi/SDL_hidapi.c @@ -31,14 +31,12 @@ #include "SDL_loadso.h" #include "SDL_hidapi.h" +#include "SDL_hidapi_c.h" -#ifdef SDL_JOYSTICK_HIDAPI +#ifndef SDL_DISABLE_HIDAPI /* Platform HIDAPI Implementation */ -#define hid_device_ PLATFORM_hid_device_ -#define hid_device PLATFORM_hid_device -#define hid_device_info PLATFORM_hid_device_info #define hid_init PLATFORM_hid_init #define hid_exit PLATFORM_hid_exit #define hid_enumerate PLATFORM_hid_enumerate @@ -99,11 +97,18 @@ static const SDL_UDEV_Symbols *udev_ctx = NULL; #include "windows/hid.c" #define HAVE_PLATFORM_BACKEND 1 #define udev_ctx 1 +#elif __ANDROID__ +/* The implementation for Android is in a separate .cpp file */ +#include "hidapi/hidapi.h" +#define HAVE_PLATFORM_BACKEND 1 +#define udev_ctx 1 +#elif __IPHONEOS__ || __TVOS__ +/* The implementation for iOS and tvOS is in a separate .m file */ +#include "hidapi/hidapi.h" +#define HAVE_PLATFORM_BACKEND 1 +#define udev_ctx 1 #endif -#undef hid_device_ -#undef hid_device -#undef hid_device_info #undef hid_init #undef hid_exit #undef hid_enumerate @@ -137,9 +142,6 @@ static const SDL_UDEV_Symbols *udev_ctx = NULL; /* DRIVER HIDAPI Implementation */ -#define hid_device_ DRIVER_hid_device_ -#define hid_device DRIVER_hid_device -#define hid_device_info DRIVER_hid_device_info #define hid_init DRIVER_hid_init #define hid_exit DRIVER_hid_exit #define hid_enumerate DRIVER_hid_enumerate @@ -166,9 +168,6 @@ static const SDL_UDEV_Symbols *udev_ctx = NULL; #error Need a driver hid.c for this platform! #endif -#undef hid_device_ -#undef hid_device -#undef hid_device_info #undef hid_init #undef hid_exit #undef hid_enumerate @@ -276,9 +275,6 @@ static struct #define libusb_handle_events libusb_ctx.handle_events #define libusb_handle_events_completed libusb_ctx.handle_events_completed -#define hid_device_ LIBUSB_hid_device_ -#define hid_device LIBUSB_hid_device -#define hid_device_info LIBUSB_hid_device_info #define hid_init LIBUSB_hid_init #define hid_exit LIBUSB_hid_exit #define hid_enumerate LIBUSB_hid_enumerate @@ -327,9 +323,6 @@ SDL_libusb_get_string_descriptor(libusb_device_handle *dev, #undef HIDAPI_H__ #include "libusb/hid.c" -#undef hid_device_ -#undef hid_device -#undef hid_device_info #undef hid_init #undef hid_exit #undef hid_enumerate @@ -357,24 +350,23 @@ SDL_libusb_get_string_descriptor(libusb_device_handle *dev, #endif /* SDL_LIBUSB_DYNAMIC */ +#endif /* !SDL_DISABLE_HIDAPI */ + /* Shared HIDAPI Implementation */ -#undef HIDAPI_H__ -#include "hidapi/hidapi.h" - struct hidapi_backend { - int (*hid_write)(hid_device* device, const unsigned char* data, size_t length); - int (*hid_read_timeout)(hid_device* device, unsigned char* data, size_t length, int milliseconds); - int (*hid_read)(hid_device* device, unsigned char* data, size_t length); - int (*hid_set_nonblocking)(hid_device* device, int nonblock); - int (*hid_send_feature_report)(hid_device* device, const unsigned char* data, size_t length); - int (*hid_get_feature_report)(hid_device* device, unsigned char* data, size_t length); - void (*hid_close)(hid_device* device); - int (*hid_get_manufacturer_string)(hid_device* device, wchar_t* string, size_t maxlen); - int (*hid_get_product_string)(hid_device* device, wchar_t* string, size_t maxlen); - int (*hid_get_serial_number_string)(hid_device* device, wchar_t* string, size_t maxlen); - int (*hid_get_indexed_string)(hid_device* device, int string_index, wchar_t* string, size_t maxlen); - const wchar_t* (*hid_error)(hid_device* device); + int (*hid_write)(SDL_hid_device* device, const unsigned char* data, size_t length); + int (*hid_read_timeout)(SDL_hid_device* device, unsigned char* data, size_t length, int milliseconds); + int (*hid_read)(SDL_hid_device* device, unsigned char* data, size_t length); + int (*hid_set_nonblocking)(SDL_hid_device* device, int nonblock); + int (*hid_send_feature_report)(SDL_hid_device* device, const unsigned char* data, size_t length); + int (*hid_get_feature_report)(SDL_hid_device* device, unsigned char* data, size_t length); + void (*hid_close)(SDL_hid_device* device); + int (*hid_get_manufacturer_string)(SDL_hid_device* device, wchar_t* string, size_t maxlen); + int (*hid_get_product_string)(SDL_hid_device* device, wchar_t* string, size_t maxlen); + int (*hid_get_serial_number_string)(SDL_hid_device* device, wchar_t* string, size_t maxlen); + int (*hid_get_indexed_string)(SDL_hid_device* device, int string_index, wchar_t* string, size_t maxlen); + const wchar_t* (*hid_error)(SDL_hid_device* device); }; #if HAVE_PLATFORM_BACKEND @@ -431,14 +423,14 @@ static const struct hidapi_backend LIBUSB_Backend = { typedef struct _HIDDeviceWrapper HIDDeviceWrapper; struct _HIDDeviceWrapper { - hid_device *device; /* must be first field */ + SDL_hid_device *device; /* must be first field */ const struct hidapi_backend *backend; }; #if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC) static HIDDeviceWrapper * -CreateHIDDeviceWrapper(hid_device *device, const struct hidapi_backend *backend) +CreateHIDDeviceWrapper(SDL_hid_device *device, const struct hidapi_backend *backend) { HIDDeviceWrapper *ret = (HIDDeviceWrapper *)SDL_malloc(sizeof(*ret)); ret->device = device; @@ -446,16 +438,16 @@ CreateHIDDeviceWrapper(hid_device *device, const struct hidapi_backend *backend) return ret; } -static hid_device * +static SDL_hid_device * WrapHIDDevice(HIDDeviceWrapper *wrapper) { - return (hid_device *)wrapper; + return (SDL_hid_device *)wrapper; } #endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */ static HIDDeviceWrapper * -UnwrapHIDDevice(hid_device *device) +UnwrapHIDDevice(SDL_hid_device *device) { return (HIDDeviceWrapper *)device; } @@ -466,6 +458,8 @@ DeleteHIDDeviceWrapper(HIDDeviceWrapper *device) SDL_free(device); } +#ifndef SDL_DISABLE_HIDAPI + #define COPY_IF_EXISTS(var) \ if (pSrc->var != NULL) { \ pDst->var = SDL_strdup(pSrc->var); \ @@ -479,10 +473,8 @@ DeleteHIDDeviceWrapper(HIDDeviceWrapper *device) pDst->var = NULL; \ } -#ifdef SDL_LIBUSB_DYNAMIC static void -LIBUSB_CopyHIDDeviceInfo(struct LIBUSB_hid_device_info *pSrc, - struct hid_device_info *pDst) +CopyHIDDeviceInfo(struct SDL_hid_device_info *pSrc, struct SDL_hid_device_info *pDst) { COPY_IF_EXISTS(path) pDst->vendor_id = pSrc->vendor_id; @@ -499,58 +491,26 @@ LIBUSB_CopyHIDDeviceInfo(struct LIBUSB_hid_device_info *pSrc, pDst->interface_protocol = pSrc->interface_protocol; pDst->next = NULL; } -#endif /* SDL_LIBUSB_DYNAMIC */ - -#if HAVE_DRIVER_BACKEND -static void -DRIVER_CopyHIDDeviceInfo(struct DRIVER_hid_device_info *pSrc, - struct hid_device_info *pDst) -{ - COPY_IF_EXISTS(path) - pDst->vendor_id = pSrc->vendor_id; - pDst->product_id = pSrc->product_id; - WCOPY_IF_EXISTS(serial_number) - pDst->release_number = pSrc->release_number; - WCOPY_IF_EXISTS(manufacturer_string) - WCOPY_IF_EXISTS(product_string) - pDst->usage_page = pSrc->usage_page; - pDst->usage = pSrc->usage; - pDst->interface_number = pSrc->interface_number; - pDst->interface_class = pSrc->interface_class; - pDst->interface_subclass = pSrc->interface_subclass; - pDst->interface_protocol = pSrc->interface_protocol; - pDst->next = NULL; -} -#endif /* HAVE_DRIVER_BACKEND */ - -#if HAVE_PLATFORM_BACKEND -static void -PLATFORM_CopyHIDDeviceInfo(struct PLATFORM_hid_device_info *pSrc, - struct hid_device_info *pDst) -{ - COPY_IF_EXISTS(path) - pDst->vendor_id = pSrc->vendor_id; - pDst->product_id = pSrc->product_id; - WCOPY_IF_EXISTS(serial_number) - pDst->release_number = pSrc->release_number; - WCOPY_IF_EXISTS(manufacturer_string) - WCOPY_IF_EXISTS(product_string) - pDst->usage_page = pSrc->usage_page; - pDst->usage = pSrc->usage; - pDst->interface_number = pSrc->interface_number; - pDst->interface_class = pSrc->interface_class; - pDst->interface_subclass = pSrc->interface_subclass; - pDst->interface_protocol = pSrc->interface_protocol; - pDst->next = NULL; -} -#endif /* HAVE_PLATFORM_BACKEND */ #undef COPY_IF_EXISTS #undef WCOPY_IF_EXISTS +#endif /* SDL_DISABLE_HIDAPI */ + static SDL_bool SDL_hidapi_wasinit = SDL_FALSE; -int HID_API_EXPORT HID_API_CALL hid_init(void) +static void SDL_SetHIDAPIError( const wchar_t *error ) +{ + if (error) { + char *error_utf8 = SDL_iconv_wchar_utf8(error); + if (error_utf8) { + SDL_SetError("%s", error_utf8); + SDL_free(error_utf8); + } + } +} + +int SDL_hid_init(void) { int attempts = 0, success = 0; @@ -624,7 +584,7 @@ int HID_API_EXPORT HID_API_CALL hid_init(void) return 0; } -int HID_API_EXPORT HID_API_CALL hid_exit(void) +int SDL_hid_exit(void) { int result = 0; @@ -650,24 +610,24 @@ int HID_API_EXPORT HID_API_CALL hid_exit(void) return result; } -struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned short vendor_id, unsigned short product_id) +struct SDL_hid_device_info *SDL_hid_enumerate(unsigned short vendor_id, unsigned short product_id) { #if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC) #ifdef SDL_LIBUSB_DYNAMIC - struct LIBUSB_hid_device_info *usb_devs = NULL; - struct LIBUSB_hid_device_info *usb_dev; + struct SDL_hid_device_info *usb_devs = NULL; + struct SDL_hid_device_info *usb_dev; #endif #if HAVE_DRIVER_BACKEND - struct DRIVER_hid_device_info* driver_devs = NULL; - struct DRIVER_hid_device_info* driver_dev; + struct SDL_hid_device_info* driver_devs = NULL; + struct SDL_hid_device_info* driver_dev; #endif #if HAVE_PLATFORM_BACKEND - struct PLATFORM_hid_device_info *raw_devs = NULL; - struct PLATFORM_hid_device_info *raw_dev; + struct SDL_hid_device_info *raw_devs = NULL; + struct SDL_hid_device_info *raw_dev; #endif - struct hid_device_info *devs = NULL, *last = NULL, *new_dev; + struct SDL_hid_device_info *devs = NULL, *last = NULL, *new_dev; - if (hid_init() != 0) { + if (SDL_hid_init() != 0) { return NULL; } @@ -678,14 +638,14 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor SDL_Log("libusb devices found:"); #endif for (usb_dev = usb_devs; usb_dev; usb_dev = usb_dev->next) { - new_dev = (struct hid_device_info*) SDL_malloc(sizeof(struct hid_device_info)); + new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info)); if (!new_dev) { LIBUSB_hid_free_enumeration(usb_devs); - hid_free_enumeration(devs); + SDL_hid_free_enumeration(devs); SDL_OutOfMemory(); return NULL; } - LIBUSB_CopyHIDDeviceInfo(usb_dev, new_dev); + CopyHIDDeviceInfo(usb_dev, new_dev); #ifdef DEBUG_HIDAPI SDL_Log(" - %ls %ls 0x%.4hx 0x%.4hx", usb_dev->manufacturer_string, usb_dev->product_string, @@ -705,8 +665,8 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor #ifdef HAVE_DRIVER_BACKEND driver_devs = DRIVER_hid_enumerate(vendor_id, product_id); for (driver_dev = driver_devs; driver_dev; driver_dev = driver_dev->next) { - new_dev = (struct hid_device_info*) SDL_malloc(sizeof(struct hid_device_info)); - DRIVER_CopyHIDDeviceInfo(driver_dev, new_dev); + new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info)); + CopyHIDDeviceInfo(driver_dev, new_dev); if (last != NULL) { last->next = new_dev; @@ -751,7 +711,7 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor } #endif if (!bFound) { - new_dev = (struct hid_device_info*) SDL_malloc(sizeof(struct hid_device_info)); + new_dev = (struct SDL_hid_device_info*) SDL_malloc(sizeof(struct SDL_hid_device_info)); if (!new_dev) { #ifdef SDL_LIBUSB_DYNAMIC if (libusb_ctx.libhandle) { @@ -759,11 +719,11 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor } #endif PLATFORM_hid_free_enumeration(raw_devs); - hid_free_enumeration(devs); + SDL_hid_free_enumeration(devs); SDL_OutOfMemory(); return NULL; } - PLATFORM_CopyHIDDeviceInfo(raw_dev, new_dev); + CopyHIDDeviceInfo(raw_dev, new_dev); new_dev->next = NULL; if (last != NULL) { @@ -790,10 +750,10 @@ struct hid_device_info HID_API_EXPORT * HID_API_CALL hid_enumerate(unsigned shor #endif /* HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || SDL_LIBUSB_DYNAMIC */ } -void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *devs) +void SDL_hid_free_enumeration(struct SDL_hid_device_info *devs) { while (devs) { - struct hid_device_info *next = devs->next; + struct SDL_hid_device_info *next = devs->next; SDL_free(devs->path); SDL_free(devs->serial_number); SDL_free(devs->manufacturer_string); @@ -803,18 +763,18 @@ void HID_API_EXPORT HID_API_CALL hid_free_enumeration(struct hid_device_info *d } } -HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number) +SDL_hid_device *SDL_hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number) { #if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC) - hid_device *pDevice = NULL; + SDL_hid_device *pDevice = NULL; - if (hid_init() != 0) { + if (SDL_hid_init() != 0) { return NULL; } #if HAVE_PLATFORM_BACKEND if (udev_ctx && - (pDevice = (hid_device*) PLATFORM_hid_open(vendor_id, product_id, serial_number)) != NULL) { + (pDevice = (SDL_hid_device*) PLATFORM_hid_open(vendor_id, product_id, serial_number)) != NULL) { HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &PLATFORM_Backend); return WrapHIDDevice(wrapper); @@ -822,7 +782,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi #endif /* HAVE_PLATFORM_BACKEND */ #if HAVE_DRIVER_BACKEND - if ((pDevice = (hid_device*) DRIVER_hid_open(vendor_id, product_id, serial_number)) != NULL) { + if ((pDevice = (SDL_hid_device*) DRIVER_hid_open(vendor_id, product_id, serial_number)) != NULL) { HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &DRIVER_Backend); return WrapHIDDevice(wrapper); @@ -831,7 +791,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi #ifdef SDL_LIBUSB_DYNAMIC if (libusb_ctx.libhandle && - (pDevice = (hid_device*) LIBUSB_hid_open(vendor_id, product_id, serial_number)) != NULL) { + (pDevice = (SDL_hid_device*) LIBUSB_hid_open(vendor_id, product_id, serial_number)) != NULL) { HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend); return WrapHIDDevice(wrapper); @@ -843,18 +803,18 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsi return NULL; } -HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bExclusive /* = false */) +SDL_hid_device *SDL_hid_open_path(const char *path, int bExclusive /* = false */) { #if HAVE_PLATFORM_BACKEND || HAVE_DRIVER_BACKEND || defined(SDL_LIBUSB_DYNAMIC) - hid_device *pDevice = NULL; + SDL_hid_device *pDevice = NULL; - if (hid_init() != 0) { + if (SDL_hid_init() != 0) { return NULL; } #if HAVE_PLATFORM_BACKEND if (udev_ctx && - (pDevice = (hid_device*) PLATFORM_hid_open_path(path, bExclusive)) != NULL) { + (pDevice = (SDL_hid_device*) PLATFORM_hid_open_path(path, bExclusive)) != NULL) { HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &PLATFORM_Backend); return WrapHIDDevice(wrapper); @@ -862,7 +822,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx #endif /* HAVE_PLATFORM_BACKEND */ #if HAVE_DRIVER_BACKEND - if ((pDevice = (hid_device*) DRIVER_hid_open_path(path, bExclusive)) != NULL) { + if ((pDevice = (SDL_hid_device*) DRIVER_hid_open_path(path, bExclusive)) != NULL) { HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &DRIVER_Backend); return WrapHIDDevice(wrapper); @@ -871,7 +831,7 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx #ifdef SDL_LIBUSB_DYNAMIC if (libusb_ctx.libhandle && - (pDevice = (hid_device*) LIBUSB_hid_open_path(path, bExclusive)) != NULL) { + (pDevice = (SDL_hid_device*) LIBUSB_hid_open_path(path, bExclusive)) != NULL) { HIDDeviceWrapper *wrapper = CreateHIDDeviceWrapper(pDevice, &LIBUSB_Backend); return WrapHIDDevice(wrapper); @@ -883,77 +843,111 @@ HID_API_EXPORT hid_device * HID_API_CALL hid_open_path(const char *path, int bEx return NULL; } -int HID_API_EXPORT HID_API_CALL hid_write(hid_device *device, const unsigned char *data, size_t length) +int SDL_hid_write(SDL_hid_device *device, const unsigned char *data, size_t length) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_write(wrapper->device, data, length); + int result = wrapper->backend->hid_write(wrapper->device, data, length); + if (result < 0) { + SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device)); + } + return result; } -int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *device, unsigned char *data, size_t length, int milliseconds) +int SDL_hid_read_timeout(SDL_hid_device *device, unsigned char *data, size_t length, int milliseconds) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_read_timeout(wrapper->device, data, length, milliseconds); + int result = wrapper->backend->hid_read_timeout(wrapper->device, data, length, milliseconds); + if (result < 0) { + SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device)); + } + return result; } -int HID_API_EXPORT HID_API_CALL hid_read(hid_device *device, unsigned char *data, size_t length) +int SDL_hid_read(SDL_hid_device *device, unsigned char *data, size_t length) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_read(wrapper->device, data, length); + int result = wrapper->backend->hid_read(wrapper->device, data, length); + if (result < 0) { + SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device)); + } + return result; } -int HID_API_EXPORT HID_API_CALL hid_set_nonblocking(hid_device *device, int nonblock) +int SDL_hid_set_nonblocking(SDL_hid_device *device, int nonblock) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_set_nonblocking(wrapper->device, nonblock); + int result = wrapper->backend->hid_set_nonblocking(wrapper->device, nonblock); + if (result < 0) { + SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device)); + } + return result; } -int HID_API_EXPORT HID_API_CALL hid_send_feature_report(hid_device *device, const unsigned char *data, size_t length) +int SDL_hid_send_feature_report(SDL_hid_device *device, const unsigned char *data, size_t length) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_send_feature_report(wrapper->device, data, length); + int result = wrapper->backend->hid_send_feature_report(wrapper->device, data, length); + if (result < 0) { + SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device)); + } + return result; } -int HID_API_EXPORT HID_API_CALL hid_get_feature_report(hid_device *device, unsigned char *data, size_t length) +int SDL_hid_get_feature_report(SDL_hid_device *device, unsigned char *data, size_t length) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_get_feature_report(wrapper->device, data, length); + int result = wrapper->backend->hid_get_feature_report(wrapper->device, data, length); + if (result < 0) { + SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device)); + } + return result; } -void HID_API_EXPORT HID_API_CALL hid_close(hid_device *device) +void SDL_hid_close(SDL_hid_device *device) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); wrapper->backend->hid_close(wrapper->device); DeleteHIDDeviceWrapper(wrapper); } -int HID_API_EXPORT_CALL hid_get_manufacturer_string(hid_device *device, wchar_t *string, size_t maxlen) +int SDL_hid_get_manufacturer_string(SDL_hid_device *device, wchar_t *string, size_t maxlen) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_get_manufacturer_string(wrapper->device, string, maxlen); + int result = wrapper->backend->hid_get_manufacturer_string(wrapper->device, string, maxlen); + if (result < 0) { + SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device)); + } + return result; } -int HID_API_EXPORT_CALL hid_get_product_string(hid_device *device, wchar_t *string, size_t maxlen) +int SDL_hid_get_product_string(SDL_hid_device *device, wchar_t *string, size_t maxlen) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_get_product_string(wrapper->device, string, maxlen); + int result = wrapper->backend->hid_get_product_string(wrapper->device, string, maxlen); + if (result < 0) { + SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device)); + } + return result; } -int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *device, wchar_t *string, size_t maxlen) +int SDL_hid_get_serial_number_string(SDL_hid_device *device, wchar_t *string, size_t maxlen) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_get_serial_number_string(wrapper->device, string, maxlen); + int result = wrapper->backend->hid_get_serial_number_string(wrapper->device, string, maxlen); + if (result < 0) { + SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device)); + } + return result; } -int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *device, int string_index, wchar_t *string, size_t maxlen) +int SDL_hid_get_indexed_string(SDL_hid_device *device, int string_index, wchar_t *string, size_t maxlen) { HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_get_indexed_string(wrapper->device, string_index, string, maxlen); -} - -HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *device) -{ - HIDDeviceWrapper *wrapper = UnwrapHIDDevice(device); - return wrapper->backend->hid_error(wrapper->device); + int result = wrapper->backend->hid_get_indexed_string(wrapper->device, string_index, string, maxlen); + if (result < 0) { + SDL_SetHIDAPIError(wrapper->backend->hid_error(wrapper->device)); + } + return result; } #ifdef HAVE_ENABLE_GAMECUBE_ADAPTORS @@ -1013,6 +1007,4 @@ void SDL_EnableGameCubeAdaptors(void) } #endif /* HAVE_ENABLE_GAMECUBE_ADAPTORS */ -#endif /* SDL_JOYSTICK_HIDAPI */ - /* vi: set sts=4 ts=4 sw=4 expandtab: */ diff --git a/src/hidapi/SDL_hidapi.h b/src/hidapi/SDL_hidapi_c.h similarity index 100% rename from src/hidapi/SDL_hidapi.h rename to src/hidapi/SDL_hidapi_c.h diff --git a/src/hidapi/android/hid.cpp b/src/hidapi/android/hid.cpp index 4bba20794..bed88674d 100644 --- a/src/hidapi/android/hid.cpp +++ b/src/hidapi/android/hid.cpp @@ -22,6 +22,27 @@ // // This layer glues the hidapi API to Android's USB and BLE stack. +#ifndef SDL_DISABLE_HIDAPI + +#define hid_init PLATFORM_hid_init +#define hid_exit PLATFORM_hid_exit +#define hid_enumerate PLATFORM_hid_enumerate +#define hid_free_enumeration PLATFORM_hid_free_enumeration +#define hid_open PLATFORM_hid_open +#define hid_open_path PLATFORM_hid_open_path +#define hid_write PLATFORM_hid_write +#define hid_read_timeout PLATFORM_hid_read_timeout +#define hid_read PLATFORM_hid_read +#define hid_set_nonblocking PLATFORM_hid_set_nonblocking +#define hid_send_feature_report PLATFORM_hid_send_feature_report +#define hid_get_feature_report PLATFORM_hid_get_feature_report +#define hid_close PLATFORM_hid_close +#define hid_get_manufacturer_string PLATFORM_hid_get_manufacturer_string +#define hid_get_product_string PLATFORM_hid_get_product_string +#define hid_get_serial_number_string PLATFORM_hid_get_serial_number_string +#define hid_get_indexed_string PLATFORM_hid_get_indexed_string +#define hid_error PLATFORM_hid_error + #include #include #include @@ -1264,3 +1285,5 @@ int hid_exit(void) } } + +#endif /* SDL_DISABLE_HIDAPI */ diff --git a/src/hidapi/hidapi/hidapi.h b/src/hidapi/hidapi/hidapi.h index 1896a38a8..01d87e3f3 100644 --- a/src/hidapi/hidapi/hidapi.h +++ b/src/hidapi/hidapi/hidapi.h @@ -29,7 +29,14 @@ #include -#if defined(_WIN32) && !defined(NAMESPACE) && (0) /* SDL: don't export hidapi syms */ +#ifdef SDL_hidapi_h_ +#define SDL_HIDAPI_IMPLEMENTATION +#define hid_device_ SDL_hid_device_ +#define hid_device SDL_hid_device +#define hid_device_info SDL_hid_device_info +#endif + +#if defined(_WIN32) && !defined(NAMESPACE) && !defined(SDL_HIDAPI_IMPLEMENTATION) /* SDL: don't export hidapi syms */ #define HID_API_EXPORT __declspec(dllexport) #define HID_API_CALL #else @@ -50,6 +57,7 @@ extern "C" { namespace NAMESPACE { #endif +#ifndef SDL_HIDAPI_IMPLEMENTATION struct hid_device_; typedef struct hid_device_ hid_device; /**< opaque hidapi structure */ @@ -93,6 +101,7 @@ namespace NAMESPACE { /** Pointer to the next device */ struct hid_device_info *next; }; +#endif /* !SDL_HIDAPI_IMPLEMENTATION */ /** @brief Initialize the HIDAPI library. diff --git a/src/hidapi/ios/hid.m b/src/hidapi/ios/hid.m index 4c747673f..ba1aaa9e0 100644 --- a/src/hidapi/ios/hid.m +++ b/src/hidapi/ios/hid.m @@ -20,7 +20,26 @@ */ #include "../../SDL_internal.h" -#ifdef SDL_JOYSTICK_HIDAPI +#ifndef SDL_DISABLE_HIDAPI + +#define hid_init PLATFORM_hid_init +#define hid_exit PLATFORM_hid_exit +#define hid_enumerate PLATFORM_hid_enumerate +#define hid_free_enumeration PLATFORM_hid_free_enumeration +#define hid_open PLATFORM_hid_open +#define hid_open_path PLATFORM_hid_open_path +#define hid_write PLATFORM_hid_write +#define hid_read_timeout PLATFORM_hid_read_timeout +#define hid_read PLATFORM_hid_read +#define hid_set_nonblocking PLATFORM_hid_set_nonblocking +#define hid_send_feature_report PLATFORM_hid_send_feature_report +#define hid_get_feature_report PLATFORM_hid_get_feature_report +#define hid_close PLATFORM_hid_close +#define hid_get_manufacturer_string PLATFORM_hid_get_manufacturer_string +#define hid_get_product_string PLATFORM_hid_get_product_string +#define hid_get_serial_number_string PLATFORM_hid_get_serial_number_string +#define hid_get_indexed_string PLATFORM_hid_get_indexed_string +#define hid_error PLATFORM_hid_error #include #include @@ -737,7 +756,12 @@ void HID_API_EXPORT HID_API_CALL hid_ble_scan( bool bStart ) } } -hid_device * HID_API_EXPORT hid_open_path( const char *path, int bExclusive /* = false */ ) +HID_API_EXPORT hid_device * HID_API_CALL hid_open(unsigned short vendor_id, unsigned short product_id, const wchar_t *serial_number) +{ + return NULL; +} + +HID_API_EXPORT hid_device * HID_API_CALL hid_open_path( const char *path, int bExclusive /* = false */ ) { hid_device *result = NULL; NSString *nssPath = [NSString stringWithUTF8String:path]; @@ -851,6 +875,11 @@ int HID_API_EXPORT_CALL hid_get_serial_number_string(hid_device *dev, wchar_t *s return 0; } +int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index, wchar_t *string, size_t maxlen) +{ + return -1; +} + int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length) { HIDBLEDevice *device_handle = (__bridge HIDBLEDevice *)dev->device_handle; @@ -927,4 +956,9 @@ int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t return result; } -#endif /* SDL_JOYSTICK_HIDAPI */ +HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev) +{ + return NULL; +} + +#endif /* !SDL_DISABLE_HIDAPI */ diff --git a/src/hidapi/libusb/hid.c b/src/hidapi/libusb/hid.c index fa1d588f8..d4fd9da69 100644 --- a/src/hidapi/libusb/hid.c +++ b/src/hidapi/libusb/hid.c @@ -31,8 +31,6 @@ #include "SDL_thread.h" #include "SDL_mutex.h" -#ifdef SDL_JOYSTICK_HIDAPI - #if defined(HAVE__WCSDUP) && !defined(HAVE_WCSDUP) #define wcsdup _wcsdup #endif @@ -1742,5 +1740,3 @@ uint16_t get_usb_code_for_current_locale(void) #ifdef NAMESPACE } #endif - -#endif /* SDL_JOYSTICK_HIDAPI */ diff --git a/src/hidapi/linux/hid.c b/src/hidapi/linux/hid.c index 28e9847d4..2c7128f45 100644 --- a/src/hidapi/linux/hid.c +++ b/src/hidapi/linux/hid.c @@ -22,8 +22,6 @@ ********************************************************/ #include "../../SDL_internal.h" -#ifdef SDL_JOYSTICK_HIDAPI - #ifndef _GNU_SOURCE #define _GNU_SOURCE /* needed for wcsdup() before glibc 2.10 */ #endif @@ -902,5 +900,3 @@ HID_API_EXPORT const wchar_t * HID_API_CALL hid_error(hid_device *dev) #ifdef NAMESPACE } #endif - -#endif /* SDL_JOYSTICK_HIDAPI */ diff --git a/src/hidapi/mac/hid.c b/src/hidapi/mac/hid.c index e678c1a09..1ad042d49 100644 --- a/src/hidapi/mac/hid.c +++ b/src/hidapi/mac/hid.c @@ -21,8 +21,6 @@ ********************************************************/ #include "../../SDL_internal.h" -#ifdef SDL_JOYSTICK_HIDAPI - /* See Apple Technical Note TN2187 for details on IOHidManager. */ #include @@ -1191,5 +1189,3 @@ int main(void) return 0; } #endif - -#endif /* SDL_JOYSTICK_HIDAPI */ diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c index e6fbf85da..2f617692e 100644 --- a/src/hidapi/windows/hid.c +++ b/src/hidapi/windows/hid.c @@ -21,8 +21,6 @@ ********************************************************/ #include "../../SDL_internal.h" -#ifdef SDL_JOYSTICK_HIDAPI - #include #ifndef _WIN32_WINNT_WIN8 @@ -1099,5 +1097,3 @@ int __cdecl main(int argc, char* argv[]) #ifdef __cplusplus } /* extern "C" */ #endif - -#endif /* SDL_JOYSTICK_HIDAPI */ diff --git a/src/joystick/hidapi/SDL_hidapi_gamecube.c b/src/joystick/hidapi/SDL_hidapi_gamecube.c index e4407f063..21b217fc7 100644 --- a/src/joystick/hidapi/SDL_hidapi_gamecube.c +++ b/src/joystick/hidapi/SDL_hidapi_gamecube.c @@ -32,7 +32,7 @@ #include "../SDL_sysjoystick.h" #include "SDL_hidapijoystick_c.h" #include "SDL_hidapi_rumble.h" -#include "../../hidapi/SDL_hidapi.h" +#include "../../hidapi/SDL_hidapi_c.h" #ifdef SDL_JOYSTICK_HIDAPI_GAMECUBE @@ -129,7 +129,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device) return SDL_FALSE; } - device->dev = hid_open_path(device->path, 0); + device->dev = SDL_hid_open_path(device->path, 0); if (!device->dev) { SDL_free(ctx); SDL_SetError("Couldn't open %s", device->path); @@ -154,7 +154,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device) } } else { /* This is all that's needed to initialize the device. Really! */ - if (hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) { + if (SDL_hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) { SDL_SetError("Couldn't initialize WUP-028"); goto error; } @@ -163,7 +163,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device) SDL_Delay(10); /* Add all the applicable joysticks */ - while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) { + while ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) { #ifdef DEBUG_GAMECUBE_PROTOCOL HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size); #endif @@ -204,7 +204,7 @@ error: SDL_LockMutex(device->dev_lock); { if (device->dev) { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; } if (device->context) { @@ -389,7 +389,7 @@ HIDAPI_DriverGameCube_UpdateDevice(SDL_HIDAPI_Device *device) int size; /* Read input packet */ - while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) { + while ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) { #ifdef DEBUG_GAMECUBE_PROTOCOL //HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size); #endif @@ -510,7 +510,7 @@ HIDAPI_DriverGameCube_FreeDevice(SDL_HIDAPI_Device *device) SDL_LockMutex(device->dev_lock); { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; SDL_free(device->context); diff --git a/src/joystick/hidapi/SDL_hidapi_luna.c b/src/joystick/hidapi/SDL_hidapi_luna.c index 78d5c5ed6..3734a9849 100644 --- a/src/joystick/hidapi/SDL_hidapi_luna.c +++ b/src/joystick/hidapi/SDL_hidapi_luna.c @@ -87,7 +87,7 @@ HIDAPI_DriverLuna_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick return SDL_FALSE; } - device->dev = hid_open_path(device->path, 0); + device->dev = SDL_hid_open_path(device->path, 0); if (!device->dev) { SDL_SetError("Couldn't open %s", device->path); SDL_free(ctx); @@ -386,7 +386,7 @@ HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device) return SDL_FALSE; } - while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { + while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { #ifdef DEBUG_LUNA_PROTOCOL HIDAPI_DumpPacket("Amazon Luna packet: size = %d", data, size); #endif @@ -413,7 +413,7 @@ HIDAPI_DriverLuna_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic SDL_LockMutex(device->dev_lock); { if (device->dev) { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; } diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c index 319dec4b4..95ee894e9 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps4.c +++ b/src/joystick/hidapi/SDL_hidapi_ps4.c @@ -163,11 +163,11 @@ HIDAPI_DriverPS4_GetDeviceName(Uint16 vendor_id, Uint16 product_id) return NULL; } -static int ReadFeatureReport(hid_device *dev, Uint8 report_id, Uint8 *report, size_t length) +static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length) { SDL_memset(report, 0, length); report[0] = report_id; - return hid_get_feature_report(dev, report, length); + return SDL_hid_get_feature_report(dev, report, length); } static SDL_bool HIDAPI_DriverPS4_CanRumble(Uint16 vendor_id, Uint16 product_id) @@ -479,7 +479,7 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) ctx->joystick = joystick; ctx->last_packet = SDL_GetTicks(); - device->dev = hid_open_path(device->path, 0); + device->dev = SDL_hid_open_path(device->path, 0); if (!device->dev) { SDL_free(ctx); SDL_SetError("Couldn't open %s", device->path); @@ -511,7 +511,7 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) ctx->is_bluetooth = SDL_TRUE; /* Read a report to see if we're in enhanced mode */ - size = hid_read_timeout(device->dev, data, sizeof(data), 16); + size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 16); #ifdef DEBUG_PS4_PROTOCOL if (size > 0) { HIDAPI_DumpPacket("PS4 first packet: size = %d", data, size); @@ -684,7 +684,7 @@ HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti } static void -HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet) +HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet) { static const float TOUCHPAD_SCALEX = 1.0f / 1920; static const float TOUCHPAD_SCALEY = 1.0f / 920; /* This is noted as being 944 resolution, but 920 feels better */ @@ -846,7 +846,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device) return SDL_FALSE; } - while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { + while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { #ifdef DEBUG_PS4_PROTOCOL HIDAPI_DumpPacket("PS4 packet: size = %d", data, size); #endif @@ -908,7 +908,7 @@ HIDAPI_DriverPS4_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick SDL_LockMutex(device->dev_lock); { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; SDL_free(device->context); diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c index b0aa3c9c1..e64c56246 100644 --- a/src/joystick/hidapi/SDL_hidapi_ps5.c +++ b/src/joystick/hidapi/SDL_hidapi_ps5.c @@ -192,11 +192,11 @@ HIDAPI_DriverPS5_GetDeviceName(Uint16 vendor_id, Uint16 product_id) return NULL; } -static int ReadFeatureReport(hid_device *dev, Uint8 report_id, Uint8 *report, size_t length) +static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length) { SDL_memset(report, 0, length); report[0] = report_id; - return hid_get_feature_report(dev, report, length); + return SDL_hid_get_feature_report(dev, report, length); } static void @@ -553,7 +553,7 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) ctx->joystick = joystick; ctx->last_packet = SDL_GetTicks(); - device->dev = hid_open_path(device->path, 0); + device->dev = SDL_hid_open_path(device->path, 0); if (!device->dev) { SDL_free(ctx); SDL_SetError("Couldn't open %s", device->path); @@ -562,7 +562,7 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick) device->context = ctx; /* Read a report to see what mode we're in */ - size = hid_read_timeout(device->dev, data, sizeof(data), 16); + size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 16); #ifdef DEBUG_PS5_PROTOCOL if (size > 0) { HIDAPI_DumpPacket("PS5 first packet: size = %d", data, size); @@ -761,7 +761,7 @@ HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti } static void -HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverPS5_Context *ctx, PS5SimpleStatePacket_t *packet) +HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5SimpleStatePacket_t *packet) { Sint16 axis; @@ -855,7 +855,7 @@ HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, hid_device *dev } static void -HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacket_t *packet) +HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacket_t *packet) { static const float TOUCHPAD_SCALEX = 1.0f / 1920; static const float TOUCHPAD_SCALEY = 1.0f / 1070; @@ -1010,7 +1010,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device) return SDL_FALSE; } - while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { + while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { #ifdef DEBUG_PS5_PROTOCOL HIDAPI_DumpPacket("PS5 packet: size = %d", data, size); #endif @@ -1071,7 +1071,7 @@ HIDAPI_DriverPS5_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick SDL_LockMutex(device->dev_lock); { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; SDL_free(device->context); diff --git a/src/joystick/hidapi/SDL_hidapi_rumble.c b/src/joystick/hidapi/SDL_hidapi_rumble.c index 869bef322..152215cfb 100644 --- a/src/joystick/hidapi/SDL_hidapi_rumble.c +++ b/src/joystick/hidapi/SDL_hidapi_rumble.c @@ -80,7 +80,7 @@ static int SDL_HIDAPI_RumbleThread(void *data) #ifdef DEBUG_RUMBLE HIDAPI_DumpPacket("Rumble packet: size = %d", request->data, request->size); #endif - hid_write(request->device->dev, request->data, request->size); + SDL_hid_write(request->device->dev, request->data, request->size); } SDL_UnlockMutex(request->device->dev_lock); (void)SDL_AtomicDecRef(&request->device->rumble_pending); diff --git a/src/joystick/hidapi/SDL_hidapi_stadia.c b/src/joystick/hidapi/SDL_hidapi_stadia.c index c11aadd05..4180f51a0 100644 --- a/src/joystick/hidapi/SDL_hidapi_stadia.c +++ b/src/joystick/hidapi/SDL_hidapi_stadia.c @@ -88,7 +88,7 @@ HIDAPI_DriverStadia_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti return SDL_FALSE; } - device->dev = hid_open_path(device->path, 0); + device->dev = SDL_hid_open_path(device->path, 0); if (!device->dev) { SDL_SetError("Couldn't open %s", device->path); SDL_free(ctx); @@ -267,7 +267,7 @@ HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device) return SDL_FALSE; } - while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { + while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { #ifdef DEBUG_STADIA_PROTOCOL HIDAPI_DumpPacket("Google Stadia packet: size = %d", data, size); #endif @@ -287,7 +287,7 @@ HIDAPI_DriverStadia_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst SDL_LockMutex(device->dev_lock); { if (device->dev) { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; } diff --git a/src/joystick/hidapi/SDL_hidapi_steam.c b/src/joystick/hidapi/SDL_hidapi_steam.c index fdec0f072..3131011fb 100644 --- a/src/joystick/hidapi/SDL_hidapi_steam.c +++ b/src/joystick/hidapi/SDL_hidapi_steam.c @@ -305,7 +305,7 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs #define BLE_MAX_READ_RETRIES 8 -static int SetFeatureReport( hid_device *dev, unsigned char uBuffer[65], int nActualDataLen ) +static int SetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65], int nActualDataLen ) { int nRet = -1; bool bBle = true; // only wireless/BLE for now, though macOS could do wired in the future @@ -339,7 +339,7 @@ static int SetFeatureReport( hid_device *dev, unsigned char uBuffer[65], int nAc pBufferPtr += nBytesInPacket; nSegmentNumber++; - nRet = hid_send_feature_report( dev, uPacketBuffer, sizeof( uPacketBuffer ) ); + nRet = SDL_hid_send_feature_report( dev, uPacketBuffer, sizeof( uPacketBuffer ) ); DPRINTF("SetFeatureReport() ret = %d\n", nRet); } } @@ -347,7 +347,7 @@ static int SetFeatureReport( hid_device *dev, unsigned char uBuffer[65], int nAc return nRet; } -static int GetFeatureReport( hid_device *dev, unsigned char uBuffer[65] ) +static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] ) { int nRet = -1; bool bBle = true; @@ -366,7 +366,7 @@ static int GetFeatureReport( hid_device *dev, unsigned char uBuffer[65] ) { memset( uSegmentBuffer, 0, sizeof( uSegmentBuffer ) ); uSegmentBuffer[ 0 ] = BLE_REPORT_NUMBER; - nRet = hid_get_feature_report( dev, uSegmentBuffer, sizeof( uSegmentBuffer ) ); + nRet = SDL_hid_get_feature_report( dev, uSegmentBuffer, sizeof( uSegmentBuffer ) ); DPRINTF( "GetFeatureReport ble ret=%d\n", nRet ); HEXDUMP( uSegmentBuffer, nRet ); @@ -400,7 +400,7 @@ static int GetFeatureReport( hid_device *dev, unsigned char uBuffer[65] ) return nRet; } -static int ReadResponse( hid_device *dev, uint8_t uBuffer[65], int nExpectedResponse ) +static int ReadResponse( SDL_hid_device *dev, uint8_t uBuffer[65], int nExpectedResponse ) { int nRet = GetFeatureReport( dev, uBuffer ); @@ -421,7 +421,7 @@ static int ReadResponse( hid_device *dev, uint8_t uBuffer[65], int nExpectedResp //--------------------------------------------------------------------------- // Reset steam controller (unmap buttons and pads) and re-fetch capability bits //--------------------------------------------------------------------------- -static bool ResetSteamController( hid_device *dev, bool bSuppressErrorSpew, uint32_t *punUpdateRateUS ) +static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew, uint32_t *punUpdateRateUS ) { // Firmware quirk: Set Feature and Get Feature requests always require a 65-byte buffer. unsigned char buf[65]; @@ -606,18 +606,18 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \ //--------------------------------------------------------------------------- // Read from a Steam Controller //--------------------------------------------------------------------------- -static int ReadSteamController( hid_device *dev, uint8_t *pData, int nDataSize ) +static int ReadSteamController( SDL_hid_device *dev, uint8_t *pData, int nDataSize ) { memset( pData, 0, nDataSize ); pData[ 0 ] = BLE_REPORT_NUMBER; // hid_read will also overwrite this with the same value, 0x03 - return hid_read( dev, pData, nDataSize ); + return SDL_hid_read( dev, pData, nDataSize ); } //--------------------------------------------------------------------------- // Close a Steam Controller //--------------------------------------------------------------------------- -static void CloseSteamController( hid_device *dev ) +static void CloseSteamController( SDL_hid_device *dev ) { // Switch the Steam Controller back to lizard mode so it works with the OS unsigned char buf[65]; @@ -1040,12 +1040,12 @@ HIDAPI_DriverSteam_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic } device->context = ctx; - device->dev = hid_open_path(device->path, 0); + device->dev = SDL_hid_open_path(device->path, 0); if (!device->dev) { SDL_SetError("Couldn't open %s", device->path); goto error; } - hid_set_nonblocking(device->dev, 1); + SDL_hid_set_nonblocking(device->dev, 1); if (!ResetSteamController(device->dev, false, &update_rate_in_us)) { SDL_SetError("Couldn't reset controller"); @@ -1070,7 +1070,7 @@ error: SDL_LockMutex(device->dev_lock); { if (device->dev) { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; } if (device->context) { @@ -1266,7 +1266,7 @@ HIDAPI_DriverSteam_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti { CloseSteamController(device->dev); - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; SDL_free(device->context); diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c index 70fa710c8..daf61b811 100644 --- a/src/joystick/hidapi/SDL_hidapi_switch.c +++ b/src/joystick/hidapi/SDL_hidapi_switch.c @@ -346,13 +346,13 @@ static int ReadInput(SDL_DriverSwitch_Context *ctx) return 0; } - return hid_read_timeout(ctx->device->dev, ctx->m_rgucReadBuffer, sizeof(ctx->m_rgucReadBuffer), 0); + return SDL_hid_read_timeout(ctx->device->dev, ctx->m_rgucReadBuffer, sizeof(ctx->m_rgucReadBuffer), 0); } static int WriteOutput(SDL_DriverSwitch_Context *ctx, const Uint8 *data, int size) { #ifdef SWITCH_SYNCHRONOUS_WRITES - return hid_write(ctx->device->dev, data, size); + return SDL_hid_write(ctx->device->dev, data, size); #else /* Use the rumble thread for general asynchronous writes */ if (SDL_HIDAPI_LockRumble() < 0) { @@ -856,7 +856,7 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti ctx->device = device; device->context = ctx; - device->dev = hid_open_path(device->path, 0); + device->dev = SDL_hid_open_path(device->path, 0); if (!device->dev) { SDL_SetError("Couldn't open %s", device->path); goto error; @@ -986,7 +986,7 @@ error: SDL_LockMutex(device->dev_lock); { if (device->dev) { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; } if (device->context) { @@ -1530,7 +1530,7 @@ HIDAPI_DriverSwitch_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst SDL_LockMutex(device->dev_lock); { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; SDL_free(device->context); diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360.c b/src/joystick/hidapi/SDL_hidapi_xbox360.c index 4914fdaf1..054cd442d 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360.c @@ -88,14 +88,14 @@ HIDAPI_DriverXbox360_GetDeviceName(Uint16 vendor_id, Uint16 product_id) return NULL; } -static SDL_bool SetSlotLED(hid_device *dev, Uint8 slot) +static SDL_bool SetSlotLED(SDL_hid_device *dev, Uint8 slot) { const SDL_bool blink = SDL_FALSE; Uint8 mode = (blink ? 0x02 : 0x06) + slot; Uint8 led_packet[] = { 0x01, 0x03, 0x00 }; led_packet[2] = mode; - if (hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) { + if (SDL_hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) { return SDL_FALSE; } return SDL_TRUE; @@ -136,7 +136,7 @@ HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst return SDL_FALSE; } - device->dev = hid_open_path(device->path, 0); + device->dev = SDL_hid_open_path(device->path, 0); if (!device->dev) { SDL_SetError("Couldn't open %s", device->path); SDL_free(ctx); @@ -296,7 +296,7 @@ HIDAPI_DriverXbox360_UpdateDevice(SDL_HIDAPI_Device *device) return SDL_FALSE; } - while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { + while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { #ifdef DEBUG_XBOX_PROTOCOL HIDAPI_DumpPacket("Xbox 360 packet: size = %d", data, size); #endif @@ -318,7 +318,7 @@ HIDAPI_DriverXbox360_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joys SDL_LockMutex(device->dev_lock); { if (device->dev) { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; } diff --git a/src/joystick/hidapi/SDL_hidapi_xbox360w.c b/src/joystick/hidapi/SDL_hidapi_xbox360w.c index 247490930..78e45796f 100644 --- a/src/joystick/hidapi/SDL_hidapi_xbox360w.c +++ b/src/joystick/hidapi/SDL_hidapi_xbox360w.c @@ -62,14 +62,14 @@ HIDAPI_DriverXbox360W_GetDeviceName(Uint16 vendor_id, Uint16 product_id) return "Xbox 360 Wireless Controller"; } -static SDL_bool SetSlotLED(hid_device *dev, Uint8 slot) +static SDL_bool SetSlotLED(SDL_hid_device *dev, Uint8 slot) { const SDL_bool blink = SDL_FALSE; Uint8 mode = (blink ? 0x02 : 0x06) + slot; Uint8 led_packet[] = { 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; led_packet[3] = 0x40 + (mode % 0x0e); - if (hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) { + if (SDL_hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) { return SDL_FALSE; } return SDL_TRUE; @@ -105,7 +105,7 @@ HIDAPI_DriverXbox360W_InitDevice(SDL_HIDAPI_Device *device) return SDL_FALSE; } - device->dev = hid_open_path(device->path, 0); + device->dev = SDL_hid_open_path(device->path, 0); if (!device->dev) { SDL_free(ctx); SDL_SetError("Couldn't open %s", device->path); @@ -113,7 +113,7 @@ HIDAPI_DriverXbox360W_InitDevice(SDL_HIDAPI_Device *device) } device->context = ctx; - if (hid_write(device->dev, init_packet, sizeof(init_packet)) != sizeof(init_packet)) { + if (SDL_hid_write(device->dev, init_packet, sizeof(init_packet)) != sizeof(init_packet)) { SDL_SetError("Couldn't write init packet"); return SDL_FALSE; } @@ -199,7 +199,7 @@ HIDAPI_DriverXbox360W_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_J } static void -HIDAPI_DriverXbox360W_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverXbox360W_Context *ctx, Uint8 *data, int size) +HIDAPI_DriverXbox360W_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverXbox360W_Context *ctx, Uint8 *data, int size) { Sint16 axis; const SDL_bool invert_y_axes = SDL_TRUE; @@ -259,7 +259,7 @@ HIDAPI_DriverXbox360W_UpdateDevice(SDL_HIDAPI_Device *device) joystick = SDL_JoystickFromInstanceID(device->joysticks[0]); } - while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { + while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { #ifdef DEBUG_XBOX_PROTOCOL HIDAPI_DumpPacket("Xbox 360 wireless packet: size = %d", data, size); #endif @@ -321,7 +321,7 @@ HIDAPI_DriverXbox360W_FreeDevice(SDL_HIDAPI_Device *device) { SDL_LockMutex(device->dev_lock); { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; SDL_free(device->context); diff --git a/src/joystick/hidapi/SDL_hidapi_xboxone.c b/src/joystick/hidapi/SDL_hidapi_xboxone.c index 6da46b407..ad80b6cc6 100644 --- a/src/joystick/hidapi/SDL_hidapi_xboxone.c +++ b/src/joystick/hidapi/SDL_hidapi_xboxone.c @@ -317,7 +317,7 @@ HIDAPI_DriverXboxOne_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst return SDL_FALSE; } - device->dev = hid_open_path(device->path, 0); + device->dev = SDL_hid_open_path(device->path, 0); if (!device->dev) { SDL_free(ctx); SDL_SetError("Couldn't open %s", device->path); @@ -945,7 +945,7 @@ HIDAPI_DriverXboxOne_UpdateJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joy Uint8 data[USB_PACKET_LENGTH]; int size; - while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { + while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) { #ifdef DEBUG_XBOX_PROTOCOL HIDAPI_DumpPacket("Xbox One packet: size = %d", data, size); #endif @@ -1099,7 +1099,7 @@ HIDAPI_DriverXboxOne_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joys { SDL_LockMutex(device->dev_lock); { - hid_close(device->dev); + SDL_hid_close(device->dev); device->dev = NULL; SDL_free(device->context); diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c index 73b7ac95d..e4c9f647b 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick.c +++ b/src/joystick/hidapi/SDL_hidapijoystick.c @@ -767,17 +767,7 @@ HIDAPI_JoystickInit(void) } #endif -#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__TVOS__) - /* The hidapi framwork is weak-linked on Apple platforms */ - int HID_API_EXPORT HID_API_CALL hid_init(void) __attribute__((weak_import)); - - if (hid_init == NULL) { - SDL_SetError("Couldn't initialize hidapi, framework not available"); - return -1; - } -#endif /* __MACOSX__ || __IPHONEOS__ || __TVOS__ */ - - if (hid_init() < 0) { + if (SDL_hid_init() < 0) { SDL_SetError("Couldn't initialize hidapi"); return -1; } @@ -874,7 +864,7 @@ HIDAPI_ConvertString(const wchar_t *wide_string) } static void -HIDAPI_AddDevice(struct hid_device_info *info) +HIDAPI_AddDevice(struct SDL_hid_device_info *info) { SDL_HIDAPI_Device *device; SDL_HIDAPI_Device *curr, *last = NULL; @@ -994,6 +984,7 @@ HIDAPI_AddDevice(struct hid_device_info *info) HIDAPI_SetupDeviceDriver(device); +#define DEBUG_HIDAPI #ifdef DEBUG_HIDAPI SDL_Log("Added HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, serial %s, interface %d, interface_class %d, interface_subclass %d, interface_protocol %d, usage page 0x%.4x, usage 0x%.4x, path = %s, driver = %s (%s)\n", device->name, device->vendor_id, device->product_id, device->version, device->serial ? device->serial : "NONE", device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol, device->usage_page, device->usage, device->path, device->driver ? device->driver->hint : "NONE", device->driver && device->driver->enabled ? "ENABLED" : "DISABLED"); #endif @@ -1038,7 +1029,7 @@ static void HIDAPI_UpdateDeviceList(void) { SDL_HIDAPI_Device *device; - struct hid_device_info *devs, *info; + struct SDL_hid_device_info *devs, *info; SDL_LockJoysticks(); @@ -1051,7 +1042,7 @@ HIDAPI_UpdateDeviceList(void) /* Enumerate the devices */ if (SDL_HIDAPI_numdrivers > 0) { - devs = hid_enumerate(0, 0); + devs = SDL_hid_enumerate(0, 0); if (devs) { for (info = devs; info; info = info->next) { device = HIDAPI_GetJoystickByInfo(info->path, info->vendor_id, info->product_id); @@ -1061,7 +1052,7 @@ HIDAPI_UpdateDeviceList(void) HIDAPI_AddDevice(info); } } - hid_free_enumeration(devs); + SDL_hid_free_enumeration(devs); } } @@ -1495,7 +1486,7 @@ HIDAPI_JoystickQuit(void) SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPIDriverHintChanged, NULL); - hid_exit(); + SDL_hid_exit(); shutting_down = SDL_FALSE; initialized = SDL_FALSE; diff --git a/src/joystick/hidapi/SDL_hidapijoystick_c.h b/src/joystick/hidapi/SDL_hidapijoystick_c.h index 9722775ee..ff44aad51 100644 --- a/src/joystick/hidapi/SDL_hidapijoystick_c.h +++ b/src/joystick/hidapi/SDL_hidapijoystick_c.h @@ -27,7 +27,7 @@ #include "SDL_mutex.h" #include "SDL_joystick.h" #include "SDL_gamecontroller.h" -#include "../../hidapi/hidapi/hidapi.h" +#include "SDL_hidapi.h" #include "../usb_ids.h" /* This is the full set of HIDAPI drivers available */ @@ -70,7 +70,7 @@ typedef struct _SDL_HIDAPI_Device struct _SDL_HIDAPI_DeviceDriver *driver; void *context; SDL_mutex *dev_lock; - hid_device *dev; + SDL_hid_device *dev; SDL_atomic_t rumble_pending; int num_joysticks; SDL_JoystickID *joysticks; diff --git a/src/stdlib/SDL_iconv.c b/src/stdlib/SDL_iconv.c index 2defa6eb5..e235541f3 100644 --- a/src/stdlib/SDL_iconv.c +++ b/src/stdlib/SDL_iconv.c @@ -146,6 +146,11 @@ static struct { "US-ASCII", ENCODING_ASCII }, { "8859-1", ENCODING_LATIN1 }, { "ISO-8859-1", ENCODING_LATIN1 }, +#ifdef __WIN32__ + { "WCHAR_T", ENCODING_UTF16LE }, +#else + { "WCHAR_T", ENCODING_UCS4NATIVE }, +#endif { "UTF8", ENCODING_UTF8 }, { "UTF-8", ENCODING_UTF8 }, { "UTF16", ENCODING_UTF16 },