Path: blob/master/thirdparty/sdl/joystick/hidapi/SDL_hidapijoystick_c.h
9906 views
/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/20#include "SDL_internal.h"2122#ifndef SDL_JOYSTICK_HIDAPI_H23#define SDL_JOYSTICK_HIDAPI_H2425#include "../usb_ids.h"2627// This is the full set of HIDAPI drivers available28#define SDL_JOYSTICK_HIDAPI_GAMECUBE29#define SDL_JOYSTICK_HIDAPI_LUNA30#define SDL_JOYSTICK_HIDAPI_PS331#define SDL_JOYSTICK_HIDAPI_PS432#define SDL_JOYSTICK_HIDAPI_PS533#define SDL_JOYSTICK_HIDAPI_STADIA34#define SDL_JOYSTICK_HIDAPI_STEAM35#define SDL_JOYSTICK_HIDAPI_STEAMDECK36#define SDL_JOYSTICK_HIDAPI_SWITCH37#define SDL_JOYSTICK_HIDAPI_WII38#define SDL_JOYSTICK_HIDAPI_XBOX36039#define SDL_JOYSTICK_HIDAPI_XBOXONE40#define SDL_JOYSTICK_HIDAPI_SHIELD41#define SDL_JOYSTICK_HIDAPI_STEAM_HORI4243// Joystick capability definitions44#define SDL_JOYSTICK_CAP_MONO_LED 0x0000000145#define SDL_JOYSTICK_CAP_RGB_LED 0x0000000246#define SDL_JOYSTICK_CAP_PLAYER_LED 0x0000000447#define SDL_JOYSTICK_CAP_RUMBLE 0x0000001048#define SDL_JOYSTICK_CAP_TRIGGER_RUMBLE 0x000000204950// Whether HIDAPI is enabled by default51#if defined(SDL_PLATFORM_ANDROID) || \52defined(SDL_PLATFORM_IOS) || \53defined(SDL_PLATFORM_TVOS) || \54defined(SDL_PLATFORM_VISIONOS)55// 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.56#define SDL_HIDAPI_DEFAULT false57#else58#define SDL_HIDAPI_DEFAULT true59#endif6061// The maximum size of a USB packet for HID devices62#define USB_PACKET_LENGTH 646364// Forward declaration65struct SDL_HIDAPI_DeviceDriver;6667typedef struct SDL_HIDAPI_Device68{69char *name;70char *manufacturer_string;71char *product_string;72char *path;73Uint16 vendor_id;74Uint16 product_id;75Uint16 version;76char *serial;77SDL_GUID guid;78int interface_number; // Available on Windows and Linux79int interface_class;80int interface_subclass;81int interface_protocol;82Uint16 usage_page; // Available on Windows and macOS83Uint16 usage; // Available on Windows and macOS84bool is_bluetooth;85SDL_JoystickType joystick_type;86SDL_GamepadType type;87int steam_virtual_gamepad_slot;8889struct SDL_HIDAPI_DeviceDriver *driver;90void *context;91SDL_Mutex *dev_lock;92SDL_hid_device *dev;93SDL_AtomicInt rumble_pending;94int num_joysticks;95SDL_JoystickID *joysticks;9697// Used during scanning for device changes98bool seen;99100// Used to flag that the device is being updated101bool updating;102103// Used to flag devices that failed open104// This can happen on Windows with Bluetooth devices that have turned off105bool broken;106107struct SDL_HIDAPI_Device *parent;108int num_children;109struct SDL_HIDAPI_Device **children;110111struct SDL_HIDAPI_Device *next;112} SDL_HIDAPI_Device;113114typedef struct SDL_HIDAPI_DeviceDriver115{116const char *name;117bool enabled;118void (*RegisterHints)(SDL_HintCallback callback, void *userdata);119void (*UnregisterHints)(SDL_HintCallback callback, void *userdata);120bool (*IsEnabled)(void);121bool (*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);122bool (*InitDevice)(SDL_HIDAPI_Device *device);123int (*GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id);124void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index);125bool (*UpdateDevice)(SDL_HIDAPI_Device *device);126bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);127bool (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);128bool (*RumbleJoystickTriggers)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble);129Uint32 (*GetJoystickCapabilities)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);130bool (*SetJoystickLED)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue);131bool (*SendJoystickEffect)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size);132bool (*SetJoystickSensorsEnabled)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled);133void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);134void (*FreeDevice)(SDL_HIDAPI_Device *device);135136} SDL_HIDAPI_DeviceDriver;137138// HIDAPI device support139extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverCombined;140extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube;141extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverJoyCons;142extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverLuna;143extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverNintendoClassic;144extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3;145extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3ThirdParty;146extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS3SonySixaxis;147extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4;148extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS5;149extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverShield;150extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverStadia;151extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam;152extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamDeck;153extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch;154extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverWii;155extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360;156extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W;157extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne;158extern SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamHori;159160// Return true if a HID device is present and supported as a joystick of the given type161extern bool HIDAPI_IsDeviceTypePresent(SDL_GamepadType type);162163// Return true if a HID device is present and supported as a joystick164extern bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);165166// Return the name of a connected device, which should be freed with SDL_free(), or NULL if it's not available167extern char *HIDAPI_GetDeviceProductName(Uint16 vendor_id, Uint16 product_id);168169// Return the manufacturer of a connected device, which should be freed with SDL_free(), or NULL if it's not available170extern char *HIDAPI_GetDeviceManufacturerName(Uint16 vendor_id, Uint16 product_id);171172// Return the type of a joystick if it's present and supported173extern SDL_JoystickType HIDAPI_GetJoystickTypeFromGUID(SDL_GUID guid);174175// Return the type of a game controller if it's present and supported176extern SDL_GamepadType HIDAPI_GetGamepadTypeFromGUID(SDL_GUID guid);177178extern void HIDAPI_UpdateDevices(void);179extern void HIDAPI_SetDeviceName(SDL_HIDAPI_Device *device, const char *name);180extern void HIDAPI_SetDeviceProduct(SDL_HIDAPI_Device *device, Uint16 vendor_id, Uint16 product_id);181extern void HIDAPI_SetDeviceSerial(SDL_HIDAPI_Device *device, const char *serial);182extern bool HIDAPI_HasConnectedUSBDevice(const char *serial);183extern void HIDAPI_DisconnectBluetoothDevice(const char *serial);184extern bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID);185extern void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID);186extern void HIDAPI_UpdateDeviceProperties(SDL_HIDAPI_Device *device);187188extern void HIDAPI_DumpPacket(const char *prefix, const Uint8 *data, int size);189190extern bool HIDAPI_SupportsPlaystationDetection(Uint16 vendor, Uint16 product);191192extern float HIDAPI_RemapVal(float val, float val_min, float val_max, float output_min, float output_max);193194#endif // SDL_JOYSTICK_HIDAPI_H195196197