SDL_hidapi_steamdeck.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 2023 Max Maisel <[email protected]>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #ifdef SDL_JOYSTICK_HIDAPI
  20. #include "../SDL_sysjoystick.h"
  21. #include "SDL_hidapijoystick_c.h"
  22. #ifdef SDL_JOYSTICK_HIDAPI_STEAMDECK
  23. /*****************************************************************************************************/
  24. #include "steam/controller_constants.h"
  25. #include "steam/controller_structs.h"
  26. enum
  27. {
  28. SDL_GAMEPAD_BUTTON_STEAM_DECK_QAM = 11,
  29. SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_PADDLE1,
  30. SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE1,
  31. SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_PADDLE2,
  32. SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE2,
  33. SDL_GAMEPAD_NUM_STEAM_DECK_BUTTONS,
  34. };
  35. typedef enum
  36. {
  37. STEAMDECK_LBUTTON_R2 = 0x00000001,
  38. STEAMDECK_LBUTTON_L2 = 0x00000002,
  39. STEAMDECK_LBUTTON_R = 0x00000004,
  40. STEAMDECK_LBUTTON_L = 0x00000008,
  41. STEAMDECK_LBUTTON_Y = 0x00000010,
  42. STEAMDECK_LBUTTON_B = 0x00000020,
  43. STEAMDECK_LBUTTON_X = 0x00000040,
  44. STEAMDECK_LBUTTON_A = 0x00000080,
  45. STEAMDECK_LBUTTON_DPAD_UP = 0x00000100,
  46. STEAMDECK_LBUTTON_DPAD_RIGHT = 0x00000200,
  47. STEAMDECK_LBUTTON_DPAD_LEFT = 0x00000400,
  48. STEAMDECK_LBUTTON_DPAD_DOWN = 0x00000800,
  49. STEAMDECK_LBUTTON_VIEW = 0x00001000,
  50. STEAMDECK_LBUTTON_STEAM = 0x00002000,
  51. STEAMDECK_LBUTTON_MENU = 0x00004000,
  52. STEAMDECK_LBUTTON_L5 = 0x00008000,
  53. STEAMDECK_LBUTTON_R5 = 0x00010000,
  54. STEAMDECK_LBUTTON_LEFT_PAD = 0x00020000,
  55. STEAMDECK_LBUTTON_RIGHT_PAD = 0x00040000,
  56. STEAMDECK_LBUTTON_L3 = 0x00400000,
  57. STEAMDECK_LBUTTON_R3 = 0x04000000,
  58. STEAMDECK_HBUTTON_L4 = 0x00000200,
  59. STEAMDECK_HBUTTON_R4 = 0x00000400,
  60. STEAMDECK_HBUTTON_QAM = 0x00040000,
  61. } SteamDeckButtons;
  62. typedef struct
  63. {
  64. Uint32 update_rate_us;
  65. Uint32 sensor_timestamp_us;
  66. Uint64 last_button_state;
  67. Uint8 watchdog_counter;
  68. } SDL_DriverSteamDeck_Context;
  69. static SDL_bool DisableDeckLizardMode(SDL_hid_device *dev)
  70. {
  71. int rc;
  72. Uint8 buffer[HID_FEATURE_REPORT_BYTES + 1] = { 0 };
  73. FeatureReportMsg *msg = (FeatureReportMsg *)(buffer + 1);
  74. msg->header.type = ID_CLEAR_DIGITAL_MAPPINGS;
  75. rc = SDL_hid_send_feature_report(dev, buffer, sizeof(buffer));
  76. if (rc != sizeof(buffer))
  77. return SDL_FALSE;
  78. msg->header.type = ID_SET_SETTINGS_VALUES;
  79. msg->header.length = 5 * sizeof(ControllerSetting);
  80. msg->payload.setSettingsValues.settings[0].settingNum = SETTING_SMOOTH_ABSOLUTE_MOUSE;
  81. msg->payload.setSettingsValues.settings[0].settingValue = 0;
  82. msg->payload.setSettingsValues.settings[1].settingNum = SETTING_LEFT_TRACKPAD_MODE;
  83. msg->payload.setSettingsValues.settings[1].settingValue = TRACKPAD_NONE;
  84. msg->payload.setSettingsValues.settings[2].settingNum = SETTING_RIGHT_TRACKPAD_MODE; // disable mouse
  85. msg->payload.setSettingsValues.settings[2].settingValue = TRACKPAD_NONE;
  86. msg->payload.setSettingsValues.settings[3].settingNum = SETTING_LEFT_TRACKPAD_CLICK_PRESSURE; // disable clicky pad
  87. msg->payload.setSettingsValues.settings[3].settingValue = 0xFFFF;
  88. msg->payload.setSettingsValues.settings[4].settingNum = SETTING_RIGHT_TRACKPAD_CLICK_PRESSURE; // disable clicky pad
  89. msg->payload.setSettingsValues.settings[4].settingValue = 0xFFFF;
  90. rc = SDL_hid_send_feature_report(dev, buffer, sizeof(buffer));
  91. if (rc != sizeof(buffer))
  92. return SDL_FALSE;
  93. // There may be a lingering report read back after changing settings.
  94. // Discard it.
  95. SDL_hid_get_feature_report(dev, buffer, sizeof(buffer));
  96. return SDL_TRUE;
  97. }
  98. static SDL_bool FeedDeckLizardWatchdog(SDL_hid_device *dev)
  99. {
  100. int rc;
  101. Uint8 buffer[HID_FEATURE_REPORT_BYTES + 1] = { 0 };
  102. FeatureReportMsg *msg = (FeatureReportMsg *)(buffer + 1);
  103. msg->header.type = ID_CLEAR_DIGITAL_MAPPINGS;
  104. rc = SDL_hid_send_feature_report(dev, buffer, sizeof(buffer));
  105. if (rc != sizeof(buffer))
  106. return SDL_FALSE;
  107. msg->header.type = ID_SET_SETTINGS_VALUES;
  108. msg->header.length = 1 * sizeof(ControllerSetting);
  109. msg->payload.setSettingsValues.settings[0].settingNum = SETTING_RIGHT_TRACKPAD_MODE;
  110. msg->payload.setSettingsValues.settings[0].settingValue = TRACKPAD_NONE;
  111. rc = SDL_hid_send_feature_report(dev, buffer, sizeof(buffer));
  112. if (rc != sizeof(buffer))
  113. return SDL_FALSE;
  114. // There may be a lingering report read back after changing settings.
  115. // Discard it.
  116. SDL_hid_get_feature_report(dev, buffer, sizeof(buffer));
  117. return SDL_TRUE;
  118. }
  119. static void HIDAPI_DriverSteamDeck_HandleState(SDL_HIDAPI_Device *device,
  120. SDL_Joystick *joystick,
  121. ValveInReport_t *pInReport)
  122. {
  123. float values[3];
  124. SDL_DriverSteamDeck_Context *ctx = (SDL_DriverSteamDeck_Context *)device->context;
  125. Uint64 timestamp = SDL_GetTicksNS();
  126. if (pInReport->payload.deckState.ulButtons != ctx->last_button_state) {
  127. Uint8 hat = 0;
  128. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_SOUTH,
  129. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_A) ? SDL_PRESSED : SDL_RELEASED);
  130. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST,
  131. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_B) ? SDL_PRESSED : SDL_RELEASED);
  132. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST,
  133. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_X) ? SDL_PRESSED : SDL_RELEASED);
  134. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH,
  135. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_Y) ? SDL_PRESSED : SDL_RELEASED);
  136. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
  137. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L) ? SDL_PRESSED : SDL_RELEASED);
  138. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
  139. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R) ? SDL_PRESSED : SDL_RELEASED);
  140. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK,
  141. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_VIEW) ? SDL_PRESSED : SDL_RELEASED);
  142. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START,
  143. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_MENU) ? SDL_PRESSED : SDL_RELEASED);
  144. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE,
  145. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_STEAM) ? SDL_PRESSED : SDL_RELEASED);
  146. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_QAM,
  147. (pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_QAM) ? SDL_PRESSED : SDL_RELEASED);
  148. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK,
  149. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L3) ? SDL_PRESSED : SDL_RELEASED);
  150. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK,
  151. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R3) ? SDL_PRESSED : SDL_RELEASED);
  152. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_PADDLE1,
  153. (pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_R4) ? SDL_PRESSED : SDL_RELEASED);
  154. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE1,
  155. (pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_L4) ? SDL_PRESSED : SDL_RELEASED);
  156. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_PADDLE2,
  157. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R5) ? SDL_PRESSED : SDL_RELEASED);
  158. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE2,
  159. (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L5) ? SDL_PRESSED : SDL_RELEASED);
  160. if (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_DPAD_UP) {
  161. hat |= SDL_HAT_UP;
  162. }
  163. if (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_DPAD_DOWN) {
  164. hat |= SDL_HAT_DOWN;
  165. }
  166. if (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_DPAD_LEFT) {
  167. hat |= SDL_HAT_LEFT;
  168. }
  169. if (pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_DPAD_RIGHT) {
  170. hat |= SDL_HAT_RIGHT;
  171. }
  172. SDL_SendJoystickHat(timestamp, joystick, 0, hat);
  173. ctx->last_button_state = pInReport->payload.deckState.ulButtons;
  174. }
  175. SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFT_TRIGGER,
  176. (int)pInReport->payload.deckState.sTriggerRawL * 2 - 32768);
  177. SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHT_TRIGGER,
  178. (int)pInReport->payload.deckState.sTriggerRawR * 2 - 32768);
  179. SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTX,
  180. pInReport->payload.deckState.sLeftStickX);
  181. SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_LEFTY,
  182. -pInReport->payload.deckState.sLeftStickY);
  183. SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTX,
  184. pInReport->payload.deckState.sRightStickX);
  185. SDL_SendJoystickAxis(timestamp, joystick, SDL_GAMEPAD_AXIS_RIGHTY,
  186. -pInReport->payload.deckState.sRightStickY);
  187. ctx->sensor_timestamp_us += ctx->update_rate_us;
  188. values[0] = (pInReport->payload.deckState.sGyroX / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
  189. values[1] = (pInReport->payload.deckState.sGyroZ / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
  190. values[2] = (-pInReport->payload.deckState.sGyroY / 32768.0f) * (2000.0f * (SDL_PI_F / 180.0f));
  191. SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_GYRO, ctx->sensor_timestamp_us, values, 3);
  192. values[0] = (pInReport->payload.deckState.sAccelX / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
  193. values[1] = (pInReport->payload.deckState.sAccelZ / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
  194. values[2] = (-pInReport->payload.deckState.sAccelY / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
  195. SDL_SendJoystickSensor(timestamp, joystick, SDL_SENSOR_ACCEL, ctx->sensor_timestamp_us, values, 3);
  196. }
  197. /*****************************************************************************************************/
  198. static void HIDAPI_DriverSteamDeck_RegisterHints(SDL_HintCallback callback, void *userdata)
  199. {
  200. SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK, callback, userdata);
  201. }
  202. static void HIDAPI_DriverSteamDeck_UnregisterHints(SDL_HintCallback callback, void *userdata)
  203. {
  204. SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK, callback, userdata);
  205. }
  206. static SDL_bool HIDAPI_DriverSteamDeck_IsEnabled(void)
  207. {
  208. return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK,
  209. SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
  210. }
  211. static SDL_bool HIDAPI_DriverSteamDeck_IsSupportedDevice(
  212. SDL_HIDAPI_Device *device,
  213. const char *name,
  214. SDL_GamepadType type,
  215. Uint16 vendor_id,
  216. Uint16 product_id,
  217. Uint16 version,
  218. int interface_number,
  219. int interface_class,
  220. int interface_subclass,
  221. int interface_protocol)
  222. {
  223. return SDL_IsJoystickSteamDeck(vendor_id, product_id);
  224. }
  225. static SDL_bool HIDAPI_DriverSteamDeck_InitDevice(SDL_HIDAPI_Device *device)
  226. {
  227. int size;
  228. Uint8 data[64];
  229. SDL_DriverSteamDeck_Context *ctx;
  230. ctx = (SDL_DriverSteamDeck_Context *)SDL_calloc(1, sizeof(*ctx));
  231. if (ctx == NULL) {
  232. return SDL_FALSE;
  233. }
  234. // Always 1kHz according to USB descriptor, but actually about 4 ms.
  235. ctx->update_rate_us = 4000;
  236. device->context = ctx;
  237. // Read a report to see if this is the correct endpoint.
  238. // Mouse, Keyboard and Controller have the same VID/PID but
  239. // only the controller hidraw device receives hid reports.
  240. size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 16);
  241. if (size == 0)
  242. return SDL_FALSE;
  243. if (!DisableDeckLizardMode(device->dev))
  244. return SDL_FALSE;
  245. HIDAPI_SetDeviceName(device, "Steam Deck");
  246. return HIDAPI_JoystickConnected(device, NULL);
  247. }
  248. static int HIDAPI_DriverSteamDeck_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
  249. {
  250. return -1;
  251. }
  252. static void HIDAPI_DriverSteamDeck_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
  253. {
  254. }
  255. static SDL_bool HIDAPI_DriverSteamDeck_UpdateDevice(SDL_HIDAPI_Device *device)
  256. {
  257. SDL_DriverSteamDeck_Context *ctx = (SDL_DriverSteamDeck_Context *)device->context;
  258. SDL_Joystick *joystick = NULL;
  259. int r;
  260. uint8_t data[64];
  261. ValveInReport_t *pInReport = (ValveInReport_t *)data;
  262. if (device->num_joysticks > 0) {
  263. joystick = SDL_GetJoystickFromID(device->joysticks[0]);
  264. if (joystick == NULL) {
  265. return SDL_FALSE;
  266. }
  267. } else {
  268. return SDL_FALSE;
  269. }
  270. if (ctx->watchdog_counter++ > 200) {
  271. ctx->watchdog_counter = 0;
  272. if (!FeedDeckLizardWatchdog(device->dev))
  273. return SDL_FALSE;
  274. }
  275. SDL_memset(data, 0, sizeof(data));
  276. do {
  277. r = SDL_hid_read(device->dev, data, sizeof(data));
  278. if (r < 0) {
  279. /* Failed to read from controller */
  280. HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
  281. return SDL_FALSE;
  282. } else if (r == 64 &&
  283. pInReport->header.unReportVersion == k_ValveInReportMsgVersion &&
  284. pInReport->header.ucType == ID_CONTROLLER_DECK_STATE &&
  285. pInReport->header.ucLength == 64) {
  286. HIDAPI_DriverSteamDeck_HandleState(device, joystick, pInReport);
  287. }
  288. } while (r > 0);
  289. return SDL_TRUE;
  290. }
  291. static SDL_bool HIDAPI_DriverSteamDeck_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
  292. {
  293. SDL_DriverSteamDeck_Context *ctx = (SDL_DriverSteamDeck_Context *)device->context;
  294. float update_rate_in_hz = 1.0f / (float)(ctx->update_rate_us) * 1.0e6f;
  295. SDL_AssertJoysticksLocked();
  296. // Initialize the joystick capabilities
  297. joystick->nbuttons = SDL_GAMEPAD_NUM_STEAM_DECK_BUTTONS;
  298. joystick->naxes = SDL_GAMEPAD_AXIS_MAX;
  299. joystick->nhats = 1;
  300. SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, update_rate_in_hz);
  301. SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, update_rate_in_hz);
  302. return SDL_TRUE;
  303. }
  304. static int HIDAPI_DriverSteamDeck_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
  305. {
  306. int rc;
  307. Uint8 buffer[HID_FEATURE_REPORT_BYTES + 1] = { 0 };
  308. FeatureReportMsg *msg = (FeatureReportMsg *)(buffer + 1);
  309. msg->header.type = ID_TRIGGER_RUMBLE_CMD;
  310. msg->payload.simpleRumble.unRumbleType = 0;
  311. msg->payload.simpleRumble.unIntensity = HAPTIC_INTENSITY_SYSTEM;
  312. msg->payload.simpleRumble.unLeftMotorSpeed = low_frequency_rumble;
  313. msg->payload.simpleRumble.unRightMotorSpeed = high_frequency_rumble;
  314. msg->payload.simpleRumble.nLeftGain = 2;
  315. msg->payload.simpleRumble.nRightGain = 0;
  316. rc = SDL_hid_send_feature_report(device->dev, buffer, sizeof(buffer));
  317. if (rc != sizeof(buffer))
  318. return -1;
  319. return 0;
  320. }
  321. static int HIDAPI_DriverSteamDeck_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
  322. {
  323. return SDL_Unsupported();
  324. }
  325. static Uint32 HIDAPI_DriverSteamDeck_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
  326. {
  327. return SDL_JOYSTICK_CAP_RUMBLE;
  328. }
  329. static int HIDAPI_DriverSteamDeck_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
  330. {
  331. return SDL_Unsupported();
  332. }
  333. static int HIDAPI_DriverSteamDeck_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
  334. {
  335. return SDL_Unsupported();
  336. }
  337. static int HIDAPI_DriverSteamDeck_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled)
  338. {
  339. // On steam deck, sensors are enabled by default. Nothing to do here.
  340. return 0;
  341. }
  342. static void HIDAPI_DriverSteamDeck_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
  343. {
  344. // Lizard mode id automatically re-enabled by watchdog. Nothing to do here.
  345. }
  346. static void HIDAPI_DriverSteamDeck_FreeDevice(SDL_HIDAPI_Device *device)
  347. {
  348. }
  349. SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamDeck = {
  350. SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK,
  351. SDL_TRUE,
  352. HIDAPI_DriverSteamDeck_RegisterHints,
  353. HIDAPI_DriverSteamDeck_UnregisterHints,
  354. HIDAPI_DriverSteamDeck_IsEnabled,
  355. HIDAPI_DriverSteamDeck_IsSupportedDevice,
  356. HIDAPI_DriverSteamDeck_InitDevice,
  357. HIDAPI_DriverSteamDeck_GetDevicePlayerIndex,
  358. HIDAPI_DriverSteamDeck_SetDevicePlayerIndex,
  359. HIDAPI_DriverSteamDeck_UpdateDevice,
  360. HIDAPI_DriverSteamDeck_OpenJoystick,
  361. HIDAPI_DriverSteamDeck_RumbleJoystick,
  362. HIDAPI_DriverSteamDeck_RumbleJoystickTriggers,
  363. HIDAPI_DriverSteamDeck_GetJoystickCapabilities,
  364. HIDAPI_DriverSteamDeck_SetJoystickLED,
  365. HIDAPI_DriverSteamDeck_SendJoystickEffect,
  366. HIDAPI_DriverSteamDeck_SetSensorsEnabled,
  367. HIDAPI_DriverSteamDeck_CloseJoystick,
  368. HIDAPI_DriverSteamDeck_FreeDevice,
  369. };
  370. #endif /* SDL_JOYSTICK_HIDAPI_STEAMDECK */
  371. #endif /* SDL_JOYSTICK_HIDAPI */