Skip to content

Commit

Permalink
nsyshid: Make Libusb the Windows backend (#1471)
Browse files Browse the repository at this point in the history
  • Loading branch information
deReeperJosh authored Jan 12, 2025
1 parent 8dd809d commit 0a59085
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 757 deletions.
17 changes: 0 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,6 @@ if (WIN32)
endif()
option(ENABLE_CUBEB "Enabled cubeb backend" ON)

# usb hid backends
if (WIN32)
option(ENABLE_NSYSHID_WINDOWS_HID "Enables the native Windows HID backend for nsyshid" ON)
endif ()
# libusb and windows hid backends shouldn't be active at the same time; otherwise we'd see all devices twice!
if (NOT ENABLE_NSYSHID_WINDOWS_HID)
option(ENABLE_NSYSHID_LIBUSB "Enables the libusb backend for nsyshid" ON)
else ()
set(ENABLE_NSYSHID_LIBUSB OFF CACHE BOOL "" FORCE)
endif ()
if (ENABLE_NSYSHID_WINDOWS_HID)
add_compile_definitions(NSYSHID_ENABLE_BACKEND_WINDOWS_HID)
endif ()
if (ENABLE_NSYSHID_LIBUSB)
add_compile_definitions(NSYSHID_ENABLE_BACKEND_LIBUSB)
endif ()

option(ENABLE_WXWIDGETS "Build with wxWidgets UI (Currently required)" ON)

set(THREADS_PREFER_PTHREAD_FLAG true)
Expand Down
21 changes: 10 additions & 11 deletions src/Cafe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,6 @@ add_library(CemuCafe
OS/libs/nsyshid/BackendEmulated.h
OS/libs/nsyshid/BackendLibusb.cpp
OS/libs/nsyshid/BackendLibusb.h
OS/libs/nsyshid/BackendWindowsHID.cpp
OS/libs/nsyshid/BackendWindowsHID.h
OS/libs/nsyshid/Dimensions.cpp
OS/libs/nsyshid/Dimensions.h
OS/libs/nsyshid/Infinity.cpp
Expand Down Expand Up @@ -569,15 +567,16 @@ if (ENABLE_WAYLAND)
target_link_libraries(CemuCafe PUBLIC Wayland::Client)
endif()

if (ENABLE_NSYSHID_LIBUSB)
if (ENABLE_VCPKG)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0)
target_link_libraries(CemuCafe PRIVATE PkgConfig::libusb)
else ()
find_package(libusb MODULE REQUIRED)
target_link_libraries(CemuCafe PRIVATE libusb::libusb)
endif ()
if (ENABLE_VCPKG)
if(WIN32)
set(PKG_CONFIG_EXECUTABLE "${VCPKG_INSTALLED_DIR}/x64-windows/tools/pkgconf/pkgconf.exe")
endif()
find_package(PkgConfig REQUIRED)
pkg_check_modules(libusb REQUIRED IMPORTED_TARGET libusb-1.0)
target_link_libraries(CemuCafe PRIVATE PkgConfig::libusb)
else ()
find_package(libusb MODULE REQUIRED)
target_link_libraries(CemuCafe PRIVATE libusb::libusb)
endif ()

if (ENABLE_WXWIDGETS)
Expand Down
23 changes: 0 additions & 23 deletions src/Cafe/OS/libs/nsyshid/AttachDefaultBackends.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
#include "nsyshid.h"
#include "Backend.h"
#include "BackendEmulated.h"

#if NSYSHID_ENABLE_BACKEND_LIBUSB

#include "BackendLibusb.h"

#endif

#if NSYSHID_ENABLE_BACKEND_WINDOWS_HID

#include "BackendWindowsHID.h"

#endif

namespace nsyshid::backend
{
void AttachDefaultBackends()
{
#if NSYSHID_ENABLE_BACKEND_LIBUSB
// add libusb backend
{
auto backendLibusb = std::make_shared<backend::libusb::BackendLibusb>();
Expand All @@ -27,17 +15,6 @@ namespace nsyshid::backend
AttachBackend(backendLibusb);
}
}
#endif // NSYSHID_ENABLE_BACKEND_LIBUSB
#if NSYSHID_ENABLE_BACKEND_WINDOWS_HID
// add windows hid backend
{
auto backendWindowsHID = std::make_shared<backend::windows::BackendWindowsHID>();
if (backendWindowsHID->IsInitialisedOk())
{
AttachBackend(backendWindowsHID);
}
}
#endif // NSYSHID_ENABLE_BACKEND_WINDOWS_HID
// add emulated backend
{
auto backendEmulated = std::make_shared<backend::emulated::BackendEmulated>();
Expand Down
38 changes: 19 additions & 19 deletions src/Cafe/OS/libs/nsyshid/Backend.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef CEMU_NSYSHID_BACKEND_H
#define CEMU_NSYSHID_BACKEND_H
#pragma once

#include <list>
#include <memory>
Expand All @@ -26,9 +25,9 @@ namespace nsyshid
struct TransferCommand
{
uint8* data;
sint32 length;
uint32 length;

TransferCommand(uint8* data, sint32 length)
TransferCommand(uint8* data, uint32 length)
: data(data), length(length)
{
}
Expand All @@ -39,7 +38,7 @@ namespace nsyshid
{
sint32 bytesRead;

ReadMessage(uint8* data, sint32 length, sint32 bytesRead)
ReadMessage(uint8* data, uint32 length, sint32 bytesRead)
: bytesRead(bytesRead), TransferCommand(data, length)
{
}
Expand All @@ -50,7 +49,7 @@ namespace nsyshid
{
sint32 bytesWritten;

WriteMessage(uint8* data, sint32 length, sint32 bytesWritten)
WriteMessage(uint8* data, uint32 length, sint32 bytesWritten)
: bytesWritten(bytesWritten), TransferCommand(data, length)
{
}
Expand All @@ -59,14 +58,11 @@ namespace nsyshid

struct ReportMessage final : TransferCommand
{
uint8* reportData;
sint32 length;
uint8* originalData;
sint32 originalLength;

ReportMessage(uint8* reportData, sint32 length, uint8* originalData, sint32 originalLength)
: reportData(reportData), length(length), originalData(originalData),
originalLength(originalLength), TransferCommand(reportData, length)
uint8 reportType;
uint8 reportId;

ReportMessage(uint8 reportType, uint8 reportId, uint8* data, uint32 length)
: reportType(reportType), reportId(reportId), TransferCommand(data, length)
{
}
using TransferCommand::TransferCommand;
Expand All @@ -77,7 +73,8 @@ namespace nsyshid
static_assert(offsetof(HID_t, ifIndex) == 0xC, "");
static_assert(offsetof(HID_t, protocol) == 0xE, "");

class Device {
class Device
{
public:
Device() = delete;

Expand Down Expand Up @@ -131,16 +128,21 @@ namespace nsyshid

virtual bool GetDescriptor(uint8 descType,
uint8 descIndex,
uint8 lang,
uint16 lang,
uint8* output,
uint32 outputMaxLength) = 0;

virtual bool SetIdle(uint8 ifIndex,
uint8 reportId,
uint8 duration) = 0;

virtual bool SetProtocol(uint8 ifIndex, uint8 protocol) = 0;

virtual bool SetReport(ReportMessage* message) = 0;
};

class Backend {
class Backend
{
public:
Backend();

Expand Down Expand Up @@ -188,5 +190,3 @@ namespace nsyshid
void AttachDefaultBackends();
}
} // namespace nsyshid

#endif // CEMU_NSYSHID_BACKEND_H
Loading

0 comments on commit 0a59085

Please sign in to comment.