From 447acce4559f355ffca0522eefb5ae519b673865 Mon Sep 17 00:00:00 2001 From: Jake Date: Fri, 28 Apr 2017 19:32:22 -0500 Subject: [PATCH] Implement hid_write_control, so we can use HidD_SetOutputReport on win, all others are just a wrapper until tested --- hidapi/hidapi.h | 5 +++++ libusb/hid.c | 5 +++++ linux/hid.c | 6 ++++++ mac/hid.c | 6 ++++++ windows/hid.c | 13 +++++++++++++ windows/hidapi_hidsdi.h | 1 + 6 files changed, 36 insertions(+) diff --git a/hidapi/hidapi.h b/hidapi/hidapi.h index 959c912..2a910d0 100644 --- a/hidapi/hidapi.h +++ b/hidapi/hidapi.h @@ -514,6 +514,11 @@ extern "C" { */ HID_API_EXPORT const char* HID_API_CALL hid_version_str(void); + /** RPCS3 EDIT: This attempts to write the output on the 'control' channel + Otherwise it's the exact same as hid_write + */ + int HID_API_EXPORT HID_API_CALL hid_write_control(hid_device *device, const unsigned char *data, size_t length); + #ifdef __cplusplus } #endif diff --git a/libusb/hid.c b/libusb/hid.c index 3103f03..f01706e 100644 --- a/libusb/hid.c +++ b/libusb/hid.c @@ -1052,6 +1052,11 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path) } } +int HID_API_EXPORT hid_write_control(hid_device *dev, const unsigned char *data, size_t length) +{ + //RPCS3 TODO: Test if this needs to be changed for control if we ever use it + return hid_write(dev, data, length); +} HID_API_EXPORT hid_device * HID_API_CALL hid_libusb_wrap_sys_device(intptr_t sys_dev, int interface_num) { diff --git a/linux/hid.c b/linux/hid.c index 1d79117..7e010e6 100644 --- a/linux/hid.c +++ b/linux/hid.c @@ -982,6 +982,12 @@ int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t return bytes_written; } +int HID_API_EXPORT hid_write_control(hid_device *dev, const unsigned char *data, size_t length) +{ + //RPCS3 TODO: Test if this needs to be changed for control if we ever use it + return hid_write(dev, data, length); +} + int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds) { diff --git a/mac/hid.c b/mac/hid.c index d78ac9b..b7128d3 100644 --- a/mac/hid.c +++ b/mac/hid.c @@ -943,6 +943,12 @@ static int get_report(hid_device *dev, IOHIDReportType type, unsigned char *data return -1; } +int HID_API_EXPORT hid_write_control(hid_device *dev, const unsigned char *data, size_t length) +{ + //RPCS3 TODO: Test if this needs to be changed for control on mac if we ever use it + return hid_write(dev, data, length); +} + int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length) { return set_report(dev, kIOHIDReportTypeOutput, data, length); diff --git a/windows/hid.c b/windows/hid.c index da47ff6..4df0549 100644 --- a/windows/hid.c +++ b/windows/hid.c @@ -95,6 +95,7 @@ static HidD_GetPreparsedData_ HidD_GetPreparsedData; static HidD_FreePreparsedData_ HidD_FreePreparsedData; static HidP_GetCaps_ HidP_GetCaps; static HidD_SetNumInputBuffers_ HidD_SetNumInputBuffers; +static HidD_SetOutputReport_ HidD_SetOutputReport; static CM_Locate_DevNodeW_ CM_Locate_DevNodeW = NULL; static CM_Get_Parent_ CM_Get_Parent = NULL; @@ -148,6 +149,7 @@ static int lookup_functions() RESOLVE(hid_lib_handle, HidD_FreePreparsedData); RESOLVE(hid_lib_handle, HidP_GetCaps); RESOLVE(hid_lib_handle, HidD_SetNumInputBuffers); + RESOLVE(hid_lib_handle, HidD_SetOutputReport); RESOLVE(cfgmgr32_lib_handle, CM_Locate_DevNodeW); RESOLVE(cfgmgr32_lib_handle, CM_Get_Parent); @@ -879,6 +881,17 @@ end_of_function: return function_result; } +int HID_API_EXPORT HID_API_CALL hid_write_control(hid_device *dev, const unsigned char *data, size_t length) +{ + BOOL res = HidD_SetOutputReport(dev->device_handle, (PVOID)data, (ULONG)length); + + if (!res) { + register_winapi_error(dev, L"SetOutputReport"); + return -1; + } + + return (int)length; +} int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds) { diff --git a/windows/hidapi_hidsdi.h b/windows/hidapi_hidsdi.h index 453f899..1be909a 100644 --- a/windows/hidapi_hidsdi.h +++ b/windows/hidapi_hidsdi.h @@ -54,6 +54,7 @@ typedef BOOLEAN (__stdcall *HidD_GetIndexedString_)(HANDLE handle, ULONG string_ typedef BOOLEAN (__stdcall *HidD_GetPreparsedData_)(HANDLE handle, PHIDP_PREPARSED_DATA *preparsed_data); typedef BOOLEAN (__stdcall *HidD_FreePreparsedData_)(PHIDP_PREPARSED_DATA preparsed_data); typedef BOOLEAN (__stdcall *HidD_SetNumInputBuffers_)(HANDLE handle, ULONG number_buffers); +typedef BOOLEAN (__stdcall *HidD_SetOutputReport_)(HANDLE handle, PVOID data, ULONG length); #endif