mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-16 16:28:13 +00:00
Add steam deck detection and HIDAPI driver scaffold.
This commit is contained in:
156
src/joystick/hidapi/SDL_hidapi_steamdeck.c
Normal file
156
src/joystick/hidapi/SDL_hidapi_steamdeck.c
Normal file
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 2023 Max Maisel <max.maisel@posteo.de>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "SDL_internal.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI
|
||||
|
||||
#include "../SDL_sysjoystick.h"
|
||||
#include "SDL_hidapijoystick_c.h"
|
||||
|
||||
#ifdef SDL_JOYSTICK_HIDAPI_STEAMDECK
|
||||
|
||||
/*****************************************************************************************************/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/*****************************************************************************************************/
|
||||
|
||||
static void HIDAPI_DriverSteamDeck_RegisterHints(SDL_HintCallback callback, void *userdata)
|
||||
{
|
||||
SDL_AddHintCallback(SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK, callback, userdata);
|
||||
}
|
||||
|
||||
static void HIDAPI_DriverSteamDeck_UnregisterHints(SDL_HintCallback callback, void *userdata)
|
||||
{
|
||||
SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK, callback, userdata);
|
||||
}
|
||||
|
||||
static SDL_bool HIDAPI_DriverSteamDeck_IsEnabled(void)
|
||||
{
|
||||
return SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK,
|
||||
SDL_GetHintBoolean(SDL_HINT_JOYSTICK_HIDAPI, SDL_HIDAPI_DEFAULT));
|
||||
}
|
||||
|
||||
static SDL_bool HIDAPI_DriverSteamDeck_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)
|
||||
{
|
||||
return SDL_IsJoystickSteamDeck(vendor_id, product_id);
|
||||
}
|
||||
|
||||
static SDL_bool HIDAPI_DriverSteamDeck_InitDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static int HIDAPI_DriverSteamDeck_GetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void HIDAPI_DriverSteamDeck_SetDevicePlayerIndex(SDL_HIDAPI_Device *device, SDL_JoystickID instance_id, int player_index)
|
||||
{
|
||||
}
|
||||
|
||||
static SDL_bool HIDAPI_DriverSteamDeck_UpdateDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static SDL_bool HIDAPI_DriverSteamDeck_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static int HIDAPI_DriverSteamDeck_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
|
||||
{
|
||||
/* You should use the full Steam Input API for rumble support */
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int HIDAPI_DriverSteamDeck_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static Uint32 HIDAPI_DriverSteamDeck_GetJoystickCapabilities(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int HIDAPI_DriverSteamDeck_SetJoystickLED(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int HIDAPI_DriverSteamDeck_SendJoystickEffect(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, const void *data, int size)
|
||||
{
|
||||
return SDL_Unsupported();
|
||||
}
|
||||
|
||||
static int HIDAPI_DriverSteamDeck_SetSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, SDL_bool enabled)
|
||||
{
|
||||
// On steam deck, sensors are enabled by default. Nothing to do here.
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void HIDAPI_DriverSteamDeck_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
|
||||
{
|
||||
// Lizard mode id automatically re-enabled by watchdog. Nothing to do here.
|
||||
}
|
||||
|
||||
static void HIDAPI_DriverSteamDeck_FreeDevice(SDL_HIDAPI_Device *device)
|
||||
{
|
||||
}
|
||||
|
||||
SDL_HIDAPI_DeviceDriver SDL_HIDAPI_DriverSteamDeck = {
|
||||
SDL_HINT_JOYSTICK_HIDAPI_STEAMDECK,
|
||||
SDL_TRUE,
|
||||
HIDAPI_DriverSteamDeck_RegisterHints,
|
||||
HIDAPI_DriverSteamDeck_UnregisterHints,
|
||||
HIDAPI_DriverSteamDeck_IsEnabled,
|
||||
HIDAPI_DriverSteamDeck_IsSupportedDevice,
|
||||
HIDAPI_DriverSteamDeck_InitDevice,
|
||||
HIDAPI_DriverSteamDeck_GetDevicePlayerIndex,
|
||||
HIDAPI_DriverSteamDeck_SetDevicePlayerIndex,
|
||||
HIDAPI_DriverSteamDeck_UpdateDevice,
|
||||
HIDAPI_DriverSteamDeck_OpenJoystick,
|
||||
HIDAPI_DriverSteamDeck_RumbleJoystick,
|
||||
HIDAPI_DriverSteamDeck_RumbleJoystickTriggers,
|
||||
HIDAPI_DriverSteamDeck_GetJoystickCapabilities,
|
||||
HIDAPI_DriverSteamDeck_SetJoystickLED,
|
||||
HIDAPI_DriverSteamDeck_SendJoystickEffect,
|
||||
HIDAPI_DriverSteamDeck_SetSensorsEnabled,
|
||||
HIDAPI_DriverSteamDeck_CloseJoystick,
|
||||
HIDAPI_DriverSteamDeck_FreeDevice,
|
||||
};
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI_STEAMDECK */
|
||||
|
||||
#endif /* SDL_JOYSTICK_HIDAPI */
|
Reference in New Issue
Block a user