SDL  2.0
SDL_hidapijoystick_c.h
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2020 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 "SDL_atomic.h"
27 #include "SDL_mutex.h"
28 #include "SDL_joystick.h"
29 #include "SDL_gamecontroller.h"
30 #include "../../hidapi/hidapi/hidapi.h"
31 #include "../usb_ids.h"
32 
33 /* This is the full set of HIDAPI drivers available */
34 #define SDL_JOYSTICK_HIDAPI_PS4
35 #define SDL_JOYSTICK_HIDAPI_SWITCH
36 #define SDL_JOYSTICK_HIDAPI_XBOX360
37 #define SDL_JOYSTICK_HIDAPI_XBOXONE
38 #define SDL_JOYSTICK_HIDAPI_GAMECUBE
39 
40 #ifdef __WINDOWS__
41 /* On Windows, Xbox One controllers are handled by the Xbox 360 driver */
42 #undef SDL_JOYSTICK_HIDAPI_XBOXONE
43 /* It turns out HIDAPI for Xbox controllers doesn't allow background input */
44 #undef SDL_JOYSTICK_HIDAPI_XBOX360
45 #endif
46 
47 #ifdef __MACOSX__
48 /* On Mac OS X, Xbox One controllers are handled by the Xbox 360 driver */
49 #undef SDL_JOYSTICK_HIDAPI_XBOXONE
50 #endif
51 
52 #if defined(__IPHONEOS__) || defined(__TVOS__) || defined(__ANDROID__)
53 /* Very basic Steam Controller support on mobile devices */
54 #define SDL_JOYSTICK_HIDAPI_STEAM
55 #endif
56 
57 /* The maximum size of a USB packet for HID devices */
58 #define USB_PACKET_LENGTH 64
59 
60 /* Forward declaration */
61 struct _SDL_HIDAPI_DeviceDriver;
62 
63 typedef struct _SDL_HIDAPI_Device
64 {
65  char *name;
66  char *path;
71  int interface_number; /* Available on Windows and Linux */
75  Uint16 usage_page; /* Available on Windows and Mac OS X */
76  Uint16 usage; /* Available on Windows and Mac OS X */
77 
78  struct _SDL_HIDAPI_DeviceDriver *driver;
79  void *context;
85 
86  /* Used during scanning for device changes */
88 
89  struct _SDL_HIDAPI_Device *next;
91 
92 typedef struct _SDL_HIDAPI_DeviceDriver
93 {
94  const char *hint;
96  SDL_bool (*IsSupportedDevice)(const char *name, SDL_GameControllerType type, Uint16 vendor_id, Uint16 product_id, Uint16 version, int interface_number, int interface_class, int interface_subclass, int interface_protocol);
97  const char *(*GetDeviceName)(Uint16 vendor_id, Uint16 product_id);
99  int (*GetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id);
100  void (*SetDevicePlayerIndex)(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index);
101  SDL_bool (*UpdateDevice)(SDL_HIDAPI_Device *device);
102  SDL_bool (*OpenJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
103  int (*RumbleJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble);
104  void (*CloseJoystick)(SDL_HIDAPI_Device *device, SDL_Joystick *joystick);
105  void (*FreeDevice)(SDL_HIDAPI_Device *device);
106 
108 
109 
110 /* HIDAPI device support */
118 
119 /* Return true if a HID device is present and supported as a joystick */
120 extern SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name);
121 
122 extern void HIDAPI_UpdateDevices(void);
125 
126 #endif /* SDL_JOYSTICK_HIDAPI_H */
127 
128 /* vi: set ts=4 sw=4 expandtab: */
SDL_HIDAPI_DriverPS4
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverPS4
Uint16
uint16_t Uint16
Definition: SDL_stdinc.h:191
SDL_atomic.h
HIDAPI_JoystickConnected
SDL_bool HIDAPI_JoystickConnected(SDL_HIDAPI_Device *device, SDL_JoystickID *pJoystickID)
SDL_HIDAPI_Device::product_id
Uint16 product_id
Definition: SDL_hidapijoystick_c.h:68
SDL_joystick.h
SDL_JoystickID
Sint32 SDL_JoystickID
Definition: SDL_joystick.h:81
SDL_HIDAPI_Device::usage_page
Uint16 usage_page
Definition: SDL_hidapijoystick_c.h:75
SDL_mutex
Definition: SDL_sysmutex.c:30
SDL_HIDAPI_Device::interface_number
int interface_number
Definition: SDL_hidapijoystick_c.h:71
SDL_HIDAPI_Device::driver
struct _SDL_HIDAPI_DeviceDriver * driver
Definition: SDL_hidapijoystick_c.h:78
HIDAPI_IsDevicePresent
SDL_bool HIDAPI_IsDevicePresent(Uint16 vendor_id, Uint16 product_id, Uint16 version, const char *name)
SDL_HIDAPI_Device::joysticks
SDL_JoystickID * joysticks
Definition: SDL_hidapijoystick_c.h:84
SDL_HIDAPI_Device::next
struct _SDL_HIDAPI_Device * next
Definition: SDL_hidapijoystick_c.h:89
SDL_HIDAPI_Device
Definition: SDL_hidapijoystick_c.h:64
SDL_HIDAPI_Device::context
void * context
Definition: SDL_hidapijoystick_c.h:79
SDL_HIDAPI_DriverSwitch
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSwitch
SDL_HIDAPI_DriverXbox360
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360
SDL_HIDAPI_Device::usage
Uint16 usage
Definition: SDL_hidapijoystick_c.h:76
SDL_mutex.h
SDL_HIDAPI_DeviceDriver::enabled
SDL_bool enabled
Definition: SDL_hidapijoystick_c.h:95
name
GLuint const GLchar * name
Definition: SDL_opengl_glext.h:663
SDL_HIDAPI_DeviceDriver
Definition: SDL_hidapijoystick_c.h:93
SDL_HIDAPI_Device::interface_class
int interface_class
Definition: SDL_hidapijoystick_c.h:72
SDL_gamecontroller.h
SDL_HIDAPI_Device::guid
SDL_JoystickGUID guid
Definition: SDL_hidapijoystick_c.h:70
SDL_HIDAPI_Device::path
char * path
Definition: SDL_hidapijoystick_c.h:66
SDL_HIDAPI_Device::interface_subclass
int interface_subclass
Definition: SDL_hidapijoystick_c.h:73
SDL_HIDAPI_DriverXboxOne
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXboxOne
SDL_HIDAPI_Device::vendor_id
Uint16 vendor_id
Definition: SDL_hidapijoystick_c.h:67
HIDAPI_JoystickDisconnected
void HIDAPI_JoystickDisconnected(SDL_HIDAPI_Device *device, SDL_JoystickID joystickID)
SDL_HIDAPI_DriverSteam
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteam
SDL_GameControllerType
SDL_GameControllerType
Definition: SDL_gamecontroller.h:61
SDL_HIDAPI_Device::name
char * name
Definition: SDL_hidapijoystick_c.h:65
SDL_HIDAPI_Device::version
Uint16 version
Definition: SDL_hidapijoystick_c.h:69
SDL_atomic_t
A type representing an atomic integer value. It is a struct so people don't accidentally use numeric ...
Definition: SDL_atomic.h:216
SDL_HIDAPI_DriverGameCube
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverGameCube
SDL_HIDAPI_Device::dev
hid_device * dev
Definition: SDL_hidapijoystick_c.h:81
SDL_bool
SDL_bool
Definition: SDL_stdinc.h:162
HIDAPI_UpdateDevices
void HIDAPI_UpdateDevices(void)
hid_device
struct hid_device_ hid_device
Definition: hidapi.h:54
void
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 void
Definition: SDL_dynapi_procs.h:89
SDL_HIDAPI_Device::interface_protocol
int interface_protocol
Definition: SDL_hidapijoystick_c.h:74
device
static SDL_AudioDeviceID device
Definition: loopwave.c:37
SDL_JoystickGUID
Definition: SDL_joystick.h:70
SDL_HIDAPI_Device::rumble_pending
SDL_atomic_t rumble_pending
Definition: SDL_hidapijoystick_c.h:82
type
GLuint GLuint GLsizei GLenum type
Definition: SDL_opengl.h:1571
SDL_HIDAPI_DeviceDriver::hint
const char * hint
Definition: SDL_hidapijoystick_c.h:94
SDL_HIDAPI_Device::num_joysticks
int num_joysticks
Definition: SDL_hidapijoystick_c.h:83
SDL_HIDAPI_Device::dev_lock
SDL_mutex * dev_lock
Definition: SDL_hidapijoystick_c.h:80
SDL_HIDAPI_Device::seen
SDL_bool seen
Definition: SDL_hidapijoystick_c.h:87
SDL_HIDAPI_DriverXbox360W
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverXbox360W