Build hidapi code into SDL as a new public API

This prevents conflicts with hidapi linked with applications, as well as allowing applications to make use of HIDAPI on Android and other platforms that might not normally have an implementation available.
This commit is contained in:
Sam Lantinga
2021-11-07 22:58:44 -08:00
parent 94c1276a5f
commit 5b646cd19e
35 changed files with 798 additions and 633 deletions

View File

@@ -32,7 +32,7 @@
#include "../SDL_sysjoystick.h"
#include "SDL_hidapijoystick_c.h"
#include "SDL_hidapi_rumble.h"
#include "../../hidapi/SDL_hidapi.h"
#include "../../hidapi/SDL_hidapi_c.h"
#ifdef SDL_JOYSTICK_HIDAPI_GAMECUBE
@@ -129,7 +129,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_free(ctx);
SDL_SetError("Couldn't open %s", device->path);
@@ -154,7 +154,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
}
} else {
/* This is all that's needed to initialize the device. Really! */
if (hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) {
if (SDL_hid_write(device->dev, &initMagic, sizeof(initMagic)) != sizeof(initMagic)) {
SDL_SetError("Couldn't initialize WUP-028");
goto error;
}
@@ -163,7 +163,7 @@ HIDAPI_DriverGameCube_InitDevice(SDL_HIDAPI_Device *device)
SDL_Delay(10);
/* Add all the applicable joysticks */
while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
#ifdef DEBUG_GAMECUBE_PROTOCOL
HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size);
#endif
@@ -204,7 +204,7 @@ error:
SDL_LockMutex(device->dev_lock);
{
if (device->dev) {
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
}
if (device->context) {
@@ -389,7 +389,7 @@ HIDAPI_DriverGameCube_UpdateDevice(SDL_HIDAPI_Device *device)
int size;
/* Read input packet */
while ((size = hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, packet, sizeof(packet), 0)) > 0) {
#ifdef DEBUG_GAMECUBE_PROTOCOL
//HIDAPI_DumpPacket("Nintendo GameCube packet: size = %d", packet, size);
#endif
@@ -510,7 +510,7 @@ HIDAPI_DriverGameCube_FreeDevice(SDL_HIDAPI_Device *device)
SDL_LockMutex(device->dev_lock);
{
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
SDL_free(device->context);

View File

@@ -87,7 +87,7 @@ HIDAPI_DriverLuna_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick
return SDL_FALSE;
}
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_SetError("Couldn't open %s", device->path);
SDL_free(ctx);
@@ -386,7 +386,7 @@ HIDAPI_DriverLuna_UpdateDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
#ifdef DEBUG_LUNA_PROTOCOL
HIDAPI_DumpPacket("Amazon Luna packet: size = %d", data, size);
#endif
@@ -413,7 +413,7 @@ HIDAPI_DriverLuna_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
SDL_LockMutex(device->dev_lock);
{
if (device->dev) {
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
}

View File

@@ -163,11 +163,11 @@ HIDAPI_DriverPS4_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
return NULL;
}
static int ReadFeatureReport(hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
{
SDL_memset(report, 0, length);
report[0] = report_id;
return hid_get_feature_report(dev, report, length);
return SDL_hid_get_feature_report(dev, report, length);
}
static SDL_bool HIDAPI_DriverPS4_CanRumble(Uint16 vendor_id, Uint16 product_id)
@@ -479,7 +479,7 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
ctx->joystick = joystick;
ctx->last_packet = SDL_GetTicks();
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_free(ctx);
SDL_SetError("Couldn't open %s", device->path);
@@ -511,7 +511,7 @@ HIDAPI_DriverPS4_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
ctx->is_bluetooth = SDL_TRUE;
/* Read a report to see if we're in enhanced mode */
size = hid_read_timeout(device->dev, data, sizeof(data), 16);
size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 16);
#ifdef DEBUG_PS4_PROTOCOL
if (size > 0) {
HIDAPI_DumpPacket("PS4 first packet: size = %d", data, size);
@@ -684,7 +684,7 @@ HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
}
static void
HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet)
HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS4_Context *ctx, PS4StatePacket_t *packet)
{
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
static const float TOUCHPAD_SCALEY = 1.0f / 920; /* This is noted as being 944 resolution, but 920 feels better */
@@ -846,7 +846,7 @@ HIDAPI_DriverPS4_UpdateDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
#ifdef DEBUG_PS4_PROTOCOL
HIDAPI_DumpPacket("PS4 packet: size = %d", data, size);
#endif
@@ -908,7 +908,7 @@ HIDAPI_DriverPS4_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick
SDL_LockMutex(device->dev_lock);
{
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
SDL_free(device->context);

View File

@@ -192,11 +192,11 @@ HIDAPI_DriverPS5_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
return NULL;
}
static int ReadFeatureReport(hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
static int ReadFeatureReport(SDL_hid_device *dev, Uint8 report_id, Uint8 *report, size_t length)
{
SDL_memset(report, 0, length);
report[0] = report_id;
return hid_get_feature_report(dev, report, length);
return SDL_hid_get_feature_report(dev, report, length);
}
static void
@@ -553,7 +553,7 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
ctx->joystick = joystick;
ctx->last_packet = SDL_GetTicks();
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_free(ctx);
SDL_SetError("Couldn't open %s", device->path);
@@ -562,7 +562,7 @@ HIDAPI_DriverPS5_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick)
device->context = ctx;
/* Read a report to see what mode we're in */
size = hid_read_timeout(device->dev, data, sizeof(data), 16);
size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 16);
#ifdef DEBUG_PS5_PROTOCOL
if (size > 0) {
HIDAPI_DumpPacket("PS5 first packet: size = %d", data, size);
@@ -761,7 +761,7 @@ HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
}
static void
HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverPS5_Context *ctx, PS5SimpleStatePacket_t *packet)
HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5SimpleStatePacket_t *packet)
{
Sint16 axis;
@@ -855,7 +855,7 @@ HIDAPI_DriverPS5_HandleSimpleStatePacket(SDL_Joystick *joystick, hid_device *dev
}
static void
HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacket_t *packet)
HIDAPI_DriverPS5_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverPS5_Context *ctx, PS5StatePacket_t *packet)
{
static const float TOUCHPAD_SCALEX = 1.0f / 1920;
static const float TOUCHPAD_SCALEY = 1.0f / 1070;
@@ -1010,7 +1010,7 @@ HIDAPI_DriverPS5_UpdateDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
#ifdef DEBUG_PS5_PROTOCOL
HIDAPI_DumpPacket("PS5 packet: size = %d", data, size);
#endif
@@ -1071,7 +1071,7 @@ HIDAPI_DriverPS5_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick
SDL_LockMutex(device->dev_lock);
{
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
SDL_free(device->context);

View File

@@ -80,7 +80,7 @@ static int SDL_HIDAPI_RumbleThread(void *data)
#ifdef DEBUG_RUMBLE
HIDAPI_DumpPacket("Rumble packet: size = %d", request->data, request->size);
#endif
hid_write(request->device->dev, request->data, request->size);
SDL_hid_write(request->device->dev, request->data, request->size);
}
SDL_UnlockMutex(request->device->dev_lock);
(void)SDL_AtomicDecRef(&request->device->rumble_pending);

View File

@@ -88,7 +88,7 @@ HIDAPI_DriverStadia_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
return SDL_FALSE;
}
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_SetError("Couldn't open %s", device->path);
SDL_free(ctx);
@@ -267,7 +267,7 @@ HIDAPI_DriverStadia_UpdateDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
#ifdef DEBUG_STADIA_PROTOCOL
HIDAPI_DumpPacket("Google Stadia packet: size = %d", data, size);
#endif
@@ -287,7 +287,7 @@ HIDAPI_DriverStadia_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
SDL_LockMutex(device->dev_lock);
{
if (device->dev) {
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
}

View File

@@ -305,7 +305,7 @@ static int WriteSegmentToSteamControllerPacketAssembler( SteamControllerPacketAs
#define BLE_MAX_READ_RETRIES 8
static int SetFeatureReport( hid_device *dev, unsigned char uBuffer[65], int nActualDataLen )
static int SetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65], int nActualDataLen )
{
int nRet = -1;
bool bBle = true; // only wireless/BLE for now, though macOS could do wired in the future
@@ -339,7 +339,7 @@ static int SetFeatureReport( hid_device *dev, unsigned char uBuffer[65], int nAc
pBufferPtr += nBytesInPacket;
nSegmentNumber++;
nRet = hid_send_feature_report( dev, uPacketBuffer, sizeof( uPacketBuffer ) );
nRet = SDL_hid_send_feature_report( dev, uPacketBuffer, sizeof( uPacketBuffer ) );
DPRINTF("SetFeatureReport() ret = %d\n", nRet);
}
}
@@ -347,7 +347,7 @@ static int SetFeatureReport( hid_device *dev, unsigned char uBuffer[65], int nAc
return nRet;
}
static int GetFeatureReport( hid_device *dev, unsigned char uBuffer[65] )
static int GetFeatureReport( SDL_hid_device *dev, unsigned char uBuffer[65] )
{
int nRet = -1;
bool bBle = true;
@@ -366,7 +366,7 @@ static int GetFeatureReport( hid_device *dev, unsigned char uBuffer[65] )
{
memset( uSegmentBuffer, 0, sizeof( uSegmentBuffer ) );
uSegmentBuffer[ 0 ] = BLE_REPORT_NUMBER;
nRet = hid_get_feature_report( dev, uSegmentBuffer, sizeof( uSegmentBuffer ) );
nRet = SDL_hid_get_feature_report( dev, uSegmentBuffer, sizeof( uSegmentBuffer ) );
DPRINTF( "GetFeatureReport ble ret=%d\n", nRet );
HEXDUMP( uSegmentBuffer, nRet );
@@ -400,7 +400,7 @@ static int GetFeatureReport( hid_device *dev, unsigned char uBuffer[65] )
return nRet;
}
static int ReadResponse( hid_device *dev, uint8_t uBuffer[65], int nExpectedResponse )
static int ReadResponse( SDL_hid_device *dev, uint8_t uBuffer[65], int nExpectedResponse )
{
int nRet = GetFeatureReport( dev, uBuffer );
@@ -421,7 +421,7 @@ static int ReadResponse( hid_device *dev, uint8_t uBuffer[65], int nExpectedResp
//---------------------------------------------------------------------------
// Reset steam controller (unmap buttons and pads) and re-fetch capability bits
//---------------------------------------------------------------------------
static bool ResetSteamController( hid_device *dev, bool bSuppressErrorSpew, uint32_t *punUpdateRateUS )
static bool ResetSteamController( SDL_hid_device *dev, bool bSuppressErrorSpew, uint32_t *punUpdateRateUS )
{
// Firmware quirk: Set Feature and Get Feature requests always require a 65-byte buffer.
unsigned char buf[65];
@@ -606,18 +606,18 @@ buf[3+nSettings*3+2] = ((uint16_t)VALUE)>>8; \
//---------------------------------------------------------------------------
// Read from a Steam Controller
//---------------------------------------------------------------------------
static int ReadSteamController( hid_device *dev, uint8_t *pData, int nDataSize )
static int ReadSteamController( SDL_hid_device *dev, uint8_t *pData, int nDataSize )
{
memset( pData, 0, nDataSize );
pData[ 0 ] = BLE_REPORT_NUMBER; // hid_read will also overwrite this with the same value, 0x03
return hid_read( dev, pData, nDataSize );
return SDL_hid_read( dev, pData, nDataSize );
}
//---------------------------------------------------------------------------
// Close a Steam Controller
//---------------------------------------------------------------------------
static void CloseSteamController( hid_device *dev )
static void CloseSteamController( SDL_hid_device *dev )
{
// Switch the Steam Controller back to lizard mode so it works with the OS
unsigned char buf[65];
@@ -1040,12 +1040,12 @@ HIDAPI_DriverSteam_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystic
}
device->context = ctx;
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_SetError("Couldn't open %s", device->path);
goto error;
}
hid_set_nonblocking(device->dev, 1);
SDL_hid_set_nonblocking(device->dev, 1);
if (!ResetSteamController(device->dev, false, &update_rate_in_us)) {
SDL_SetError("Couldn't reset controller");
@@ -1070,7 +1070,7 @@ error:
SDL_LockMutex(device->dev_lock);
{
if (device->dev) {
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
}
if (device->context) {
@@ -1266,7 +1266,7 @@ HIDAPI_DriverSteam_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
{
CloseSteamController(device->dev);
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
SDL_free(device->context);

View File

@@ -346,13 +346,13 @@ static int ReadInput(SDL_DriverSwitch_Context *ctx)
return 0;
}
return hid_read_timeout(ctx->device->dev, ctx->m_rgucReadBuffer, sizeof(ctx->m_rgucReadBuffer), 0);
return SDL_hid_read_timeout(ctx->device->dev, ctx->m_rgucReadBuffer, sizeof(ctx->m_rgucReadBuffer), 0);
}
static int WriteOutput(SDL_DriverSwitch_Context *ctx, const Uint8 *data, int size)
{
#ifdef SWITCH_SYNCHRONOUS_WRITES
return hid_write(ctx->device->dev, data, size);
return SDL_hid_write(ctx->device->dev, data, size);
#else
/* Use the rumble thread for general asynchronous writes */
if (SDL_HIDAPI_LockRumble() < 0) {
@@ -856,7 +856,7 @@ HIDAPI_DriverSwitch_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
ctx->device = device;
device->context = ctx;
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_SetError("Couldn't open %s", device->path);
goto error;
@@ -986,7 +986,7 @@ error:
SDL_LockMutex(device->dev_lock);
{
if (device->dev) {
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
}
if (device->context) {
@@ -1530,7 +1530,7 @@ HIDAPI_DriverSwitch_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
SDL_LockMutex(device->dev_lock);
{
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
SDL_free(device->context);

View File

@@ -88,14 +88,14 @@ HIDAPI_DriverXbox360_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
return NULL;
}
static SDL_bool SetSlotLED(hid_device *dev, Uint8 slot)
static SDL_bool SetSlotLED(SDL_hid_device *dev, Uint8 slot)
{
const SDL_bool blink = SDL_FALSE;
Uint8 mode = (blink ? 0x02 : 0x06) + slot;
Uint8 led_packet[] = { 0x01, 0x03, 0x00 };
led_packet[2] = mode;
if (hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) {
if (SDL_hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) {
return SDL_FALSE;
}
return SDL_TRUE;
@@ -136,7 +136,7 @@ HIDAPI_DriverXbox360_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
return SDL_FALSE;
}
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_SetError("Couldn't open %s", device->path);
SDL_free(ctx);
@@ -296,7 +296,7 @@ HIDAPI_DriverXbox360_UpdateDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
#ifdef DEBUG_XBOX_PROTOCOL
HIDAPI_DumpPacket("Xbox 360 packet: size = %d", data, size);
#endif
@@ -318,7 +318,7 @@ HIDAPI_DriverXbox360_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joys
SDL_LockMutex(device->dev_lock);
{
if (device->dev) {
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
}

View File

@@ -62,14 +62,14 @@ HIDAPI_DriverXbox360W_GetDeviceName(Uint16 vendor_id, Uint16 product_id)
return "Xbox 360 Wireless Controller";
}
static SDL_bool SetSlotLED(hid_device *dev, Uint8 slot)
static SDL_bool SetSlotLED(SDL_hid_device *dev, Uint8 slot)
{
const SDL_bool blink = SDL_FALSE;
Uint8 mode = (blink ? 0x02 : 0x06) + slot;
Uint8 led_packet[] = { 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
led_packet[3] = 0x40 + (mode % 0x0e);
if (hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) {
if (SDL_hid_write(dev, led_packet, sizeof(led_packet)) != sizeof(led_packet)) {
return SDL_FALSE;
}
return SDL_TRUE;
@@ -105,7 +105,7 @@ HIDAPI_DriverXbox360W_InitDevice(SDL_HIDAPI_Device *device)
return SDL_FALSE;
}
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_free(ctx);
SDL_SetError("Couldn't open %s", device->path);
@@ -113,7 +113,7 @@ HIDAPI_DriverXbox360W_InitDevice(SDL_HIDAPI_Device *device)
}
device->context = ctx;
if (hid_write(device->dev, init_packet, sizeof(init_packet)) != sizeof(init_packet)) {
if (SDL_hid_write(device->dev, init_packet, sizeof(init_packet)) != sizeof(init_packet)) {
SDL_SetError("Couldn't write init packet");
return SDL_FALSE;
}
@@ -199,7 +199,7 @@ HIDAPI_DriverXbox360W_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_J
}
static void
HIDAPI_DriverXbox360W_HandleStatePacket(SDL_Joystick *joystick, hid_device *dev, SDL_DriverXbox360W_Context *ctx, Uint8 *data, int size)
HIDAPI_DriverXbox360W_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev, SDL_DriverXbox360W_Context *ctx, Uint8 *data, int size)
{
Sint16 axis;
const SDL_bool invert_y_axes = SDL_TRUE;
@@ -259,7 +259,7 @@ HIDAPI_DriverXbox360W_UpdateDevice(SDL_HIDAPI_Device *device)
joystick = SDL_JoystickFromInstanceID(device->joysticks[0]);
}
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
#ifdef DEBUG_XBOX_PROTOCOL
HIDAPI_DumpPacket("Xbox 360 wireless packet: size = %d", data, size);
#endif
@@ -321,7 +321,7 @@ HIDAPI_DriverXbox360W_FreeDevice(SDL_HIDAPI_Device *device)
{
SDL_LockMutex(device->dev_lock);
{
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
SDL_free(device->context);

View File

@@ -317,7 +317,7 @@ HIDAPI_DriverXboxOne_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joyst
return SDL_FALSE;
}
device->dev = hid_open_path(device->path, 0);
device->dev = SDL_hid_open_path(device->path, 0);
if (!device->dev) {
SDL_free(ctx);
SDL_SetError("Couldn't open %s", device->path);
@@ -945,7 +945,7 @@ HIDAPI_DriverXboxOne_UpdateJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joy
Uint8 data[USB_PACKET_LENGTH];
int size;
while ((size = hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
while ((size = SDL_hid_read_timeout(device->dev, data, sizeof(data), 0)) > 0) {
#ifdef DEBUG_XBOX_PROTOCOL
HIDAPI_DumpPacket("Xbox One packet: size = %d", data, size);
#endif
@@ -1099,7 +1099,7 @@ HIDAPI_DriverXboxOne_CloseJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joys
{
SDL_LockMutex(device->dev_lock);
{
hid_close(device->dev);
SDL_hid_close(device->dev);
device->dev = NULL;
SDL_free(device->context);

View File

@@ -767,17 +767,7 @@ HIDAPI_JoystickInit(void)
}
#endif
#if defined(__MACOSX__) || defined(__IPHONEOS__) || defined(__TVOS__)
/* The hidapi framwork is weak-linked on Apple platforms */
int HID_API_EXPORT HID_API_CALL hid_init(void) __attribute__((weak_import));
if (hid_init == NULL) {
SDL_SetError("Couldn't initialize hidapi, framework not available");
return -1;
}
#endif /* __MACOSX__ || __IPHONEOS__ || __TVOS__ */
if (hid_init() < 0) {
if (SDL_hid_init() < 0) {
SDL_SetError("Couldn't initialize hidapi");
return -1;
}
@@ -874,7 +864,7 @@ HIDAPI_ConvertString(const wchar_t *wide_string)
}
static void
HIDAPI_AddDevice(struct hid_device_info *info)
HIDAPI_AddDevice(struct SDL_hid_device_info *info)
{
SDL_HIDAPI_Device *device;
SDL_HIDAPI_Device *curr, *last = NULL;
@@ -994,6 +984,7 @@ HIDAPI_AddDevice(struct hid_device_info *info)
HIDAPI_SetupDeviceDriver(device);
#define DEBUG_HIDAPI
#ifdef DEBUG_HIDAPI
SDL_Log("Added HIDAPI device '%s' VID 0x%.4x, PID 0x%.4x, version %d, serial %s, interface %d, interface_class %d, interface_subclass %d, interface_protocol %d, usage page 0x%.4x, usage 0x%.4x, path = %s, driver = %s (%s)\n", device->name, device->vendor_id, device->product_id, device->version, device->serial ? device->serial : "NONE", device->interface_number, device->interface_class, device->interface_subclass, device->interface_protocol, device->usage_page, device->usage, device->path, device->driver ? device->driver->hint : "NONE", device->driver && device->driver->enabled ? "ENABLED" : "DISABLED");
#endif
@@ -1038,7 +1029,7 @@ static void
HIDAPI_UpdateDeviceList(void)
{
SDL_HIDAPI_Device *device;
struct hid_device_info *devs, *info;
struct SDL_hid_device_info *devs, *info;
SDL_LockJoysticks();
@@ -1051,7 +1042,7 @@ HIDAPI_UpdateDeviceList(void)
/* Enumerate the devices */
if (SDL_HIDAPI_numdrivers > 0) {
devs = hid_enumerate(0, 0);
devs = SDL_hid_enumerate(0, 0);
if (devs) {
for (info = devs; info; info = info->next) {
device = HIDAPI_GetJoystickByInfo(info->path, info->vendor_id, info->product_id);
@@ -1061,7 +1052,7 @@ HIDAPI_UpdateDeviceList(void)
HIDAPI_AddDevice(info);
}
}
hid_free_enumeration(devs);
SDL_hid_free_enumeration(devs);
}
}
@@ -1495,7 +1486,7 @@ HIDAPI_JoystickQuit(void)
SDL_DelHintCallback(SDL_HINT_JOYSTICK_HIDAPI,
SDL_HIDAPIDriverHintChanged, NULL);
hid_exit();
SDL_hid_exit();
shutting_down = SDL_FALSE;
initialized = SDL_FALSE;

View File

@@ -27,7 +27,7 @@
#include "SDL_mutex.h"
#include "SDL_joystick.h"
#include "SDL_gamecontroller.h"
#include "../../hidapi/hidapi/hidapi.h"
#include "SDL_hidapi.h"
#include "../usb_ids.h"
/* This is the full set of HIDAPI drivers available */
@@ -70,7 +70,7 @@ typedef struct _SDL_HIDAPI_Device
struct _SDL_HIDAPI_DeviceDriver *driver;
void *context;
SDL_mutex *dev_lock;
hid_device *dev;
SDL_hid_device *dev;
SDL_atomic_t rumble_pending;
int num_joysticks;
SDL_JoystickID *joysticks;