diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 31f781afd..61b25e440 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -513,6 +513,8 @@ add_library(core STATIC hle/service/hid/hid.h hle/service/hid/hid_debug_server.cpp hle/service/hid/hid_debug_server.h + hle/service/hid/hid_firmware_settings.cpp + hle/service/hid/hid_firmware_settings.h hle/service/hid/hid_result.h hle/service/hid/hid_server.cpp hle/service/hid/hid_server.h diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 6c1337e95..6f180fa46 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -11,15 +11,18 @@ #include "core/hle/service/hid/resource_manager.h" #include "core/hle/service/hid/xcd.h" #include "core/hle/service/server_manager.h" +#include "core/hle/service/hid/hid_firmware_settings.h" namespace Service::HID { void LoopProcess(Core::System& system) { auto server_manager = std::make_unique(system); std::shared_ptr resouce_manager = std::make_shared(system); + std::shared_ptr firmware_settings = + std::make_shared(); - server_manager->RegisterNamedService("hid", - std::make_shared(system, resouce_manager)); + server_manager->RegisterNamedService( + "hid", std::make_shared(system, resouce_manager, firmware_settings)); server_manager->RegisterNamedService( "hid:dbg", std::make_shared(system, resouce_manager)); server_manager->RegisterNamedService( diff --git a/src/core/hle/service/hid/hid_debug_server.cpp b/src/core/hle/service/hid/hid_debug_server.cpp index 7ec1c8539..b6c06e502 100644 --- a/src/core/hle/service/hid/hid_debug_server.cpp +++ b/src/core/hle/service/hid/hid_debug_server.cpp @@ -326,11 +326,7 @@ void IHidDebugServer::GetGyroscopeOdr(HLERequestContext& ctx) {} void IHidDebugServer::SetGyroscopeOdr(HLERequestContext& ctx) {} std::shared_ptr IHidDebugServer::GetResourceManager() { - if (!is_resource_manager_initialized) { - resource_manager->Initialize(); - is_resource_manager_initialized = true; - } - + resource_manager->VerifiyInitalization(); return resource_manager; } diff --git a/src/core/hle/service/hid/hid_debug_server.h b/src/core/hle/service/hid/hid_debug_server.h index 3d6f9aa0c..c8b4e5b1f 100644 --- a/src/core/hle/service/hid/hid_debug_server.h +++ b/src/core/hle/service/hid/hid_debug_server.h @@ -36,8 +36,6 @@ private: std::shared_ptr GetResourceManager(); - bool is_resource_manager_initialized{}; - std::shared_ptr resource_manager = nullptr; }; diff --git a/src/core/hle/service/hid/hid_firmware_settings.cpp b/src/core/hle/service/hid/hid_firmware_settings.cpp new file mode 100644 index 000000000..3f27e70a0 --- /dev/null +++ b/src/core/hle/service/hid/hid_firmware_settings.cpp @@ -0,0 +1,148 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/hid/hid_firmware_settings.h" + +namespace Service::HID { + +HidFirmwareSettings::HidFirmwareSettings() { + LoadSettings(true); +} + +void HidFirmwareSettings::Reload() { + LoadSettings(true); +} + +void HidFirmwareSettings::LoadSettings(bool should_initialize) { + // TODO: uncomment this code when we can talk between services + + if (is_debug_settings_initalized && !should_initialize) { + return; + } + + is_debugpad_enabled = true; + // nn::settings::fwdbg::GetSettingsItemValue(&is_debugpad_enabled, 1, "hid_debug", + // "enables_debugpad") + + is_device_managed = true; + // nn::settings::fwdbg::GetSettingsItemValue(&is_device_managed, 1, "hid_debug", + // "manages_devices"); + + is_touch_i2c_managed = is_device_managed; + if (is_device_managed) { + // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_manages_touch_ic_i2c, 1, + // "hid_debug", "manages_touch_ic_i2c"); + } + + is_future_devices_emulated = false; + // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_emulate_future_device, 1, + // "hid_debug", "emulate_future_device"); + + is_mcu_hardware_error_emulated = false; + // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_emulate_mcu_hardware_error, 1, + // "hid_debug", "emulate_mcu_hardware_error"); + + is_rail_enabled = true; + // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_enables_rail, 1, "hid_debug", + // "enables_rail"); + + is_firmware_update_failure_emulated = false; + // nn::settings::fwdbg::GetSettingsItemValue(setting_hid_debug_emulate_firmware_update_failure, + // 1, "hid_debug", "emulate_firmware_update_failure"); + + is_firmware_update_failure = {}; + if (is_firmware_update_failure_emulated) { + const std::size_t size = 0; // GetSettingsItemValueSize("hid_debug", + // "firmware_update_failure"); if (size != 0) { + [[maybe_unused]] const std::size_t setting_size = + std::min(size, is_firmware_update_failure.size()); + // nn::settings::fwdbg::GetSettingsItemValue(&is_firmware_update_failure, setting_size, + // "hid_debug", "firmware_update_failure"); + //} + } + + is_ble_disabled = false; + // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_ble_disabled, 1, "hid_debug", + // "ble_disabled"); + + is_dscale_disabled = false; + // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_dscale_disabled, 1, "hid_debug", + // "dscale_disabled"); + + is_handheld_forced = true; + // nn::settings::fwdbg::GetSettingsItemValue(&force_handheld, 1, "hid_debug", "force_handheld"); + + features_per_id_disabled = {}; + // nn::settings::fwdbg::GetSettingsItemValue(&disabled_features_per_id, + // is_features_per_id_disabled.size(), "hid_debug", + // "disabled_features_per_id"); + + is_touch_firmware_auto_update_disabled = false; + // nn::settings::fwdbg::GetSettingsItemValue( + // &setting_hid_debug_touch_firmware_auto_update_disabled, 1, "hid_debug", + // "touch_firmware_auto_update_disabled"); + + is_debug_settings_initalized = true; +} + +bool HidFirmwareSettings::IsDebugPadEnabled() { + LoadSettings(false); + return is_debugpad_enabled; +} + +bool HidFirmwareSettings::IsDeviceManaged() { + LoadSettings(false); + return is_device_managed; +} + +bool HidFirmwareSettings::IsEmulateFutureDevice() { + LoadSettings(false); + return is_future_devices_emulated; +} + +bool HidFirmwareSettings::IsTouchI2cManaged() { + LoadSettings(false); + return is_touch_i2c_managed; +} + +bool HidFirmwareSettings::IsHandheldForced() { + LoadSettings(false); + return is_handheld_forced; +} + +bool HidFirmwareSettings::IsRailEnabled() { + LoadSettings(false); + return is_rail_enabled; +} + +bool HidFirmwareSettings::IsHardwareErrorEmulated() { + LoadSettings(false); + return is_mcu_hardware_error_emulated; +} + +bool HidFirmwareSettings::IsBleDisabled() { + LoadSettings(false); + return is_ble_disabled; +} + +bool HidFirmwareSettings::IsDscaleDisabled() { + LoadSettings(false); + return is_dscale_disabled; +} + +bool HidFirmwareSettings::IsTouchAutoUpdateDisabled() { + LoadSettings(false); + return is_touch_firmware_auto_update_disabled; +} + +HidFirmwareSettings::FirmwareSetting HidFirmwareSettings::GetFirmwareUpdateFailure() { + LoadSettings(false); + return is_firmware_update_failure; +} + +HidFirmwareSettings::FeaturesPerId HidFirmwareSettings::FeaturesDisabledPerId() { + LoadSettings(false); + return features_per_id_disabled; +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/hid_firmware_settings.h b/src/core/hle/service/hid/hid_firmware_settings.h new file mode 100644 index 000000000..3b55846e6 --- /dev/null +++ b/src/core/hle/service/hid/hid_firmware_settings.h @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/common_types.h" + +namespace Service::HID { + +/// Loads firmware config from nn::settings::fwdbg +class HidFirmwareSettings { +public: + using FirmwareSetting = std::array; + using FeaturesPerId = std::array; + + HidFirmwareSettings(); + + void Reload(); + void LoadSettings(bool should_initialize); + + bool IsDebugPadEnabled(); + bool IsDeviceManaged(); + bool IsEmulateFutureDevice(); + bool IsTouchI2cManaged(); + bool IsHandheldForced(); + bool IsRailEnabled(); + bool IsHardwareErrorEmulated(); + bool IsBleDisabled(); + bool IsDscaleDisabled(); + bool IsTouchAutoUpdateDisabled(); + + FirmwareSetting GetFirmwareUpdateFailure(); + FeaturesPerId FeaturesDisabledPerId(); + +private: + bool is_debug_settings_initalized{}; + + // Debug settings + bool is_debugpad_enabled{}; + bool is_device_managed{}; + bool is_touch_i2c_managed{}; + bool is_future_devices_emulated{}; + bool is_mcu_hardware_error_emulated{}; + bool is_rail_enabled{}; + bool is_firmware_update_failure_emulated{}; + bool is_ble_disabled{}; + bool is_dscale_disabled{}; + bool is_handheld_forced{}; + bool is_touch_firmware_auto_update_disabled{}; + FirmwareSetting is_firmware_update_failure{}; + FeaturesPerId features_per_id_disabled{}; +}; + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index b278b1413..a2d9c462a 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp @@ -19,6 +19,7 @@ #include "core/hle/service/hid/resource_manager/palma.h" #include "core/hle/service/hid/resource_manager/sixaxis.h" #include "core/hle/service/hid/resource_manager/touch_screen.h" +#include "core/hle/service/hid/hid_firmware_settings.h" #include "core/hle/service/ipc_helpers.h" namespace Service::HID { @@ -70,15 +71,16 @@ void IAppletResource::GetSharedMemoryHandle(HLERequestContext& ctx) { rb.PushCopyObjects(&system.Kernel().GetHidSharedMem()); } -IHidServer::IHidServer(Core::System& system_, std::shared_ptr resource) - : ServiceFramework{system_, "hid"}, resource_manager{resource} { +IHidServer::IHidServer(Core::System& system_, std::shared_ptr resource, + std::shared_ptr settings) + : ServiceFramework{system_, "hid"}, resource_manager{resource}, firmware_settings{settings} { // clang-format off static const FunctionInfo functions[] = { {0, &IHidServer::CreateAppletResource, "CreateAppletResource"}, {1, &IHidServer::ActivateDebugPad, "ActivateDebugPad"}, {11, &IHidServer::ActivateTouchScreen, "ActivateTouchScreen"}, {21, &IHidServer::ActivateMouse, "ActivateMouse"}, - {26, nullptr, "ActivateDebugMouse"}, + {26, &IHidServer::ActivateDebugMouse, "ActivateDebugMouse"}, {31, &IHidServer::ActivateKeyboard, "ActivateKeyboard"}, {32, &IHidServer::SendKeyboardLockKeyEvent, "SendKeyboardLockKeyEvent"}, {40, &IHidServer::AcquireXpadIdEventHandle, "AcquireXpadIdEventHandle"}, @@ -258,7 +260,7 @@ void IHidServer::ActivateDebugPad(HLERequestContext& ctx) { Result result = ResultSuccess; auto debug_pad = GetResourceManager()->GetDebugPad(); - if (IsDeviceManaged()) { + if (firmware_settings->IsDeviceManaged()) { result = debug_pad->Activate(applet_resource_user_id); } else { result = debug_pad->Activate(); @@ -277,7 +279,7 @@ void IHidServer::ActivateTouchScreen(HLERequestContext& ctx) { Result result = ResultSuccess; auto touch_screen = GetResourceManager()->GetTouchScreen(); - if (IsDeviceManaged()) { + if (firmware_settings->IsDeviceManaged()) { result = touch_screen->Activate(applet_resource_user_id); } else { result = touch_screen->Activate(); @@ -296,7 +298,26 @@ void IHidServer::ActivateMouse(HLERequestContext& ctx) { Result result = ResultSuccess; auto mouse = GetResourceManager()->GetMouse(); - if (IsDeviceManaged()) { + if (firmware_settings->IsDeviceManaged()) { + result = mouse->Activate(applet_resource_user_id); + } else { + result = mouse->Activate(); + } + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} + +void IHidServer::ActivateDebugMouse(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto applet_resource_user_id{rp.Pop()}; + + LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + + Result result = ResultSuccess; + auto mouse = GetResourceManager()->GetDebugMouse(); + + if (firmware_settings->IsDeviceManaged()) { result = mouse->Activate(applet_resource_user_id); } else { result = mouse->Activate(); @@ -315,7 +336,7 @@ void IHidServer::ActivateKeyboard(HLERequestContext& ctx) { Result result = ResultSuccess; auto keyboard = GetResourceManager()->GetKeyboard(); - if (IsDeviceManaged()) { + if (firmware_settings->IsDeviceManaged()) { result = keyboard->Activate(applet_resource_user_id); } else { result = keyboard->Activate(); @@ -325,7 +346,20 @@ void IHidServer::ActivateKeyboard(HLERequestContext& ctx) { rb.Push(result); } -void IHidServer::SendKeyboardLockKeyEvent(HLERequestContext& ctx) {} +void IHidServer::SendKeyboardLockKeyEvent(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto keyboard_lock_key_event{rp.Pop()}; + const auto applet_resource_user_id{rp.Pop()}; + + LOG_INFO(Service_HID, "called, keyboard_lock_key_event={}, applet_resource_user_id={}", + keyboard_lock_key_event, applet_resource_user_id); + + const Result result = + GetResourceManager()->GetKeyboard()->SendKeyboardLockKeyEvent(keyboard_lock_key_event); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} void IHidServer::AcquireXpadIdEventHandle(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; @@ -978,13 +1012,13 @@ void IHidServer::IsSixAxisSensorAtRest(HLERequestContext& ctx) { parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); - // const auto npad = GetResourceManager()->GetNpad(); - // const auto sixaxis = npad()->GetNpadSharedMemory(parameters.sixaxis_handle); - // const bool is_at_rest = sixaxis->IsAtRest(); + const auto sixaxis_sensor_state = + GetResourceManager()->GetNpad()->GetSixAxisSensorState(parameters.sixaxis_handle); + const bool is_at_rest = sixaxis_sensor_state.IsAtRest(); - // IPC::ResponseBuilder rb{ctx, 3}; - // rb.Push(ResultSuccess); - // rb.Push(is_at_rest); + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(is_at_rest); } void IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor(HLERequestContext& ctx) { @@ -1094,20 +1128,21 @@ void IHidServer::StoreSixAxisSensorCalibrationParameter(HLERequestContext& ctx) parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); - // SixAxisSensorCalibrationParameter calibration{}; - // const auto npad = GetResourceManager()->GetNpad(); - // const auto sixaxis = npad()->GetNpadSharedMemory(parameters.sixaxis_handle); + const auto sixaxis_config = + GetResourceManager()->GetNpad()->GetSixAxisSensorConfig(parameters.sixaxis_handle); - // if (sixaxis == nullptr) { - // IPC::ResponseBuilder rb{ctx, 2}; - // rb.Push(ResultUnknown108); - // } + if (sixaxis_config == nullptr) { + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultUnknown108); + return; + } - // memcpy(&calibration, buffer.data(), sizeof(SixAxisSensorCalibrationParameter)); - // const auto result = sixaxis.StoreSixAxisSensorCalibrationParameter(calibration); + SixAxisSensorCalibrationParameter calibration{}; + memcpy(&calibration, buffer.data(), sizeof(SixAxisSensorCalibrationParameter)); + const auto result = ResultSuccess; // sixaxis_config.StoreSixAxisSensorCalibrationParameter(calibration); - // IPC::ResponseBuilder rb{ctx, 2}; - // rb.Push(result); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); } void IHidServer::LoadSixAxisSensorCalibrationParameter(HLERequestContext& ctx) { @@ -1127,23 +1162,25 @@ void IHidServer::LoadSixAxisSensorCalibrationParameter(HLERequestContext& ctx) { parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); - // SixAxisSensorCalibrationParameter calibration{}; - // const auto npad = GetResourceManager()->GetNpad(); - // const auto sixaxis = npad()->GetNpadSharedMemory(parameters.sixaxis_handle); + const auto sixaxis_config = + GetResourceManager()->GetNpad()->GetSixAxisSensorConfig(parameters.sixaxis_handle); - // if (sixaxis == nullptr) { - // IPC::ResponseBuilder rb{ctx, 2}; - // rb.Push(ResultUnknown108); - // } + if (sixaxis_config == nullptr) { + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultUnknown108); + return; + } - // const auto result = sixaxis.LoadSixAxisSensorCalibrationParameter(calibration); + SixAxisSensorCalibrationParameter calibration{}; + const auto result = + ResultSuccess; // sixaxis_config.LoadSixAxisSensorCalibrationParameter(calibration); - // if (result.IsSuccess()) { - // ctx.WriteBuffer(calibration); - // } + if (result.IsSuccess()) { + ctx.WriteBuffer(calibration); + } - // IPC::ResponseBuilder rb{ctx, 2}; - // rb.Push(result); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); } void IHidServer::GetSixAxisSensorIcInformation(HLERequestContext& ctx) { @@ -1163,23 +1200,24 @@ void IHidServer::GetSixAxisSensorIcInformation(HLERequestContext& ctx) { parameters.sixaxis_handle.npad_type, parameters.sixaxis_handle.npad_id, parameters.sixaxis_handle.device_index, parameters.applet_resource_user_id); - // SixAxisSensorIcInformation ic_information{}; - // const auto npad = GetResourceManager()->GetNpad(); - // const auto sixaxis = npad()->GetNpadSharedMemory(parameters.sixaxis_handle); + const auto sixaxis_config = + GetResourceManager()->GetNpad()->GetSixAxisSensorConfig(parameters.sixaxis_handle); - // if (sixaxis == nullptr) { - // IPC::ResponseBuilder rb{ctx, 2}; - // rb.Push(ResultUnknown108); - // } + if (sixaxis_config == nullptr) { + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultUnknown108); + return; + } - // const auto result = sixaxis.GetSixAxisSensorIcInformation(ic_information); + SixAxisSensorIcInformation ic_information{}; + const auto result = ResultSuccess; // sixaxis.GetSixAxisSensorIcInformation(ic_information); - // if (result.IsSuccess()) { - // ctx.WriteBuffer(ic_information); - // } + if (result.IsSuccess()) { + ctx.WriteBuffer(ic_information); + } - // IPC::ResponseBuilder rb{ctx, 2}; - // rb.Push(result); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); } void IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx) { @@ -1224,7 +1262,7 @@ void IHidServer::ActivateGesture(HLERequestContext& ctx) { Result result = ResultSuccess; auto gesture = GetResourceManager()->GetGesture(); - if (IsDeviceManaged()) { + if (firmware_settings->IsDeviceManaged()) { result = gesture->Activate(parameters.applet_resource_user_id, parameters.basic_gesture_id); } else { result = gesture->Activate(); @@ -2128,7 +2166,7 @@ void IHidServer::ActivateConsoleSixAxisSensor(HLERequestContext& ctx) { Result result = ResultSuccess; auto sixaxis = GetResourceManager()->GetConsoleSixAxis(); - // if (IsDeviceManaged()) { + // if (firmware_settings->IsDeviceManaged()) { // result = sixaxis->Activate(applet_resource_user_id); // } else { // result = sixaxis->Activate(); @@ -2177,7 +2215,7 @@ void IHidServer::ActivateSevenSixAxisSensor(HLERequestContext& ctx) { Result result = ResultSuccess; auto sixaxis = GetResourceManager()->GetConsoleSixAxis(); - // if (IsDeviceManaged()) { + // if (firmware_settings->IsDeviceManaged()) { // result = sixaxis->Activate(applet_resource_user_id); // } else { // result = sixaxis->Activate(); @@ -2854,89 +2892,8 @@ void IHidServer::IsFirmwareUpdateNeededForNotification(HLERequestContext& ctx) { void IHidServer::ActivateDigitizer(HLERequestContext& ctx) {} -bool IHidServer::IsDeviceManaged() { - InitializeDebugSettings(); - return is_device_managed; -} - -void IHidServer::InitializeDebugSettings() { - if (is_debug_settings_initalized) { - return; - } - - // TODO: uncomment this code when we can talk between services - - is_debugpad_enabled = true; - // nn::settings::fwdbg::GetSettingsItemValue(&is_debugpad_enabled, 1, "hid_debug", - // "enables_debugpad") - - is_device_managed = true; - // nn::settings::fwdbg::GetSettingsItemValue(&is_device_managed, 1, "hid_debug", - // "manages_devices"); - - is_touch_i2c_managed = is_device_managed; - if (is_device_managed) { - // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_manages_touch_ic_i2c, 1, - // "hid_debug", "manages_touch_ic_i2c"); - } - - is_future_devices_emulated = false; - // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_emulate_future_device, 1, - // "hid_debug", "emulate_future_device"); - - is_mcu_hardware_error_emulated = false; - // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_emulate_mcu_hardware_error, 1, - // "hid_debug", "emulate_mcu_hardware_error"); - - is_rail_enabled = true; - // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_enables_rail, 1, "hid_debug", - // "enables_rail"); - - is_firmware_update_failure_emulated = false; - // nn::settings::fwdbg::GetSettingsItemValue(setting_hid_debug_emulate_firmware_update_failure, - // 1, "hid_debug", "emulate_firmware_update_failure"); - - is_firmware_update_failure = {}; - if (is_firmware_update_failure_emulated) { - const std::size_t size = 0; // GetSettingsItemValueSize("hid_debug", - // "firmware_update_failure"); if (size != 0) { - [[maybe_unused]] const std::size_t setting_size = - std::min(size, is_firmware_update_failure.size()); - // nn::settings::fwdbg::GetSettingsItemValue(&is_firmware_update_failure, setting_size, - // "hid_debug", "firmware_update_failure"); - //} - } - - is_ble_disabled = false; - // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_ble_disabled, 1, "hid_debug", - // "ble_disabled"); - - is_dscale_disabled = false; - // nn::settings::fwdbg::GetSettingsItemValue(&setting_hid_debug_dscale_disabled, 1, "hid_debug", - // "dscale_disabled"); - - is_handheld_forced = true; - // nn::settings::fwdbg::GetSettingsItemValue(&force_handheld, 1, "hid_debug", "force_handheld"); - - is_features_per_id_disabled = {}; - // nn::settings::fwdbg::GetSettingsItemValue(&disabled_features_per_id, - // is_features_per_id_disabled.size(), "hid_debug", - // "disabled_features_per_id"); - - is_touch_firmware_auto_update_disabled = false; - // nn::settings::fwdbg::GetSettingsItemValue( - // &setting_hid_debug_touch_firmware_auto_update_disabled, 1, "hid_debug", - // "touch_firmware_auto_update_disabled"); - - is_debug_settings_initalized = true; -} - std::shared_ptr IHidServer::GetResourceManager() { - if (!is_resource_manager_initialized) { - resource_manager->Initialize(); - is_resource_manager_initialized = true; - } - + resource_manager->VerifiyInitalization(); return resource_manager; } diff --git a/src/core/hle/service/hid/hid_server.h b/src/core/hle/service/hid/hid_server.h index ac70ca9bc..54f5b8502 100644 --- a/src/core/hle/service/hid/hid_server.h +++ b/src/core/hle/service/hid/hid_server.h @@ -14,6 +14,7 @@ struct VibrationDeviceHandle; struct VibrationValue; class ResourceManager; +class HidFirmwareSettings; } // namespace Service::HID namespace Service::HID { @@ -41,15 +42,16 @@ private: class IHidServer final : public ServiceFramework { public: - explicit IHidServer(Core::System& system_, std::shared_ptr resource); + explicit IHidServer(Core::System& system_, std::shared_ptr resource, + std::shared_ptr settings); ~IHidServer() override; private: - // Service calls void CreateAppletResource(HLERequestContext& ctx); void ActivateDebugPad(HLERequestContext& ctx); void ActivateTouchScreen(HLERequestContext& ctx); void ActivateMouse(HLERequestContext& ctx); + void ActivateDebugMouse(HLERequestContext& ctx); void ActivateKeyboard(HLERequestContext& ctx); void SendKeyboardLockKeyEvent(HLERequestContext& ctx); void AcquireXpadIdEventHandle(HLERequestContext& ctx); @@ -189,31 +191,11 @@ private: Result SendVibrationValueImpl(const u64 aruid, const VibrationDeviceHandle& handle, const VibrationValue& value); - bool IsDeviceManaged(); - void InitializeDebugSettings(); std::shared_ptr GetResourceManager(); - // Server state - bool is_debug_settings_initalized{}; - bool is_resource_manager_initialized{}; - - // Debug settings - bool is_debugpad_enabled{}; - bool is_device_managed{}; - bool is_touch_i2c_managed{}; - bool is_future_devices_emulated{}; - bool is_mcu_hardware_error_emulated{}; - bool is_rail_enabled{}; - bool is_firmware_update_failure_emulated{}; - std::array is_firmware_update_failure{}; - bool is_ble_disabled{}; - bool is_dscale_disabled{}; - bool is_handheld_forced{}; - std::array is_features_per_id_disabled{}; - bool is_touch_firmware_auto_update_disabled{}; - std::shared_ptr resource_manager = nullptr; std::shared_ptr applet_resource = nullptr; + std::shared_ptr firmware_settings = nullptr; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/hid_system_server.cpp b/src/core/hle/service/hid/hid_system_server.cpp index 186f6f7e8..8d1e1765b 100644 --- a/src/core/hle/service/hid/hid_system_server.cpp +++ b/src/core/hle/service/hid/hid_system_server.cpp @@ -396,11 +396,7 @@ void IHidSystemServer::GetTouchScreenDefaultConfiguration(HLERequestContext& ctx } std::shared_ptr IHidSystemServer::GetResourceManager() { - if (!is_resource_manager_initialized) { - resource_manager->Initialize(); - is_resource_manager_initialized = true; - } - + resource_manager->VerifiyInitalization(); return resource_manager; } diff --git a/src/core/hle/service/hid/hid_system_server.h b/src/core/hle/service/hid/hid_system_server.h index c948d5c83..da8a3489d 100644 --- a/src/core/hle/service/hid/hid_system_server.h +++ b/src/core/hle/service/hid/hid_system_server.h @@ -33,8 +33,6 @@ private: std::shared_ptr GetResourceManager(); - bool is_resource_manager_initialized{}; - std::shared_ptr resource_manager = nullptr; }; diff --git a/src/core/hle/service/hid/resource_manager.cpp b/src/core/hle/service/hid/resource_manager.cpp index 3af7f55d2..64024a089 100644 --- a/src/core/hle/service/hid/resource_manager.cpp +++ b/src/core/hle/service/hid/resource_manager.cpp @@ -83,6 +83,14 @@ void ResourceManager::Initialize() { palma = std::make_shared(); sixaxis = std::make_shared(); touch_screen = std::make_shared(); + + is_initialized = true; +} + +void ResourceManager::VerifiyInitalization() { + if (!is_initialized) { + Initialize(); + } } Result ResourceManager::GetVibrationDeviceInfo(VibrationDeviceInfo& out_device_info, @@ -182,6 +190,10 @@ std::shared_ptr ResourceManager::GetMouse() { return mouse; } +std::shared_ptr ResourceManager::GetDebugMouse() { + return debug_mouse; +} + std::shared_ptr ResourceManager::GetNpad() { return npad; } diff --git a/src/core/hle/service/hid/resource_manager.h b/src/core/hle/service/hid/resource_manager.h index 1609b083f..61ac68e62 100644 --- a/src/core/hle/service/hid/resource_manager.h +++ b/src/core/hle/service/hid/resource_manager.h @@ -33,6 +33,7 @@ public: ~ResourceManager(); void Initialize(); + void VerifiyInitalization(); Result GetVibrationDeviceInfo(VibrationDeviceInfo& out_device_info, const VibrationDeviceHandle& handle) const; @@ -42,6 +43,7 @@ public: std::shared_ptr GetGesture(); std::shared_ptr GetKeyboard(); std::shared_ptr GetMouse(); + std::shared_ptr GetDebugMouse(); std::shared_ptr GetNpad(); std::shared_ptr GetPalma(); std::shared_ptr GetSixAxis(); @@ -52,10 +54,13 @@ public: std::shared_ptr GetGCVibration(const VibrationDeviceHandle& handle); std::shared_ptr GetN64Vibration(const VibrationDeviceHandle& handle); + bool is_initialized; + std::shared_ptr debug_pad = nullptr; std::shared_ptr gesture = nullptr; std::shared_ptr keyboard = nullptr; std::shared_ptr mouse = nullptr; + std::shared_ptr debug_mouse = nullptr; std::shared_ptr npad = nullptr; std::shared_ptr palma = nullptr; std::shared_ptr sixaxis = nullptr; diff --git a/src/core/hle/service/hid/resource_manager/keyboard.h b/src/core/hle/service/hid/resource_manager/keyboard.h index 1ec593148..cfc7d8b51 100644 --- a/src/core/hle/service/hid/resource_manager/keyboard.h +++ b/src/core/hle/service/hid/resource_manager/keyboard.h @@ -23,6 +23,8 @@ public: Result Activate(const u64 aruid); Result Activate(); + Result SendKeyboardLockKeyEvent(const u32 keyboard_lock_key_event); + private: bool is_activated; }; diff --git a/src/core/hle/service/hid/resource_manager/npad_resource/npad.cpp b/src/core/hle/service/hid/resource_manager/npad_resource/npad.cpp index 4ea9f6783..668c372b4 100644 --- a/src/core/hle/service/hid/resource_manager/npad_resource/npad.cpp +++ b/src/core/hle/service/hid/resource_manager/npad_resource/npad.cpp @@ -281,6 +281,34 @@ Result Npad::ResetIsSixAxisSensorDeviceNewlyAssigned(const u64 aruid, return ResultSuccess; } +SixAxisSensorSharedState Npad::GetSixAxisSensorState(const SixAxisSensorHandle& handle) { + auto npad_index = NpadIdTypeToIndex(static_cast(handle.device_index)); + if (!IsNpadIdValid(static_cast(handle.npad_id))) { + return; + } + + auto& abtract = abstract_npad_state[npad_index]; + + if (handle.npad_type == NpadStyleIndex::FullKey) { + } + + // TODO: Implement this part +} + +std::shared_ptr Npad::GetSixAxisSensorConfig(const SixAxisSensorHandle& handle) { + auto npad_index = NpadIdTypeToIndex(static_cast(handle.device_index)); + if (!IsNpadIdValid(static_cast(handle.npad_id))) { + return; + } + + auto& abtract = abstract_npad_state[npad_index]; + + if (handle.npad_type == NpadStyleIndex::FullKey) { + } + + return +} + void Npad::SetNpadJoyAssignmentModeSingleByDefault(const u64 aruid, const NpadIdType npad_id) { if (aruid != GetNpadActiveAruid()) { return; diff --git a/src/core/hle/service/hid/resource_manager/npad_resource/npad.h b/src/core/hle/service/hid/resource_manager/npad_resource/npad.h index 852ca95a3..f991ac813 100644 --- a/src/core/hle/service/hid/resource_manager/npad_resource/npad.h +++ b/src/core/hle/service/hid/resource_manager/npad_resource/npad.h @@ -40,6 +40,12 @@ class NpadState; namespace Service::HID { +class SixAxisSensorSharedState { +public: + bool IsAtRest() const; +}; +class SixAxisSensorSharedConfig {}; + class AbstractNpadState { public: explicit AbstractNpadState(); @@ -108,6 +114,9 @@ public: bool IsFirmwareUpdateAvailableForSixAxisSensor(const SixAxisSensorHandle& handle) const; Result ResetIsSixAxisSensorDeviceNewlyAssigned(const u64 aruid, const SixAxisSensorHandle& handle); + SixAxisSensorSharedState GetSixAxisSensorState(const SixAxisSensorHandle& handle); + std::shared_ptr < + SixAxisSensorSharedConfig> GetSixAxisSensorConfig(const SixAxisSensorHandle& handle); // Assignment, merge, swap or split npad void SetNpadJoyAssignmentModeSingleByDefault(const u64 aruid, const NpadIdType npad_id);