Skip to content

Commit 9c712bb

Browse files
jarvesonMegamouse
authored andcommitted
Implement hid_write_control, so we can use HidD_SetOutputReport on win, all others are just a wrapper until tested
1 parent d3013f0 commit 9c712bb

File tree

6 files changed

+36
-0
lines changed

6 files changed

+36
-0
lines changed

hidapi/hidapi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,11 @@ extern "C" {
617617
*/
618618
HID_API_EXPORT const char* HID_API_CALL hid_version_str(void);
619619

620+
/** RPCS3 EDIT: This attempts to write the output on the 'control' channel
621+
Otherwise it's the exact same as hid_write
622+
*/
623+
int HID_API_EXPORT HID_API_CALL hid_write_control(hid_device *device, const unsigned char *data, size_t length);
624+
620625
#ifdef __cplusplus
621626
}
622627
#endif

libusb/hid.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,11 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
11971197
}
11981198
}
11991199

1200+
int HID_API_EXPORT hid_write_control(hid_device *dev, const unsigned char *data, size_t length)
1201+
{
1202+
//RPCS3 TODO: Test if this needs to be changed for control if we ever use it
1203+
return hid_write(dev, data, length);
1204+
}
12001205

12011206
HID_API_EXPORT hid_device * HID_API_CALL hid_libusb_wrap_sys_device(intptr_t sys_dev, int interface_num)
12021207
{

linux/hid.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,12 @@ int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t
10391039
return bytes_written;
10401040
}
10411041

1042+
int HID_API_EXPORT hid_write_control(hid_device *dev, const unsigned char *data, size_t length)
1043+
{
1044+
//RPCS3 TODO: Test if this needs to be changed for control if we ever use it
1045+
return hid_write(dev, data, length);
1046+
}
1047+
10421048

10431049
int HID_API_EXPORT hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
10441050
{

mac/hid.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,12 @@ static int get_report(hid_device *dev, IOHIDReportType type, unsigned char *data
11761176
return (int) report_length;
11771177
}
11781178

1179+
int HID_API_EXPORT hid_write_control(hid_device *dev, const unsigned char *data, size_t length)
1180+
{
1181+
//RPCS3 TODO: Test if this needs to be changed for control on mac if we ever use it
1182+
return hid_write(dev, data, length);
1183+
}
1184+
11791185
int HID_API_EXPORT hid_write(hid_device *dev, const unsigned char *data, size_t length)
11801186
{
11811187
return set_report(dev, kIOHIDReportTypeOutput, data, length);

windows/hid.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static HidD_GetPreparsedData_ HidD_GetPreparsedData;
9494
static HidD_FreePreparsedData_ HidD_FreePreparsedData;
9595
static HidP_GetCaps_ HidP_GetCaps;
9696
static HidD_SetNumInputBuffers_ HidD_SetNumInputBuffers;
97+
static HidD_SetOutputReport_ HidD_SetOutputReport;
9798

9899
static CM_Locate_DevNodeW_ CM_Locate_DevNodeW = NULL;
99100
static CM_Get_Parent_ CM_Get_Parent = NULL;
@@ -147,6 +148,7 @@ static int lookup_functions()
147148
RESOLVE(hid_lib_handle, HidD_FreePreparsedData);
148149
RESOLVE(hid_lib_handle, HidP_GetCaps);
149150
RESOLVE(hid_lib_handle, HidD_SetNumInputBuffers);
151+
RESOLVE(hid_lib_handle, HidD_SetOutputReport);
150152

151153
RESOLVE(cfgmgr32_lib_handle, CM_Locate_DevNodeW);
152154
RESOLVE(cfgmgr32_lib_handle, CM_Get_Parent);
@@ -1074,6 +1076,17 @@ int HID_API_EXPORT HID_API_CALL hid_write(hid_device *dev, const unsigned char *
10741076
return function_result;
10751077
}
10761078

1079+
int HID_API_EXPORT HID_API_CALL hid_write_control(hid_device *dev, const unsigned char *data, size_t length)
1080+
{
1081+
BOOL res = HidD_SetOutputReport(dev->device_handle, (PVOID)data, (ULONG)length);
1082+
1083+
if (!res) {
1084+
register_winapi_error(dev, L"SetOutputReport");
1085+
return -1;
1086+
}
1087+
1088+
return (int)length;
1089+
}
10771090

10781091
int HID_API_EXPORT HID_API_CALL hid_read_timeout(hid_device *dev, unsigned char *data, size_t length, int milliseconds)
10791092
{

windows/hidapi_hidsdi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ typedef BOOLEAN (__stdcall *HidD_GetIndexedString_)(HANDLE handle, ULONG string_
5454
typedef BOOLEAN (__stdcall *HidD_GetPreparsedData_)(HANDLE handle, PHIDP_PREPARSED_DATA *preparsed_data);
5555
typedef BOOLEAN (__stdcall *HidD_FreePreparsedData_)(PHIDP_PREPARSED_DATA preparsed_data);
5656
typedef BOOLEAN (__stdcall *HidD_SetNumInputBuffers_)(HANDLE handle, ULONG number_buffers);
57+
typedef BOOLEAN (__stdcall *HidD_SetOutputReport_)(HANDLE handle, PVOID data, ULONG length);
5758

5859
#endif
5960

0 commit comments

Comments
 (0)