diff options
author | liamwhite <[email protected]> | 2024-02-01 11:33:44 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2024-02-01 11:33:44 -0500 |
commit | 21138b6a867632c56330a48a7389430ae2b6e321 (patch) | |
tree | 6be048ee977f29f4c132d0cfb0bcdb79a7c5966d /src/core/hle/service/hid | |
parent | c98d0e185f688bdf241efdfa33c0d3c128648b92 (diff) | |
parent | 87e26de0fca682e48c21edd98c7636e797f8b2f2 (diff) | |
download | yuzu-mainline-21138b6a867632c56330a48a7389430ae2b6e321.tar.gz yuzu-mainline-21138b6a867632c56330a48a7389430ae2b6e321.zip |
Merge pull request #12780 from german77/touch_resource5
service: hid: Fully implement touch resource
Diffstat (limited to 'src/core/hle/service/hid')
-rw-r--r-- | src/core/hle/service/hid/hid.cpp | 5 | ||||
-rw-r--r-- | src/core/hle/service/hid/hid_debug_server.cpp | 196 | ||||
-rw-r--r-- | src/core/hle/service/hid/hid_debug_server.h | 15 | ||||
-rw-r--r-- | src/core/hle/service/hid/hid_server.cpp | 24 | ||||
-rw-r--r-- | src/core/hle/service/hid/hid_system_server.cpp | 64 | ||||
-rw-r--r-- | src/core/hle/service/hid/hid_system_server.h | 3 |
6 files changed, 277 insertions, 30 deletions
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 5b28be577..b60fb9139 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -18,9 +18,10 @@ namespace Service::HID { void LoopProcess(Core::System& system) { auto server_manager = std::make_unique<ServerManager>(system); - std::shared_ptr<ResourceManager> resource_manager = std::make_shared<ResourceManager>(system); std::shared_ptr<HidFirmwareSettings> firmware_settings = std::make_shared<HidFirmwareSettings>(system); + std::shared_ptr<ResourceManager> resource_manager = + std::make_shared<ResourceManager>(system, firmware_settings); // TODO: Remove this hack when am is emulated properly. resource_manager->Initialize(); @@ -31,7 +32,7 @@ void LoopProcess(Core::System& system) { server_manager->RegisterNamedService( "hid", std::make_shared<IHidServer>(system, resource_manager, firmware_settings)); server_manager->RegisterNamedService( - "hid:dbg", std::make_shared<IHidDebugServer>(system, resource_manager)); + "hid:dbg", std::make_shared<IHidDebugServer>(system, resource_manager, firmware_settings)); server_manager->RegisterNamedService( "hid:sys", std::make_shared<IHidSystemServer>(system, resource_manager, firmware_settings)); diff --git a/src/core/hle/service/hid/hid_debug_server.cpp b/src/core/hle/service/hid/hid_debug_server.cpp index f2a767d37..610af34dd 100644 --- a/src/core/hle/service/hid/hid_debug_server.cpp +++ b/src/core/hle/service/hid/hid_debug_server.cpp @@ -1,27 +1,37 @@ // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project // SPDX-License-Identifier: GPL-3.0-or-later +#include <algorithm> + #include "core/hle/service/hid/hid_debug_server.h" #include "core/hle/service/ipc_helpers.h" +#include "hid_core/hid_types.h" #include "hid_core/resource_manager.h" +#include "hid_core/resources/hid_firmware_settings.h" + +#include "hid_core/resources/touch_screen/gesture.h" +#include "hid_core/resources/touch_screen/touch_screen.h" +#include "hid_core/resources/touch_screen/touch_types.h" namespace Service::HID { -IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptr<ResourceManager> resource) - : ServiceFramework{system_, "hid:dbg"}, resource_manager{resource} { +IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptr<ResourceManager> resource, + std::shared_ptr<HidFirmwareSettings> settings) + : ServiceFramework{system_, "hid:dbg"}, resource_manager{resource}, firmware_settings{ + settings} { // clang-format off static const FunctionInfo functions[] = { {0, nullptr, "DeactivateDebugPad"}, {1, nullptr, "SetDebugPadAutoPilotState"}, {2, nullptr, "UnsetDebugPadAutoPilotState"}, - {10, nullptr, "DeactivateTouchScreen"}, - {11, nullptr, "SetTouchScreenAutoPilotState"}, - {12, nullptr, "UnsetTouchScreenAutoPilotState"}, - {13, nullptr, "GetTouchScreenConfiguration"}, - {14, nullptr, "ProcessTouchScreenAutoTune"}, - {15, nullptr, "ForceStopTouchScreenManagement"}, - {16, nullptr, "ForceRestartTouchScreenManagement"}, - {17, nullptr, "IsTouchScreenManaged"}, + {10, &IHidDebugServer::DeactivateTouchScreen, "DeactivateTouchScreen"}, + {11, &IHidDebugServer::SetTouchScreenAutoPilotState, "SetTouchScreenAutoPilotState"}, + {12, &IHidDebugServer::UnsetTouchScreenAutoPilotState, "UnsetTouchScreenAutoPilotState"}, + {13, &IHidDebugServer::GetTouchScreenConfiguration, "GetTouchScreenConfiguration"}, + {14, &IHidDebugServer::ProcessTouchScreenAutoTune, "ProcessTouchScreenAutoTune"}, + {15, &IHidDebugServer::ForceStopTouchScreenManagement, "ForceStopTouchScreenManagement"}, + {16, &IHidDebugServer::ForceRestartTouchScreenManagement, "ForceRestartTouchScreenManagement"}, + {17, &IHidDebugServer::IsTouchScreenManaged, "IsTouchScreenManaged"}, {20, nullptr, "DeactivateMouse"}, {21, nullptr, "SetMouseAutoPilotState"}, {22, nullptr, "UnsetMouseAutoPilotState"}, @@ -37,7 +47,7 @@ IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptr<Resource {60, nullptr, "ClearNpadSystemCommonPolicy"}, {61, nullptr, "DeactivateNpad"}, {62, nullptr, "ForceDisconnectNpad"}, - {91, nullptr, "DeactivateGesture"}, + {91, &IHidDebugServer::DeactivateGesture, "DeactivateGesture"}, {110, nullptr, "DeactivateHomeButton"}, {111, nullptr, "SetHomeButtonAutoPilotState"}, {112, nullptr, "UnsetHomeButtonAutoPilotState"}, @@ -150,6 +160,170 @@ IHidDebugServer::IHidDebugServer(Core::System& system_, std::shared_ptr<Resource } IHidDebugServer::~IHidDebugServer() = default; +void IHidDebugServer::DeactivateTouchScreen(HLERequestContext& ctx) { + LOG_INFO(Service_HID, "called"); + + Result result = ResultSuccess; + + if (!firmware_settings->IsDeviceManaged()) { + result = GetResourceManager()->GetTouchScreen()->Deactivate(); + } + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} + +void IHidDebugServer::SetTouchScreenAutoPilotState(HLERequestContext& ctx) { + AutoPilotState auto_pilot{}; + auto_pilot.count = ctx.GetReadBufferNumElements<TouchState>(); + const auto buffer = ctx.ReadBuffer(); + + auto_pilot.count = std::min(auto_pilot.count, static_cast<u64>(auto_pilot.state.size())); + memcpy(auto_pilot.state.data(), buffer.data(), auto_pilot.count * sizeof(TouchState)); + + LOG_INFO(Service_HID, "called, auto_pilot_count={}", auto_pilot.count); + + const Result result = + GetResourceManager()->GetTouchScreen()->SetTouchScreenAutoPilotState(auto_pilot); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} + +void IHidDebugServer::UnsetTouchScreenAutoPilotState(HLERequestContext& ctx) { + LOG_INFO(Service_HID, "called"); + + const Result result = GetResourceManager()->GetTouchScreen()->UnsetTouchScreenAutoPilotState(); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} + +void IHidDebugServer::GetTouchScreenConfiguration(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto applet_resource_user_id{rp.Pop<u64>()}; + + LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + + Core::HID::TouchScreenConfigurationForNx touchscreen_config{}; + const Result result = GetResourceManager()->GetTouchScreen()->GetTouchScreenConfiguration( + touchscreen_config, applet_resource_user_id); + + if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 && + touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) { + touchscreen_config.mode = Core::HID::TouchScreenModeForNx::UseSystemSetting; + } + + IPC::ResponseBuilder rb{ctx, 6}; + rb.Push(result); + rb.PushRaw(touchscreen_config); +} + +void IHidDebugServer::ProcessTouchScreenAutoTune(HLERequestContext& ctx) { + LOG_INFO(Service_HID, "called"); + + Result result = GetResourceManager()->GetTouchScreen()->ProcessTouchScreenAutoTune(); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} + +void IHidDebugServer::ForceStopTouchScreenManagement(HLERequestContext& ctx) { + LOG_INFO(Service_HID, "called"); + + if (!firmware_settings->IsDeviceManaged()) { + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); + return; + } + + Result result = ResultSuccess; + bool is_touch_active{}; + bool is_gesture_active{}; + auto touch_screen = GetResourceManager()->GetTouchScreen(); + auto gesture = GetResourceManager()->GetGesture(); + + if (firmware_settings->IsTouchI2cManaged()) { + result = touch_screen->IsActive(is_touch_active); + if (result.IsSuccess()) { + result = gesture->IsActive(is_gesture_active); + } + if (result.IsSuccess() && is_touch_active) { + result = touch_screen->Deactivate(); + } + if (result.IsSuccess() && is_gesture_active) { + result = gesture->Deactivate(); + } + } + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} + +void IHidDebugServer::ForceRestartTouchScreenManagement(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + struct Parameters { + u32 basic_gesture_id; + INSERT_PADDING_WORDS_NOINIT(1); + u64 applet_resource_user_id; + }; + static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); + + const auto parameters{rp.PopRaw<Parameters>()}; + + LOG_INFO(Service_HID, "called, basic_gesture_id={}, applet_resource_user_id={}", + parameters.basic_gesture_id, parameters.applet_resource_user_id); + + Result result = ResultSuccess; + auto touch_screen = GetResourceManager()->GetTouchScreen(); + auto gesture = GetResourceManager()->GetGesture(); + + if (firmware_settings->IsDeviceManaged() && firmware_settings->IsTouchI2cManaged()) { + result = gesture->Activate(); + if (result.IsSuccess()) { + result = + gesture->Activate(parameters.applet_resource_user_id, parameters.basic_gesture_id); + } + if (result.IsSuccess()) { + result = touch_screen->Activate(); + } + if (result.IsSuccess()) { + result = touch_screen->Activate(parameters.applet_resource_user_id); + } + } + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} + +void IHidDebugServer::IsTouchScreenManaged(HLERequestContext& ctx) { + LOG_INFO(Service_HID, "called"); + + bool is_touch_active{}; + bool is_gesture_active{}; + + Result result = GetResourceManager()->GetTouchScreen()->IsActive(is_touch_active); + if (result.IsSuccess()) { + result = GetResourceManager()->GetGesture()->IsActive(is_gesture_active); + } + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(result); + rb.Push(is_touch_active | is_gesture_active); +} + +void IHidDebugServer::DeactivateGesture(HLERequestContext& ctx) { + LOG_INFO(Service_HID, "called"); + + Result result = ResultSuccess; + + if (!firmware_settings->IsDeviceManaged()) { + result = GetResourceManager()->GetGesture()->Deactivate(); + } + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} std::shared_ptr<ResourceManager> IHidDebugServer::GetResourceManager() { resource_manager->Initialize(); diff --git a/src/core/hle/service/hid/hid_debug_server.h b/src/core/hle/service/hid/hid_debug_server.h index 406db2211..7d5b082b3 100644 --- a/src/core/hle/service/hid/hid_debug_server.h +++ b/src/core/hle/service/hid/hid_debug_server.h @@ -11,16 +11,29 @@ class System; namespace Service::HID { class ResourceManager; +class HidFirmwareSettings; class IHidDebugServer final : public ServiceFramework<IHidDebugServer> { public: - explicit IHidDebugServer(Core::System& system_, std::shared_ptr<ResourceManager> resource); + explicit IHidDebugServer(Core::System& system_, std::shared_ptr<ResourceManager> resource, + std::shared_ptr<HidFirmwareSettings> settings); ~IHidDebugServer() override; private: + void DeactivateTouchScreen(HLERequestContext& ctx); + void SetTouchScreenAutoPilotState(HLERequestContext& ctx); + void UnsetTouchScreenAutoPilotState(HLERequestContext& ctx); + void GetTouchScreenConfiguration(HLERequestContext& ctx); + void ProcessTouchScreenAutoTune(HLERequestContext& ctx); + void ForceStopTouchScreenManagement(HLERequestContext& ctx); + void ForceRestartTouchScreenManagement(HLERequestContext& ctx); + void IsTouchScreenManaged(HLERequestContext& ctx); + void DeactivateGesture(HLERequestContext& ctx); + std::shared_ptr<ResourceManager> GetResourceManager(); std::shared_ptr<ResourceManager> resource_manager; + std::shared_ptr<HidFirmwareSettings> firmware_settings; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index 938b93451..3603d8ccf 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp @@ -990,8 +990,7 @@ void IHidServer::ActivateGesture(HLERequestContext& ctx) { } if (result.IsSuccess()) { - // TODO: Use gesture id here - result = gesture->Activate(parameters.applet_resource_user_id); + result = gesture->Activate(parameters.applet_resource_user_id, parameters.basic_gesture_id); } IPC::ResponseBuilder rb{ctx, 2}; @@ -2470,14 +2469,22 @@ void IHidServer::GetNpadCommunicationMode(HLERequestContext& ctx) { void IHidServer::SetTouchScreenConfiguration(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto touchscreen_mode{rp.PopRaw<Core::HID::TouchScreenConfigurationForNx>()}; + auto touchscreen_config{rp.PopRaw<Core::HID::TouchScreenConfigurationForNx>()}; const auto applet_resource_user_id{rp.Pop<u64>()}; - LOG_WARNING(Service_HID, "(STUBBED) called, touchscreen_mode={}, applet_resource_user_id={}", - touchscreen_mode.mode, applet_resource_user_id); + LOG_INFO(Service_HID, "called, touchscreen_config={}, applet_resource_user_id={}", + touchscreen_config.mode, applet_resource_user_id); + + if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 && + touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) { + touchscreen_config.mode = Core::HID::TouchScreenModeForNx::UseSystemSetting; + } + + const Result result = GetResourceManager()->GetTouchScreen()->SetTouchScreenConfiguration( + touchscreen_config, applet_resource_user_id); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(result); } void IHidServer::IsFirmwareUpdateNeededForNotification(HLERequestContext& ctx) { @@ -2505,11 +2512,12 @@ void IHidServer::SetTouchScreenResolution(HLERequestContext& ctx) { const auto height{rp.Pop<u32>()}; const auto applet_resource_user_id{rp.Pop<u64>()}; - GetResourceManager()->GetTouchScreen()->SetTouchscreenDimensions(width, height); - LOG_INFO(Service_HID, "called, width={}, height={}, applet_resource_user_id={}", width, height, applet_resource_user_id); + GetResourceManager()->GetTouchScreen()->SetTouchScreenResolution(width, height, + applet_resource_user_id); + IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } diff --git a/src/core/hle/service/hid/hid_system_server.cpp b/src/core/hle/service/hid/hid_system_server.cpp index d1ec42edc..22471e9e2 100644 --- a/src/core/hle/service/hid/hid_system_server.cpp +++ b/src/core/hle/service/hid/hid_system_server.cpp @@ -155,9 +155,9 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptr<Resour {1133, nullptr, "StartUsbFirmwareUpdate"}, {1134, nullptr, "GetUsbFirmwareUpdateState"}, {1135, &IHidSystemServer::InitializeUsbFirmwareUpdateWithoutMemory, "InitializeUsbFirmwareUpdateWithoutMemory"}, - {1150, nullptr, "SetTouchScreenMagnification"}, - {1151, nullptr, "GetTouchScreenFirmwareVersion"}, - {1152, nullptr, "SetTouchScreenDefaultConfiguration"}, + {1150, &IHidSystemServer::SetTouchScreenMagnification, "SetTouchScreenMagnification"}, + {1151, &IHidSystemServer::GetTouchScreenFirmwareVersion, "GetTouchScreenFirmwareVersion"}, + {1152, &IHidSystemServer::SetTouchScreenDefaultConfiguration, "SetTouchScreenDefaultConfiguration"}, {1153, &IHidSystemServer::GetTouchScreenDefaultConfiguration, "GetTouchScreenDefaultConfiguration"}, {1154, nullptr, "IsFirmwareAvailableForNotification"}, {1155, &IHidSystemServer::SetForceHandheldStyleVibration, "SetForceHandheldStyleVibration"}, @@ -845,12 +845,60 @@ void IHidSystemServer::InitializeUsbFirmwareUpdateWithoutMemory(HLERequestContex rb.Push(ResultSuccess); } +void IHidSystemServer::SetTouchScreenMagnification(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto point1x{rp.Pop<f32>()}; + const auto point1y{rp.Pop<f32>()}; + const auto point2x{rp.Pop<f32>()}; + const auto point2y{rp.Pop<f32>()}; + + LOG_INFO(Service_HID, "called, point1=-({},{}), point2=({},{})", point1x, point1y, point2x, + point2y); + + const Result result = GetResourceManager()->GetTouchScreen()->SetTouchScreenMagnification( + point1x, point1y, point2x, point2y); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} + +void IHidSystemServer::GetTouchScreenFirmwareVersion(HLERequestContext& ctx) { + LOG_INFO(Service_HID, "called"); + + Core::HID::FirmwareVersion firmware{}; + const auto result = GetResourceManager()->GetTouchScreenFirmwareVersion(firmware); + + IPC::ResponseBuilder rb{ctx, 6}; + rb.Push(result); + rb.PushRaw(firmware); +} + +void IHidSystemServer::SetTouchScreenDefaultConfiguration(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + auto touchscreen_config{rp.PopRaw<Core::HID::TouchScreenConfigurationForNx>()}; + + LOG_INFO(Service_HID, "called, touchscreen_config={}", touchscreen_config.mode); + + if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 && + touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) { + touchscreen_config.mode = Core::HID::TouchScreenModeForNx::UseSystemSetting; + } + + const Result result = + GetResourceManager()->GetTouchScreen()->SetTouchScreenDefaultConfiguration( + touchscreen_config); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(result); +} + void IHidSystemServer::GetTouchScreenDefaultConfiguration(HLERequestContext& ctx) { - LOG_WARNING(Service_HID, "(STUBBED) called"); + LOG_INFO(Service_HID, "called"); - Core::HID::TouchScreenConfigurationForNx touchscreen_config{ - .mode = Core::HID::TouchScreenModeForNx::Finger, - }; + Core::HID::TouchScreenConfigurationForNx touchscreen_config{}; + const Result result = + GetResourceManager()->GetTouchScreen()->GetTouchScreenDefaultConfiguration( + touchscreen_config); if (touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Heat2 && touchscreen_config.mode != Core::HID::TouchScreenModeForNx::Finger) { @@ -858,7 +906,7 @@ void IHidSystemServer::GetTouchScreenDefaultConfiguration(HLERequestContext& ctx } IPC::ResponseBuilder rb{ctx, 6}; - rb.Push(ResultSuccess); + rb.Push(result); rb.PushRaw(touchscreen_config); } diff --git a/src/core/hle/service/hid/hid_system_server.h b/src/core/hle/service/hid/hid_system_server.h index 4ab4d3931..738313e08 100644 --- a/src/core/hle/service/hid/hid_system_server.h +++ b/src/core/hle/service/hid/hid_system_server.h @@ -71,6 +71,9 @@ private: void FinalizeUsbFirmwareUpdate(HLERequestContext& ctx); void CheckUsbFirmwareUpdateRequired(HLERequestContext& ctx); void InitializeUsbFirmwareUpdateWithoutMemory(HLERequestContext& ctx); + void SetTouchScreenMagnification(HLERequestContext& ctx); + void GetTouchScreenFirmwareVersion(HLERequestContext& ctx); + void SetTouchScreenDefaultConfiguration(HLERequestContext& ctx); void GetTouchScreenDefaultConfiguration(HLERequestContext& ctx); void SetForceHandheldStyleVibration(HLERequestContext& ctx); void IsUsingCustomButtonConfig(HLERequestContext& ctx); |