Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement proper libusb async polling #53

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,017 changes: 572 additions & 445 deletions 3rdparty/ViGEm/Client.h

Large diffs are not rendered by default.

71 changes: 65 additions & 6 deletions 3rdparty/ViGEm/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@ typedef enum _VIGEM_TARGET_TYPE
//
// Microsoft Xbox 360 Controller (wired)
//
Xbox360Wired,
//
// Microsoft Xbox One Controller (wired)
//
XboxOneWired,
Xbox360Wired = 0,
//
// Sony DualShock 4 (wired)
//
DualShock4Wired
DualShock4Wired = 2 // NOTE: 1 skipped on purpose to maintain compatibility

} VIGEM_TARGET_TYPE, *PVIGEM_TARGET_TYPE;

Expand Down Expand Up @@ -204,3 +200,66 @@ VOID FORCEINLINE DS4_REPORT_INIT(
DS4_SET_DPAD(Report, DS4_BUTTON_DPAD_NONE);
}

#include <pshpack1.h> // pack structs tightly
//
// DualShock 4 HID Touchpad structure
//
typedef struct _DS4_TOUCH
{
BYTE bPacketCounter; // timestamp / packet counter associated with touch event
BYTE bIsUpTrackingNum1; // 0 means down; active low
// unique to each finger down, so for a lift and repress the value is incremented
BYTE bTouchData1[3]; // Two 12 bits values (for X and Y)
// middle byte holds last 4 bits of X and the starting 4 bits of Y
BYTE bIsUpTrackingNum2; // second touch data immediately follows data of first touch
BYTE bTouchData2[3]; // resolution is 1920x943
} DS4_TOUCH, * PDS4_TOUCH;

//
// DualShock 4 v1 complete HID Input report
//
typedef struct _DS4_REPORT_EX
{
union
{
struct
{
BYTE bThumbLX;
BYTE bThumbLY;
BYTE bThumbRX;
BYTE bThumbRY;
USHORT wButtons;
BYTE bSpecial;
BYTE bTriggerL;
BYTE bTriggerR;
USHORT wTimestamp;
BYTE bBatteryLvl;
SHORT wGyroX;
SHORT wGyroY;
SHORT wGyroZ;
SHORT wAccelX;
SHORT wAccelY;
SHORT wAccelZ;
BYTE _bUnknown1[5];
BYTE bBatteryLvlSpecial;
// really should have a enum to show everything that this can represent (USB charging, battery level; EXT, headset, microphone connected)
BYTE _bUnknown2[2];
BYTE bTouchPacketsN; // 0x00 to 0x03 (USB max)
DS4_TOUCH sCurrentTouch;
DS4_TOUCH sPreviousTouch[2];
} Report;

UCHAR ReportBuffer[63];
};
} DS4_REPORT_EX, *PDS4_REPORT_EX;

typedef struct _DS4_OUTPUT_BUFFER
{
//
// The output report buffer
//
_Out_ UCHAR Buffer[64];

} DS4_OUTPUT_BUFFER, *PDS4_OUTPUT_BUFFER;

#include <poppack.h>
146 changes: 77 additions & 69 deletions 3rdparty/ViGEm/km/BusShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,19 @@ DEFINE_GUID(GUID_DEVINTERFACE_BUSENUM_VIGEM,
//
// IO control codes
//
#define IOCTL_VIGEM_PLUGIN_TARGET BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x000)
#define IOCTL_VIGEM_UNPLUG_TARGET BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x001)
#define IOCTL_VIGEM_CHECK_VERSION BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x002)
#define IOCTL_VIGEM_PLUGIN_TARGET BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x000)
#define IOCTL_VIGEM_UNPLUG_TARGET BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x001)
#define IOCTL_VIGEM_CHECK_VERSION BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x002)
#define IOCTL_VIGEM_WAIT_DEVICE_READY BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x003)

#define IOCTL_XUSB_REQUEST_NOTIFICATION BUSENUM_RW_IOCTL(IOCTL_VIGEM_BASE + 0x200)
#define IOCTL_XUSB_SUBMIT_REPORT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x201)
#define IOCTL_DS4_SUBMIT_REPORT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x202)
#define IOCTL_DS4_REQUEST_NOTIFICATION BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x203)
#define IOCTL_XGIP_SUBMIT_REPORT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x204)
#define IOCTL_XGIP_SUBMIT_INTERRUPT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x205)
#define IOCTL_XUSB_GET_USER_INDEX BUSENUM_RW_IOCTL(IOCTL_VIGEM_BASE + 0x206)
#define IOCTL_XUSB_REQUEST_NOTIFICATION BUSENUM_RW_IOCTL(IOCTL_VIGEM_BASE + 0x200)
#define IOCTL_XUSB_SUBMIT_REPORT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x201)
#define IOCTL_DS4_SUBMIT_REPORT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x202)
#define IOCTL_DS4_REQUEST_NOTIFICATION BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x203)
//#define IOCTL_XGIP_SUBMIT_REPORT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x204)
//#define IOCTL_XGIP_SUBMIT_INTERRUPT BUSENUM_W_IOCTL (IOCTL_VIGEM_BASE + 0x205)
#define IOCTL_XUSB_GET_USER_INDEX BUSENUM_RW_IOCTL(IOCTL_VIGEM_BASE + 0x206)
#define IOCTL_DS4_AWAIT_OUTPUT_AVAILABLE BUSENUM_RW_IOCTL(IOCTL_VIGEM_BASE + 0x207)


//
Expand Down Expand Up @@ -184,6 +186,29 @@ VOID FORCEINLINE VIGEM_CHECK_VERSION_INIT(
CheckVersion->Version = Version;
}

#pragma endregion

#pragma region Wait device ready

typedef struct _VIGEM_WAIT_DEVICE_READY
{
IN ULONG Size;

IN ULONG SerialNo;

} VIGEM_WAIT_DEVICE_READY, * PVIGEM_WAIT_DEVICE_READY;

VOID FORCEINLINE VIGEM_WAIT_DEVICE_READY_INIT(
_Out_ PVIGEM_WAIT_DEVICE_READY WaitReady,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(WaitReady, sizeof(VIGEM_WAIT_DEVICE_READY));

WaitReady->Size = sizeof(VIGEM_WAIT_DEVICE_READY);
WaitReady->SerialNo = SerialNo;
}

#pragma endregion

#pragma region XUSB (aka Xbox 360 device) section
Expand Down Expand Up @@ -400,99 +425,82 @@ VOID FORCEINLINE DS4_SUBMIT_REPORT_INIT(
DS4_REPORT_INIT(&Report->Report);
}

#pragma endregion

#pragma region XGIP (aka Xbox One device) section - EXPERIMENTAL

typedef struct _XGIP_REPORT
{
UCHAR Buttons1;
UCHAR Buttons2;
SHORT LeftTrigger;
SHORT RightTrigger;
SHORT ThumbLX;
SHORT ThumbLY;
SHORT ThumbRX;
SHORT ThumbRY;

} XGIP_REPORT, *PXGIP_REPORT;
#include <pshpack1.h>

//
// Xbox One request data
// DualShock 4 extended report request
//
typedef struct _XGIP_SUBMIT_REPORT
typedef struct _DS4_SUBMIT_REPORT_EX
{
//
// sizeof(struct _XGIP_SUBMIT_REPORT)
//
ULONG Size;
// sizeof(struct _DS4_SUBMIT_REPORT_EX)
//
_In_ ULONG Size;

//
// Serial number of target device.
//
ULONG SerialNo;
_In_ ULONG SerialNo;

//
// HID Input report
// Full size HID report excluding fixed Report ID.
//
XGIP_REPORT Report;
_In_ DS4_REPORT_EX Report;

} DS4_SUBMIT_REPORT_EX, * PDS4_SUBMIT_REPORT_EX;

} XGIP_SUBMIT_REPORT, *PXGIP_SUBMIT_REPORT;
#include <poppack.h>

//
// Initializes an Xbox One report.
// Initializes a DualShock 4 extended report.
//
VOID FORCEINLINE XGIP_SUBMIT_REPORT_INIT(
_Out_ PXGIP_SUBMIT_REPORT Report,
VOID FORCEINLINE DS4_SUBMIT_REPORT_EX_INIT(
_Out_ PDS4_SUBMIT_REPORT_EX Report,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(Report, sizeof(XGIP_SUBMIT_REPORT));
RtlZeroMemory(Report, sizeof(DS4_SUBMIT_REPORT_EX));

Report->Size = sizeof(XGIP_SUBMIT_REPORT);
Report->Size = sizeof(DS4_SUBMIT_REPORT_EX);
Report->SerialNo = SerialNo;
}

//
// Xbox One interrupt data
//
typedef struct _XGIP_SUBMIT_INTERRUPT
{
//
// sizeof(struct _XGIP_SUBMIT_INTERRUPT)
//
ULONG Size;
#pragma endregion

//
// Serial number of target device.
//
ULONG SerialNo;
#pragma region DS4 Await Output

//
// Interrupt buffer.
//
UCHAR Interrupt[64];
#include <pshpack1.h>

typedef struct _DS4_AWAIT_OUTPUT
{
//
// sizeof(struct _DS4_AWAIT_OUTPUT)
//
_In_ ULONG Size;

//
// Serial number of target device.
//
_Inout_ ULONG SerialNo;

//
// Length of interrupt buffer.
// The payload
//
ULONG InterruptLength;
_Out_ DS4_OUTPUT_BUFFER Report;

} DS4_AWAIT_OUTPUT, * PDS4_AWAIT_OUTPUT;

} XGIP_SUBMIT_INTERRUPT, *PXGIP_SUBMIT_INTERRUPT;
#include <poppack.h>

//
// Initializes an Xbox One interrupt.
//
VOID FORCEINLINE XGIP_SUBMIT_INTERRUPT_INIT(
_Out_ PXGIP_SUBMIT_INTERRUPT Report,
VOID FORCEINLINE DS4_AWAIT_OUTPUT_INIT(
_Out_ PDS4_AWAIT_OUTPUT Output,
_In_ ULONG SerialNo
)
{
RtlZeroMemory(Report, sizeof(XGIP_SUBMIT_INTERRUPT));
RtlZeroMemory(Output, sizeof(DS4_AWAIT_OUTPUT));

Report->Size = sizeof(XGIP_SUBMIT_INTERRUPT);
Report->SerialNo = SerialNo;
Output->Size = sizeof(DS4_AWAIT_OUTPUT);
Output->SerialNo = SerialNo;
}

#pragma endregion

Binary file modified 3rdparty/libusb-1.0/MS32/libusb-1.0.dll
Binary file not shown.
Binary file modified 3rdparty/libusb-1.0/MS32/libusb-1.0.lib
Binary file not shown.
Binary file modified 3rdparty/libusb-1.0/MS32/libusb-1.0.pdb
Binary file not shown.
Binary file modified 3rdparty/libusb-1.0/MS64/libusb-1.0.dll
Binary file not shown.
Binary file modified 3rdparty/libusb-1.0/MS64/libusb-1.0.lib
Binary file not shown.
Binary file modified 3rdparty/libusb-1.0/MS64/libusb-1.0.pdb
Binary file not shown.
Loading