From 8027ddf88819733320f2b1ebec63d32a8570e836 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 | 17 +++++++++++++++++ 5 files changed, 39 insertions(+) diff --git a/hidapi/hidapi.h b/hidapi/hidapi.h index 21cbd9db..ea35cdf4 100644 --- a/hidapi/hidapi.h +++ b/hidapi/hidapi.h @@ -490,6 +490,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 756a5916..9f012f96 100644 --- a/libusb/hid.c +++ b/libusb/hid.c @@ -1053,6 +1053,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 4ee6032e..c84022ab 100644 --- a/linux/hid.c +++ b/linux/hid.c @@ -976,6 +976,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 12648d9c..be589838 100644 --- a/mac/hid.c +++ b/mac/hid.c @@ -945,6 +945,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 24756a46..61c3be42 100644 --- a/windows/hid.c +++ b/windows/hid.c @@ -125,6 +125,7 @@ static struct hid_api_version api_version = { typedef BOOLEAN (__stdcall *HidD_FreePreparsedData_)(PHIDP_PREPARSED_DATA preparsed_data); typedef NTSTATUS (__stdcall *HidP_GetCaps_)(PHIDP_PREPARSED_DATA preparsed_data, HIDP_CAPS *caps); typedef BOOLEAN (__stdcall *HidD_SetNumInputBuffers_)(HANDLE handle, ULONG number_buffers); + typedef BOOLEAN(__stdcall *HidD_SetOutputReport_)(HANDLE handle, PVOID data, ULONG length); static HidD_GetHidGuid_ HidD_GetHidGuid; static HidD_GetAttributes_ HidD_GetAttributes; @@ -139,6 +140,7 @@ static struct hid_api_version api_version = { static HidD_FreePreparsedData_ HidD_FreePreparsedData; static HidP_GetCaps_ HidP_GetCaps; static HidD_SetNumInputBuffers_ HidD_SetNumInputBuffers; + static HidD_SetOutputReport_ HidD_SetOutputReport; static HMODULE lib_handle = NULL; static BOOLEAN initialized = FALSE; @@ -278,6 +280,7 @@ static int lookup_functions() RESOLVE(HidD_FreePreparsedData); RESOLVE(HidP_GetCaps); RESOLVE(HidD_SetNumInputBuffers); + RESOLVE(HidD_SetOutputReport); #undef RESOLVE #if defined(__GNUC__) # pragma GCC diagnostic pop @@ -917,6 +920,20 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char * return function_result; } +int HID_API_EXPORT HID_API_CALL hid_write_control(hid_device *dev, const unsigned char *data, size_t length) +{ + DWORD bytes_written = length; + BOOL res; + + res = HidD_SetOutputReport(dev->device_handle, (PVOID)data, (ULONG)length); + + if (!res) { + register_error(dev, "SetOutputReport"); + bytes_written = -1; + } + + return length; +} int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds) {