sysconf stub cuz crash(?) + some stderrp stuff

This commit is contained in:
lizzie 2025-12-01 09:33:59 +00:00
parent 8a76f316fb
commit 550f4f87f0
14 changed files with 506 additions and 73 deletions

View file

@ -41,8 +41,8 @@ Common::Input::DriverResult JoyconDriver::RequestDeviceAccess(SDL_hid_device_inf
return Common::Input::DriverResult::UnsupportedControllerType;
}
hidapi_handle->handle =
SDL_hid_open(device_info->vendor_id, device_info->product_id, device_info->serial_number);
#if SDL_VERSION_ATLEAST(2, 26, 4)
hidapi_handle->handle = SDL_hid_open(device_info->vendor_id, device_info->product_id, device_info->serial_number);
std::memcpy(&handle_serial_number, device_info->serial_number, 15);
if (!hidapi_handle->handle) {
LOG_ERROR(Input, "Yuzu can't gain access to this device: ID {:04X}:{:04X}.",
@ -51,6 +51,9 @@ Common::Input::DriverResult JoyconDriver::RequestDeviceAccess(SDL_hid_device_inf
}
SDL_hid_set_nonblocking(hidapi_handle->handle, 1);
return Common::Input::DriverResult::Success;
#else
return Common::Input::DriverResult::UnsupportedControllerType;
#endif
}
Common::Input::DriverResult JoyconDriver::InitializeDevice() {
@ -141,8 +144,6 @@ void JoyconDriver::InputThread(std::stop_token stop_token) {
Common::SetCurrentThreadName("JoyconInput");
input_thread_running = true;
// Max update rate is 5ms, ensure we are always able to read a bit faster
constexpr int ThreadDelay = 3;
std::vector<u8> buffer(MaxBufferSize);
while (!stop_token.stop_requested()) {
@ -153,14 +154,17 @@ void JoyconDriver::InputThread(std::stop_token stop_token) {
continue;
}
#if SDL_VERSION_ATLEAST(2, 26, 4)
// Max update rate is 5ms, ensure we are always able to read a bit faster
int constexpr thread_delay = 3;
// By disabling the input thread we can ensure custom commands will succeed as no package is
// skipped
if (!disable_input_thread) {
status = SDL_hid_read_timeout(hidapi_handle->handle, buffer.data(), buffer.size(),
ThreadDelay);
status = SDL_hid_read_timeout(hidapi_handle->handle, buffer.data(), buffer.size(), thread_delay);
} else {
std::this_thread::sleep_for(std::chrono::milliseconds(ThreadDelay));
std::this_thread::sleep_for(std::chrono::milliseconds(thread_delay));
}
#endif
if (IsPayloadCorrect(status, buffer)) {
OnNewData(buffer);
@ -693,19 +697,18 @@ void JoyconDriver::SetCallbacks(const JoyconCallbacks& callbacks) {
joycon_poller->SetCallbacks(callbacks);
}
Common::Input::DriverResult JoyconDriver::GetDeviceType(SDL_hid_device_info* device_info,
ControllerType& controller_type) {
Common::Input::DriverResult JoyconDriver::GetDeviceType(SDL_hid_device_info* device_info, ControllerType& controller_type) {
#if SDL_VERSION_ATLEAST(2, 26, 4)
static constexpr std::array<std::pair<u32, ControllerType>, 6> supported_devices{
std::pair<u32, ControllerType>{0x2006, ControllerType::Left},
{0x2007, ControllerType::Right},
{0x2009, ControllerType::Pro},
};
constexpr u16 nintendo_vendor_id = 0x057e;
constexpr u16 nintendo_vendor_id = 0x057e;
controller_type = ControllerType::None;
if (device_info->vendor_id != nintendo_vendor_id) {
if (device_info->vendor_id != nintendo_vendor_id)
return Common::Input::DriverResult::UnsupportedControllerType;
}
for (const auto& [product_id, type] : supported_devices) {
if (device_info->product_id == static_cast<u16>(product_id)) {
@ -713,16 +716,20 @@ Common::Input::DriverResult JoyconDriver::GetDeviceType(SDL_hid_device_info* dev
return Common::Input::DriverResult::Success;
}
}
#endif
return Common::Input::DriverResult::UnsupportedControllerType;
}
Common::Input::DriverResult JoyconDriver::GetSerialNumber(SDL_hid_device_info* device_info,
SerialNumber& serial_number) {
Common::Input::DriverResult JoyconDriver::GetSerialNumber(SDL_hid_device_info* device_info, SerialNumber& serial_number) {
#if SDL_VERSION_ATLEAST(2, 26, 4)
if (device_info->serial_number == nullptr) {
return Common::Input::DriverResult::Unknown;
}
std::memcpy(&serial_number, device_info->serial_number, 15);
return Common::Input::DriverResult::Success;
#else
return Common::Input::DriverResult::Unknown;
#endif
}
} // namespace InputCommon::Joycon

View file

@ -18,11 +18,15 @@ u8 JoyconCommonProtocol::GetCounter() {
}
void JoyconCommonProtocol::SetBlocking() {
#if SDL_VERSION_ATLEAST(2, 26, 4)
SDL_hid_set_nonblocking(hidapi_handle->handle, 0);
#endif
}
void JoyconCommonProtocol::SetNonBlocking() {
#if SDL_VERSION_ATLEAST(2, 26, 4)
SDL_hid_set_nonblocking(hidapi_handle->handle, 1);
#endif
}
Common::Input::DriverResult JoyconCommonProtocol::GetDeviceType(ControllerType& controller_type) {
@ -38,26 +42,23 @@ Common::Input::DriverResult JoyconCommonProtocol::GetDeviceType(ControllerType&
return result;
}
Common::Input::DriverResult JoyconCommonProtocol::CheckDeviceAccess(
SDL_hid_device_info* device_info) {
Common::Input::DriverResult JoyconCommonProtocol::CheckDeviceAccess(SDL_hid_device_info* device_info) {
ControllerType controller_type{ControllerType::None};
const auto result = GetDeviceType(controller_type);
if (result != Common::Input::DriverResult::Success || controller_type == ControllerType::None) {
return Common::Input::DriverResult::UnsupportedControllerType;
}
hidapi_handle->handle =
SDL_hid_open(device_info->vendor_id, device_info->product_id, device_info->serial_number);
#if SDL_VERSION_ATLEAST(2, 26, 4)
hidapi_handle->handle = SDL_hid_open(device_info->vendor_id, device_info->product_id, device_info->serial_number);
if (!hidapi_handle->handle) {
LOG_ERROR(Input, "Yuzu can't gain access to this device: ID {:04X}:{:04X}.",
device_info->vendor_id, device_info->product_id);
LOG_ERROR(Input, "Yuzu can't gain access to this device: ID {:04X}:{:04X}.", device_info->vendor_id, device_info->product_id);
return Common::Input::DriverResult::HandleInUse;
}
SetNonBlocking();
return Common::Input::DriverResult::Success;
#else
return Common::Input::DriverResult::UnsupportedControllerType;
#endif
}
Common::Input::DriverResult JoyconCommonProtocol::SetReportMode(ReportMode report_mode) {
@ -66,21 +67,21 @@ Common::Input::DriverResult JoyconCommonProtocol::SetReportMode(ReportMode repor
}
Common::Input::DriverResult JoyconCommonProtocol::SendRawData(std::span<const u8> buffer) {
const auto result = SDL_hid_write(hidapi_handle->handle, buffer.data(), buffer.size());
if (result == -1) {
#if SDL_VERSION_ATLEAST(2, 26, 4)
auto const result = SDL_hid_write(hidapi_handle->handle, buffer.data(), buffer.size());
if (result == -1)
return Common::Input::DriverResult::ErrorWritingData;
}
return Common::Input::DriverResult::Success;
#else
return Common::Input::DriverResult::ErrorWritingData;
#endif
}
Common::Input::DriverResult JoyconCommonProtocol::GetSubCommandResponse(
SubCommand sc, SubCommandResponse& output) {
Common::Input::DriverResult JoyconCommonProtocol::GetSubCommandResponse(SubCommand sc, SubCommandResponse& output) {
#if SDL_VERSION_ATLEAST(2, 26, 4)
constexpr int timeout_mili = 66;
constexpr int MaxTries = 10;
int tries = 0;
do {
int result = SDL_hid_read_timeout(hidapi_handle->handle, reinterpret_cast<u8*>(&output),
sizeof(SubCommandResponse), timeout_mili);
@ -91,9 +92,8 @@ Common::Input::DriverResult JoyconCommonProtocol::GetSubCommandResponse(
if (tries++ > MaxTries) {
return Common::Input::DriverResult::Timeout;
}
} while (output.input_report.report_mode != ReportMode::SUBCMD_REPLY &&
output.sub_command != sc);
} while (output.input_report.report_mode != ReportMode::SUBCMD_REPLY && output.sub_command != sc);
#endif
return Common::Input::DriverResult::Success;
}
@ -221,12 +221,11 @@ Common::Input::DriverResult JoyconCommonProtocol::ConfigureMCU(const MCUConfig&
return result;
}
Common::Input::DriverResult JoyconCommonProtocol::GetMCUDataResponse(ReportMode report_mode,
MCUCommandResponse& output) {
Common::Input::DriverResult JoyconCommonProtocol::GetMCUDataResponse(ReportMode report_mode, MCUCommandResponse& output) {
#if SDL_VERSION_ATLEAST(2, 26, 4)
constexpr int TimeoutMili = 200;
constexpr int MaxTries = 9;
int tries = 0;
do {
int result = SDL_hid_read_timeout(hidapi_handle->handle, reinterpret_cast<u8*>(&output),
sizeof(MCUCommandResponse), TimeoutMili);
@ -237,9 +236,8 @@ Common::Input::DriverResult JoyconCommonProtocol::GetMCUDataResponse(ReportMode
if (tries++ > MaxTries) {
return Common::Input::DriverResult::Timeout;
}
} while (output.input_report.report_mode != report_mode ||
output.mcu_report == MCUReport::EmptyAwaitingCmd);
} while (output.input_report.report_mode != report_mode || output.mcu_report == MCUReport::EmptyAwaitingCmd);
#endif
return Common::Input::DriverResult::Success;
}

View file

@ -10,7 +10,14 @@
#include <array>
#include <functional>
#include <SDL_hidapi.h>
#include <SDL.h>
#if SDL_VERSION_ATLEAST(2, 26, 4)
# include <SDL_hidapi.h>
#else
struct SDL_hid_device;
struct SDL_hid_device_info;
#endif
#include "common/bit_field.h"
#include "common/common_funcs.h"