summaryrefslogtreecommitdiff
path: root/contrib/SDL-3.2.8/src/joystick/hidapi/SDL_hidapijoystick_c.h
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
committer3gg <3gg@shellblade.net>2025-12-27 12:03:39 -0800
commit5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch)
tree8926ab44f168acf787d8e19608857b3af0f82758 /contrib/SDL-3.2.8/src/joystick/hidapi/SDL_hidapijoystick_c.h
Initial commit
Diffstat (limited to 'contrib/SDL-3.2.8/src/joystick/hidapi/SDL_hidapijoystick_c.h')
-rw-r--r--contrib/SDL-3.2.8/src/joystick/hidapi/SDL_hidapijoystick_c.h195
1 files changed, 195 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/joystick/hidapi/SDL_hidapijoystick_c.h b/contrib/SDL-3.2.8/src/joystick/hidapi/SDL_hidapijoystick_c.h
new file mode 100644
index 0000000..9cd9f40
--- /dev/null
+++ b/contrib/SDL-3.2.8/src/joystick/hidapi/SDL_hidapijoystick_c.h
@@ -0,0 +1,195 @@
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21#include "SDL_internal.h"
22
23#ifndef SDL_JOYSTICK_HIDAPI_H
24#define SDL_JOYSTICK_HIDAPI_H
25
26#include "../usb_ids.h"
27
28// This is the full set of HIDAPI drivers available
29#define SDL_JOYSTICK_HIDAPI_GAMECUBE
30#define SDL_JOYSTICK_HIDAPI_LUNA
31#define SDL_JOYSTICK_HIDAPI_PS3
32#define SDL_JOYSTICK_HIDAPI_PS4
33#define SDL_JOYSTICK_HIDAPI_PS5
34#define SDL_JOYSTICK_HIDAPI_STADIA
35#define SDL_JOYSTICK_HIDAPI_STEAM
36#define SDL_JOYSTICK_HIDAPI_STEAMDECK
37#define SDL_JOYSTICK_HIDAPI_SWITCH
38#define SDL_JOYSTICK_HIDAPI_WII
39#define SDL_JOYSTICK_HIDAPI_XBOX360
40#define SDL_JOYSTICK_HIDAPI_XBOXONE
41#define SDL_JOYSTICK_HIDAPI_SHIELD
42#define SDL_JOYSTICK_HIDAPI_STEAM_HORI
43
44// Joystick capability definitions
45#define SDL_JOYSTICK_CAP_MONO_LED 0x00000001
46#define SDL_JOYSTICK_CAP_RGB_LED 0x00000002
47#define SDL_JOYSTICK_CAP_PLAYER_LED 0x00000004
48#define SDL_JOYSTICK_CAP_RUMBLE 0x00000010
49#define SDL_JOYSTICK_CAP_TRIGGER_RUMBLE 0x00000020
50
51// Whether HIDAPI is enabled by default
52#if defined(SDL_PLATFORM_ANDROID) || \
53 defined(SDL_PLATFORM_IOS) || \
54 defined(SDL_PLATFORM_TVOS) || \
55 defined(SDL_PLATFORM_VISIONOS)
56// On Android, HIDAPI prompts for permissions and acquires exclusive access to the device, and on Apple mobile platforms it doesn't do anything except for handling Bluetooth Steam Controllers, so we'll leave it off by default.
57#define SDL_HIDAPI_DEFAULT false
58#else
59#define SDL_HIDAPI_DEFAULT true
60#endif
61
62// The maximum size of a USB packet for HID devices
63#define USB_PACKET_LENGTH 64
64
65// Forward declaration
66struct SDL_HIDAPI_DeviceDriver;
67
68typedef struct SDL_HIDAPI_Device
69{
70 char *name;
71 char *manufacturer_string;
72 char *product_string;
73 char *path;
74 Uint16 vendor_id;
75 Uint16 product_id;
76 Uint16 version;
77 char *serial;
78 SDL_GUID guid;
79 int interface_number; // Available on Windows and Linux
80 int interface_class;
81 int interface_subclass;
82 int interface_protocol;
83 Uint16 usage_page; // Available on Windows and macOS
84 Uint16 usage; // Available on Windows and macOS
85 bool is_bluetooth;
86 SDL_JoystickType joystick_type;
87 SDL_GamepadType type;
88 int steam_virtual_gamepad_slot;
89
90 struct SDL_HIDAPI_DeviceDriver *driver;
91 void *context;
92 SDL_Mutex *dev_lock;
93 SDL_hid_device *dev;
94 SDL_AtomicInt rumble_pending;
95 int num_joysticks;
96 SDL_JoystickID *joysticks;
97
98 // Used during scanning for device changes
99 bool seen;
100
101 // Used to flag that the device is being updated
102 bool updating;
103
104 // Used to flag devices that failed open
105 // This can happen on Windows with Bluetooth devices that have turned off
106 bool broken;
107
108 struct SDL_HIDAPI_Device *parent;
109 int num_children;
110 struct SDL_HIDAPI_Device **children;
111
112 struct SDL_HIDAPI_Device *next;
113} SDL_HIDAPI_Device;
114
115typedef struct SDL_HIDAPI_DeviceDriver
116{
117 const char *name;
118 bool enabled;
119 void (*RegisterHints)(SDL_HintCallback callback, void *userdata);
120 void (*UnregisterHints)(SDL_HintCallback callback, void *userdata);
121 bool (*IsEnabled)(void);
122 bool (*IsSupportedDevice)(SDL_HIDAPI_Device *device, const char *name, SDL_GamepadType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol);
123 bool (*InitDevice)(SDL_HIDAPI_Device *device);
124 int (*GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id);
125 void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index);
126 bool (*UpdateDevice)(SDL_HIDAPI_Device *device);
127 bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
128 bool (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
129 bool (*RumbleJoystickTriggers)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);
130 Uint32 (*GetJoystickCapabilities)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
131 bool (*SetJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);
132 bool (*SendJoystickEffect)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size);
133 bool (*SetJoystickSensorsEnabled)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled);
134 void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
135 void (*FreeDevice)(SDL_HIDAPI_Device *device);
136
137} SDL_HIDAPI_DeviceDriver;
138
139// HIDAPI device support
140extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverCombined;
141extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;
142extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverJoyCons;
143extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna;
144extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverNintendoClassic;
145extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3;
146extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3ThirdParty;
147extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3SonySixaxis;
148extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;
149extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5;
150extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverShield;
151extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverStadia;
152extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;
153extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamDeck;
154extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;
155extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverWii;
156extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;
157extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W;
158extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;
159extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamHori;
160
161// Return true if a HID device is present and supported as a joystick of the given type
162extern bool HIDAPI_IsDeviceTypePresent(SDL_GamepadType type);
163
164// Return true if a HID device is present and supported as a joystick
165extern bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
166
167// Return the name of a connected device, which should be freed with SDL_free(), or NULL if it's not available
168extern char *HIDAPI_GetDeviceProductName(Uint16 vendor_id, Uint16 product_id);
169
170// Return the manufacturer of a connected device, which should be freed with SDL_free(), or NULL if it's not available
171extern char *HIDAPI_GetDeviceManufacturerName(Uint16 vendor_id, Uint16 product_id);
172
173// Return the type of a joystick if it's present and supported
174extern SDL_JoystickType HIDAPI_GetJoystickTypeFromGUID(SDL_GUID guid);
175
176// Return the type of a game controller if it's present and supported
177extern SDL_GamepadType HIDAPI_GetGamepadTypeFromGUID(SDL_GUID guid);
178
179extern void HIDAPI_UpdateDevices(void);
180extern void HIDAPI_SetDeviceName(SDL_HIDAPI_Device *device, const char *name);
181extern void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 vendor_id, Uint16 product_id);
182extern void HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial);
183extern bool HIDAPI_HasConnectedUSBDevice(const char *serial);
184extern void HIDAPI_DisconnectBluetoothDevice(const char *serial);
185extern bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID);
186extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID);
187extern void HIDAPI_UpdateDeviceProperties(SDL_HIDAPI_Device *device);
188
189extern void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size);
190
191extern bool HIDAPI_SupportsPlaystationDetection(Uint16 vendor, Uint16 product);
192
193extern float HIDAPI_RemapVal(float val, float val_min, float val_max, float output_min, float output_max);
194
195#endif // SDL_JOYSTICK_HIDAPI_H