Merge pull request #12780 from german77/touch_resource5

service: hid: Fully implement touch resource
This commit is contained in:
liamwhite 2024-02-01 11:33:44 -05:00 • committed by GitHub
commit 6e85d48a8b
32 changed files with 1894 additions and 739 deletions

View file

@ -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));

View file

@ -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();

View file

@ -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

View file

@ -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);
}

View file

@ -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::GetTouchScreenDefaultConfiguration(HLERequestContext& ctx) {
LOG_WARNING(Service_HID, "(STUBBED) called");
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>()};
Core::HID::TouchScreenConfigurationForNx touchscreen_config{
.mode = Core::HID::TouchScreenModeForNx::Finger,
};
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_INFO(Service_HID, "called");
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);
}

View file

@ -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);

View file

@ -12,6 +12,7 @@
#include "common/vector_math.h"
#include "core/hle/service/set/setting_formats/private_settings.h"
#include "core/hle/service/set/settings_types.h"
#include "hid_core/resources/touch_screen/touch_types.h"
namespace Service::Set {
@ -257,8 +258,7 @@ struct SystemSettings {
std::array<u8, 0x10> analog_stick_user_calibration_left;
std::array<u8, 0x10> analog_stick_user_calibration_right;
// nn::settings::system::TouchScreenMode
s32 touch_screen_mode;
TouchScreenMode touch_screen_mode;
INSERT_PADDING_BYTES(0x14); // Reserved
TvSettings tv_settings;

View file

@ -275,8 +275,8 @@ ISystemSettingsServer::ISystemSettingsServer(Core::System& system_)
{184, nullptr, "SetPlatformRegion"},
{185, &ISystemSettingsServer::GetHomeMenuSchemeModel, "GetHomeMenuSchemeModel"},
{186, nullptr, "GetMemoryUsageRateFlag"},
{187, nullptr, "GetTouchScreenMode"},
{188, nullptr, "SetTouchScreenMode"},
{187, &ISystemSettingsServer::GetTouchScreenMode, "GetTouchScreenMode"},
{188, &ISystemSettingsServer::SetTouchScreenMode, "SetTouchScreenMode"},
{189, nullptr, "GetButtonConfigSettingsFull"},
{190, nullptr, "SetButtonConfigSettingsFull"},
{191, nullptr, "GetButtonConfigSettingsEmbedded"},
@ -1395,6 +1395,28 @@ void ISystemSettingsServer::GetHomeMenuSchemeModel(HLERequestContext& ctx) {
rb.Push(0);
}
void ISystemSettingsServer::GetTouchScreenMode(HLERequestContext& ctx) {
TouchScreenMode touch_screen_mode{};
auto res = GetTouchScreenMode(touch_screen_mode);
LOG_INFO(Service_SET, "called, touch_screen_mode={}", touch_screen_mode);
IPC::ResponseBuilder rb{ctx, 3};
rb.Push(res);
rb.PushEnum(touch_screen_mode);
}
void ISystemSettingsServer::SetTouchScreenMode(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const auto touch_screen_mode = rp.PopEnum<TouchScreenMode>();
auto res = SetTouchScreenMode(touch_screen_mode);
LOG_INFO(Service_SET, "called, touch_screen_mode={}", touch_screen_mode);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(res);
}
void ISystemSettingsServer::GetFieldTestingFlag(HLERequestContext& ctx) {
LOG_INFO(Service_SET, "called, field_testing_flag={}", m_system_settings.field_testing_flag);
@ -1670,4 +1692,15 @@ Result ISystemSettingsServer::SetUserSystemClockAutomaticCorrectionUpdatedTime(
R_SUCCEED();
}
Result ISystemSettingsServer::GetTouchScreenMode(TouchScreenMode& touch_screen_mode) const {
touch_screen_mode = m_system_settings.touch_screen_mode;
R_SUCCEED();
}
Result ISystemSettingsServer::SetTouchScreenMode(TouchScreenMode touch_screen_mode) {
m_system_settings.touch_screen_mode = touch_screen_mode;
SetSaveNeeded();
R_SUCCEED();
}
} // namespace Service::Set

View file

@ -74,6 +74,8 @@ public:
Service::PSC::Time::SteadyClockTimePoint& out_time_point) const;
Result SetUserSystemClockAutomaticCorrectionUpdatedTime(
const Service::PSC::Time::SteadyClockTimePoint& time_point);
Result GetTouchScreenMode(TouchScreenMode& touch_screen_mode) const;
Result SetTouchScreenMode(TouchScreenMode touch_screen_mode);
private:
void SetLanguageCode(HLERequestContext& ctx);
@ -154,6 +156,8 @@ private:
void GetChineseTraditionalInputMethod(HLERequestContext& ctx);
void GetHomeMenuScheme(HLERequestContext& ctx);
void GetHomeMenuSchemeModel(HLERequestContext& ctx);
void GetTouchScreenMode(HLERequestContext& ctx);
void SetTouchScreenMode(HLERequestContext& ctx);
void GetFieldTestingFlag(HLERequestContext& ctx);
void GetPanelCrcMode(HLERequestContext& ctx);
void SetPanelCrcMode(HLERequestContext& ctx);

View file

@ -190,9 +190,9 @@ void Config::ReadTouchscreenValues() {
Settings::values.touchscreen.rotation_angle =
static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_angle"), 0));
Settings::values.touchscreen.diameter_x =
static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_diameter_x"), 15));
static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_diameter_x"), 90));
Settings::values.touchscreen.diameter_y =
static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_diameter_y"), 15));
static_cast<u32>(ReadIntegerSetting(std::string("touchscreen_diameter_y"), 90));
}
void Config::ReadAudioValues() {
@ -478,9 +478,9 @@ void Config::SaveTouchscreenValues() {
WriteIntegerSetting(std::string("touchscreen_angle"), touchscreen.rotation_angle,
std::make_optional(static_cast<u32>(0)));
WriteIntegerSetting(std::string("touchscreen_diameter_x"), touchscreen.diameter_x,
std::make_optional(static_cast<u32>(15)));
std::make_optional(static_cast<u32>(90)));
WriteIntegerSetting(std::string("touchscreen_diameter_y"), touchscreen.diameter_y,
std::make_optional(static_cast<u32>(15)));
std::make_optional(static_cast<u32>(90)));
}
void Config::SaveMotionTouchValues() {

View file

@ -99,9 +99,14 @@ add_library(hid_core STATIC
resources/system_buttons/system_button_types.h
resources/touch_screen/gesture.cpp
resources/touch_screen/gesture.h
resources/touch_screen/gesture_types.h
resources/touch_screen/gesture_handler.cpp
resources/touch_screen/gesture_handler.h
resources/touch_screen/touch_screen.cpp
resources/touch_screen/touch_screen.h
resources/touch_screen/touch_screen_driver.cpp
resources/touch_screen/touch_screen_driver.h
resources/touch_screen/touch_screen_resource.cpp
resources/touch_screen/touch_screen_resource.h
resources/touch_screen/touch_types.h
resources/unique_pad/unique_pad.cpp
resources/unique_pad/unique_pad.h

View file

@ -8,6 +8,10 @@
namespace Service::HID {
constexpr Result PalmaResultSuccess{ErrorModule::HID, 0};
constexpr Result ResultTouchNotInitialized{ErrorModule::HID, 41};
constexpr Result ResultTouchOverflow{ErrorModule::HID, 42};
constexpr Result NpadInvalidHandle{ErrorModule::HID, 100};
constexpr Result NpadDeviceIndexOutOfRange{ErrorModule::HID, 107};
@ -23,6 +27,10 @@ constexpr Result InvalidSixAxisFusionRange{ErrorModule::HID, 423};
constexpr Result ResultNfcIsNotReady{ErrorModule::HID, 461};
constexpr Result ResultNfcXcdHandleIsNotInitialized{ErrorModule::HID, 464};
constexpr Result ResultIrSensorIsNotReady{ErrorModule::HID, 501};
constexpr Result ResultGestureOverflow{ErrorModule::HID, 522};
constexpr Result ResultGestureNotInitialized{ErrorModule::HID, 523};
constexpr Result ResultMcuIsNotReady{ErrorModule::HID, 541};
constexpr Result NpadIsDualJoycon{ErrorModule::HID, 601};

View file

@ -299,12 +299,6 @@ enum class GyroscopeZeroDriftMode : u32 {
Tight = 2,
};
// This is nn::settings::system::TouchScreenMode
enum class TouchScreenMode : u32 {
Stylus = 0,
Standard = 1,
};
// This is nn::hid::TouchScreenModeForNx
enum class TouchScreenModeForNx : u8 {
UseSystemSetting,
@ -354,18 +348,6 @@ struct TouchAttribute {
};
static_assert(sizeof(TouchAttribute) == 0x4, "TouchAttribute is an invalid size");
// This is nn::hid::TouchState
struct TouchState {
u64 delta_time{};
TouchAttribute attribute{};
u32 finger{};
Common::Point<u32> position{};
u32 diameter_x{};
u32 diameter_y{};
u32 rotation_angle{};
};
static_assert(sizeof(TouchState) == 0x28, "Touchstate is an invalid size");
struct TouchFinger {
u64 last_touch{};
Common::Point<float> position{};
@ -756,4 +738,14 @@ struct UniquePadId {
};
static_assert(sizeof(UniquePadId) == 0x8, "UniquePadId is an invalid size");
// This is nn::hid::system::FirmwareVersion
struct FirmwareVersion {
u8 major;
u8 minor;
u8 micro;
u8 revision;
std::array<char, 0xc> device_identifier;
};
static_assert(sizeof(FirmwareVersion) == 0x10, "FirmwareVersion is an invalid size");
} // namespace Core::HID

View file

@ -15,6 +15,7 @@
#include "hid_core/resources/applet_resource.h"
#include "hid_core/resources/debug_pad/debug_pad.h"
#include "hid_core/resources/digitizer/digitizer.h"
#include "hid_core/resources/hid_firmware_settings.h"
#include "hid_core/resources/keyboard/keyboard.h"
#include "hid_core/resources/mouse/debug_mouse.h"
#include "hid_core/resources/mouse/mouse.h"
@ -29,6 +30,8 @@
#include "hid_core/resources/system_buttons/sleep_button.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_screen_driver.h"
#include "hid_core/resources/touch_screen/touch_screen_resource.h"
#include "hid_core/resources/unique_pad/unique_pad.h"
#include "hid_core/resources/vibration/gc_vibration_device.h"
#include "hid_core/resources/vibration/n64_vibration_device.h"
@ -45,12 +48,16 @@ constexpr auto default_update_ns = std::chrono::nanoseconds{4 * 1000 * 1000}; //
constexpr auto mouse_keyboard_update_ns = std::chrono::nanoseconds{8 * 1000 * 1000}; // (8ms, 125Hz)
constexpr auto motion_update_ns = std::chrono::nanoseconds{5 * 1000 * 1000}; // (5ms, 200Hz)
ResourceManager::ResourceManager(Core::System& system_)
: system{system_}, service_context{system_, "hid"} {
ResourceManager::ResourceManager(Core::System& system_,
std::shared_ptr<HidFirmwareSettings> settings)
: firmware_settings{settings}, system{system_}, service_context{system_, "hid"} {
applet_resource = std::make_shared<AppletResource>(system);
}
ResourceManager::~ResourceManager() = default;
ResourceManager::~ResourceManager() {
system.CoreTiming().UnscheduleEvent(touch_update_event);
input_event->Finalize();
};
void ResourceManager::Initialize() {
if (is_initialized) {
@ -59,7 +66,9 @@ void ResourceManager::Initialize() {
system.HIDCore().ReloadInputDevices();
handheld_config = std::make_shared<HandheldConfig>();
input_event = service_context.CreateEvent("ResourceManager:InputEvent");
InitializeHandheldConfig();
InitializeHidCommonSampler();
InitializeTouchScreenSampler();
InitializeConsoleSixAxisSampler();
@ -154,6 +163,7 @@ Result ResourceManager::CreateAppletResource(u64 aruid) {
npad->Activate();
six_axis->Activate();
touch_screen->Activate();
gesture->Activate();
return GetNpad()->ActivateNpadResource(aruid);
}
@ -163,6 +173,17 @@ Result ResourceManager::CreateAppletResourceImpl(u64 aruid) {
return applet_resource->CreateAppletResource(aruid);
}
void ResourceManager::InitializeHandheldConfig() {
handheld_config = std::make_shared<HandheldConfig>();
handheld_config->is_handheld_hid_enabled = true;
handheld_config->is_joycon_rail_enabled = true;
handheld_config->is_force_handheld_style_vibration = false;
handheld_config->is_force_handheld = false;
if (firmware_settings->IsHandheldForced()) {
handheld_config->is_joycon_rail_enabled = false;
}
}
void ResourceManager::InitializeHidCommonSampler() {
debug_pad = std::make_shared<DebugPad>(system.HIDCore());
mouse = std::make_shared<Mouse>(system.HIDCore());
@ -170,7 +191,6 @@ void ResourceManager::InitializeHidCommonSampler() {
keyboard = std::make_shared<Keyboard>(system.HIDCore());
unique_pad = std::make_shared<UniquePad>(system.HIDCore());
npad = std::make_shared<NPad>(system.HIDCore(), service_context);
gesture = std::make_shared<Gesture>(system.HIDCore());
home_button = std::make_shared<HomeButton>(system.HIDCore());
sleep_button = std::make_shared<SleepButton>(system.HIDCore());
capture_button = std::make_shared<CaptureButton>(system.HIDCore());
@ -185,7 +205,8 @@ void ResourceManager::InitializeHidCommonSampler() {
const auto settings =
system.ServiceManager().GetService<Service::Set::ISystemSettingsServer>("set:sys", true);
npad->SetNpadExternals(applet_resource, &shared_mutex, handheld_config, settings);
npad->SetNpadExternals(applet_resource, &shared_mutex, handheld_config, input_event,
&input_mutex, settings);
six_axis->SetAppletResource(applet_resource, &shared_mutex);
mouse->SetAppletResource(applet_resource, &shared_mutex);
@ -196,11 +217,25 @@ void ResourceManager::InitializeHidCommonSampler() {
}
void ResourceManager::InitializeTouchScreenSampler() {
gesture = std::make_shared<Gesture>(system.HIDCore());
touch_screen = std::make_shared<TouchScreen>(system.HIDCore());
// This is nn.hid.TouchScreenSampler
touch_resource = std::make_shared<TouchResource>(system);
touch_driver = std::make_shared<TouchDriver>(system.HIDCore());
touch_screen = std::make_shared<TouchScreen>(touch_resource);
gesture = std::make_shared<Gesture>(touch_resource);
touch_screen->SetAppletResource(applet_resource, &shared_mutex);
gesture->SetAppletResource(applet_resource, &shared_mutex);
touch_update_event = Core::Timing::CreateEvent(
"HID::TouchUpdateCallback",
[this](s64 time,
std::chrono::nanoseconds ns_late) -> std::optional<std::chrono::nanoseconds> {
touch_resource->OnTouchUpdate(time);
return std::nullopt;
});
touch_resource->SetTouchDriver(touch_driver);
touch_resource->SetAppletResource(applet_resource, &shared_mutex);
touch_resource->SetInputEvent(input_event, &input_mutex);
touch_resource->SetHandheldConfig(handheld_config);
touch_resource->SetTimerEvent(touch_update_event);
}
void ResourceManager::InitializeConsoleSixAxisSampler() {
@ -388,13 +423,15 @@ Result ResourceManager::SendVibrationValue(u64 aruid,
return result;
}
Result ResourceManager::GetTouchScreenFirmwareVersion(Core::HID::FirmwareVersion& firmware) const {
return ResultSuccess;
}
void ResourceManager::UpdateControllers(std::chrono::nanoseconds ns_late) {
auto& core_timing = system.CoreTiming();
debug_pad->OnUpdate(core_timing);
digitizer->OnUpdate(core_timing);
unique_pad->OnUpdate(core_timing);
gesture->OnUpdate(core_timing);
touch_screen->OnUpdate(core_timing);
palma->OnUpdate(core_timing);
home_button->OnUpdate(core_timing);
sleep_button->OnUpdate(core_timing);

View file

@ -11,6 +11,7 @@ class System;
}
namespace Core::HID {
struct FirmwareVersion;
struct VibrationDeviceHandle;
struct VibrationValue;
struct VibrationDeviceInfo;
@ -21,8 +22,9 @@ struct EventType;
}
namespace Kernel {
class KEvent;
class KSharedMemory;
}
} // namespace Kernel
namespace Service::HID {
class AppletResource;
@ -33,6 +35,7 @@ class DebugMouse;
class DebugPad;
class Digitizer;
class Gesture;
class HidFirmwareSettings;
class HomeButton;
class Keyboard;
class Mouse;
@ -42,6 +45,8 @@ class SevenSixAxis;
class SixAxis;
class SleepButton;
class TouchScreen;
class TouchDriver;
class TouchResource;
class UniquePad;
class NpadVibrationBase;
class NpadN64VibrationDevice;
@ -52,7 +57,7 @@ struct HandheldConfig;
class ResourceManager {
public:
explicit ResourceManager(Core::System& system_);
explicit ResourceManager(Core::System& system_, std::shared_ptr<HidFirmwareSettings> settings);
~ResourceManager();
void Initialize();
@ -102,6 +107,8 @@ public:
Result SendVibrationValue(u64 aruid, const Core::HID::VibrationDeviceHandle& handle,
const Core::HID::VibrationValue& value);
Result GetTouchScreenFirmwareVersion(Core::HID::FirmwareVersion& firmware) const;
void UpdateControllers(std::chrono::nanoseconds ns_late);
void UpdateNpad(std::chrono::nanoseconds ns_late);
void UpdateMouseKeyboard(std::chrono::nanoseconds ns_late);
@ -109,6 +116,7 @@ public:
private:
Result CreateAppletResourceImpl(u64 aruid);
void InitializeHandheldConfig();
void InitializeHidCommonSampler();
void InitializeTouchScreenSampler();
void InitializeConsoleSixAxisSampler();
@ -117,37 +125,46 @@ private:
bool is_initialized{false};
mutable std::recursive_mutex shared_mutex;
std::shared_ptr<AppletResource> applet_resource = nullptr;
std::shared_ptr<AppletResource> applet_resource{nullptr};
std::shared_ptr<CaptureButton> capture_button = nullptr;
std::shared_ptr<ConsoleSixAxis> console_six_axis = nullptr;
std::shared_ptr<DebugMouse> debug_mouse = nullptr;
std::shared_ptr<DebugPad> debug_pad = nullptr;
std::shared_ptr<Digitizer> digitizer = nullptr;
std::shared_ptr<Gesture> gesture = nullptr;
std::shared_ptr<HomeButton> home_button = nullptr;
std::shared_ptr<Keyboard> keyboard = nullptr;
std::shared_ptr<Mouse> mouse = nullptr;
std::shared_ptr<NPad> npad = nullptr;
std::shared_ptr<Palma> palma = nullptr;
std::shared_ptr<SevenSixAxis> seven_six_axis = nullptr;
std::shared_ptr<SixAxis> six_axis = nullptr;
std::shared_ptr<SleepButton> sleep_button = nullptr;
std::shared_ptr<TouchScreen> touch_screen = nullptr;
std::shared_ptr<UniquePad> unique_pad = nullptr;
mutable std::mutex input_mutex;
Kernel::KEvent* input_event{nullptr};
std::shared_ptr<HandheldConfig> handheld_config = nullptr;
std::shared_ptr<HandheldConfig> handheld_config{nullptr};
std::shared_ptr<HidFirmwareSettings> firmware_settings{nullptr};
std::shared_ptr<CaptureButton> capture_button{nullptr};
std::shared_ptr<ConsoleSixAxis> console_six_axis{nullptr};
std::shared_ptr<DebugMouse> debug_mouse{nullptr};
std::shared_ptr<DebugPad> debug_pad{nullptr};
std::shared_ptr<Digitizer> digitizer{nullptr};
std::shared_ptr<HomeButton> home_button{nullptr};
std::shared_ptr<Keyboard> keyboard{nullptr};
std::shared_ptr<Mouse> mouse{nullptr};
std::shared_ptr<NPad> npad{nullptr};
std::shared_ptr<Palma> palma{nullptr};
std::shared_ptr<SevenSixAxis> seven_six_axis{nullptr};
std::shared_ptr<SixAxis> six_axis{nullptr};
std::shared_ptr<SleepButton> sleep_button{nullptr};
std::shared_ptr<UniquePad> unique_pad{nullptr};
// TODO: Create these resources
// std::shared_ptr<AudioControl> audio_control = nullptr;
// std::shared_ptr<ButtonConfig> button_config = nullptr;
// std::shared_ptr<Config> config = nullptr;
// std::shared_ptr<Connection> connection = nullptr;
// std::shared_ptr<CustomConfig> custom_config = nullptr;
// std::shared_ptr<Digitizer> digitizer = nullptr;
// std::shared_ptr<Hdls> hdls = nullptr;
// std::shared_ptr<PlayReport> play_report = nullptr;
// std::shared_ptr<Rail> rail = nullptr;
// std::shared_ptr<AudioControl> audio_control{nullptr};
// std::shared_ptr<ButtonConfig> button_config{nullptr};
// std::shared_ptr<Config> config{nullptr};
// std::shared_ptr<Connection> connection{nullptr};
// std::shared_ptr<CustomConfig> custom_config{nullptr};
// std::shared_ptr<Digitizer> digitizer{nullptr};
// std::shared_ptr<Hdls> hdls{nullptr};
// std::shared_ptr<PlayReport> play_report{nullptr};
// std::shared_ptr<Rail> rail{nullptr};
// Touch Resources
std::shared_ptr<Gesture> gesture{nullptr};
std::shared_ptr<TouchScreen> touch_screen{nullptr};
std::shared_ptr<TouchResource> touch_resource{nullptr};
std::shared_ptr<TouchDriver> touch_driver{nullptr};
std::shared_ptr<Core::Timing::EventType> touch_update_event{nullptr};
Core::System& system;
KernelHelpers::ServiceContext service_context;
@ -162,12 +179,12 @@ public:
private:
void GetSharedMemoryHandle(HLERequestContext& ctx);
std::shared_ptr<Core::Timing::EventType> npad_update_event;
std::shared_ptr<Core::Timing::EventType> default_update_event;
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event;
std::shared_ptr<Core::Timing::EventType> motion_update_event;
std::shared_ptr<Core::Timing::EventType> npad_update_event{nullptr};
std::shared_ptr<Core::Timing::EventType> default_update_event{nullptr};
std::shared_ptr<Core::Timing::EventType> mouse_keyboard_update_event{nullptr};
std::shared_ptr<Core::Timing::EventType> motion_update_event{nullptr};
u64 aruid;
u64 aruid{};
std::shared_ptr<ResourceManager> resource_manager;
};

View file

@ -118,6 +118,12 @@ void AppletResource::UnregisterAppletResourceUserId(u64 aruid) {
data[index].aruid = 0;
registration_list.flag[index] = RegistrationStatus::PendingDelete;
for (std::size_t i = 0; i < AruidIndexMax; i++) {
if (registration_list.flag[i] == RegistrationStatus::Initialized) {
active_aruid = registration_list.aruid[i];
}
}
}
void AppletResource::FreeAppletResourceId(u64 aruid) {

View file

@ -13,11 +13,12 @@
namespace Core {
class System;
}
} // namespace Core
namespace Kernel {
class KEvent;
class KSharedMemory;
}
} // namespace Kernel
namespace Service::HID {
struct SharedMemoryFormat;
@ -73,7 +74,8 @@ struct AppletResourceHolder {
std::recursive_mutex* shared_mutex{nullptr};
NPadResource* shared_npad_resource{nullptr};
std::shared_ptr<HandheldConfig> handheld_config{nullptr};
long* handle_1;
Kernel::KEvent* input_event{nullptr};
std::mutex* input_mutex{nullptr};
};
class AppletResource {

View file

@ -1070,11 +1070,14 @@ void NPad::UnregisterAppletResourceUserId(u64 aruid) {
void NPad::SetNpadExternals(std::shared_ptr<AppletResource> resource,
std::recursive_mutex* shared_mutex,
std::shared_ptr<HandheldConfig> handheld_config,
Kernel::KEvent* input_event, std::mutex* input_mutex,
std::shared_ptr<Service::Set::ISystemSettingsServer> settings) {
applet_resource_holder.applet_resource = resource;
applet_resource_holder.shared_mutex = shared_mutex;
applet_resource_holder.shared_npad_resource = &npad_resource;
applet_resource_holder.handheld_config = handheld_config;
applet_resource_holder.input_event = input_event;
applet_resource_holder.input_mutex = input_mutex;
vibration_handler.SetSettingsService(settings);

View file

@ -131,6 +131,7 @@ public:
void SetNpadExternals(std::shared_ptr<AppletResource> resource,
std::recursive_mutex* shared_mutex,
std::shared_ptr<HandheldConfig> handheld_config,
Kernel::KEvent* input_event, std::mutex* input_mutex,
std::shared_ptr<Service::Set::ISystemSettingsServer> settings);
AppletDetailedUiType GetAppletDetailedUiType(Core::HID::NpadIdType npad_id);
@ -204,9 +205,6 @@ private:
std::array<AbstractPad, MaxSupportedNpadIdTypes> abstracted_pads;
NpadVibration vibration_handler{};
Kernel::KEvent* input_event{nullptr};
std::mutex* input_mutex{nullptr};
std::atomic<u64> press_state{};
std::array<std::array<NpadControllerData, MaxSupportedNpadIdTypes>, AruidIndexMax>
controller_data{};

View file

@ -72,6 +72,12 @@ void NPadResource::UnregisterAppletResourceUserId(u64 aruid) {
state[aruid_index] = {};
registration_list.flag[aruid_index] = RegistrationStatus::PendingDelete;
}
for (std::size_t i = 0; i < AruidIndexMax; i++) {
if (registration_list.flag[i] == RegistrationStatus::Initialized) {
active_data_aruid = registration_list.aruid[i];
}
}
}
void NPadResource::DestroyStyleSetUpdateEvents(u64 aruid) {

Some files were not shown because too many files have changed in this diff Show more