SDL_hidapi_steamdeck.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 2023 Max Maisel <max.maisel@posteo.de>
  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. Uint64 sensor_timestamp_ns;
  66. Uint64 last_button_state;
  67. Uint8 watchdog_counter;
  68. } SDL_DriverSteamDeck_Context;
  69. static 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 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 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 true;
  97. }
  98. static 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 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 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 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) != 0));
  130. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_EAST,
  131. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_B) != 0));
  132. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_WEST,
  133. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_X) != 0));
  134. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_NORTH,
  135. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_Y) != 0));
  136. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_SHOULDER,
  137. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L) != 0));
  138. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_SHOULDER,
  139. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R) != 0));
  140. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_BACK,
  141. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_VIEW) != 0));
  142. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_START,
  143. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_MENU) != 0));
  144. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_GUIDE,
  145. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_STEAM) != 0));
  146. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_QAM,
  147. ((pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_QAM) != 0));
  148. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_LEFT_STICK,
  149. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L3) != 0));
  150. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_RIGHT_STICK,
  151. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R3) != 0));
  152. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_PADDLE1,
  153. ((pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_R4) != 0));
  154. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE1,
  155. ((pInReport->payload.deckState.ulButtonsH & STEAMDECK_HBUTTON_L4) != 0));
  156. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_RIGHT_PADDLE2,
  157. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_R5) != 0));
  158. SDL_SendJoystickButton(timestamp, joystick, SDL_GAMEPAD_BUTTON_STEAM_DECK_LEFT_PADDLE2,
  159. ((pInReport->payload.deckState.ulButtonsL & STEAMDECK_LBUTTON_L5) != 0));
  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_ns += SDL_US_TO_NS(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_ns, 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_ns, values, 3);
  196. SDL_SendJoystickTouchpad(timestamp, joystick, 0, 0,
  197. pInReport->payload.deckState.sPressurePadLeft > 0,
  198. pInReport->payload.deckState.sLeftPadX / 65536.0f + 0.5f,
  199. pInReport->payload.deckState.sLeftPadY / 65536.0f + 0.5f,
  200. pInReport->payload.deckState.sPressurePadLeft / 32768.0f);
  201. SDL_SendJoystickTouchpad(timestamp, joystick, 1, 0,
  202. pInReport->payload.deckState.sPressurePadRight > 0,
  203. pInReport->payload.deckState.sRightPadX / 65536.0f + 0.5f,
  204. pInReport->payload.deckState.sRightPadY / 65536.0f + 0.5f,
  205. pInReport->payload.deckState.sPressurePadRight / 32768.0f);
  206. }
  207. /*****************************************************************************************************/
  208. static void HIDAPI_DriverSteamDeck_RegisterHints(SDL_HintCallback callback, void *userdata)
  209. {
  210. SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK, callback, userdata);
  211. }
  212. static void HIDAPI_DriverSteamDeck_UnregisterHints(SDL_HintCallback callback, void *userdata)
  213. {
  214. SDL_RemoveHintCallback(SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK, callback, userdata);
  215. }
  216. static bool HIDAPI_DriverSteamDeck_IsEnabled(void)
  217. {
  218. return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK,
  219. SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
  220. }
  221. static bool HIDAPI_DriverSteamDeck_IsSupportedDevice(
  222. SDL_HIDAPI_Device *device,
  223. const char *name,
  224. SDL_GamepadType type,
  225. Uint16 vendor_id,
  226. Uint16 product_id,
  227. Uint16 version,
  228. int interface_number,
  229. int interface_class,
  230. int interface_subclass,
  231. int interface_protocol)
  232. {
  233. return SDL_IsJoystickSteamDeck(vendor_id, product_id);
  234. }
  235. static bool HIDAPI_DriverSteamDeck_InitDevice(SDL_HIDAPI_Device *device)
  236. {
  237. int size;
  238. Uint8 data[64];
  239. SDL_DriverSteamDeck_Context *ctx;
  240. ctx = (SDL_DriverSteamDeck_Context *)SDL_calloc(1, sizeof(*ctx));
  241. if (ctx == NULL) {
  242. return false;
  243. }
  244. // Always 1kHz according to USB descriptor, but actually about 4 ms.
  245. ctx->update_rate_us = 4000;
  246. device->context = ctx;
  247. // Read a report to see if this is the correct endpoint.
  248. // Mouse, Keyboard and Controller have the same VID/PID but
  249. // only the controller hidraw device receives hid reports.
  250. size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 16);
  251. if (size == 0)
  252. return false;
  253. if (!DisableDeckLizardMode(device->dev))
  254. return false;
  255. HIDAPI_SetDeviceName(device, "Steam Deck");
  256. return HIDAPI_JoystickConnected(device, NULL);
  257. }
  258. static int HIDAPI_DriverSteamDeck_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
  259. {
  260. return -1;
  261. }
  262. static void HIDAPI_DriverSteamDeck_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
  263. {
  264. }
  265. static bool HIDAPI_DriverSteamDeck_UpdateDevice(SDL_HIDAPI_Device *device)
  266. {
  267. SDL_DriverSteamDeck_Context *ctx = (SDL_DriverSteamDeck_Context *)device->context;
  268. SDL_Joystick *joystick = NULL;
  269. int r;
  270. uint8_t data[64];
  271. ValveInReport_t *pInReport = (ValveInReport_t *)data;
  272. if (device->num_joysticks > 0) {
  273. joystick = SDL_GetJoystickFromID(device->joysticks[0]);
  274. if (joystick == NULL) {
  275. return false;
  276. }
  277. } else {
  278. return false;
  279. }
  280. if (ctx->watchdog_counter++ > 200) {
  281. ctx->watchdog_counter = 0;
  282. if (!FeedDeckLizardWatchdog(device->dev))
  283. return false;
  284. }
  285. SDL_zeroa(data);
  286. do {
  287. r = SDL_hid_read(device->dev, data, sizeof(data));
  288. if (r < 0) {
  289. // Failed to read from controller
  290. HIDAPI_JoystickDisconnected(device, device->joysticks[0]);
  291. return false;
  292. } else if (r == 64 &&
  293. pInReport->header.unReportVersion == k_ValveInReportMsgVersion &&
  294. pInReport->header.ucType == ID_CONTROLLER_DECK_STATE &&
  295. pInReport->header.ucLength == 64) {
  296. HIDAPI_DriverSteamDeck_HandleState(device, joystick, pInReport);
  297. }
  298. } while (r > 0);
  299. return true;
  300. }
  301. static bool HIDAPI_DriverSteamDeck_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
  302. {
  303. SDL_DriverSteamDeck_Context *ctx = (SDL_DriverSteamDeck_Context *)device->context;
  304. float update_rate_in_hz = 1.0f / (float)(ctx->update_rate_us) * 1.0e6f;
  305. SDL_AssertJoysticksLocked();
  306. // Initialize the joystick capabilities
  307. joystick->nbuttons = SDL_GAMEPAD_NUM_STEAM_DECK_BUTTONS;
  308. joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
  309. joystick->nhats = 1;
  310. SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, update_rate_in_hz);
  311. SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, update_rate_in_hz);
  312. SDL_PrivateJoystickAddTouchpad(joystick, 1);
  313. SDL_PrivateJoystickAddTouchpad(joystick, 1);
  314. return true;
  315. }
  316. static bool HIDAPI_DriverSteamDeck_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
  317. {
  318. int rc;
  319. Uint8 buffer[HID_FEATURE_REPORT_BYTES + 1] = { 0 };
  320. FeatureReportMsg *msg = (FeatureReportMsg *)(buffer + 1);
  321. msg->header.type = ID_TRIGGER_RUMBLE_CMD;
  322. msg->payload.simpleRumble.unRumbleType = 0;
  323. msg->payload.simpleRumble.unIntensity = HAPTIC_INTENSITY_SYSTEM;
  324. msg->payload.simpleRumble.unLeftMotorSpeed = low_frequency_rumble;
  325. msg->payload.simpleRumble.unRightMotorSpeed = high_frequency_rumble;
  326. msg->payload.simpleRumble.nLeftGain = 2;
  327. msg->payload.simpleRumble.nRightGain = 0;
  328. rc = SDL_hid_send_feature_report(device->dev, buffer, sizeof(buffer));
  329. if (rc != sizeof(buffer))
  330. return false;
  331. return true;
  332. }
  333. static bool HIDAPI_DriverSteamDeck_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
  334. {
  335. return SDL_Unsupported();
  336. }
  337. static Uint32 HIDAPI_DriverSteamDeck_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
  338. {
  339. return SDL_JOYSTICK_CAP_RUMBLE;
  340. }
  341. static bool HIDAPI_DriverSteamDeck_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
  342. {
  343. return SDL_Unsupported();
  344. }
  345. static bool HIDAPI_DriverSteamDeck_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
  346. {
  347. return SDL_Unsupported();
  348. }
  349. static bool HIDAPI_DriverSteamDeck_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, bool enabled)
  350. {
  351. // On steam deck, sensors are enabled by default. Nothing to do here.
  352. return true;
  353. }
  354. static void HIDAPI_DriverSteamDeck_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
  355. {
  356. // Lizard mode id automatically re-enabled by watchdog. Nothing to do here.
  357. }
  358. static void HIDAPI_DriverSteamDeck_FreeDevice(SDL_HIDAPI_Device *device)
  359. {
  360. }
  361. SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamDeck = {
  362. SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK,
  363. true,
  364. HIDAPI_DriverSteamDeck_RegisterHints,
  365. HIDAPI_DriverSteamDeck_UnregisterHints,
  366. HIDAPI_DriverSteamDeck_IsEnabled,
  367. HIDAPI_DriverSteamDeck_IsSupportedDevice,
  368. HIDAPI_DriverSteamDeck_InitDevice,
  369. HIDAPI_DriverSteamDeck_GetDevicePlayerIndex,
  370. HIDAPI_DriverSteamDeck_SetDevicePlayerIndex,
  371. HIDAPI_DriverSteamDeck_UpdateDevice,
  372. HIDAPI_DriverSteamDeck_OpenJoystick,
  373. HIDAPI_DriverSteamDeck_RumbleJoystick,
  374. HIDAPI_DriverSteamDeck_RumbleJoystickTriggers,
  375. HIDAPI_DriverSteamDeck_GetJoystickCapabilities,
  376. HIDAPI_DriverSteamDeck_SetJoystickLED,
  377. HIDAPI_DriverSteamDeck_SendJoystickEffect,
  378. HIDAPI_DriverSteamDeck_SetSensorsEnabled,
  379. HIDAPI_DriverSteamDeck_CloseJoystick,
  380. HIDAPI_DriverSteamDeck_FreeDevice,
  381. };
  382. #endif // SDL_JOYSTICK_HIDAPI_STEAMDECK
  383. #endif // SDL_JOYSTICK_HIDAPI