From 57cf830862bac1d68d660c120014e7d5021b72e8 Mon Sep 17 00:00:00 2001 From: german77 Date: Thu, 2 Nov 2023 17:42:47 -0600 Subject: core: hid: Fix wrong battery values --- src/core/hle/service/hid/controllers/npad.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core/hle/service/hid/controllers') diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index bc822f19e..21695bda2 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -1108,9 +1108,9 @@ Result Controller_NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) { shared_memory->sixaxis_dual_right_properties.raw = 0; shared_memory->sixaxis_left_properties.raw = 0; shared_memory->sixaxis_right_properties.raw = 0; - shared_memory->battery_level_dual = 0; - shared_memory->battery_level_left = 0; - shared_memory->battery_level_right = 0; + shared_memory->battery_level_dual = Core::HID::NpadBatteryLevel::Empty; + shared_memory->battery_level_left = Core::HID::NpadBatteryLevel::Empty; + shared_memory->battery_level_right = Core::HID::NpadBatteryLevel::Empty; shared_memory->fullkey_color = { .attribute = ColorAttribute::NoController, .fullkey = {}, -- cgit v1.2.3 From ae57a99d7d2063661cc15e76e8183122d8e0bc1b Mon Sep 17 00:00:00 2001 From: german77 Date: Sat, 11 Nov 2023 20:54:06 -0600 Subject: core: hid: Split SL and SR buttons --- src/common/settings_input.cpp | 9 +- src/common/settings_input.h | 7 +- src/core/hid/emulated_controller.cpp | 28 +- src/core/hle/service/hid/controllers/npad.cpp | 6 +- src/input_common/drivers/gc_adapter.cpp | 8 +- src/input_common/drivers/joycon.cpp | 8 +- src/input_common/drivers/sdl_driver.cpp | 20 +- src/input_common/drivers/sdl_driver.h | 2 +- src/input_common/drivers/udp_client.cpp | 8 +- src/yuzu/configuration/config.cpp | 1 + src/yuzu/configuration/configure_input_player.cpp | 36 +- src/yuzu/configuration/configure_input_player.ui | 389 ++++++++++++++------- .../configure_input_player_widget.cpp | 45 ++- 13 files changed, 382 insertions(+), 185 deletions(-) (limited to 'src/core/hle/service/hid/controllers') diff --git a/src/common/settings_input.cpp b/src/common/settings_input.cpp index 0a6eea3cf..a6007e7b2 100644 --- a/src/common/settings_input.cpp +++ b/src/common/settings_input.cpp @@ -6,10 +6,11 @@ namespace Settings { namespace NativeButton { const std::array mapping = {{ - "button_a", "button_b", "button_x", "button_y", "button_lstick", - "button_rstick", "button_l", "button_r", "button_zl", "button_zr", - "button_plus", "button_minus", "button_dleft", "button_dup", "button_dright", - "button_ddown", "button_sl", "button_sr", "button_home", "button_screenshot", + "button_a", "button_b", "button_x", "button_y", "button_lstick", + "button_rstick", "button_l", "button_r", "button_zl", "button_zr", + "button_plus", "button_minus", "button_dleft", "button_dup", "button_dright", + "button_ddown", "button_slleft", "button_srleft", "button_home", "button_screenshot", + "button_slright", "button_srright", }}; } diff --git a/src/common/settings_input.h b/src/common/settings_input.h index 46f38c703..53a95ef8f 100644 --- a/src/common/settings_input.h +++ b/src/common/settings_input.h @@ -29,12 +29,15 @@ enum Values : int { DRight, DDown, - SL, - SR, + SLLeft, + SRLeft, Home, Screenshot, + SLRight, + SRRight, + NumButtons, }; diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index b08a71446..34927cddd 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -243,10 +243,12 @@ void EmulatedController::LoadTASParams() { tas_button_params[Settings::NativeButton::DUp].Set("button", 13); tas_button_params[Settings::NativeButton::DRight].Set("button", 14); tas_button_params[Settings::NativeButton::DDown].Set("button", 15); - tas_button_params[Settings::NativeButton::SL].Set("button", 16); - tas_button_params[Settings::NativeButton::SR].Set("button", 17); + tas_button_params[Settings::NativeButton::SLLeft].Set("button", 16); + tas_button_params[Settings::NativeButton::SRLeft].Set("button", 17); tas_button_params[Settings::NativeButton::Home].Set("button", 18); tas_button_params[Settings::NativeButton::Screenshot].Set("button", 19); + tas_button_params[Settings::NativeButton::SLRight].Set("button", 20); + tas_button_params[Settings::NativeButton::SRRight].Set("button", 21); tas_stick_params[Settings::NativeAnalog::LStick].Set("axis_x", 0); tas_stick_params[Settings::NativeAnalog::LStick].Set("axis_y", 1); @@ -296,10 +298,12 @@ void EmulatedController::LoadVirtualGamepadParams() { virtual_button_params[Settings::NativeButton::DUp].Set("button", 13); virtual_button_params[Settings::NativeButton::DRight].Set("button", 14); virtual_button_params[Settings::NativeButton::DDown].Set("button", 15); - virtual_button_params[Settings::NativeButton::SL].Set("button", 16); - virtual_button_params[Settings::NativeButton::SR].Set("button", 17); + virtual_button_params[Settings::NativeButton::SLLeft].Set("button", 16); + virtual_button_params[Settings::NativeButton::SRLeft].Set("button", 17); virtual_button_params[Settings::NativeButton::Home].Set("button", 18); virtual_button_params[Settings::NativeButton::Screenshot].Set("button", 19); + virtual_button_params[Settings::NativeButton::SLRight].Set("button", 20); + virtual_button_params[Settings::NativeButton::SRRight].Set("button", 21); virtual_stick_params[Settings::NativeAnalog::LStick].Set("axis_x", 0); virtual_stick_params[Settings::NativeAnalog::LStick].Set("axis_y", 1); @@ -867,12 +871,16 @@ void EmulatedController::SetButton(const Common::Input::CallbackStatus& callback controller.npad_button_state.down.Assign(current_status.value); controller.debug_pad_button_state.d_down.Assign(current_status.value); break; - case Settings::NativeButton::SL: + case Settings::NativeButton::SLLeft: controller.npad_button_state.left_sl.Assign(current_status.value); + break; + case Settings::NativeButton::SLRight: controller.npad_button_state.right_sl.Assign(current_status.value); break; - case Settings::NativeButton::SR: + case Settings::NativeButton::SRLeft: controller.npad_button_state.left_sr.Assign(current_status.value); + break; + case Settings::NativeButton::SRRight: controller.npad_button_state.right_sr.Assign(current_status.value); break; case Settings::NativeButton::Home: @@ -1890,12 +1898,16 @@ NpadButton EmulatedController::GetTurboButtonMask() const { case Settings::NativeButton::DDown: button_mask.down.Assign(1); break; - case Settings::NativeButton::SL: + case Settings::NativeButton::SLLeft: button_mask.left_sl.Assign(1); + break; + case Settings::NativeButton::SLRight: button_mask.right_sl.Assign(1); break; - case Settings::NativeButton::SR: + case Settings::NativeButton::SRLeft: button_mask.left_sr.Assign(1); + break; + case Settings::NativeButton::SRRight: button_mask.right_sr.Assign(1); break; default: diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 21695bda2..d46bf917e 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -457,12 +457,14 @@ void Controller_NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) { pad_entry.l_stick = stick_state.left; } - if (controller_type == Core::HID::NpadStyleIndex::JoyconLeft) { + if (controller_type == Core::HID::NpadStyleIndex::JoyconLeft || + controller_type == Core::HID::NpadStyleIndex::JoyconDual) { pad_entry.npad_buttons.left_sl.Assign(button_state.left_sl); pad_entry.npad_buttons.left_sr.Assign(button_state.left_sr); } - if (controller_type == Core::HID::NpadStyleIndex::JoyconRight) { + if (controller_type == Core::HID::NpadStyleIndex::JoyconRight || + controller_type == Core::HID::NpadStyleIndex::JoyconDual) { pad_entry.npad_buttons.right_sl.Assign(button_state.right_sl); pad_entry.npad_buttons.right_sr.Assign(button_state.right_sr); } diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp index 3ad34884d..1ff296af5 100644 --- a/src/input_common/drivers/gc_adapter.cpp +++ b/src/input_common/drivers/gc_adapter.cpp @@ -415,7 +415,7 @@ ButtonMapping GCAdapter::GetButtonMappingForDevice(const Common::ParamPackage& p // This list is missing ZL/ZR since those are not considered buttons. // We will add those afterwards // This list also excludes any button that can't be really mapped - static constexpr std::array, 12> + static constexpr std::array, 14> switch_to_gcadapter_button = { std::pair{Settings::NativeButton::A, PadButton::ButtonA}, {Settings::NativeButton::B, PadButton::ButtonB}, @@ -426,8 +426,10 @@ ButtonMapping GCAdapter::GetButtonMappingForDevice(const Common::ParamPackage& p {Settings::NativeButton::DUp, PadButton::ButtonUp}, {Settings::NativeButton::DRight, PadButton::ButtonRight}, {Settings::NativeButton::DDown, PadButton::ButtonDown}, - {Settings::NativeButton::SL, PadButton::TriggerL}, - {Settings::NativeButton::SR, PadButton::TriggerR}, + {Settings::NativeButton::SLLeft, PadButton::TriggerL}, + {Settings::NativeButton::SRLeft, PadButton::TriggerR}, + {Settings::NativeButton::SLRight, PadButton::TriggerL}, + {Settings::NativeButton::SRRight, PadButton::TriggerR}, {Settings::NativeButton::R, PadButton::TriggerZ}, }; if (!params.Has("port")) { diff --git a/src/input_common/drivers/joycon.cpp b/src/input_common/drivers/joycon.cpp index 0aca5a3a3..72d2951f3 100644 --- a/src/input_common/drivers/joycon.cpp +++ b/src/input_common/drivers/joycon.cpp @@ -680,8 +680,8 @@ ButtonMapping Joycons::GetButtonMappingForDevice(const Common::ParamPackage& par Common::ParamPackage sr_button_params = button_params; sl_button_params.Set("button", static_cast(Joycon::PadButton::LeftSL)); sr_button_params.Set("button", static_cast(Joycon::PadButton::LeftSR)); - mapping.insert_or_assign(Settings::NativeButton::SL, std::move(sl_button_params)); - mapping.insert_or_assign(Settings::NativeButton::SR, std::move(sr_button_params)); + mapping.insert_or_assign(Settings::NativeButton::SLLeft, std::move(sl_button_params)); + mapping.insert_or_assign(Settings::NativeButton::SRLeft, std::move(sr_button_params)); } // Map SL and SR buttons for right joycons @@ -693,8 +693,8 @@ ButtonMapping Joycons::GetButtonMappingForDevice(const Common::ParamPackage& par Common::ParamPackage sr_button_params = button_params; sl_button_params.Set("button", static_cast(Joycon::PadButton::RightSL)); sr_button_params.Set("button", static_cast(Joycon::PadButton::RightSR)); - mapping.insert_or_assign(Settings::NativeButton::SL, std::move(sl_button_params)); - mapping.insert_or_assign(Settings::NativeButton::SR, std::move(sr_button_params)); + mapping.insert_or_assign(Settings::NativeButton::SLRight, std::move(sl_button_params)); + mapping.insert_or_assign(Settings::NativeButton::SRRight, std::move(sr_button_params)); } return mapping; diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index 66e3ae9af..78f458afe 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp @@ -828,16 +828,18 @@ ButtonMapping SDLDriver::GetButtonMappingForDevice(const Common::ParamPackage& p ButtonBindings SDLDriver::GetDefaultButtonBinding( const std::shared_ptr& joystick) const { // Default SL/SR mapping for other controllers - auto sl_button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER; - auto sr_button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; + auto sll_button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER; + auto srl_button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; + auto slr_button = SDL_CONTROLLER_BUTTON_LEFTSHOULDER; + auto srr_button = SDL_CONTROLLER_BUTTON_RIGHTSHOULDER; if (joystick->IsJoyconLeft()) { - sl_button = SDL_CONTROLLER_BUTTON_PADDLE2; - sr_button = SDL_CONTROLLER_BUTTON_PADDLE4; + sll_button = SDL_CONTROLLER_BUTTON_PADDLE2; + srl_button = SDL_CONTROLLER_BUTTON_PADDLE4; } if (joystick->IsJoyconRight()) { - sl_button = SDL_CONTROLLER_BUTTON_PADDLE3; - sr_button = SDL_CONTROLLER_BUTTON_PADDLE1; + slr_button = SDL_CONTROLLER_BUTTON_PADDLE3; + srr_button = SDL_CONTROLLER_BUTTON_PADDLE1; } return { @@ -855,8 +857,10 @@ ButtonBindings SDLDriver::GetDefaultButtonBinding( {Settings::NativeButton::DUp, SDL_CONTROLLER_BUTTON_DPAD_UP}, {Settings::NativeButton::DRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT}, {Settings::NativeButton::DDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN}, - {Settings::NativeButton::SL, sl_button}, - {Settings::NativeButton::SR, sr_button}, + {Settings::NativeButton::SLLeft, sll_button}, + {Settings::NativeButton::SRLeft, srl_button}, + {Settings::NativeButton::SLRight, slr_button}, + {Settings::NativeButton::SRRight, srr_button}, {Settings::NativeButton::Home, SDL_CONTROLLER_BUTTON_GUIDE}, {Settings::NativeButton::Screenshot, SDL_CONTROLLER_BUTTON_MISC1}, }; diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h index fcba4e3c6..08e49a0da 100644 --- a/src/input_common/drivers/sdl_driver.h +++ b/src/input_common/drivers/sdl_driver.h @@ -24,7 +24,7 @@ namespace InputCommon { class SDLJoystick; using ButtonBindings = - std::array, 18>; + std::array, 20>; using ZButtonBindings = std::array, 2>; diff --git a/src/input_common/drivers/udp_client.cpp b/src/input_common/drivers/udp_client.cpp index 77db60e92..60821b31a 100644 --- a/src/input_common/drivers/udp_client.cpp +++ b/src/input_common/drivers/udp_client.cpp @@ -396,7 +396,7 @@ std::vector UDPClient::GetInputDevices() const { ButtonMapping UDPClient::GetButtonMappingForDevice(const Common::ParamPackage& params) { // This list excludes any button that can't be really mapped - static constexpr std::array, 20> + static constexpr std::array, 22> switch_to_dsu_button = { std::pair{Settings::NativeButton::A, PadButton::Circle}, {Settings::NativeButton::B, PadButton::Cross}, @@ -412,8 +412,10 @@ ButtonMapping UDPClient::GetButtonMappingForDevice(const Common::ParamPackage& p {Settings::NativeButton::R, PadButton::R1}, {Settings::NativeButton::ZL, PadButton::L2}, {Settings::NativeButton::ZR, PadButton::R2}, - {Settings::NativeButton::SL, PadButton::L2}, - {Settings::NativeButton::SR, PadButton::R2}, + {Settings::NativeButton::SLLeft, PadButton::L2}, + {Settings::NativeButton::SRLeft, PadButton::R2}, + {Settings::NativeButton::SLRight, PadButton::L2}, + {Settings::NativeButton::SRRight, PadButton::R2}, {Settings::NativeButton::LStick, PadButton::L3}, {Settings::NativeButton::RStick, PadButton::R3}, {Settings::NativeButton::Home, PadButton::Home}, diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index baa3e55f3..09cd8d180 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -35,6 +35,7 @@ const std::array Config::default_button Qt::Key_G, Qt::Key_Q, Qt::Key_E, Qt::Key_R, Qt::Key_T, Qt::Key_M, Qt::Key_N, Qt::Key_Left, Qt::Key_Up, Qt::Key_Right, Qt::Key_Down, Qt::Key_Q, Qt::Key_E, 0, 0, + Qt::Key_Q, Qt::Key_E, }; const std::array Config::default_motions = { diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 576f5b571..9259e2a5d 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp @@ -322,11 +322,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i setFocusPolicy(Qt::ClickFocus); button_map = { - ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, - ui->buttonLStick, ui->buttonRStick, ui->buttonL, ui->buttonR, - ui->buttonZL, ui->buttonZR, ui->buttonPlus, ui->buttonMinus, - ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown, - ui->buttonSL, ui->buttonSR, ui->buttonHome, ui->buttonScreenshot, + ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, + ui->buttonLStick, ui->buttonRStick, ui->buttonL, ui->buttonR, + ui->buttonZL, ui->buttonZR, ui->buttonPlus, ui->buttonMinus, + ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown, + ui->buttonSLLeft, ui->buttonSRLeft, ui->buttonHome, ui->buttonScreenshot, + ui->buttonSLRight, ui->buttonSRRight, }; analog_map_buttons = {{ @@ -1181,10 +1182,13 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() { // List of all the widgets that will be hidden by any of the following layouts that need // "unhidden" after the controller type changes - const std::array layout_show = { - ui->buttonShoulderButtonsSLSR, + const std::array layout_show = { + ui->buttonShoulderButtonsSLSRLeft, + ui->buttonShoulderButtonsSLSRRight, ui->horizontalSpacerShoulderButtonsWidget, ui->horizontalSpacerShoulderButtonsWidget2, + ui->horizontalSpacerShoulderButtonsWidget3, + ui->horizontalSpacerShoulderButtonsWidget4, ui->buttonShoulderButtonsLeft, ui->buttonMiscButtonsMinusScreenshot, ui->bottomLeft, @@ -1202,16 +1206,19 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() { std::vector layout_hidden; switch (layout) { case Core::HID::NpadStyleIndex::ProController: - case Core::HID::NpadStyleIndex::JoyconDual: case Core::HID::NpadStyleIndex::Handheld: layout_hidden = { - ui->buttonShoulderButtonsSLSR, + ui->buttonShoulderButtonsSLSRLeft, + ui->buttonShoulderButtonsSLSRRight, ui->horizontalSpacerShoulderButtonsWidget2, + ui->horizontalSpacerShoulderButtonsWidget4, }; break; case Core::HID::NpadStyleIndex::JoyconLeft: layout_hidden = { + ui->buttonShoulderButtonsSLSRRight, ui->horizontalSpacerShoulderButtonsWidget2, + ui->horizontalSpacerShoulderButtonsWidget3, ui->buttonShoulderButtonsRight, ui->buttonMiscButtonsPlusHome, ui->bottomRight, @@ -1219,16 +1226,17 @@ void ConfigureInputPlayer::UpdateControllerAvailableButtons() { break; case Core::HID::NpadStyleIndex::JoyconRight: layout_hidden = { - ui->horizontalSpacerShoulderButtonsWidget, - ui->buttonShoulderButtonsLeft, - ui->buttonMiscButtonsMinusScreenshot, - ui->bottomLeft, + ui->buttonShoulderButtonsSLSRLeft, ui->horizontalSpacerShoulderButtonsWidget, + ui->horizontalSpacerShoulderButtonsWidget4, ui->buttonShoulderButtonsLeft, + ui->buttonMiscButtonsMinusScreenshot, ui->bottomLeft, }; break; case Core::HID::NpadStyleIndex::GameCube: layout_hidden = { - ui->buttonShoulderButtonsSLSR, + ui->buttonShoulderButtonsSLSRLeft, + ui->buttonShoulderButtonsSLSRRight, ui->horizontalSpacerShoulderButtonsWidget2, + ui->horizontalSpacerShoulderButtonsWidget4, ui->buttonMiscButtonsMinusGroup, ui->buttonMiscButtonsScreenshotGroup, }; diff --git a/src/yuzu/configuration/configure_input_player.ui b/src/yuzu/configuration/configure_input_player.ui index 611a79477..5518cccd1 100644 --- a/src/yuzu/configuration/configure_input_player.ui +++ b/src/yuzu/configuration/configure_input_player.ui @@ -1208,6 +1208,159 @@ 3 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + SL + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 68 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + SL + + + + + + + + + + SR + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 68 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + SR + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + @@ -1830,125 +1983,125 @@ - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - SL - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - SL - - - - - - - - - - SR - - - Qt::AlignCenter - - - - 3 - - - 3 - - - 3 - - - 3 - - - 3 - - - - - - 68 - 0 - - - - - 68 - 16777215 - - - - min-width: 68px; - - - SR - - - + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + SL + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 68 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + SL + + + + + + + + + + SR + + + Qt::AlignCenter + + + + 3 + + + 3 + + + 3 + + + 3 + + + 3 + + + + + + 68 + 0 + + + + + 68 + 16777215 + + + + min-width: 68px; + + + SR + + + + + + - - - - - + + diff --git a/src/yuzu/configuration/configure_input_player_widget.cpp b/src/yuzu/configuration/configure_input_player_widget.cpp index a188eef92..550cff9a0 100644 --- a/src/yuzu/configuration/configure_input_player_widget.cpp +++ b/src/yuzu/configuration/configure_input_player_widget.cpp @@ -297,8 +297,8 @@ void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center) // Sideview SL and SR buttons button_color = colors.slider_button; - DrawRoundButton(p, center + QPoint(59, 52), button_values[SR], 5, 12, Direction::Left); - DrawRoundButton(p, center + QPoint(59, -69), button_values[SL], 5, 12, Direction::Left); + DrawRoundButton(p, center + QPoint(59, 52), button_values[SRLeft], 5, 12, Direction::Left); + DrawRoundButton(p, center + QPoint(59, -69), button_values[SLLeft], 5, 12, Direction::Left); DrawLeftBody(p, center); @@ -353,8 +353,10 @@ void PlayerControlPreview::DrawLeftController(QPainter& p, const QPointF center) // SR and SL buttons p.setPen(colors.outline); button_color = colors.slider_button; - DrawRoundButton(p, center + QPoint(155, 52), button_values[SR], 5.2f, 12, Direction::None, 4); - DrawRoundButton(p, center + QPoint(155, -69), button_values[SL], 5.2f, 12, Direction::None, 4); + DrawRoundButton(p, center + QPoint(155, 52), button_values[SRLeft], 5.2f, 12, Direction::None, + 4); + DrawRoundButton(p, center + QPoint(155, -69), button_values[SLLeft], 5.2f, 12, Direction::None, + 4); // SR and SL text p.setPen(colors.transparent); @@ -428,8 +430,10 @@ void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center // Sideview SL and SR buttons button_color = colors.slider_button; - DrawRoundButton(p, center + QPoint(-59, 52), button_values[SL], 5, 11, Direction::Right); - DrawRoundButton(p, center + QPoint(-59, -69), button_values[SR], 5, 11, Direction::Right); + DrawRoundButton(p, center + QPoint(-59, 52), button_values[SLRight], 5, 11, + Direction::Right); + DrawRoundButton(p, center + QPoint(-59, -69), button_values[SRRight], 5, 11, + Direction::Right); DrawRightBody(p, center); @@ -484,8 +488,10 @@ void PlayerControlPreview::DrawRightController(QPainter& p, const QPointF center // SR and SL buttons p.setPen(colors.outline); button_color = colors.slider_button; - DrawRoundButton(p, center + QPoint(-155, 52), button_values[SL], 5, 12, Direction::None, 4.0f); - DrawRoundButton(p, center + QPoint(-155, -69), button_values[SR], 5, 12, Direction::None, 4.0f); + DrawRoundButton(p, center + QPoint(-155, 52), button_values[SLRight], 5, 12, Direction::None, + 4.0f); + DrawRoundButton(p, center + QPoint(-155, -69), button_values[SRRight], 5, 12, Direction::None, + 4.0f); // SR and SL text p.setPen(colors.transparent); @@ -557,6 +563,19 @@ void PlayerControlPreview::DrawDualController(QPainter& p, const QPointF center) DrawRoundButton(p, center + QPoint(-154, -72), button_values[Minus], 7, 4, Direction::Up, 1); + // Left SR and SL sideview buttons + button_color = colors.slider_button; + DrawRoundButton(p, center + QPoint(-20, -62), button_values[SLLeft], 4, 11, + Direction::Left); + DrawRoundButton(p, center + QPoint(-20, 47), button_values[SRLeft], 4, 11, Direction::Left); + + // Right SR and SL sideview buttons + button_color = colors.slider_button; + DrawRoundButton(p, center + QPoint(20, 47), button_values[SLRight], 4, 11, + Direction::Right); + DrawRoundButton(p, center + QPoint(20, -62), button_values[SRRight], 4, 11, + Direction::Right); + DrawDualBody(p, center); // Right trigger top view @@ -1792,16 +1811,6 @@ void PlayerControlPreview::DrawDualBody(QPainter& p, const QPointF center) { p.setBrush(colors.right); DrawPolygon(p, qright_joycon_topview); - // Right SR and SL sideview buttons - p.setPen(colors.outline); - p.setBrush(colors.slider_button); - DrawRoundRectangle(p, center + QPoint(19, 47), 7, 22, 1); - DrawRoundRectangle(p, center + QPoint(19, -62), 7, 22, 1); - - // Left SR and SL sideview buttons - DrawRoundRectangle(p, center + QPoint(-19, 47), 7, 22, 1); - DrawRoundRectangle(p, center + QPoint(-19, -62), 7, 22, 1); - // Right Sideview body p.setBrush(colors.slider); DrawPolygon(p, qright_joycon_slider); -- cgit v1.2.3 From 862e66202c1e612f56dad9bb0d9403b4af502178 Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Thu, 16 Nov 2023 17:58:05 -0600 Subject: service: hid: Introduce firmware settings and update activate controller calls --- src/core/CMakeLists.txt | 2 + .../service/hid/controllers/controller_base.cpp | 9 +- .../hle/service/hid/controllers/controller_base.h | 4 +- src/core/hle/service/hid/controllers/npad.h | 7 + src/core/hle/service/hid/controllers/palma.cpp | 2 +- src/core/hle/service/hid/hid.cpp | 7 +- src/core/hle/service/hid/hid_firmware_settings.cpp | 99 ++++++++++++++ src/core/hle/service/hid/hid_firmware_settings.h | 54 ++++++++ src/core/hle/service/hid/hid_server.cpp | 146 ++++++++++++++++----- src/core/hle/service/hid/hid_server.h | 5 +- src/core/hle/service/hid/resource_manager.cpp | 12 +- src/core/hle/service/hid/resource_manager.h | 2 - 12 files changed, 295 insertions(+), 54 deletions(-) create mode 100644 src/core/hle/service/hid/hid_firmware_settings.cpp create mode 100644 src/core/hle/service/hid/hid_firmware_settings.h (limited to 'src/core/hle/service/hid/controllers') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 3aa2e4340..555807e19 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -523,6 +523,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_server.cpp hle/service/hid/hid_server.h hle/service/hid/hid_system_server.cpp diff --git a/src/core/hle/service/hid/controllers/controller_base.cpp b/src/core/hle/service/hid/controllers/controller_base.cpp index c58d67d7d..0bcd87062 100644 --- a/src/core/hle/service/hid/controllers/controller_base.cpp +++ b/src/core/hle/service/hid/controllers/controller_base.cpp @@ -8,12 +8,17 @@ namespace Service::HID { ControllerBase::ControllerBase(Core::HID::HIDCore& hid_core_) : hid_core(hid_core_) {} ControllerBase::~ControllerBase() = default; -void ControllerBase::ActivateController() { +Result ControllerBase::Activate() { if (is_activated) { - return; + return ResultSuccess; } is_activated = true; OnInit(); + return ResultSuccess; +} + +Result ControllerBase::Activate(u64 aruid) { + return Activate(); } void ControllerBase::DeactivateController() { diff --git a/src/core/hle/service/hid/controllers/controller_base.h b/src/core/hle/service/hid/controllers/controller_base.h index d6f7a5073..9a44ee41e 100644 --- a/src/core/hle/service/hid/controllers/controller_base.h +++ b/src/core/hle/service/hid/controllers/controller_base.h @@ -4,6 +4,7 @@ #pragma once #include "common/common_types.h" +#include "core/hle/result.h" namespace Core::Timing { class CoreTiming; @@ -31,7 +32,8 @@ public: // When the controller is requesting a motion update for the shared memory virtual void OnMotionUpdate(const Core::Timing::CoreTiming& core_timing) {} - void ActivateController(); + Result Activate(); + Result Activate(u64 aruid); void DeactivateController(); diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index 949e58a4c..e23b4986c 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -86,6 +86,13 @@ public: Default = 3, }; + enum class NpadRevision : u32 { + Revision0 = 0, + Revision1 = 1, + Revision2 = 2, + Revision3 = 3, + }; + void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set); Core::HID::NpadStyleTag GetSupportedStyleSet() const; diff --git a/src/core/hle/service/hid/controllers/palma.cpp b/src/core/hle/service/hid/controllers/palma.cpp index 73a2a2b91..51a18335f 100644 --- a/src/core/hle/service/hid/controllers/palma.cpp +++ b/src/core/hle/service/hid/controllers/palma.cpp @@ -44,7 +44,7 @@ Result Controller_Palma::InitializePalma(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } - ActivateController(); + Activate(); return ResultSuccess; } diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 801a4d08f..1b7381d8d 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -3,6 +3,7 @@ #include "core/hle/service/hid/hid.h" #include "core/hle/service/hid/hid_debug_server.h" +#include "core/hle/service/hid/hid_firmware_settings.h" #include "core/hle/service/hid/hid_server.h" #include "core/hle/service/hid/hid_system_server.h" #include "core/hle/service/hid/hidbus.h" @@ -16,9 +17,11 @@ 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_firmware_settings.cpp b/src/core/hle/service/hid/hid_firmware_settings.cpp new file mode 100644 index 000000000..59bd6825c --- /dev/null +++ b/src/core/hle/service/hid/hid_firmware_settings.cpp @@ -0,0 +1,99 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.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 reload_config) { + if (is_initalized && !reload_config) { + return; + } + + // TODO: Use nn::settings::fwdbg::GetSettingsItemValue to load config values + + is_debug_pad_enabled = true; + is_device_managed = true; + is_touch_i2c_managed = is_device_managed; + is_future_devices_emulated = false; + is_mcu_hardware_error_emulated = false; + is_rail_enabled = true; + is_firmware_update_failure_emulated = false; + is_firmware_update_failure = {}; + is_ble_disabled = false; + is_dscale_disabled = false; + is_handheld_forced = true; + features_per_id_disabled = {}; + is_touch_firmware_auto_update_disabled = false; + is_initalized = true; +} + +bool HidFirmwareSettings::IsDebugPadEnabled() { + LoadSettings(false); + return is_debug_pad_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..6c10c440b --- /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-3.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 reload_config); + + 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_initalized{}; + + // Debug settings + bool is_debug_pad_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 2fb31cf47..0be6a7186 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp @@ -10,6 +10,7 @@ #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/kernel/kernel.h" #include "core/hle/service/hid/errors.h" +#include "core/hle/service/hid/hid_firmware_settings.h" #include "core/hle/service/hid/hid_server.h" #include "core/hle/service/hid/resource_manager.h" #include "core/hle/service/ipc_helpers.h" @@ -64,8 +65,9 @@ private: std::shared_ptr resource_manager; }; -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"}, @@ -230,48 +232,87 @@ void IHidServer::ActivateDebugPad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager()->ActivateController(HidController::DebugPad); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + Result result = ResultSuccess; + auto& debug_pad = + GetResourceManager()->GetController(HidController::DebugPad); + + if (!firmware_settings->IsDeviceManaged()) { + result = debug_pad.Activate(); + } + + if (result.IsSuccess()) { + result = debug_pad.Activate(applet_resource_user_id); + } + IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(result); } void IHidServer::ActivateTouchScreen(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager()->ActivateController(HidController::Touchscreen); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + Result result = ResultSuccess; + auto& touch_screen = + GetResourceManager()->GetController(HidController::Touchscreen); + + if (!firmware_settings->IsDeviceManaged()) { + result = touch_screen.Activate(); + } + + if (result.IsSuccess()) { + result = touch_screen.Activate(applet_resource_user_id); + } + IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(result); } void IHidServer::ActivateMouse(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager()->ActivateController(HidController::Mouse); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + Result result = ResultSuccess; + auto& mouse = GetResourceManager()->GetController(HidController::Mouse); + + if (!firmware_settings->IsDeviceManaged()) { + result = mouse.Activate(); + } + + if (result.IsSuccess()) { + result = mouse.Activate(applet_resource_user_id); + } + IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(result); } void IHidServer::ActivateKeyboard(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager()->ActivateController(HidController::Keyboard); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + Result result = ResultSuccess; + auto& keyboard = + GetResourceManager()->GetController(HidController::Keyboard); + + if (!firmware_settings->IsDeviceManaged()) { + result = keyboard.Activate(); + } + + if (result.IsSuccess()) { + result = keyboard.Activate(applet_resource_user_id); + } + IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(result); } void IHidServer::SendKeyboardLockKeyEvent(HLERequestContext& ctx) { @@ -898,7 +939,7 @@ void IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx) void IHidServer::ActivateGesture(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { - u32 unknown; + u32 basic_gesture_id; INSERT_PADDING_WORDS_NOINIT(1); u64 applet_resource_user_id; }; @@ -906,13 +947,23 @@ void IHidServer::ActivateGesture(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - GetResourceManager()->ActivateController(HidController::Gesture); + LOG_INFO(Service_HID, "called, basic_gesture_id={}, applet_resource_user_id={}", + parameters.basic_gesture_id, parameters.applet_resource_user_id); - LOG_WARNING(Service_HID, "(STUBBED) called, unknown={}, applet_resource_user_id={}", - parameters.unknown, parameters.applet_resource_user_id); + Result result = ResultSuccess; + auto& gesture = GetResourceManager()->GetController(HidController::Gesture); + + if (!firmware_settings->IsDeviceManaged()) { + result = gesture.Activate(); + } + + if (result.IsSuccess()) { + // TODO: Use gesture id here + result = gesture.Activate(parameters.applet_resource_user_id); + } IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(result); } void IHidServer::SetSupportedNpadStyleSet(HLERequestContext& ctx) { @@ -969,22 +1020,25 @@ void IHidServer::ActivateNpad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager()->ActivateController(HidController::NPad); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + auto& npad = GetResourceManager()->GetController(HidController::NPad); + + // TODO: npad->SetRevision(applet_resource_user_id, NpadRevision::Revision0); + const Result result = npad.Activate(applet_resource_user_id); + IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(result); } void IHidServer::DeactivateNpad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager()->DeactivateController(HidController::NPad); - LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + // This function does nothing since 10.0.0+ + IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); } @@ -1053,10 +1107,9 @@ void IHidServer::GetPlayerLedPattern(HLERequestContext& ctx) { } void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) { - // Should have no effect with how our npad sets up the data IPC::RequestParser rp{ctx}; struct Parameters { - s32 revision; + Controller_NPad::NpadRevision revision; INSERT_PADDING_WORDS_NOINIT(1); u64 applet_resource_user_id; }; @@ -1064,13 +1117,16 @@ void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - GetResourceManager()->ActivateController(HidController::NPad); - LOG_DEBUG(Service_HID, "called, revision={}, applet_resource_user_id={}", parameters.revision, parameters.applet_resource_user_id); + auto& npad = GetResourceManager()->GetController(HidController::NPad); + + // TODO: npad->SetRevision(applet_resource_user_id, revision); + const auto result = npad.Activate(parameters.applet_resource_user_id); + IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(result); } void IHidServer::SetNpadJoyHoldType(HLERequestContext& ctx) { @@ -1718,12 +1774,22 @@ void IHidServer::ActivateConsoleSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager()->ActivateController(HidController::ConsoleSixAxisSensor); + LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + Result result = ResultSuccess; + auto console_sixaxis = GetResourceManager()->GetController( + HidController::ConsoleSixAxisSensor); + + if (!firmware_settings->IsDeviceManaged()) { + result = console_sixaxis.Activate(); + } + + if (result.IsSuccess()) { + result = console_sixaxis.Activate(applet_resource_user_id); + } IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(result); } void IHidServer::StartConsoleSixAxisSensor(HLERequestContext& ctx) { @@ -1770,9 +1836,19 @@ void IHidServer::ActivateSevenSixAxisSensor(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager()->ActivateController(HidController::ConsoleSixAxisSensor); + LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); + Result result = ResultSuccess; + auto console_sixaxis = GetResourceManager()->GetController( + HidController::ConsoleSixAxisSensor); + + if (!firmware_settings->IsDeviceManaged()) { + result = console_sixaxis.Activate(); + } + + if (result.IsSuccess()) { + console_sixaxis.Activate(applet_resource_user_id); + } IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -1837,7 +1913,7 @@ void IHidServer::InitializeSevenSixAxisSensor(HLERequestContext& ctx) { // Activate console six axis controller GetResourceManager() ->GetController(HidController::ConsoleSixAxisSensor) - .ActivateController(); + .Activate(); GetResourceManager() ->GetController(HidController::ConsoleSixAxisSensor) diff --git a/src/core/hle/service/hid/hid_server.h b/src/core/hle/service/hid/hid_server.h index 98353b0db..eb2e8e7f4 100644 --- a/src/core/hle/service/hid/hid_server.h +++ b/src/core/hle/service/hid/hid_server.h @@ -11,10 +11,12 @@ class System; namespace Service::HID { class ResourceManager; +class HidFirmwareSettings; 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; std::shared_ptr GetResourceManager(); @@ -141,6 +143,7 @@ private: void IsFirmwareUpdateNeededForNotification(HLERequestContext& ctx); std::shared_ptr resource_manager; + std::shared_ptr firmware_settings; }; } // namespace Service::HID diff --git a/src/core/hle/service/hid/resource_manager.cpp b/src/core/hle/service/hid/resource_manager.cpp index 4e462f3b3..d6f42c646 100644 --- a/src/core/hle/service/hid/resource_manager.cpp +++ b/src/core/hle/service/hid/resource_manager.cpp @@ -59,8 +59,8 @@ void ResourceManager::Initialize() { MakeControllerWithServiceContext(HidController::Palma, shared_memory); // Homebrew doesn't try to activate some controllers, so we activate them by default - GetController(HidController::NPad).ActivateController(); - GetController(HidController::Touchscreen).ActivateController(); + GetController(HidController::NPad).Activate(); + GetController(HidController::Touchscreen).Activate(); GetController(HidController::HomeButton).SetCommonHeaderOffset(0x4C00); GetController(HidController::SleepButton).SetCommonHeaderOffset(0x4E00); @@ -73,14 +73,6 @@ void ResourceManager::Initialize() { is_initialized = true; } -void ResourceManager::ActivateController(HidController controller) { - controllers[static_cast(controller)]->ActivateController(); -} - -void ResourceManager::DeactivateController(HidController controller) { - controllers[static_cast(controller)]->DeactivateController(); -} - void ResourceManager::UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { auto& core_timing = system.CoreTiming(); diff --git a/src/core/hle/service/hid/resource_manager.h b/src/core/hle/service/hid/resource_manager.h index 81b17f9a9..34dbf36bc 100644 --- a/src/core/hle/service/hid/resource_manager.h +++ b/src/core/hle/service/hid/resource_manager.h @@ -55,8 +55,6 @@ public: } void Initialize(); - void ActivateController(HidController controller); - void DeactivateController(HidController controller); void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); void UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); -- cgit v1.2.3 From cb004d1ba1bde740ba10418ac3f3cfd2db8ffac7 Mon Sep 17 00:00:00 2001 From: FrozenAra Date: Wed, 1 Nov 2023 01:09:33 +0100 Subject: Implemented qlaunch version of the controller applet --- src/core/hid/hid_types.h | 7 + src/core/hle/service/am/am.cpp | 91 ++++++- src/core/hle/service/am/am.h | 3 + .../hle/service/am/applets/applet_controller.h | 2 +- src/core/hle/service/btm/btm.cpp | 56 +++- src/core/hle/service/hid/controllers/npad.cpp | 16 ++ src/core/hle/service/hid/controllers/npad.h | 72 ++--- src/core/hle/service/hid/hid_server.cpp | 4 +- src/core/hle/service/hid/hid_system_server.cpp | 293 +++++++++++++++++++-- src/core/hle/service/hid/hid_system_server.h | 23 ++ src/core/hle/service/ldn/ldn.cpp | 10 +- src/core/hle/service/set/set_sys.cpp | 30 ++- src/core/hle/service/set/set_sys.h | 12 + src/yuzu/main.cpp | 41 ++- src/yuzu/main.h | 1 + src/yuzu/main.ui | 22 +- 16 files changed, 594 insertions(+), 89 deletions(-) (limited to 'src/core/hle/service/hid/controllers') diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h index 9d48cd90e..70fcc6b69 100644 --- a/src/core/hid/hid_types.h +++ b/src/core/hid/hid_types.h @@ -218,6 +218,13 @@ enum class NpadIdType : u32 { Invalid = 0xFFFFFFFF, }; +enum class NpadInterfaceType : u8 { + Bluetooth = 1, + Rail = 2, + Usb = 3, + Embedded = 4, +}; + // This is nn::hid::NpadStyleIndex enum class NpadStyleIndex : u8 { None = 0, diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index cc643ea09..a266d7c21 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -13,6 +13,7 @@ #include "core/file_sys/patch_manager.h" #include "core/file_sys/registered_cache.h" #include "core/file_sys/savedata_factory.h" +#include "core/hid/hid_types.h" #include "core/hle/kernel/k_event.h" #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/result.h" @@ -21,6 +22,7 @@ #include "core/hle/service/am/applet_ae.h" #include "core/hle/service/am/applet_oe.h" #include "core/hle/service/am/applets/applet_cabinet.h" +#include "core/hle/service/am/applets/applet_controller.h" #include "core/hle/service/am/applets/applet_mii_edit_types.h" #include "core/hle/service/am/applets/applet_profile_select.h" #include "core/hle/service/am/applets/applet_software_keyboard_types.h" @@ -35,6 +37,7 @@ #include "core/hle/service/caps/caps_su.h" #include "core/hle/service/caps/caps_types.h" #include "core/hle/service/filesystem/filesystem.h" +#include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/ns/ns.h" #include "core/hle/service/nvnflinger/fb_share_buffer_manager.h" @@ -73,7 +76,7 @@ IWindowController::IWindowController(Core::System& system_) static const FunctionInfo functions[] = { {0, nullptr, "CreateWindow"}, {1, &IWindowController::GetAppletResourceUserId, "GetAppletResourceUserId"}, - {2, nullptr, "GetAppletResourceUserIdOfCallerApplet"}, + {2, &IWindowController::GetAppletResourceUserIdOfCallerApplet, "GetAppletResourceUserIdOfCallerApplet"}, {10, &IWindowController::AcquireForegroundRights, "AcquireForegroundRights"}, {11, nullptr, "ReleaseForegroundRights"}, {12, nullptr, "RejectToChangeIntoBackground"}, @@ -97,6 +100,16 @@ void IWindowController::GetAppletResourceUserId(HLERequestContext& ctx) { rb.Push(process_id); } +void IWindowController::GetAppletResourceUserIdOfCallerApplet(HLERequestContext& ctx) { + const u64 process_id = 0; + + LOG_WARNING(Service_AM, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(ResultSuccess); + rb.Push(process_id); +} + void IWindowController::AcquireForegroundRights(HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -1565,7 +1578,7 @@ ILibraryAppletSelfAccessor::ILibraryAppletSelfAccessor(Core::System& system_) {6, nullptr, "GetPopInteractiveInDataEvent"}, {10, &ILibraryAppletSelfAccessor::ExitProcessAndReturn, "ExitProcessAndReturn"}, {11, &ILibraryAppletSelfAccessor::GetLibraryAppletInfo, "GetLibraryAppletInfo"}, - {12, nullptr, "GetMainAppletIdentityInfo"}, + {12, &ILibraryAppletSelfAccessor::GetMainAppletIdentityInfo, "GetMainAppletIdentityInfo"}, {13, nullptr, "CanUseApplicationCore"}, {14, &ILibraryAppletSelfAccessor::GetCallerAppletIdentityInfo, "GetCallerAppletIdentityInfo"}, {15, nullptr, "GetMainAppletApplicationControlProperty"}, @@ -1609,6 +1622,9 @@ ILibraryAppletSelfAccessor::ILibraryAppletSelfAccessor(Core::System& system_) case Applets::AppletId::SoftwareKeyboard: PushInShowSoftwareKeyboard(); break; + case Applets::AppletId::Controller: + PushInShowController(); + break; default: break; } @@ -1666,13 +1682,33 @@ void ILibraryAppletSelfAccessor::GetLibraryAppletInfo(HLERequestContext& ctx) { rb.PushRaw(applet_info); } -void ILibraryAppletSelfAccessor::GetCallerAppletIdentityInfo(HLERequestContext& ctx) { +void ILibraryAppletSelfAccessor::GetMainAppletIdentityInfo(HLERequestContext& ctx) { struct AppletIdentityInfo { Applets::AppletId applet_id; INSERT_PADDING_BYTES(0x4); u64 application_id; }; + static_assert(sizeof(AppletIdentityInfo) == 0x10, "AppletIdentityInfo has incorrect size."); + + LOG_WARNING(Service_AM, "(STUBBED) called"); + + const AppletIdentityInfo applet_info{ + .applet_id = Applets::AppletId::QLaunch, + .application_id = 0x0100000000001000ull, + }; + + IPC::ResponseBuilder rb{ctx, 6}; + rb.Push(ResultSuccess); + rb.PushRaw(applet_info); +} +void ILibraryAppletSelfAccessor::GetCallerAppletIdentityInfo(HLERequestContext& ctx) { + struct AppletIdentityInfo { + Applets::AppletId applet_id; + INSERT_PADDING_BYTES(0x4); + u64 application_id; + }; + static_assert(sizeof(AppletIdentityInfo) == 0x10, "AppletIdentityInfo has incorrect size."); LOG_WARNING(Service_AM, "(STUBBED) called"); const AppletIdentityInfo applet_info{ @@ -1737,6 +1773,55 @@ void ILibraryAppletSelfAccessor::PushInShowAlbum() { queue_data.emplace_back(std::move(settings_data)); } +void ILibraryAppletSelfAccessor::PushInShowController() { + const Applets::CommonArguments common_args = { + .arguments_version = Applets::CommonArgumentVersion::Version3, + .size = Applets::CommonArgumentSize::Version3, + .library_version = static_cast(Applets::ControllerAppletVersion::Version8), + .theme_color = Applets::ThemeColor::BasicBlack, + .play_startup_sound = true, + .system_tick = system.CoreTiming().GetClockTicks(), + }; + + Applets::ControllerSupportArgNew user_args = { + .header = {.player_count_min = 1, + .player_count_max = 4, + .enable_take_over_connection = true, + .enable_left_justify = false, + .enable_permit_joy_dual = true, + .enable_single_mode = false, + .enable_identification_color = false}, + .identification_colors = {}, + .enable_explain_text = false, + .explain_text = {}, + }; + + Applets::ControllerSupportArgPrivate private_args = { + .arg_private_size = sizeof(Applets::ControllerSupportArgPrivate), + .arg_size = sizeof(Applets::ControllerSupportArgNew), + .is_home_menu = true, + .flag_1 = true, + .mode = Applets::ControllerSupportMode::ShowControllerSupport, + .caller = Applets::ControllerSupportCaller:: + Application, // switchbrew: Always zero except with + // ShowControllerFirmwareUpdateForSystem/ShowControllerKeyRemappingForSystem, + // which sets this to the input param + .style_set = Core::HID::NpadStyleSet::None, + .joy_hold_type = 0, + }; + std::vector common_args_data(sizeof(common_args)); + std::vector private_args_data(sizeof(private_args)); + std::vector user_args_data(sizeof(user_args)); + + std::memcpy(common_args_data.data(), &common_args, sizeof(common_args)); + std::memcpy(private_args_data.data(), &private_args, sizeof(private_args)); + std::memcpy(user_args_data.data(), &user_args, sizeof(user_args)); + + queue_data.emplace_back(std::move(common_args_data)); + queue_data.emplace_back(std::move(private_args_data)); + queue_data.emplace_back(std::move(user_args_data)); +} + void ILibraryAppletSelfAccessor::PushInShowCabinetData() { const Applets::CommonArguments arguments{ .arguments_version = Applets::CommonArgumentVersion::Version3, diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 8f8cb8a9e..905a71b9f 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -87,6 +87,7 @@ public: private: void GetAppletResourceUserId(HLERequestContext& ctx); + void GetAppletResourceUserIdOfCallerApplet(HLERequestContext& ctx); void AcquireForegroundRights(HLERequestContext& ctx); }; @@ -345,6 +346,7 @@ private: void PopInData(HLERequestContext& ctx); void PushOutData(HLERequestContext& ctx); void GetLibraryAppletInfo(HLERequestContext& ctx); + void GetMainAppletIdentityInfo(HLERequestContext& ctx); void ExitProcessAndReturn(HLERequestContext& ctx); void GetCallerAppletIdentityInfo(HLERequestContext& ctx); void GetDesirableKeyboardLayout(HLERequestContext& ctx); @@ -355,6 +357,7 @@ private: void PushInShowCabinetData(); void PushInShowMiiEditData(); void PushInShowSoftwareKeyboard(); + void PushInShowController(); std::deque> queue_data; }; diff --git a/src/core/hle/service/am/applets/applet_controller.h b/src/core/hle/service/am/applets/applet_controller.h index f6c64f633..9f839f3d7 100644 --- a/src/core/hle/service/am/applets/applet_controller.h +++ b/src/core/hle/service/am/applets/applet_controller.h @@ -56,7 +56,7 @@ enum class ControllerSupportResult : u32 { struct ControllerSupportArgPrivate { u32 arg_private_size{}; u32 arg_size{}; - bool flag_0{}; + bool is_home_menu{}; bool flag_1{}; ControllerSupportMode mode{}; ControllerSupportCaller caller{}; diff --git a/src/core/hle/service/btm/btm.cpp b/src/core/hle/service/btm/btm.cpp index 8069f75b7..c65e32489 100644 --- a/src/core/hle/service/btm/btm.cpp +++ b/src/core/hle/service/btm/btm.cpp @@ -127,7 +127,7 @@ public: private: void GetCore(HLERequestContext& ctx) { - LOG_DEBUG(Service_BTM, "called"); + LOG_WARNING(Service_BTM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -263,13 +263,13 @@ public: explicit IBtmSystemCore(Core::System& system_) : ServiceFramework{system_, "IBtmSystemCore"} { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "StartGamepadPairing"}, - {1, nullptr, "CancelGamepadPairing"}, + {0, &IBtmSystemCore::StartGamepadPairing, "StartGamepadPairing"}, + {1, &IBtmSystemCore::CancelGamepadPairing, "CancelGamepadPairing"}, {2, nullptr, "ClearGamepadPairingDatabase"}, {3, nullptr, "GetPairedGamepadCount"}, {4, nullptr, "EnableRadio"}, {5, nullptr, "DisableRadio"}, - {6, nullptr, "GetRadioOnOff"}, + {6, &IBtmSystemCore::IsRadioEnabled, "IsRadioEnabled"}, {7, nullptr, "AcquireRadioEvent"}, {8, nullptr, "AcquireGamepadPairingEvent"}, {9, nullptr, "IsGamepadPairingStarted"}, @@ -280,18 +280,58 @@ public: {14, nullptr, "AcquireAudioDeviceConnectionEvent"}, {15, nullptr, "ConnectAudioDevice"}, {16, nullptr, "IsConnectingAudioDevice"}, - {17, nullptr, "GetConnectedAudioDevices"}, + {17, &IBtmSystemCore::GetConnectedAudioDevices, "GetConnectedAudioDevices"}, {18, nullptr, "DisconnectAudioDevice"}, {19, nullptr, "AcquirePairedAudioDeviceInfoChangedEvent"}, {20, nullptr, "GetPairedAudioDevices"}, {21, nullptr, "RemoveAudioDevicePairing"}, - {22, nullptr, "RequestAudioDeviceConnectionRejection"}, - {23, nullptr, "CancelAudioDeviceConnectionRejection"} + {22, &IBtmSystemCore::RequestAudioDeviceConnectionRejection, "RequestAudioDeviceConnectionRejection"}, + {23, &IBtmSystemCore::CancelAudioDeviceConnectionRejection, "CancelAudioDeviceConnectionRejection"} }; // clang-format on RegisterHandlers(functions); } + +private: + void IsRadioEnabled(HLERequestContext& ctx) { + LOG_DEBUG(Service_BTM, "(STUBBED) called"); // Spams a lot when controller applet is running + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(true); + } + + void StartGamepadPairing(HLERequestContext& ctx) { + LOG_WARNING(Service_BTM, "(STUBBED) called"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); + } + + void CancelGamepadPairing(HLERequestContext& ctx) { + LOG_WARNING(Service_BTM, "(STUBBED) called"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); + } + + void CancelAudioDeviceConnectionRejection(HLERequestContext& ctx) { + LOG_WARNING(Service_BTM, "(STUBBED) called"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); + } + + void GetConnectedAudioDevices(HLERequestContext& ctx) { + LOG_WARNING(Service_BTM, "(STUBBED) called"); + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(0); + } + + void RequestAudioDeviceConnectionRejection(HLERequestContext& ctx) { + LOG_WARNING(Service_BTM, "(STUBBED) called"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); + } }; class BTM_SYS final : public ServiceFramework { @@ -308,7 +348,7 @@ public: private: void GetCore(HLERequestContext& ctx) { - LOG_DEBUG(Service_BTM, "called"); + LOG_WARNING(Service_BTM, "called"); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index d46bf917e..127af2b82 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -344,6 +344,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { controller.device->SetPollingMode(Core::HID::EmulatedDeviceIndex::AllDevices, Common::Input::PollingMode::Active); } + SignalStyleSetChangedEvent(npad_id); WriteEmptyEntry(controller.shared_memory); hid_core.SetLastActiveController(npad_id); @@ -1726,4 +1727,19 @@ const Controller_NPad::SixaxisParameters& Controller_NPad::GetSixaxisState( } } +Controller_NPad::AppletDetailedUiType Controller_NPad::GetAppletDetailedUiType( + Core::HID::NpadIdType npad_id) { + + auto controller = GetControllerFromNpadIdType(npad_id); + auto shared_memory = controller.shared_memory; + Service::HID::Controller_NPad::AppletFooterUiType applet_footer_type = + shared_memory->applet_footer_type; + + Controller_NPad::AppletDetailedUiType detailed_ui_type{ + .ui_variant = 0, + .footer = applet_footer_type, + }; + return detailed_ui_type; +} + } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index e23b4986c..cd93abdd1 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -78,6 +78,46 @@ public: MaxActivationMode = 3, }; + // This is nn::hid::system::AppletFooterUiAttributesSet + struct AppletFooterUiAttributes { + INSERT_PADDING_BYTES(0x4); + }; + + // This is nn::hid::system::AppletFooterUiType + enum class AppletFooterUiType : u8 { + None = 0, + HandheldNone = 1, + HandheldJoyConLeftOnly = 2, + HandheldJoyConRightOnly = 3, + HandheldJoyConLeftJoyConRight = 4, + JoyDual = 5, + JoyDualLeftOnly = 6, + JoyDualRightOnly = 7, + JoyLeftHorizontal = 8, + JoyLeftVertical = 9, + JoyRightHorizontal = 10, + JoyRightVertical = 11, + SwitchProController = 12, + CompatibleProController = 13, + CompatibleJoyCon = 14, + LarkHvc1 = 15, + LarkHvc2 = 16, + LarkNesLeft = 17, + LarkNesRight = 18, + Lucia = 19, + Verification = 20, + Lagon = 21, + }; + + using AppletFooterUiVariant = u8; + + // This is "nn::hid::system::AppletDetailedUiType". + struct AppletDetailedUiType { + AppletFooterUiVariant ui_variant; + INSERT_PADDING_BYTES(0x2); + AppletFooterUiType footer; + }; + static_assert(sizeof(AppletDetailedUiType) == 0x4, "AppletDetailedUiType is an invalid size"); // This is nn::hid::NpadCommunicationMode enum class NpadCommunicationMode : u64 { Mode_5ms = 0, @@ -203,6 +243,7 @@ public: static Result IsDeviceHandleValid(const Core::HID::VibrationDeviceHandle& device_handle); static Result VerifyValidSixAxisSensorHandle( const Core::HID::SixAxisSensorHandle& device_handle); + AppletDetailedUiType GetAppletDetailedUiType(Core::HID::NpadIdType npad_id); private: static constexpr std::size_t NPAD_COUNT = 10; @@ -360,37 +401,6 @@ private: static_assert(sizeof(NfcXcdDeviceHandleStateImpl) == 0x18, "NfcXcdDeviceHandleStateImpl is an invalid size"); - // This is nn::hid::system::AppletFooterUiAttributesSet - struct AppletFooterUiAttributes { - INSERT_PADDING_BYTES(0x4); - }; - - // This is nn::hid::system::AppletFooterUiType - enum class AppletFooterUiType : u8 { - None = 0, - HandheldNone = 1, - HandheldJoyConLeftOnly = 2, - HandheldJoyConRightOnly = 3, - HandheldJoyConLeftJoyConRight = 4, - JoyDual = 5, - JoyDualLeftOnly = 6, - JoyDualRightOnly = 7, - JoyLeftHorizontal = 8, - JoyLeftVertical = 9, - JoyRightHorizontal = 10, - JoyRightVertical = 11, - SwitchProController = 12, - CompatibleProController = 13, - CompatibleJoyCon = 14, - LarkHvc1 = 15, - LarkHvc2 = 16, - LarkNesLeft = 17, - LarkNesRight = 18, - Lucia = 19, - Verification = 20, - Lagon = 21, - }; - // This is nn::hid::NpadLarkType enum class NpadLarkType : u32 { Invalid, diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index 0be6a7186..56f26a14a 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp @@ -1222,8 +1222,8 @@ void IHidServer::SetNpadJoyAssignmentModeDual(HLERequestContext& ctx) { controller.SetNpadMode(new_npad_id, parameters.npad_id, {}, Controller_NPad::NpadJoyAssignmentMode::Dual); - LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, - parameters.applet_resource_user_id); + LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, + parameters.applet_resource_user_id); // Spams a lot when controller applet is open 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 83cfadada..6f1902ee5 100644 --- a/src/core/hle/service/hid/hid_system_server.cpp +++ b/src/core/hle/service/hid/hid_system_server.cpp @@ -36,24 +36,24 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptrGetController(HidController::NPad) + .ApplyNpadSystemCommonPolicy(); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); +} + +void IHidSystemServer::GetNpadFullKeyGripColor(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto npad_id_type{rp.PopEnum()}; + + LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}", + npad_id_type); // Spams a lot when controller applet is running + + Core::HID::NpadColor left_color{}; + Core::HID::NpadColor right_color{}; + // TODO: Get colors from Npad + + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(ResultSuccess); + rb.PushRaw(left_color); + rb.PushRaw(right_color); +} + +void IHidSystemServer::GetMaskedSupportedNpadStyleSet(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + + LOG_INFO(Service_HID, "(STUBBED) called"); + + Core::HID::NpadStyleSet supported_styleset = + GetResourceManager() + ->GetController(HidController::NPad) + .GetSupportedStyleSet() + .raw; + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.PushEnum(supported_styleset); +} + +void IHidSystemServer::SetSupportedNpadStyleSetAll(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + + LOG_INFO(Service_HID, "(STUBBED) called"); + + Core::HID::NpadStyleSet supported_styleset = + GetResourceManager() + ->GetController(HidController::NPad) + .GetSupportedStyleSet() + .raw; + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.PushEnum(supported_styleset); +} + +void IHidSystemServer::GetAppletDetailedUiType(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto npad_id_type{rp.PopEnum()}; + + LOG_DEBUG(Service_HID, "called, npad_id_type={}", + npad_id_type); // Spams a lot when controller applet is running + + const Service::HID::Controller_NPad::AppletDetailedUiType detailed_ui_type = + GetResourceManager() + ->GetController(HidController::NPad) + .GetAppletDetailedUiType(npad_id_type); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.PushRaw(detailed_ui_type); +} + +void IHidSystemServer::GetNpadInterfaceType(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto npad_id_type{rp.PopEnum()}; + + LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}", + npad_id_type); // Spams a lot when controller applet is running + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.PushEnum(Core::HID::NpadInterfaceType::Bluetooth); +} + +void IHidSystemServer::GetNpadLeftRightInterfaceType(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto npad_id_type{rp.PopEnum()}; + + LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}", + npad_id_type); // Spams a lot when controller applet is running + + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(ResultSuccess); + rb.PushEnum(Core::HID::NpadInterfaceType::Bluetooth); + rb.PushEnum(Core::HID::NpadInterfaceType::Bluetooth); +} + +void IHidSystemServer::HasBattery(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto npad_id_type{rp.PopEnum()}; + + LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}", + npad_id_type); // Spams a lot when controller applet is running + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(false); +} + +void IHidSystemServer::HasLeftRightBattery(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + const auto npad_id_type{rp.PopEnum()}; + + LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}", + npad_id_type); // Spams a lot when controller applet is running + + struct LeftRightBattery { + bool left; + bool right; + }; + + LeftRightBattery left_right_battery{ + .left = false, + .right = false, + }; + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.PushRaw(left_right_battery); +} + void IHidSystemServer::GetUniquePadsFromNpad(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto npad_id_type{rp.PopEnum()}; - LOG_WARNING(Service_HID, "(STUBBED) called, npad_id_type={}", npad_id_type); + LOG_DEBUG(Service_HID, "(STUBBED) called, npad_id_type={}", + npad_id_type); // Spams a lot when controller applet is running const std::vector unique_pads{}; - ctx.WriteBuffer(unique_pads); + if (!unique_pads.empty()) { + ctx.WriteBuffer(unique_pads); + } IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); rb.Push(static_cast(unique_pads.size())); } +void IHidSystemServer::GetIrSensorState(HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + + LOG_WARNING(Service_HID, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); +} + +void IHidSystemServer::AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx) { + LOG_INFO(Service_AM, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2, 1}; + rb.Push(ResultSuccess); + rb.PushCopyObjects(acquire_device_registered_event->GetReadableEvent()); +} + +void IHidSystemServer::AcquireDeviceRegisteredEventForControllerSupport(HLERequestContext& ctx) { + LOG_INFO(Service_HID, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2, 1}; + rb.Push(ResultSuccess); + rb.PushCopyObjects(acquire_device_registered_event->GetReadableEvent()); +} + +void IHidSystemServer::GetRegisteredDevices(HLERequestContext& ctx) { + LOG_WARNING(Service_HID, "(STUBBED) called"); + + struct RegisterData { + std::array data; + }; + static_assert(sizeof(RegisterData) == 0x68, "RegisterData is an invalid size"); + std::vector registered_devices{}; + + if (!registered_devices.empty()) { + ctx.WriteBuffer(registered_devices); + } + + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(ResultSuccess); + rb.Push(registered_devices.size()); +} + +void IHidSystemServer::AcquireUniquePadConnectionEventHandle(HLERequestContext& ctx) { + LOG_WARNING(Service_HID, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2, 1}; + rb.PushCopyObjects(unique_pad_connection_event->GetReadableEvent()); + rb.Push(ResultSuccess); +} + +void IHidSystemServer::GetUniquePadIds(HLERequestContext& ctx) { + LOG_WARNING(Service_HID, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(ResultSuccess); + rb.Push(0); +} + void IHidSystemServer::AcquireJoyDetachOnBluetoothOffEventHandle(HLERequestContext& ctx) { LOG_INFO(Service_AM, "called"); @@ -279,6 +501,31 @@ void IHidSystemServer::IsUsbFullKeyControllerEnabled(HLERequestContext& ctx) { rb.Push(is_enabled); } +void IHidSystemServer::IsHandheldButtonPressedOnConsoleMode(HLERequestContext& ctx) { + const bool button_pressed = false; + + LOG_DEBUG(Service_HID, "(STUBBED) called, is_enabled={}", + button_pressed); // Spams a lot when controller applet is open + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(button_pressed); +} + +void IHidSystemServer::InitializeFirmwareUpdate(HLERequestContext& ctx) { + LOG_WARNING(Service_HID, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); +} + +void IHidSystemServer::InitializeUsbFirmwareUpdateWithoutMemory(HLERequestContext& ctx) { + LOG_WARNING(Service_HID, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); +} + void IHidSystemServer::GetTouchScreenDefaultConfiguration(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called"); diff --git a/src/core/hle/service/hid/hid_system_server.h b/src/core/hle/service/hid/hid_system_server.h index d4b3910fa..822d5e5b9 100644 --- a/src/core/hle/service/hid/hid_system_server.h +++ b/src/core/hle/service/hid/hid_system_server.h @@ -24,15 +24,38 @@ public: private: void ApplyNpadSystemCommonPolicy(HLERequestContext& ctx); + void EnableAssigningSingleOnSlSrPress(HLERequestContext& ctx); + void DisableAssigningSingleOnSlSrPress(HLERequestContext& ctx); void GetLastActiveNpad(HLERequestContext& ctx); + void ApplyNpadSystemCommonPolicyFull(HLERequestContext& ctx); + void GetNpadFullKeyGripColor(HLERequestContext& ctx); + void GetMaskedSupportedNpadStyleSet(HLERequestContext& ctx); + void SetSupportedNpadStyleSetAll(HLERequestContext& ctx); + void GetAppletDetailedUiType(HLERequestContext& ctx); + void GetNpadInterfaceType(HLERequestContext& ctx); + void GetNpadLeftRightInterfaceType(HLERequestContext& ctx); + void HasBattery(HLERequestContext& ctx); + void HasLeftRightBattery(HLERequestContext& ctx); void GetUniquePadsFromNpad(HLERequestContext& ctx); + void GetIrSensorState(HLERequestContext& ctx); + void AcquireConnectionTriggerTimeoutEvent(HLERequestContext& ctx); + void AcquireDeviceRegisteredEventForControllerSupport(HLERequestContext& ctx); + void GetRegisteredDevices(HLERequestContext& ctx); + void AcquireUniquePadConnectionEventHandle(HLERequestContext& ctx); + void GetUniquePadIds(HLERequestContext& ctx); void AcquireJoyDetachOnBluetoothOffEventHandle(HLERequestContext& ctx); void IsUsbFullKeyControllerEnabled(HLERequestContext& ctx); + void IsHandheldButtonPressedOnConsoleMode(HLERequestContext& ctx); + void InitializeFirmwareUpdate(HLERequestContext& ctx); + void InitializeUsbFirmwareUpdateWithoutMemory(HLERequestContext& ctx); void GetTouchScreenDefaultConfiguration(HLERequestContext& ctx); std::shared_ptr GetResourceManager(); + Kernel::KEvent* acquire_connection_trigger_timeout_event; + Kernel::KEvent* acquire_device_registered_event; Kernel::KEvent* joy_detach_event; + Kernel::KEvent* unique_pad_connection_event; KernelHelpers::ServiceContext service_context; std::shared_ptr resource_manager; }; diff --git a/src/core/hle/service/ldn/ldn.cpp b/src/core/hle/service/ldn/ldn.cpp index 7927f8264..961f89a14 100644 --- a/src/core/hle/service/ldn/ldn.cpp +++ b/src/core/hle/service/ldn/ldn.cpp @@ -115,12 +115,20 @@ public: {400, nullptr, "InitializeSystem"}, {401, nullptr, "FinalizeSystem"}, {402, nullptr, "SetOperationMode"}, - {403, nullptr, "InitializeSystem2"}, + {403, &ISystemLocalCommunicationService::InitializeSystem2, "InitializeSystem2"}, }; // clang-format on RegisterHandlers(functions); } + +private: + void InitializeSystem2(HLERequestContext& ctx) { + LOG_WARNING(Service_LDN, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultSuccess); + } }; class IUserLocalCommunicationService final diff --git a/src/core/hle/service/set/set_sys.cpp b/src/core/hle/service/set/set_sys.cpp index ec3af80af..19c667b42 100644 --- a/src/core/hle/service/set/set_sys.cpp +++ b/src/core/hle/service/set/set_sys.cpp @@ -431,8 +431,7 @@ void SET_SYS::GetAutoUpdateEnableFlag(HLERequestContext& ctx) { void SET_SYS::GetBatteryPercentageFlag(HLERequestContext& ctx) { u8 battery_percentage_flag{1}; - LOG_WARNING(Service_SET, "(STUBBED) called, battery_percentage_flag={}", - battery_percentage_flag); + LOG_DEBUG(Service_SET, "(STUBBED) called, battery_percentage_flag={}", battery_percentage_flag); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); @@ -492,6 +491,29 @@ void SET_SYS::GetChineseTraditionalInputMethod(HLERequestContext& ctx) { rb.PushEnum(ChineseTraditionalInputMethod::Unknown0); } +void SET_SYS::GetHomeMenuScheme(HLERequestContext& ctx) { + LOG_DEBUG(Service_SET, "(STUBBED) called"); + + const HomeMenuScheme default_color = { + .main = 0xFF323232, + .back = 0xFF323232, + .sub = 0xFFFFFFFF, + .bezel = 0xFFFFFFFF, + .extra = 0xFF000000, + }; + + IPC::ResponseBuilder rb{ctx, 7}; + rb.Push(ResultSuccess); + rb.PushRaw(default_color); +} + +void SET_SYS::GetHomeMenuSchemeModel(HLERequestContext& ctx) { + LOG_WARNING(Service_SET, "(STUBBED) called"); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(ResultSuccess); + rb.Push(0); +} void SET_SYS::GetFieldTestingFlag(HLERequestContext& ctx) { LOG_WARNING(Service_SET, "(STUBBED) called"); @@ -674,7 +696,7 @@ SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"} { {171, nullptr, "SetChineseTraditionalInputMethod"}, {172, nullptr, "GetPtmCycleCountReliability"}, {173, nullptr, "SetPtmCycleCountReliability"}, - {174, nullptr, "GetHomeMenuScheme"}, + {174, &SET_SYS::GetHomeMenuScheme, "GetHomeMenuScheme"}, {175, nullptr, "GetThemeSettings"}, {176, nullptr, "SetThemeSettings"}, {177, nullptr, "GetThemeKey"}, @@ -685,7 +707,7 @@ SET_SYS::SET_SYS(Core::System& system_) : ServiceFramework{system_, "set:sys"} { {182, nullptr, "SetT"}, {183, nullptr, "GetPlatformRegion"}, {184, nullptr, "SetPlatformRegion"}, - {185, nullptr, "GetHomeMenuSchemeModel"}, + {185, &SET_SYS::GetHomeMenuSchemeModel, "GetHomeMenuSchemeModel"}, {186, nullptr, "GetMemoryUsageRateFlag"}, {187, nullptr, "GetTouchScreenMode"}, {188, nullptr, "SetTouchScreenMode"}, diff --git a/src/core/hle/service/set/set_sys.h b/src/core/hle/service/set/set_sys.h index c7dba2a9e..93023c6dd 100644 --- a/src/core/hle/service/set/set_sys.h +++ b/src/core/hle/service/set/set_sys.h @@ -269,6 +269,16 @@ private: }; static_assert(sizeof(EulaVersion) == 0x30, "EulaVersion is incorrect size"); + /// This is nn::settings::system::HomeMenuScheme + struct HomeMenuScheme { + u32 main; + u32 back; + u32 sub; + u32 bezel; + u32 extra; + }; + static_assert(sizeof(HomeMenuScheme) == 0x14, "HomeMenuScheme is incorrect size"); + void SetLanguageCode(HLERequestContext& ctx); void GetFirmwareVersion(HLERequestContext& ctx); void GetFirmwareVersion2(HLERequestContext& ctx); @@ -305,6 +315,8 @@ private: void GetKeyboardLayout(HLERequestContext& ctx); void GetChineseTraditionalInputMethod(HLERequestContext& ctx); void GetFieldTestingFlag(HLERequestContext& ctx); + void GetHomeMenuScheme(HLERequestContext& ctx); + void GetHomeMenuSchemeModel(HLERequestContext& ctx); AccountSettings account_settings{ .flags = {}, diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index f077d7f9c..b0e995c52 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1574,6 +1574,7 @@ void GMainWindow::ConnectMenuEvents() { connect_menu(ui->action_Load_Cabinet_Formatter, [this]() { OnCabinet(Service::NFP::CabinetMode::StartFormatter); }); connect_menu(ui->action_Load_Mii_Edit, &GMainWindow::OnMiiEdit); + connect_menu(ui->action_Open_Controller_Menu, &GMainWindow::OnOpenControllerMenu); connect_menu(ui->action_Capture_Screenshot, &GMainWindow::OnCaptureScreenshot); // TAS @@ -1601,14 +1602,13 @@ void GMainWindow::UpdateMenuState() { ui->action_Pause, }; - const std::array applet_actions{ - ui->action_Load_Album, - ui->action_Load_Cabinet_Nickname_Owner, - ui->action_Load_Cabinet_Eraser, - ui->action_Load_Cabinet_Restorer, - ui->action_Load_Cabinet_Formatter, - ui->action_Load_Mii_Edit, - }; + const std::array applet_actions{ui->action_Load_Album, + ui->action_Load_Cabinet_Nickname_Owner, + ui->action_Load_Cabinet_Eraser, + ui->action_Load_Cabinet_Restorer, + ui->action_Load_Cabinet_Formatter, + ui->action_Load_Mii_Edit, + ui->action_Open_Controller_Menu}; for (QAction* action : running_actions) { action->setEnabled(emulation_running); @@ -4346,6 +4346,31 @@ void GMainWindow::OnMiiEdit() { BootGame(filename, MiiEditId); } +void GMainWindow::OnOpenControllerMenu() { + constexpr u64 ControllerAppletId = + static_cast(Service::AM::Applets::AppletProgramId::Controller); + auto bis_system = system->GetFileSystemController().GetSystemNANDContents(); + if (!bis_system) { + QMessageBox::warning(this, tr("No firmware available"), + tr("Please install the firmware to use the Controller Menu.")); + return; + } + + auto controller_applet_nca = + bis_system->GetEntry(ControllerAppletId, FileSys::ContentRecordType::Program); + if (!controller_applet_nca) { + QMessageBox::warning(this, tr("Controller Applet"), + tr("Controller Menu is not available. Please reinstall firmware.")); + return; + } + + system->GetAppletManager().SetCurrentAppletId(Service::AM::Applets::AppletId::Controller); + + const auto filename = QString::fromStdString((controller_applet_nca->GetFullPath())); + UISettings::values.roms_path = QFileInfo(filename).path(); + BootGame(filename, ControllerAppletId); +} + void GMainWindow::OnCaptureScreenshot() { if (emu_thread == nullptr || !emu_thread->IsRunning()) { return; diff --git a/src/yuzu/main.h b/src/yuzu/main.h index f9c6efe4f..19740cc52 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -402,6 +402,7 @@ private slots: void OnAlbum(); void OnCabinet(Service::NFP::CabinetMode mode); void OnMiiEdit(); + void OnOpenControllerMenu(); void OnCaptureScreenshot(); void OnReinitializeKeys(ReinitializeKeyBehavior behavior); void OnLanguageChanged(const QString& locale); diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index 88684ffb5..e53f9951e 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui @@ -25,7 +25,7 @@ - + 0 @@ -36,7 +36,7 @@ 0 0 1280 - 26 + 21 @@ -162,6 +162,7 @@ + @@ -382,9 +383,9 @@ - - Open &Album - + + Open &Album + @@ -407,9 +408,9 @@ - - Open &Mii Editor - + + Open &Mii Editor + @@ -454,6 +455,11 @@ R&ecord + + + Open &Controller Menu + + -- cgit v1.2.3 From cff2d0e19e164d879b57bab9d06306fa70a1049e Mon Sep 17 00:00:00 2001 From: Narr the Reg Date: Fri, 17 Nov 2023 11:46:26 -0600 Subject: service: hid: Create appropriate hid resources --- src/core/CMakeLists.txt | 9 +- src/core/hid/emulated_controller.cpp | 17 +- src/core/hid/hid_core.cpp | 5 +- src/core/hid/hid_types.h | 80 +-- src/core/hid/input_interpreter.cpp | 4 +- src/core/hid/input_interpreter.h | 4 +- .../service/hid/controllers/console_six_axis.cpp | 42 ++ .../hle/service/hid/controllers/console_six_axis.h | 43 ++ .../service/hid/controllers/console_sixaxis.cpp | 74 --- .../hle/service/hid/controllers/console_sixaxis.h | 78 --- src/core/hle/service/hid/controllers/debug_pad.cpp | 10 +- src/core/hle/service/hid/controllers/debug_pad.h | 6 +- src/core/hle/service/hid/controllers/gesture.cpp | 54 +- src/core/hle/service/hid/controllers/gesture.h | 6 +- src/core/hle/service/hid/controllers/keyboard.cpp | 10 +- src/core/hle/service/hid/controllers/keyboard.h | 6 +- src/core/hle/service/hid/controllers/mouse.cpp | 11 +- src/core/hle/service/hid/controllers/mouse.h | 6 +- src/core/hle/service/hid/controllers/npad.cpp | 586 ++++----------------- src/core/hle/service/hid/controllers/npad.h | 126 +---- src/core/hle/service/hid/controllers/palma.cpp | 86 ++- src/core/hle/service/hid/controllers/palma.h | 8 +- .../hle/service/hid/controllers/seven_six_axis.cpp | 66 +++ .../hle/service/hid/controllers/seven_six_axis.h | 65 +++ src/core/hle/service/hid/controllers/six_axis.cpp | 413 +++++++++++++++ src/core/hle/service/hid/controllers/six_axis.h | 111 ++++ .../hle/service/hid/controllers/touchscreen.cpp | 11 +- src/core/hle/service/hid/controllers/touchscreen.h | 6 +- src/core/hle/service/hid/controllers/xpad.cpp | 11 +- src/core/hle/service/hid/controllers/xpad.h | 6 +- src/core/hle/service/hid/hid_server.cpp | 437 +++++++-------- src/core/hle/service/hid/hid_system_server.cpp | 424 ++++++++------- src/core/hle/service/hid/hid_util.h | 146 +++++ src/core/hle/service/hid/irs.cpp | 5 +- src/core/hle/service/hid/resource_manager.cpp | 155 ++++-- src/core/hle/service/hid/resource_manager.h | 119 +++-- src/core/hle/service/nfc/common/device_manager.cpp | 3 +- src/core/memory/cheat_engine.cpp | 5 +- 38 files changed, 1732 insertions(+), 1522 deletions(-) create mode 100644 src/core/hle/service/hid/controllers/console_six_axis.cpp create mode 100644 src/core/hle/service/hid/controllers/console_six_axis.h delete mode 100644 src/core/hle/service/hid/controllers/console_sixaxis.cpp delete mode 100644 src/core/hle/service/hid/controllers/console_sixaxis.h create mode 100644 src/core/hle/service/hid/controllers/seven_six_axis.cpp create mode 100644 src/core/hle/service/hid/controllers/seven_six_axis.h create mode 100644 src/core/hle/service/hid/controllers/six_axis.cpp create mode 100644 src/core/hle/service/hid/controllers/six_axis.h create mode 100644 src/core/hle/service/hid/hid_util.h (limited to 'src/core/hle/service/hid/controllers') diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 597890655..66c10fc3f 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -529,6 +529,7 @@ add_library(core STATIC hle/service/hid/hid_server.h hle/service/hid/hid_system_server.cpp hle/service/hid/hid_system_server.h + hle/service/hid/hid_util.h hle/service/hid/hidbus.cpp hle/service/hid/hidbus.h hle/service/hid/irs.cpp @@ -540,8 +541,8 @@ add_library(core STATIC hle/service/hid/xcd.cpp hle/service/hid/xcd.h hle/service/hid/errors.h - hle/service/hid/controllers/console_sixaxis.cpp - hle/service/hid/controllers/console_sixaxis.h + hle/service/hid/controllers/console_six_axis.cpp + hle/service/hid/controllers/console_six_axis.h hle/service/hid/controllers/controller_base.cpp hle/service/hid/controllers/controller_base.h hle/service/hid/controllers/debug_pad.cpp @@ -556,6 +557,10 @@ add_library(core STATIC hle/service/hid/controllers/npad.h hle/service/hid/controllers/palma.cpp hle/service/hid/controllers/palma.h + hle/service/hid/controllers/seven_six_axis.cpp + hle/service/hid/controllers/seven_six_axis.h + hle/service/hid/controllers/six_axis.cpp + hle/service/hid/controllers/six_axis.h hle/service/hid/controllers/stubbed.cpp hle/service/hid/controllers/stubbed.h hle/service/hid/controllers/touchscreen.cpp diff --git a/src/core/hid/emulated_controller.cpp b/src/core/hid/emulated_controller.cpp index 34927cddd..a22015ada 100644 --- a/src/core/hid/emulated_controller.cpp +++ b/src/core/hid/emulated_controller.cpp @@ -8,6 +8,7 @@ #include "common/thread.h" #include "core/hid/emulated_controller.h" #include "core/hid/input_converter.h" +#include "core/hle/service/hid/hid_util.h" namespace Core::HID { constexpr s32 HID_JOYSTICK_MAX = 0x7fff; @@ -82,7 +83,7 @@ Settings::ControllerType EmulatedController::MapNPadToSettingsType(NpadStyleInde } void EmulatedController::ReloadFromSettings() { - const auto player_index = NpadIdTypeToIndex(npad_id_type); + const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); const auto& player = Settings::values.players.GetValue()[player_index]; for (std::size_t index = 0; index < player.buttons.size(); ++index) { @@ -118,7 +119,7 @@ void EmulatedController::ReloadFromSettings() { } void EmulatedController::ReloadColorsFromSettings() { - const auto player_index = NpadIdTypeToIndex(npad_id_type); + const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); const auto& player = Settings::values.players.GetValue()[player_index]; // Avoid updating colors if overridden by physical controller @@ -215,7 +216,7 @@ void EmulatedController::LoadDevices() { } void EmulatedController::LoadTASParams() { - const auto player_index = NpadIdTypeToIndex(npad_id_type); + const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); Common::ParamPackage common_params{}; common_params.Set("engine", "tas"); common_params.Set("port", static_cast(player_index)); @@ -264,7 +265,7 @@ void EmulatedController::LoadTASParams() { } void EmulatedController::LoadVirtualGamepadParams() { - const auto player_index = NpadIdTypeToIndex(npad_id_type); + const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); Common::ParamPackage common_params{}; common_params.Set("engine", "virtual_gamepad"); common_params.Set("port", static_cast(player_index)); @@ -615,7 +616,7 @@ bool EmulatedController::IsConfiguring() const { } void EmulatedController::SaveCurrentConfig() { - const auto player_index = NpadIdTypeToIndex(npad_id_type); + const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); auto& player = Settings::values.players.GetValue()[player_index]; player.connected = is_connected; player.controller_type = MapNPadToSettingsType(npad_type); @@ -1212,7 +1213,7 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v if (!output_devices[device_index]) { return false; } - const auto player_index = NpadIdTypeToIndex(npad_id_type); + const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); const auto& player = Settings::values.players.GetValue()[player_index]; const f32 strength = static_cast(player.vibration_strength) / 100.0f; @@ -1238,7 +1239,7 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v } bool EmulatedController::IsVibrationEnabled(std::size_t device_index) { - const auto player_index = NpadIdTypeToIndex(npad_id_type); + const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); const auto& player = Settings::values.players.GetValue()[player_index]; if (!player.vibration_enabled) { @@ -1648,7 +1649,7 @@ void EmulatedController::SetNpadStyleIndex(NpadStyleIndex npad_type_) { } if (is_connected) { LOG_WARNING(Service_HID, "Controller {} type changed while it's connected", - NpadIdTypeToIndex(npad_id_type)); + Service::HID::NpadIdTypeToIndex(npad_id_type)); } npad_type = npad_type_; } diff --git a/src/core/hid/hid_core.cpp b/src/core/hid/hid_core.cpp index cf53c04d9..2cf25a870 100644 --- a/src/core/hid/hid_core.cpp +++ b/src/core/hid/hid_core.cpp @@ -6,6 +6,7 @@ #include "core/hid/emulated_controller.h" #include "core/hid/emulated_devices.h" #include "core/hid/hid_core.h" +#include "core/hle/service/hid/hid_util.h" namespace Core::HID { @@ -98,11 +99,11 @@ const EmulatedDevices* HIDCore::GetEmulatedDevices() const { } EmulatedController* HIDCore::GetEmulatedControllerByIndex(std::size_t index) { - return GetEmulatedController(IndexToNpadIdType(index)); + return GetEmulatedController(Service::HID::IndexToNpadIdType(index)); } const EmulatedController* HIDCore::GetEmulatedControllerByIndex(std::size_t index) const { - return GetEmulatedController(IndexToNpadIdType(index)); + return GetEmulatedController(Service::HID::IndexToNpadIdType(index)); } void HIDCore::SetSupportedStyleTag(NpadStyleTag style_tag) { diff --git a/src/core/hid/hid_types.h b/src/core/hid/hid_types.h index 70fcc6b69..4bf285f36 100644 --- a/src/core/hid/hid_types.h +++ b/src/core/hid/hid_types.h @@ -8,6 +8,7 @@ #include "common/common_types.h" #include "common/point.h" #include "common/uuid.h" +#include "common/vector_math.h" namespace Core::HID { @@ -598,6 +599,29 @@ struct SixAxisSensorIcInformation { static_assert(sizeof(SixAxisSensorIcInformation) == 0xC8, "SixAxisSensorIcInformation is an invalid size"); +// This is nn::hid::SixAxisSensorAttribute +struct SixAxisSensorAttribute { + union { + u32 raw{}; + BitField<0, 1, u32> is_connected; + BitField<1, 1, u32> is_interpolated; + }; +}; +static_assert(sizeof(SixAxisSensorAttribute) == 4, "SixAxisSensorAttribute is an invalid size"); + +// This is nn::hid::SixAxisSensorState +struct SixAxisSensorState { + s64 delta_time{}; + s64 sampling_number{}; + Common::Vec3f accel{}; + Common::Vec3f gyro{}; + Common::Vec3f rotation{}; + std::array orientation{}; + SixAxisSensorAttribute attribute{}; + INSERT_PADDING_BYTES(4); // Reserved +}; +static_assert(sizeof(SixAxisSensorState) == 0x60, "SixAxisSensorState is an invalid size"); + // This is nn::hid::VibrationDeviceHandle struct VibrationDeviceHandle { NpadStyleIndex npad_type{NpadStyleIndex::None}; @@ -708,60 +732,4 @@ struct UniquePadId { }; static_assert(sizeof(UniquePadId) == 0x8, "UniquePadId is an invalid size"); -/// Converts a NpadIdType to an array index. -constexpr size_t NpadIdTypeToIndex(NpadIdType npad_id_type) { - switch (npad_id_type) { - case NpadIdType::Player1: - return 0; - case NpadIdType::Player2: - return 1; - case NpadIdType::Player3: - return 2; - case NpadIdType::Player4: - return 3; - case NpadIdType::Player5: - return 4; - case NpadIdType::Player6: - return 5; - case NpadIdType::Player7: - return 6; - case NpadIdType::Player8: - return 7; - case NpadIdType::Handheld: - return 8; - case NpadIdType::Other: - return 9; - default: - return 0; - } -} - -/// Converts an array index to a NpadIdType -constexpr NpadIdType IndexToNpadIdType(size_t index) { - switch (index) { - case 0: - return NpadIdType::Player1; - case 1: - return NpadIdType::Player2; - case 2: - return NpadIdType::Player3; - case 3: - return NpadIdType::Player4; - case 4: - return NpadIdType::Player5; - case 5: - return NpadIdType::Player6; - case 6: - return NpadIdType::Player7; - case 7: - return NpadIdType::Player8; - case 8: - return NpadIdType::Handheld; - case 9: - return NpadIdType::Other; - default: - return NpadIdType::Invalid; - } -} - } // namespace Core::HID diff --git a/src/core/hid/input_interpreter.cpp b/src/core/hid/input_interpreter.cpp index 11359f318..a6bdd28f2 100644 --- a/src/core/hid/input_interpreter.cpp +++ b/src/core/hid/input_interpreter.cpp @@ -13,14 +13,14 @@ InputInterpreter::InputInterpreter(Core::System& system) : npad{system.ServiceManager() .GetService("hid") ->GetResourceManager() - ->GetController(Service::HID::HidController::NPad)} { + ->GetNpad()} { ResetButtonStates(); } InputInterpreter::~InputInterpreter() = default; void InputInterpreter::PollInput() { - const auto button_state = npad.GetAndResetPressState(); + const auto button_state = npad->GetAndResetPressState(); previous_index = current_index; current_index = (current_index + 1) % button_states.size(); diff --git a/src/core/hid/input_interpreter.h b/src/core/hid/input_interpreter.h index 8c521b381..3569aac93 100644 --- a/src/core/hid/input_interpreter.h +++ b/src/core/hid/input_interpreter.h @@ -16,7 +16,7 @@ enum class NpadButton : u64; } namespace Service::HID { -class Controller_NPad; +class NPad; } /** @@ -101,7 +101,7 @@ public: } private: - Service::HID::Controller_NPad& npad; + std::shared_ptr npad; /// Stores 9 consecutive button states polled from HID. std::array button_states{}; diff --git a/src/core/hle/service/hid/controllers/console_six_axis.cpp b/src/core/hle/service/hid/controllers/console_six_axis.cpp new file mode 100644 index 000000000..b2bf1d78d --- /dev/null +++ b/src/core/hle/service/hid/controllers/console_six_axis.cpp @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/core.h" +#include "core/core_timing.h" +#include "core/hid/emulated_console.h" +#include "core/hid/hid_core.h" +#include "core/hle/service/hid/controllers/console_six_axis.h" +#include "core/memory.h" + +namespace Service::HID { +constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C200; + +ConsoleSixAxis::ConsoleSixAxis(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) + : ControllerBase{hid_core_} { + console = hid_core.GetEmulatedConsole(); + static_assert(SHARED_MEMORY_OFFSET + sizeof(ConsoleSharedMemory) < shared_memory_size, + "ConsoleSharedMemory is bigger than the shared memory"); + shared_memory = std::construct_at( + reinterpret_cast(raw_shared_memory_ + SHARED_MEMORY_OFFSET)); +} + +ConsoleSixAxis::~ConsoleSixAxis() = default; + +void ConsoleSixAxis::OnInit() {} + +void ConsoleSixAxis::OnRelease() {} + +void ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + if (!IsControllerActivated()) { + return; + } + + const auto motion_status = console->GetMotion(); + + shared_memory->sampling_number++; + shared_memory->is_seven_six_axis_sensor_at_rest = motion_status.is_at_rest; + shared_memory->verticalization_error = motion_status.verticalization_error; + shared_memory->gyro_bias = motion_status.gyro_bias; +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/console_six_axis.h b/src/core/hle/service/hid/controllers/console_six_axis.h new file mode 100644 index 000000000..5b7c6a29a --- /dev/null +++ b/src/core/hle/service/hid/controllers/console_six_axis.h @@ -0,0 +1,43 @@ +// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/vector_math.h" +#include "core/hle/service/hid/controllers/controller_base.h" + +namespace Core::HID { +class EmulatedConsole; +} // namespace Core::HID + +namespace Service::HID { +class ConsoleSixAxis final : public ControllerBase { +public: + explicit ConsoleSixAxis(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); + ~ConsoleSixAxis() override; + + // Called when the controller is initialized + void OnInit() override; + + // When the controller is released + void OnRelease() override; + + // When the controller is requesting an update for the shared memory + void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; + +private: + // This is nn::hid::detail::ConsoleSixAxisSensorSharedMemoryFormat + struct ConsoleSharedMemory { + u64 sampling_number{}; + bool is_seven_six_axis_sensor_at_rest{}; + INSERT_PADDING_BYTES(3); // padding + f32 verticalization_error{}; + Common::Vec3f gyro_bias{}; + INSERT_PADDING_BYTES(4); // padding + }; + static_assert(sizeof(ConsoleSharedMemory) == 0x20, "ConsoleSharedMemory is an invalid size"); + + ConsoleSharedMemory* shared_memory = nullptr; + Core::HID::EmulatedConsole* console = nullptr; +}; +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.cpp b/src/core/hle/service/hid/controllers/console_sixaxis.cpp deleted file mode 100644 index bcb272eaf..000000000 --- a/src/core/hle/service/hid/controllers/console_sixaxis.cpp +++ /dev/null @@ -1,74 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#include "core/core.h" -#include "core/core_timing.h" -#include "core/hid/emulated_console.h" -#include "core/hid/hid_core.h" -#include "core/hle/service/hid/controllers/console_sixaxis.h" -#include "core/memory.h" - -namespace Service::HID { -constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C200; - -Controller_ConsoleSixAxis::Controller_ConsoleSixAxis(Core::System& system_, u8* raw_shared_memory_) - : ControllerBase{system_.HIDCore()}, system{system_} { - console = hid_core.GetEmulatedConsole(); - static_assert(SHARED_MEMORY_OFFSET + sizeof(ConsoleSharedMemory) < shared_memory_size, - "ConsoleSharedMemory is bigger than the shared memory"); - shared_memory = std::construct_at( - reinterpret_cast(raw_shared_memory_ + SHARED_MEMORY_OFFSET)); -} - -Controller_ConsoleSixAxis::~Controller_ConsoleSixAxis() = default; - -void Controller_ConsoleSixAxis::OnInit() {} - -void Controller_ConsoleSixAxis::OnRelease() {} - -void Controller_ConsoleSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { - if (!IsControllerActivated() || transfer_memory == 0) { - seven_sixaxis_lifo.buffer_count = 0; - seven_sixaxis_lifo.buffer_tail = 0; - return; - } - - const auto& last_entry = seven_sixaxis_lifo.ReadCurrentEntry().state; - next_seven_sixaxis_state.sampling_number = last_entry.sampling_number + 1; - - const auto motion_status = console->GetMotion(); - last_global_timestamp = core_timing.GetGlobalTimeNs().count(); - - // This value increments every time the switch goes to sleep - next_seven_sixaxis_state.unknown = 1; - next_seven_sixaxis_state.timestamp = last_global_timestamp - last_saved_timestamp; - next_seven_sixaxis_state.accel = motion_status.accel; - next_seven_sixaxis_state.gyro = motion_status.gyro; - next_seven_sixaxis_state.quaternion = { - { - motion_status.quaternion.xyz.y, - motion_status.quaternion.xyz.x, - -motion_status.quaternion.w, - }, - -motion_status.quaternion.xyz.z, - }; - - shared_memory->sampling_number++; - shared_memory->is_seven_six_axis_sensor_at_rest = motion_status.is_at_rest; - shared_memory->verticalization_error = motion_status.verticalization_error; - shared_memory->gyro_bias = motion_status.gyro_bias; - - // Update seven six axis transfer memory - seven_sixaxis_lifo.WriteNextEntry(next_seven_sixaxis_state); - system.ApplicationMemory().WriteBlock(transfer_memory, &seven_sixaxis_lifo, - sizeof(seven_sixaxis_lifo)); -} - -void Controller_ConsoleSixAxis::SetTransferMemoryAddress(Common::ProcessAddress t_mem) { - transfer_memory = t_mem; -} - -void Controller_ConsoleSixAxis::ResetTimestamp() { - last_saved_timestamp = last_global_timestamp; -} -} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/console_sixaxis.h b/src/core/hle/service/hid/controllers/console_sixaxis.h deleted file mode 100644 index 7015d924c..000000000 --- a/src/core/hle/service/hid/controllers/console_sixaxis.h +++ /dev/null @@ -1,78 +0,0 @@ -// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project -// SPDX-License-Identifier: GPL-2.0-or-later - -#pragma once - -#include - -#include "common/quaternion.h" -#include "common/typed_address.h" -#include "core/hle/service/hid/controllers/controller_base.h" -#include "core/hle/service/hid/ring_lifo.h" - -namespace Core { -class System; -} // namespace Core - -namespace Core::HID { -class EmulatedConsole; -} // namespace Core::HID - -namespace Service::HID { -class Controller_ConsoleSixAxis final : public ControllerBase { -public: - explicit Controller_ConsoleSixAxis(Core::System& system_, u8* raw_shared_memory_); - ~Controller_ConsoleSixAxis() override; - - // Called when the controller is initialized - void OnInit() override; - - // When the controller is released - void OnRelease() override; - - // When the controller is requesting an update for the shared memory - void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; - - // Called on InitializeSevenSixAxisSensor - void SetTransferMemoryAddress(Common::ProcessAddress t_mem); - - // Called on ResetSevenSixAxisSensorTimestamp - void ResetTimestamp(); - -private: - struct SevenSixAxisState { - INSERT_PADDING_WORDS(2); // unused - u64 timestamp{}; - u64 sampling_number{}; - u64 unknown{}; - Common::Vec3f accel{}; - Common::Vec3f gyro{}; - Common::Quaternion quaternion{}; - }; - static_assert(sizeof(SevenSixAxisState) == 0x48, "SevenSixAxisState is an invalid size"); - - // This is nn::hid::detail::ConsoleSixAxisSensorSharedMemoryFormat - struct ConsoleSharedMemory { - u64 sampling_number{}; - bool is_seven_six_axis_sensor_at_rest{}; - INSERT_PADDING_BYTES(3); // padding - f32 verticalization_error{}; - Common::Vec3f gyro_bias{}; - INSERT_PADDING_BYTES(4); // padding - }; - static_assert(sizeof(ConsoleSharedMemory) == 0x20, "ConsoleSharedMemory is an invalid size"); - - Lifo seven_sixaxis_lifo{}; - static_assert(sizeof(seven_sixaxis_lifo) == 0xA70, "SevenSixAxisState is an invalid size"); - - SevenSixAxisState next_seven_sixaxis_state{}; - Common::ProcessAddress transfer_memory{}; - ConsoleSharedMemory* shared_memory = nullptr; - Core::HID::EmulatedConsole* console = nullptr; - - u64 last_saved_timestamp{}; - u64 last_global_timestamp{}; - - Core::System& system; -}; -} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp index 8ec9f4a95..9de19ebfc 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.cpp +++ b/src/core/hle/service/hid/controllers/debug_pad.cpp @@ -13,7 +13,7 @@ namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x00000; -Controller_DebugPad::Controller_DebugPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) +DebugPad::DebugPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) : ControllerBase{hid_core_} { static_assert(SHARED_MEMORY_OFFSET + sizeof(DebugPadSharedMemory) < shared_memory_size, "DebugPadSharedMemory is bigger than the shared memory"); @@ -22,13 +22,13 @@ Controller_DebugPad::Controller_DebugPad(Core::HID::HIDCore& hid_core_, u8* raw_ controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other); } -Controller_DebugPad::~Controller_DebugPad() = default; +DebugPad::~DebugPad() = default; -void Controller_DebugPad::OnInit() {} +void DebugPad::OnInit() {} -void Controller_DebugPad::OnRelease() {} +void DebugPad::OnRelease() {} -void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { +void DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { if (!IsControllerActivated()) { shared_memory->debug_pad_lifo.buffer_count = 0; shared_memory->debug_pad_lifo.buffer_tail = 0; diff --git a/src/core/hle/service/hid/controllers/debug_pad.h b/src/core/hle/service/hid/controllers/debug_pad.h index 68ff0ea79..5566dba77 100644 --- a/src/core/hle/service/hid/controllers/debug_pad.h +++ b/src/core/hle/service/hid/controllers/debug_pad.h @@ -15,10 +15,10 @@ struct AnalogStickState; } // namespace Core::HID namespace Service::HID { -class Controller_DebugPad final : public ControllerBase { +class DebugPad final : public ControllerBase { public: - explicit Controller_DebugPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); - ~Controller_DebugPad() override; + explicit DebugPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); + ~DebugPad() override; // Called when the controller is initialized void OnInit() override; diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp index 63eecd42b..59b2ec73c 100644 --- a/src/core/hle/service/hid/controllers/gesture.cpp +++ b/src/core/hle/service/hid/controllers/gesture.cpp @@ -23,7 +23,7 @@ constexpr f32 Square(s32 num) { return static_cast(num * num); } -Controller_Gesture::Controller_Gesture(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) +Gesture::Gesture(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) : ControllerBase(hid_core_) { static_assert(SHARED_MEMORY_OFFSET + sizeof(GestureSharedMemory) < shared_memory_size, "GestureSharedMemory is bigger than the shared memory"); @@ -31,17 +31,17 @@ Controller_Gesture::Controller_Gesture(Core::HID::HIDCore& hid_core_, u8* raw_sh reinterpret_cast(raw_shared_memory_ + SHARED_MEMORY_OFFSET)); console = hid_core.GetEmulatedConsole(); } -Controller_Gesture::~Controller_Gesture() = default; +Gesture::~Gesture() = default; -void Controller_Gesture::OnInit() { +void Gesture::OnInit() { shared_memory->gesture_lifo.buffer_count = 0; shared_memory->gesture_lifo.buffer_tail = 0; force_update = true; } -void Controller_Gesture::OnRelease() {} +void Gesture::OnRelease() {} -void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { +void Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { if (!IsControllerActivated()) { shared_memory->gesture_lifo.buffer_count = 0; shared_memory->gesture_lifo.buffer_tail = 0; @@ -64,7 +64,7 @@ void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing) { UpdateGestureSharedMemory(gesture, time_difference); } -void Controller_Gesture::ReadTouchInput() { +void Gesture::ReadTouchInput() { if (!Settings::values.touchscreen.enabled) { fingers = {}; return; @@ -76,8 +76,7 @@ void Controller_Gesture::ReadTouchInput() { } } -bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture, - f32 time_difference) { +bool Gesture::ShouldUpdateGesture(const GestureProperties& gesture, f32 time_difference) { const auto& last_entry = GetLastGestureEntry(); if (force_update) { force_update = false; @@ -100,8 +99,7 @@ bool Controller_Gesture::ShouldUpdateGesture(const GestureProperties& gesture, return false; } -void Controller_Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, - f32 time_difference) { +void Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, f32 time_difference) { GestureType type = GestureType::Idle; GestureAttribute attributes{}; @@ -138,8 +136,8 @@ void Controller_Gesture::UpdateGestureSharedMemory(GestureProperties& gesture, shared_memory->gesture_lifo.WriteNextEntry(next_state); } -void Controller_Gesture::NewGesture(GestureProperties& gesture, GestureType& type, - GestureAttribute& attributes) { +void Gesture::NewGesture(GestureProperties& gesture, GestureType& type, + GestureAttribute& attributes) { const auto& last_entry = GetLastGestureEntry(); gesture.detection_count++; @@ -152,8 +150,8 @@ void Controller_Gesture::NewGesture(GestureProperties& gesture, GestureType& typ } } -void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, GestureType& type, - f32 time_difference) { +void Gesture::UpdateExistingGesture(GestureProperties& gesture, GestureType& type, + f32 time_difference) { const auto& last_entry = GetLastGestureEntry(); // Promote to pan type if touch moved @@ -186,9 +184,8 @@ void Controller_Gesture::UpdateExistingGesture(GestureProperties& gesture, Gestu } } -void Controller_Gesture::EndGesture(GestureProperties& gesture, - GestureProperties& last_gesture_props, GestureType& type, - GestureAttribute& attributes, f32 time_difference) { +void Gesture::EndGesture(GestureProperties& gesture, GestureProperties& last_gesture_props, + GestureType& type, GestureAttribute& attributes, f32 time_difference) { const auto& last_entry = GetLastGestureEntry(); if (last_gesture_props.active_points != 0) { @@ -222,9 +219,8 @@ void Controller_Gesture::EndGesture(GestureProperties& gesture, } } -void Controller_Gesture::SetTapEvent(GestureProperties& gesture, - GestureProperties& last_gesture_props, GestureType& type, - GestureAttribute& attributes) { +void Gesture::SetTapEvent(GestureProperties& gesture, GestureProperties& last_gesture_props, + GestureType& type, GestureAttribute& attributes) { type = GestureType::Tap; gesture = last_gesture_props; force_update = true; @@ -236,9 +232,8 @@ void Controller_Gesture::SetTapEvent(GestureProperties& gesture, } } -void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture, - GestureProperties& last_gesture_props, GestureType& type, - f32 time_difference) { +void Gesture::UpdatePanEvent(GestureProperties& gesture, GestureProperties& last_gesture_props, + GestureType& type, f32 time_difference) { const auto& last_entry = GetLastGestureEntry(); next_state.delta = gesture.mid_point - last_entry.pos; @@ -263,9 +258,8 @@ void Controller_Gesture::UpdatePanEvent(GestureProperties& gesture, } } -void Controller_Gesture::EndPanEvent(GestureProperties& gesture, - GestureProperties& last_gesture_props, GestureType& type, - f32 time_difference) { +void Gesture::EndPanEvent(GestureProperties& gesture, GestureProperties& last_gesture_props, + GestureType& type, f32 time_difference) { const auto& last_entry = GetLastGestureEntry(); next_state.vel_x = static_cast(last_entry.delta.x) / (last_pan_time_difference + time_difference); @@ -287,8 +281,8 @@ void Controller_Gesture::EndPanEvent(GestureProperties& gesture, force_update = true; } -void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture, - GestureProperties& last_gesture_props, GestureType& type) { +void Gesture::SetSwipeEvent(GestureProperties& gesture, GestureProperties& last_gesture_props, + GestureType& type) { const auto& last_entry = GetLastGestureEntry(); type = GestureType::Swipe; @@ -311,11 +305,11 @@ void Controller_Gesture::SetSwipeEvent(GestureProperties& gesture, next_state.direction = GestureDirection::Up; } -const Controller_Gesture::GestureState& Controller_Gesture::GetLastGestureEntry() const { +const Gesture::GestureState& Gesture::GetLastGestureEntry() const { return shared_memory->gesture_lifo.ReadCurrentEntry().state; } -Controller_Gesture::GestureProperties Controller_Gesture::GetGestureProperties() { +Gesture::GestureProperties Gesture::GetGestureProperties() { GestureProperties gesture; std::array active_fingers; const auto end_iter = std::copy_if(fingers.begin(), fingers.end(), active_fingers.begin(), diff --git a/src/core/hle/service/hid/controllers/gesture.h b/src/core/hle/service/hid/controllers/gesture.h index 0d6099ea0..4c6f8ee07 100644 --- a/src/core/hle/service/hid/controllers/gesture.h +++ b/src/core/hle/service/hid/controllers/gesture.h @@ -12,10 +12,10 @@ #include "core/hle/service/hid/ring_lifo.h" namespace Service::HID { -class Controller_Gesture final : public ControllerBase { +class Gesture final : public ControllerBase { public: - explicit Controller_Gesture(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); - ~Controller_Gesture() override; + explicit Gesture(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); + ~Gesture() override; // Called when the controller is initialized void OnInit() override; diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp index 117d87433..ddb1b0ba4 100644 --- a/src/core/hle/service/hid/controllers/keyboard.cpp +++ b/src/core/hle/service/hid/controllers/keyboard.cpp @@ -12,7 +12,7 @@ namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3800; -Controller_Keyboard::Controller_Keyboard(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) +Keyboard::Keyboard(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) : ControllerBase{hid_core_} { static_assert(SHARED_MEMORY_OFFSET + sizeof(KeyboardSharedMemory) < shared_memory_size, "KeyboardSharedMemory is bigger than the shared memory"); @@ -21,13 +21,13 @@ Controller_Keyboard::Controller_Keyboard(Core::HID::HIDCore& hid_core_, u8* raw_ emulated_devices = hid_core.GetEmulatedDevices(); } -Controller_Keyboard::~Controller_Keyboard() = default; +Keyboard::~Keyboard() = default; -void Controller_Keyboard::OnInit() {} +void Keyboard::OnInit() {} -void Controller_Keyboard::OnRelease() {} +void Keyboard::OnRelease() {} -void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) { +void Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing) { if (!IsControllerActivated()) { shared_memory->keyboard_lifo.buffer_count = 0; shared_memory->keyboard_lifo.buffer_tail = 0; diff --git a/src/core/hle/service/hid/controllers/keyboard.h b/src/core/hle/service/hid/controllers/keyboard.h index 7532f53c6..172ec1309 100644 --- a/src/core/hle/service/hid/controllers/keyboard.h +++ b/src/core/hle/service/hid/controllers/keyboard.h @@ -14,10 +14,10 @@ struct KeyboardKey; } // namespace Core::HID namespace Service::HID { -class Controller_Keyboard final : public ControllerBase { +class Keyboard final : public ControllerBase { public: - explicit Controller_Keyboard(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); - ~Controller_Keyboard() override; + explicit Keyboard(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); + ~Keyboard() override; // Called when the controller is initialized void OnInit() override; diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp index 0afc66681..6e5a04e34 100644 --- a/src/core/hle/service/hid/controllers/mouse.cpp +++ b/src/core/hle/service/hid/controllers/mouse.cpp @@ -12,8 +12,7 @@ namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3400; -Controller_Mouse::Controller_Mouse(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) - : ControllerBase{hid_core_} { +Mouse::Mouse(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) : ControllerBase{hid_core_} { static_assert(SHARED_MEMORY_OFFSET + sizeof(MouseSharedMemory) < shared_memory_size, "MouseSharedMemory is bigger than the shared memory"); shared_memory = std::construct_at( @@ -21,12 +20,12 @@ Controller_Mouse::Controller_Mouse(Core::HID::HIDCore& hid_core_, u8* raw_shared emulated_devices = hid_core.GetEmulatedDevices(); } -Controller_Mouse::~Controller_Mouse() = default; +Mouse::~Mouse() = default; -void Controller_Mouse::OnInit() {} -void Controller_Mouse::OnRelease() {} +void Mouse::OnInit() {} +void Mouse::OnRelease() {} -void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { +void Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing) { if (!IsControllerActivated()) { shared_memory->mouse_lifo.buffer_count = 0; shared_memory->mouse_lifo.buffer_tail = 0; diff --git a/src/core/hle/service/hid/controllers/mouse.h b/src/core/hle/service/hid/controllers/mouse.h index 733d00577..a80f3823f 100644 --- a/src/core/hle/service/hid/controllers/mouse.h +++ b/src/core/hle/service/hid/controllers/mouse.h @@ -14,10 +14,10 @@ struct AnalogStickState; } // namespace Core::HID namespace Service::HID { -class Controller_Mouse final : public ControllerBase { +class Mouse final : public ControllerBase { public: - explicit Controller_Mouse(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); - ~Controller_Mouse() override; + explicit Mouse(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); + ~Mouse() override; // Called when the controller is initialized void OnInit() override; diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp index 127af2b82..08ee9de9c 100644 --- a/src/core/hle/service/hid/controllers/npad.cpp +++ b/src/core/hle/service/hid/controllers/npad.cpp @@ -18,6 +18,7 @@ #include "core/hle/kernel/k_readable_event.h" #include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/errors.h" +#include "core/hle/service/hid/hid_util.h" #include "core/hle/service/kernel_helpers.h" namespace Service::HID { @@ -29,60 +30,8 @@ constexpr std::array npad_id_list{ Core::HID::NpadIdType::Handheld, }; -bool Controller_NPad::IsNpadIdValid(Core::HID::NpadIdType npad_id) { - switch (npad_id) { - case Core::HID::NpadIdType::Player1: - case Core::HID::NpadIdType::Player2: - case Core::HID::NpadIdType::Player3: - case Core::HID::NpadIdType::Player4: - case Core::HID::NpadIdType::Player5: - case Core::HID::NpadIdType::Player6: - case Core::HID::NpadIdType::Player7: - case Core::HID::NpadIdType::Player8: - case Core::HID::NpadIdType::Other: - case Core::HID::NpadIdType::Handheld: - return true; - default: - LOG_ERROR(Service_HID, "Invalid npad id {}", npad_id); - return false; - } -} - -Result Controller_NPad::IsDeviceHandleValid(const Core::HID::VibrationDeviceHandle& device_handle) { - const auto npad_id = IsNpadIdValid(static_cast(device_handle.npad_id)); - const bool npad_type = device_handle.npad_type < Core::HID::NpadStyleIndex::MaxNpadType; - const bool device_index = device_handle.device_index < Core::HID::DeviceIndex::MaxDeviceIndex; - - if (!npad_type) { - return VibrationInvalidStyleIndex; - } - if (!npad_id) { - return VibrationInvalidNpadId; - } - if (!device_index) { - return VibrationDeviceIndexOutOfRange; - } - - return ResultSuccess; -} - -Result Controller_NPad::VerifyValidSixAxisSensorHandle( - const Core::HID::SixAxisSensorHandle& device_handle) { - const auto npad_id = IsNpadIdValid(static_cast(device_handle.npad_id)); - const bool device_index = device_handle.device_index < Core::HID::DeviceIndex::MaxDeviceIndex; - - if (!npad_id) { - return InvalidNpadId; - } - if (!device_index) { - return NpadDeviceIndexOutOfRange; - } - - return ResultSuccess; -} - -Controller_NPad::Controller_NPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_, - KernelHelpers::ServiceContext& service_context_) +NPad::NPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_, + KernelHelpers::ServiceContext& service_context_) : ControllerBase{hid_core_}, service_context{service_context_} { static_assert(NPAD_OFFSET + (NPAD_COUNT * sizeof(NpadInternalState)) < shared_memory_size); for (std::size_t i = 0; i < controller_data.size(); ++i) { @@ -103,7 +52,7 @@ Controller_NPad::Controller_NPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_m } } -Controller_NPad::~Controller_NPad() { +NPad::~NPad() { for (std::size_t i = 0; i < controller_data.size(); ++i) { auto& controller = controller_data[i]; controller.device->DeleteCallback(controller.callback_key); @@ -111,8 +60,7 @@ Controller_NPad::~Controller_NPad() { OnRelease(); } -void Controller_NPad::ControllerUpdate(Core::HID::ControllerTriggerType type, - std::size_t controller_idx) { +void NPad::ControllerUpdate(Core::HID::ControllerTriggerType type, std::size_t controller_idx) { if (type == Core::HID::ControllerTriggerType::All) { ControllerUpdate(Core::HID::ControllerTriggerType::Connected, controller_idx); ControllerUpdate(Core::HID::ControllerTriggerType::Battery, controller_idx); @@ -150,7 +98,7 @@ void Controller_NPad::ControllerUpdate(Core::HID::ControllerTriggerType type, } } -void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { +void NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { auto& controller = GetControllerFromNpadIdType(npad_id); if (!IsControllerSupported(controller.device->GetNpadStyleIndex())) { return; @@ -350,7 +298,7 @@ void Controller_NPad::InitNewlyAddedController(Core::HID::NpadIdType npad_id) { hid_core.SetLastActiveController(npad_id); } -void Controller_NPad::OnInit() { +void NPad::OnInit() { if (!IsControllerActivated()) { return; } @@ -384,7 +332,7 @@ void Controller_NPad::OnInit() { } } -void Controller_NPad::WriteEmptyEntry(NpadInternalState* npad) { +void NPad::WriteEmptyEntry(NpadInternalState* npad) { NPadGenericState dummy_pad_state{}; NpadGcTriggerState dummy_gc_state{}; dummy_pad_state.sampling_number = npad->fullkey_lifo.ReadCurrentEntry().sampling_number + 1; @@ -405,7 +353,7 @@ void Controller_NPad::WriteEmptyEntry(NpadInternalState* npad) { npad->gc_trigger_lifo.WriteNextEntry(dummy_gc_state); } -void Controller_NPad::OnRelease() { +void NPad::OnRelease() { is_controller_initialized = false; for (std::size_t i = 0; i < controller_data.size(); ++i) { auto& controller = controller_data[i]; @@ -416,7 +364,7 @@ void Controller_NPad::OnRelease() { } } -void Controller_NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) { +void NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) { std::scoped_lock lock{mutex}; auto& controller = GetControllerFromNpadIdType(npad_id); const auto controller_type = controller.device->GetNpadStyleIndex(); @@ -485,7 +433,7 @@ void Controller_NPad::RequestPadStateUpdate(Core::HID::NpadIdType npad_id) { } } -void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { +void NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { if (!IsControllerActivated()) { return; } @@ -615,134 +563,7 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { } } -void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing) { - if (!IsControllerActivated()) { - return; - } - - for (std::size_t i = 0; i < controller_data.size(); ++i) { - auto& controller = controller_data[i]; - - const auto& controller_type = controller.device->GetNpadStyleIndex(); - - if (controller_type == Core::HID::NpadStyleIndex::None || - !controller.device->IsConnected()) { - continue; - } - - auto* npad = controller.shared_memory; - const auto& motion_state = controller.device->GetMotions(); - auto& sixaxis_fullkey_state = controller.sixaxis_fullkey_state; - auto& sixaxis_handheld_state = controller.sixaxis_handheld_state; - auto& sixaxis_dual_left_state = controller.sixaxis_dual_left_state; - auto& sixaxis_dual_right_state = controller.sixaxis_dual_right_state; - auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; - auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; - - // Clear previous state - sixaxis_fullkey_state = {}; - sixaxis_handheld_state = {}; - sixaxis_dual_left_state = {}; - sixaxis_dual_right_state = {}; - sixaxis_left_lifo_state = {}; - sixaxis_right_lifo_state = {}; - - if (controller.sixaxis_sensor_enabled && Settings::values.motion_enabled.GetValue()) { - controller.sixaxis_at_rest = true; - for (std::size_t e = 0; e < motion_state.size(); ++e) { - controller.sixaxis_at_rest = - controller.sixaxis_at_rest && motion_state[e].is_at_rest; - } - } - - const auto set_motion_state = [&](SixAxisSensorState& state, - const Core::HID::ControllerMotion& hid_state) { - using namespace std::literals::chrono_literals; - static constexpr SixAxisSensorState default_motion_state = { - .delta_time = std::chrono::nanoseconds(5ms).count(), - .accel = {0, 0, -1.0f}, - .orientation = - { - Common::Vec3f{1.0f, 0, 0}, - Common::Vec3f{0, 1.0f, 0}, - Common::Vec3f{0, 0, 1.0f}, - }, - .attribute = {1}, - }; - if (!controller.sixaxis_sensor_enabled) { - state = default_motion_state; - return; - } - if (!Settings::values.motion_enabled.GetValue()) { - state = default_motion_state; - return; - } - state.attribute.is_connected.Assign(1); - state.delta_time = std::chrono::nanoseconds(5ms).count(); - state.accel = hid_state.accel; - state.gyro = hid_state.gyro; - state.rotation = hid_state.rotation; - state.orientation = hid_state.orientation; - }; - - switch (controller_type) { - case Core::HID::NpadStyleIndex::None: - ASSERT(false); - break; - case Core::HID::NpadStyleIndex::ProController: - set_motion_state(sixaxis_fullkey_state, motion_state[0]); - break; - case Core::HID::NpadStyleIndex::Handheld: - set_motion_state(sixaxis_handheld_state, motion_state[0]); - break; - case Core::HID::NpadStyleIndex::JoyconDual: - set_motion_state(sixaxis_dual_left_state, motion_state[0]); - set_motion_state(sixaxis_dual_right_state, motion_state[1]); - break; - case Core::HID::NpadStyleIndex::JoyconLeft: - set_motion_state(sixaxis_left_lifo_state, motion_state[0]); - break; - case Core::HID::NpadStyleIndex::JoyconRight: - set_motion_state(sixaxis_right_lifo_state, motion_state[1]); - break; - case Core::HID::NpadStyleIndex::Pokeball: - using namespace std::literals::chrono_literals; - set_motion_state(sixaxis_fullkey_state, motion_state[0]); - sixaxis_fullkey_state.delta_time = std::chrono::nanoseconds(15ms).count(); - break; - default: - break; - } - - sixaxis_fullkey_state.sampling_number = - npad->sixaxis_fullkey_lifo.ReadCurrentEntry().state.sampling_number + 1; - sixaxis_handheld_state.sampling_number = - npad->sixaxis_handheld_lifo.ReadCurrentEntry().state.sampling_number + 1; - sixaxis_dual_left_state.sampling_number = - npad->sixaxis_dual_left_lifo.ReadCurrentEntry().state.sampling_number + 1; - sixaxis_dual_right_state.sampling_number = - npad->sixaxis_dual_right_lifo.ReadCurrentEntry().state.sampling_number + 1; - sixaxis_left_lifo_state.sampling_number = - npad->sixaxis_left_lifo.ReadCurrentEntry().state.sampling_number + 1; - sixaxis_right_lifo_state.sampling_number = - npad->sixaxis_right_lifo.ReadCurrentEntry().state.sampling_number + 1; - - if (Core::HID::IndexToNpadIdType(i) == Core::HID::NpadIdType::Handheld) { - // This buffer only is updated on handheld on HW - npad->sixaxis_handheld_lifo.WriteNextEntry(sixaxis_handheld_state); - } else { - // Handheld doesn't update this buffer on HW - npad->sixaxis_fullkey_lifo.WriteNextEntry(sixaxis_fullkey_state); - } - - npad->sixaxis_dual_left_lifo.WriteNextEntry(sixaxis_dual_left_state); - npad->sixaxis_dual_right_lifo.WriteNextEntry(sixaxis_dual_right_state); - npad->sixaxis_left_lifo.WriteNextEntry(sixaxis_left_lifo_state); - npad->sixaxis_right_lifo.WriteNextEntry(sixaxis_right_lifo_state); - } -} - -void Controller_NPad::SetSupportedStyleSet(Core::HID::NpadStyleTag style_set) { +void NPad::SetSupportedStyleSet(Core::HID::NpadStyleTag style_set) { hid_core.SetSupportedStyleTag(style_set); if (is_controller_initialized) { @@ -753,14 +574,14 @@ void Controller_NPad::SetSupportedStyleSet(Core::HID::NpadStyleTag style_set) { is_controller_initialized = true; } -Core::HID::NpadStyleTag Controller_NPad::GetSupportedStyleSet() const { +Core::HID::NpadStyleTag NPad::GetSupportedStyleSet() const { if (!is_controller_initialized) { return {Core::HID::NpadStyleSet::None}; } return hid_core.GetSupportedStyleTag(); } -Result Controller_NPad::SetSupportedNpadIdTypes(std::span data) { +Result NPad::SetSupportedNpadIdTypes(std::span data) { constexpr std::size_t max_number_npad_ids = 0xa; const auto length = data.size(); ASSERT(length > 0 && (length % sizeof(u32)) == 0); @@ -776,17 +597,17 @@ Result Controller_NPad::SetSupportedNpadIdTypes(std::span data) { return ResultSuccess; } -void Controller_NPad::GetSupportedNpadIdTypes(u32* data, std::size_t max_length) { +void NPad::GetSupportedNpadIdTypes(u32* data, std::size_t max_length) { const auto copy_amount = supported_npad_id_types.size() * sizeof(u32); ASSERT(max_length <= copy_amount); std::memcpy(data, supported_npad_id_types.data(), copy_amount); } -std::size_t Controller_NPad::GetSupportedNpadIdTypesSize() const { +std::size_t NPad::GetSupportedNpadIdTypesSize() const { return supported_npad_id_types.size(); } -void Controller_NPad::SetHoldType(NpadJoyHoldType joy_hold_type) { +void NPad::SetHoldType(NpadJoyHoldType joy_hold_type) { if (joy_hold_type != NpadJoyHoldType::Horizontal && joy_hold_type != NpadJoyHoldType::Vertical) { LOG_ERROR(Service_HID, "Npad joy hold type needs to be valid, joy_hold_type={}", @@ -796,11 +617,11 @@ void Controller_NPad::SetHoldType(NpadJoyHoldType joy_hold_type) { hold_type = joy_hold_type; } -Controller_NPad::NpadJoyHoldType Controller_NPad::GetHoldType() const { +NPad::NpadJoyHoldType NPad::GetHoldType() const { return hold_type; } -void Controller_NPad::SetNpadHandheldActivationMode(NpadHandheldActivationMode activation_mode) { +void NPad::SetNpadHandheldActivationMode(NpadHandheldActivationMode activation_mode) { if (activation_mode >= NpadHandheldActivationMode::MaxActivationMode) { ASSERT_MSG(false, "Activation mode should be always None, Single or Dual"); return; @@ -809,21 +630,20 @@ void Controller_NPad::SetNpadHandheldActivationMode(NpadHandheldActivationMode a handheld_activation_mode = activation_mode; } -Controller_NPad::NpadHandheldActivationMode Controller_NPad::GetNpadHandheldActivationMode() const { +NPad::NpadHandheldActivationMode NPad::GetNpadHandheldActivationMode() const { return handheld_activation_mode; } -void Controller_NPad::SetNpadCommunicationMode(NpadCommunicationMode communication_mode_) { +void NPad::SetNpadCommunicationMode(NpadCommunicationMode communication_mode_) { communication_mode = communication_mode_; } -Controller_NPad::NpadCommunicationMode Controller_NPad::GetNpadCommunicationMode() const { +NPad::NpadCommunicationMode NPad::GetNpadCommunicationMode() const { return communication_mode; } -bool Controller_NPad::SetNpadMode(Core::HID::NpadIdType& new_npad_id, Core::HID::NpadIdType npad_id, - NpadJoyDeviceType npad_device_type, - NpadJoyAssignmentMode assignment_mode) { +bool NPad::SetNpadMode(Core::HID::NpadIdType& new_npad_id, Core::HID::NpadIdType npad_id, + NpadJoyDeviceType npad_device_type, NpadJoyAssignmentMode assignment_mode) { if (!IsNpadIdValid(npad_id)) { LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); return false; @@ -892,9 +712,8 @@ bool Controller_NPad::SetNpadMode(Core::HID::NpadIdType& new_npad_id, Core::HID: return true; } -bool Controller_NPad::VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, - std::size_t device_index, - const Core::HID::VibrationValue& vibration_value) { +bool NPad::VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, std::size_t device_index, + const Core::HID::VibrationValue& vibration_value) { auto& controller = GetControllerFromNpadIdType(npad_id); if (!controller.device->IsConnected()) { return false; @@ -938,10 +757,9 @@ bool Controller_NPad::VibrateControllerAtIndex(Core::HID::NpadIdType npad_id, return controller.device->SetVibration(device_index, vibration); } -void Controller_NPad::VibrateController( - const Core::HID::VibrationDeviceHandle& vibration_device_handle, - const Core::HID::VibrationValue& vibration_value) { - if (IsDeviceHandleValid(vibration_device_handle).IsError()) { +void NPad::VibrateController(const Core::HID::VibrationDeviceHandle& vibration_device_handle, + const Core::HID::VibrationValue& vibration_value) { + if (IsVibrationHandleValid(vibration_device_handle).IsError()) { return; } @@ -985,7 +803,7 @@ void Controller_NPad::VibrateController( } } -void Controller_NPad::VibrateControllers( +void NPad::VibrateControllers( std::span vibration_device_handles, std::span vibration_values) { if (!Settings::values.vibration_enabled.GetValue() && !permit_vibration_session_enabled) { @@ -1002,9 +820,9 @@ void Controller_NPad::VibrateControllers( } } -Core::HID::VibrationValue Controller_NPad::GetLastVibration( +Core::HID::VibrationValue NPad::GetLastVibration( const Core::HID::VibrationDeviceHandle& vibration_device_handle) const { - if (IsDeviceHandleValid(vibration_device_handle).IsError()) { + if (IsVibrationHandleValid(vibration_device_handle).IsError()) { return {}; } @@ -1013,9 +831,9 @@ Core::HID::VibrationValue Controller_NPad::GetLastVibration( return controller.vibration[device_index].latest_vibration_value; } -void Controller_NPad::InitializeVibrationDevice( +void NPad::InitializeVibrationDevice( const Core::HID::VibrationDeviceHandle& vibration_device_handle) { - if (IsDeviceHandleValid(vibration_device_handle).IsError()) { + if (IsVibrationHandleValid(vibration_device_handle).IsError()) { return; } @@ -1024,8 +842,8 @@ void Controller_NPad::InitializeVibrationDevice( InitializeVibrationDeviceAtIndex(npad_index, device_index); } -void Controller_NPad::InitializeVibrationDeviceAtIndex(Core::HID::NpadIdType npad_id, - std::size_t device_index) { +void NPad::InitializeVibrationDeviceAtIndex(Core::HID::NpadIdType npad_id, + std::size_t device_index) { auto& controller = GetControllerFromNpadIdType(npad_id); if (!Settings::values.vibration_enabled.GetValue()) { controller.vibration[device_index].device_mounted = false; @@ -1036,13 +854,13 @@ void Controller_NPad::InitializeVibrationDeviceAtIndex(Core::HID::NpadIdType npa controller.device->IsVibrationEnabled(device_index); } -void Controller_NPad::SetPermitVibrationSession(bool permit_vibration_session) { +void NPad::SetPermitVibrationSession(bool permit_vibration_session) { permit_vibration_session_enabled = permit_vibration_session; } -bool Controller_NPad::IsVibrationDeviceMounted( +bool NPad::IsVibrationDeviceMounted( const Core::HID::VibrationDeviceHandle& vibration_device_handle) const { - if (IsDeviceHandleValid(vibration_device_handle).IsError()) { + if (IsVibrationHandleValid(vibration_device_handle).IsError()) { return false; } @@ -1051,7 +869,7 @@ bool Controller_NPad::IsVibrationDeviceMounted( return controller.vibration[device_index].device_mounted; } -Kernel::KReadableEvent& Controller_NPad::GetStyleSetChangedEvent(Core::HID::NpadIdType npad_id) { +Kernel::KReadableEvent& NPad::GetStyleSetChangedEvent(Core::HID::NpadIdType npad_id) { if (!IsNpadIdValid(npad_id)) { LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); // Fallback to player 1 @@ -1063,18 +881,17 @@ Kernel::KReadableEvent& Controller_NPad::GetStyleSetChangedEvent(Core::HID::Npad return controller.styleset_changed_event->GetReadableEvent(); } -void Controller_NPad::SignalStyleSetChangedEvent(Core::HID::NpadIdType npad_id) const { +void NPad::SignalStyleSetChangedEvent(Core::HID::NpadIdType npad_id) const { const auto& controller = GetControllerFromNpadIdType(npad_id); controller.styleset_changed_event->Signal(); } -void Controller_NPad::AddNewControllerAt(Core::HID::NpadStyleIndex controller, - Core::HID::NpadIdType npad_id) { +void NPad::AddNewControllerAt(Core::HID::NpadStyleIndex controller, Core::HID::NpadIdType npad_id) { UpdateControllerAt(controller, npad_id, true); } -void Controller_NPad::UpdateControllerAt(Core::HID::NpadStyleIndex type, - Core::HID::NpadIdType npad_id, bool connected) { +void NPad::UpdateControllerAt(Core::HID::NpadStyleIndex type, Core::HID::NpadIdType npad_id, + bool connected) { auto& controller = GetControllerFromNpadIdType(npad_id); if (!connected) { DisconnectNpad(npad_id); @@ -1085,7 +902,7 @@ void Controller_NPad::UpdateControllerAt(Core::HID::NpadStyleIndex type, InitNewlyAddedController(npad_id); } -Result Controller_NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) { +Result NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) { if (!IsNpadIdValid(npad_id)) { LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); return InvalidNpadId; @@ -1134,54 +951,9 @@ Result Controller_NPad::DisconnectNpad(Core::HID::NpadIdType npad_id) { return ResultSuccess; } -Result Controller_NPad::SetGyroscopeZeroDriftMode( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::GyroscopeZeroDriftMode drift_mode) { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - auto& sixaxis = GetSixaxisState(sixaxis_handle); - auto& controller = GetControllerFromHandle(sixaxis_handle); - sixaxis.gyroscope_zero_drift_mode = drift_mode; - controller.device->SetGyroscopeZeroDriftMode(drift_mode); - - return ResultSuccess; -} - -Result Controller_NPad::GetGyroscopeZeroDriftMode( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::GyroscopeZeroDriftMode& drift_mode) const { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - const auto& sixaxis = GetSixaxisState(sixaxis_handle); - drift_mode = sixaxis.gyroscope_zero_drift_mode; - - return ResultSuccess; -} - -Result Controller_NPad::IsSixAxisSensorAtRest(const Core::HID::SixAxisSensorHandle& sixaxis_handle, - bool& is_at_rest) const { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - const auto& controller = GetControllerFromHandle(sixaxis_handle); - is_at_rest = controller.sixaxis_at_rest; - return ResultSuccess; -} - -Result Controller_NPad::IsFirmwareUpdateAvailableForSixAxisSensor( +Result NPad::IsFirmwareUpdateAvailableForSixAxisSensor( const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_firmware_available) const { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); if (is_valid.IsError()) { LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); return is_valid; @@ -1192,65 +964,9 @@ Result Controller_NPad::IsFirmwareUpdateAvailableForSixAxisSensor( return ResultSuccess; } -Result Controller_NPad::EnableSixAxisSensorUnalteredPassthrough( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool is_enabled) { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - auto& sixaxis = GetSixaxisState(sixaxis_handle); - sixaxis.unaltered_passtrough = is_enabled; - return ResultSuccess; -} - -Result Controller_NPad::IsSixAxisSensorUnalteredPassthroughEnabled( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_enabled) const { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - const auto& sixaxis = GetSixaxisState(sixaxis_handle); - is_enabled = sixaxis.unaltered_passtrough; - return ResultSuccess; -} - -Result Controller_NPad::LoadSixAxisSensorCalibrationParameter( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::SixAxisSensorCalibrationParameter& calibration) const { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - // TODO: Request this data to the controller. On error return 0xd8ca - const auto& sixaxis = GetSixaxisState(sixaxis_handle); - calibration = sixaxis.calibration; - return ResultSuccess; -} - -Result Controller_NPad::GetSixAxisSensorIcInformation( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::SixAxisSensorIcInformation& ic_information) const { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - // TODO: Request this data to the controller. On error return 0xd8ca - const auto& sixaxis = GetSixaxisState(sixaxis_handle); - ic_information = sixaxis.ic_information; - return ResultSuccess; -} - -Result Controller_NPad::ResetIsSixAxisSensorDeviceNewlyAssigned( +Result NPad::ResetIsSixAxisSensorDeviceNewlyAssigned( const Core::HID::SixAxisSensorHandle& sixaxis_handle) { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); if (is_valid.IsError()) { LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); return is_valid; @@ -1262,83 +978,32 @@ Result Controller_NPad::ResetIsSixAxisSensorDeviceNewlyAssigned( return ResultSuccess; } -Result Controller_NPad::SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, - bool sixaxis_status) { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - auto& controller = GetControllerFromHandle(sixaxis_handle); - controller.sixaxis_sensor_enabled = sixaxis_status; - return ResultSuccess; +NPad::SixAxisLifo& NPad::GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id) { + return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_fullkey_lifo; } -Result Controller_NPad::IsSixAxisSensorFusionEnabled( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_fusion_enabled) const { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - const auto& sixaxis = GetSixaxisState(sixaxis_handle); - is_fusion_enabled = sixaxis.is_fusion_enabled; - - return ResultSuccess; +NPad::SixAxisLifo& NPad::GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id) { + return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_handheld_lifo; } -Result Controller_NPad::SetSixAxisFusionEnabled( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool is_fusion_enabled) { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - auto& sixaxis = GetSixaxisState(sixaxis_handle); - sixaxis.is_fusion_enabled = is_fusion_enabled; - - return ResultSuccess; +NPad::SixAxisLifo& NPad::GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id) { + return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_dual_left_lifo; } -Result Controller_NPad::SetSixAxisFusionParameters( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters) { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - const auto param1 = sixaxis_fusion_parameters.parameter1; - if (param1 < 0.0f || param1 > 1.0f) { - return InvalidSixAxisFusionRange; - } - - auto& sixaxis = GetSixaxisState(sixaxis_handle); - sixaxis.fusion = sixaxis_fusion_parameters; - - return ResultSuccess; +NPad::SixAxisLifo& NPad::GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id) { + return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_dual_right_lifo; } -Result Controller_NPad::GetSixAxisFusionParameters( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::SixAxisSensorFusionParameters& parameters) const { - const auto is_valid = VerifyValidSixAxisSensorHandle(sixaxis_handle); - if (is_valid.IsError()) { - LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); - return is_valid; - } - - const auto& sixaxis = GetSixaxisState(sixaxis_handle); - parameters = sixaxis.fusion; +NPad::SixAxisLifo& NPad::GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id) { + return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_left_lifo; +} - return ResultSuccess; +NPad::SixAxisLifo& NPad::GetSixAxisRightLifo(Core::HID::NpadIdType npad_id) { + return GetControllerFromNpadIdType(npad_id).shared_memory->sixaxis_right_lifo; } -Result Controller_NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, - Core::HID::NpadIdType npad_id_2) { +Result NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, + Core::HID::NpadIdType npad_id_2) { if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) { LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id_1:{}, npad_id_2:{}", npad_id_1, npad_id_2); @@ -1400,18 +1065,17 @@ Result Controller_NPad::MergeSingleJoyAsDualJoy(Core::HID::NpadIdType npad_id_1, return ResultSuccess; } -void Controller_NPad::StartLRAssignmentMode() { +void NPad::StartLRAssignmentMode() { // Nothing internally is used for lr assignment mode. Since we have the ability to set the // controller types from boot, it doesn't really matter about showing a selection screen is_in_lr_assignment_mode = true; } -void Controller_NPad::StopLRAssignmentMode() { +void NPad::StopLRAssignmentMode() { is_in_lr_assignment_mode = false; } -Result Controller_NPad::SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, - Core::HID::NpadIdType npad_id_2) { +Result NPad::SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, Core::HID::NpadIdType npad_id_2) { if (!IsNpadIdValid(npad_id_1) || !IsNpadIdValid(npad_id_2)) { LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id_1:{}, npad_id_2:{}", npad_id_1, npad_id_2); @@ -1442,8 +1106,7 @@ Result Controller_NPad::SwapNpadAssignment(Core::HID::NpadIdType npad_id_1, return ResultSuccess; } -Result Controller_NPad::GetLedPattern(Core::HID::NpadIdType npad_id, - Core::HID::LedPattern& pattern) const { +Result NPad::GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const { if (!IsNpadIdValid(npad_id)) { LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); return InvalidNpadId; @@ -1453,8 +1116,8 @@ Result Controller_NPad::GetLedPattern(Core::HID::NpadIdType npad_id, return ResultSuccess; } -Result Controller_NPad::IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id, - bool& is_valid) const { +Result NPad::IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id, + bool& is_valid) const { if (!IsNpadIdValid(npad_id)) { LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); return InvalidNpadId; @@ -1464,8 +1127,8 @@ Result Controller_NPad::IsUnintendedHomeButtonInputProtectionEnabled(Core::HID:: return ResultSuccess; } -Result Controller_NPad::SetUnintendedHomeButtonInputProtectionEnabled( - bool is_protection_enabled, Core::HID::NpadIdType npad_id) { +Result NPad::SetUnintendedHomeButtonInputProtectionEnabled(bool is_protection_enabled, + Core::HID::NpadIdType npad_id) { if (!IsNpadIdValid(npad_id)) { LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); return InvalidNpadId; @@ -1475,11 +1138,11 @@ Result Controller_NPad::SetUnintendedHomeButtonInputProtectionEnabled( return ResultSuccess; } -void Controller_NPad::SetAnalogStickUseCenterClamp(bool use_center_clamp) { +void NPad::SetAnalogStickUseCenterClamp(bool use_center_clamp) { analog_stick_use_center_clamp = use_center_clamp; } -void Controller_NPad::ClearAllConnectedControllers() { +void NPad::ClearAllConnectedControllers() { for (auto& controller : controller_data) { if (controller.device->IsConnected() && controller.device->GetNpadStyleIndex() != Core::HID::NpadStyleIndex::None) { @@ -1489,13 +1152,13 @@ void Controller_NPad::ClearAllConnectedControllers() { } } -void Controller_NPad::DisconnectAllConnectedControllers() { +void NPad::DisconnectAllConnectedControllers() { for (auto& controller : controller_data) { controller.device->Disconnect(); } } -void Controller_NPad::ConnectAllDisconnectedControllers() { +void NPad::ConnectAllDisconnectedControllers() { for (auto& controller : controller_data) { if (controller.device->GetNpadStyleIndex() != Core::HID::NpadStyleIndex::None && !controller.device->IsConnected()) { @@ -1504,18 +1167,18 @@ void Controller_NPad::ConnectAllDisconnectedControllers() { } } -void Controller_NPad::ClearAllControllers() { +void NPad::ClearAllControllers() { for (auto& controller : controller_data) { controller.device->Disconnect(); controller.device->SetNpadStyleIndex(Core::HID::NpadStyleIndex::None); } } -Core::HID::NpadButton Controller_NPad::GetAndResetPressState() { +Core::HID::NpadButton NPad::GetAndResetPressState() { return static_cast(press_state.exchange(0)); } -void Controller_NPad::ApplyNpadSystemCommonPolicy() { +void NPad::ApplyNpadSystemCommonPolicy() { Core::HID::NpadStyleTag styletag{}; styletag.fullkey.Assign(1); styletag.handheld.Assign(1); @@ -1540,7 +1203,7 @@ void Controller_NPad::ApplyNpadSystemCommonPolicy() { supported_npad_id_types[9] = Core::HID::NpadIdType::Handheld; } -bool Controller_NPad::IsControllerSupported(Core::HID::NpadStyleIndex controller) const { +bool NPad::IsControllerSupported(Core::HID::NpadStyleIndex controller) const { if (controller == Core::HID::NpadStyleIndex::Handheld) { const bool support_handheld = std::find(supported_npad_id_types.begin(), supported_npad_id_types.end(), @@ -1591,51 +1254,50 @@ bool Controller_NPad::IsControllerSupported(Core::HID::NpadStyleIndex controller return false; } -Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromHandle( - const Core::HID::SixAxisSensorHandle& device_handle) { +NPad::NpadControllerData& NPad::GetControllerFromHandle( + const Core::HID::VibrationDeviceHandle& device_handle) { const auto npad_id = static_cast(device_handle.npad_id); return GetControllerFromNpadIdType(npad_id); } -const Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromHandle( - const Core::HID::SixAxisSensorHandle& device_handle) const { +const NPad::NpadControllerData& NPad::GetControllerFromHandle( + const Core::HID::VibrationDeviceHandle& device_handle) const { const auto npad_id = static_cast(device_handle.npad_id); return GetControllerFromNpadIdType(npad_id); } -Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromHandle( - const Core::HID::VibrationDeviceHandle& device_handle) { +NPad::NpadControllerData& NPad::GetControllerFromHandle( + const Core::HID::SixAxisSensorHandle& device_handle) { const auto npad_id = static_cast(device_handle.npad_id); return GetControllerFromNpadIdType(npad_id); } -const Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromHandle( - const Core::HID::VibrationDeviceHandle& device_handle) const { +const NPad::NpadControllerData& NPad::GetControllerFromHandle( + const Core::HID::SixAxisSensorHandle& device_handle) const { const auto npad_id = static_cast(device_handle.npad_id); return GetControllerFromNpadIdType(npad_id); } -Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromNpadIdType( - Core::HID::NpadIdType npad_id) { +NPad::NpadControllerData& NPad::GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) { if (!IsNpadIdValid(npad_id)) { LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); npad_id = Core::HID::NpadIdType::Player1; } - const auto npad_index = Core::HID::NpadIdTypeToIndex(npad_id); + const auto npad_index = NpadIdTypeToIndex(npad_id); return controller_data[npad_index]; } -const Controller_NPad::NpadControllerData& Controller_NPad::GetControllerFromNpadIdType( +const NPad::NpadControllerData& NPad::GetControllerFromNpadIdType( Core::HID::NpadIdType npad_id) const { if (!IsNpadIdValid(npad_id)) { LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); npad_id = Core::HID::NpadIdType::Player1; } - const auto npad_index = Core::HID::NpadIdTypeToIndex(npad_id); + const auto npad_index = NpadIdTypeToIndex(npad_id); return controller_data[npad_index]; } -Core::HID::SixAxisSensorProperties& Controller_NPad::GetSixaxisProperties( +Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties( const Core::HID::SixAxisSensorHandle& sixaxis_handle) { auto& controller = GetControllerFromHandle(sixaxis_handle); switch (sixaxis_handle.npad_type) { @@ -1658,7 +1320,7 @@ Core::HID::SixAxisSensorProperties& Controller_NPad::GetSixaxisProperties( } } -const Core::HID::SixAxisSensorProperties& Controller_NPad::GetSixaxisProperties( +const Core::HID::SixAxisSensorProperties& NPad::GetSixaxisProperties( const Core::HID::SixAxisSensorHandle& sixaxis_handle) const { const auto& controller = GetControllerFromHandle(sixaxis_handle); switch (sixaxis_handle.npad_type) { @@ -1681,65 +1343,13 @@ const Core::HID::SixAxisSensorProperties& Controller_NPad::GetSixaxisProperties( } } -Controller_NPad::SixaxisParameters& Controller_NPad::GetSixaxisState( - const Core::HID::SixAxisSensorHandle& sixaxis_handle) { - auto& controller = GetControllerFromHandle(sixaxis_handle); - switch (sixaxis_handle.npad_type) { - case Core::HID::NpadStyleIndex::ProController: - case Core::HID::NpadStyleIndex::Pokeball: - return controller.sixaxis_fullkey; - case Core::HID::NpadStyleIndex::Handheld: - return controller.sixaxis_handheld; - case Core::HID::NpadStyleIndex::JoyconDual: - if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) { - return controller.sixaxis_dual_left; - } - return controller.sixaxis_dual_right; - case Core::HID::NpadStyleIndex::JoyconLeft: - return controller.sixaxis_left; - case Core::HID::NpadStyleIndex::JoyconRight: - return controller.sixaxis_right; - default: - return controller.sixaxis_unknown; - } -} - -const Controller_NPad::SixaxisParameters& Controller_NPad::GetSixaxisState( - const Core::HID::SixAxisSensorHandle& sixaxis_handle) const { - const auto& controller = GetControllerFromHandle(sixaxis_handle); - switch (sixaxis_handle.npad_type) { - case Core::HID::NpadStyleIndex::ProController: - case Core::HID::NpadStyleIndex::Pokeball: - return controller.sixaxis_fullkey; - case Core::HID::NpadStyleIndex::Handheld: - return controller.sixaxis_handheld; - case Core::HID::NpadStyleIndex::JoyconDual: - if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) { - return controller.sixaxis_dual_left; - } - return controller.sixaxis_dual_right; - case Core::HID::NpadStyleIndex::JoyconLeft: - return controller.sixaxis_left; - case Core::HID::NpadStyleIndex::JoyconRight: - return controller.sixaxis_right; - default: - return controller.sixaxis_unknown; - } -} - -Controller_NPad::AppletDetailedUiType Controller_NPad::GetAppletDetailedUiType( - Core::HID::NpadIdType npad_id) { - - auto controller = GetControllerFromNpadIdType(npad_id); - auto shared_memory = controller.shared_memory; - Service::HID::Controller_NPad::AppletFooterUiType applet_footer_type = - shared_memory->applet_footer_type; +NPad::AppletDetailedUiType NPad::GetAppletDetailedUiType(Core::HID::NpadIdType npad_id) { + const auto& shared_memory = GetControllerFromNpadIdType(npad_id).shared_memory; - Controller_NPad::AppletDetailedUiType detailed_ui_type{ + return { .ui_variant = 0, - .footer = applet_footer_type, + .footer = shared_memory->applet_footer_type, }; - return detailed_ui_type; } } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/npad.h b/src/core/hle/service/hid/controllers/npad.h index cd93abdd1..9167c93f0 100644 --- a/src/core/hle/service/hid/controllers/npad.h +++ b/src/core/hle/service/hid/controllers/npad.h @@ -10,7 +10,6 @@ #include "common/bit_field.h" #include "common/common_types.h" -#include "common/vector_math.h" #include "core/hid/hid_types.h" #include "core/hle/service/hid/controllers/controller_base.h" @@ -34,11 +33,11 @@ union Result; namespace Service::HID { -class Controller_NPad final : public ControllerBase { +class NPad final : public ControllerBase { public: - explicit Controller_NPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_, - KernelHelpers::ServiceContext& service_context_); - ~Controller_NPad() override; + explicit NPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_, + KernelHelpers::ServiceContext& service_context_); + ~NPad() override; // Called when the controller is initialized void OnInit() override; @@ -49,9 +48,6 @@ public: // When the controller is requesting an update for the shared memory void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; - // When the controller is requesting a motion update for the shared memory - void OnMotionUpdate(const Core::Timing::CoreTiming& core_timing) override; - // This is nn::hid::NpadJoyHoldType enum class NpadJoyHoldType : u64 { Vertical = 0, @@ -133,6 +129,8 @@ public: Revision3 = 3, }; + using SixAxisLifo = Lifo; + void SetSupportedStyleSet(Core::HID::NpadStyleTag style_set); Core::HID::NpadStyleTag GetSupportedStyleSet() const; @@ -185,37 +183,18 @@ public: Result DisconnectNpad(Core::HID::NpadIdType npad_id); - Result SetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::GyroscopeZeroDriftMode drift_mode); - Result GetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::GyroscopeZeroDriftMode& drift_mode) const; - Result IsSixAxisSensorAtRest(const Core::HID::SixAxisSensorHandle& sixaxis_handle, - bool& is_at_rest) const; Result IsFirmwareUpdateAvailableForSixAxisSensor( const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_firmware_available) const; - Result EnableSixAxisSensorUnalteredPassthrough( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool is_enabled); - Result IsSixAxisSensorUnalteredPassthroughEnabled( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_enabled) const; - Result LoadSixAxisSensorCalibrationParameter( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::SixAxisSensorCalibrationParameter& calibration) const; - Result GetSixAxisSensorIcInformation( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::SixAxisSensorIcInformation& ic_information) const; Result ResetIsSixAxisSensorDeviceNewlyAssigned( const Core::HID::SixAxisSensorHandle& sixaxis_handle); - Result SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, - bool sixaxis_status); - Result IsSixAxisSensorFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, - bool& is_fusion_enabled) const; - Result SetSixAxisFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, - bool is_fusion_enabled); - Result SetSixAxisFusionParameters( - const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters); - Result GetSixAxisFusionParameters(const Core::HID::SixAxisSensorHandle& sixaxis_handle, - Core::HID::SixAxisSensorFusionParameters& parameters) const; + + SixAxisLifo& GetSixAxisFullkeyLifo(Core::HID::NpadIdType npad_id); + SixAxisLifo& GetSixAxisHandheldLifo(Core::HID::NpadIdType npad_id); + SixAxisLifo& GetSixAxisDualLeftLifo(Core::HID::NpadIdType npad_id); + SixAxisLifo& GetSixAxisDualRightLifo(Core::HID::NpadIdType npad_id); + SixAxisLifo& GetSixAxisLeftLifo(Core::HID::NpadIdType npad_id); + SixAxisLifo& GetSixAxisRightLifo(Core::HID::NpadIdType npad_id); + Result GetLedPattern(Core::HID::NpadIdType npad_id, Core::HID::LedPattern& pattern) const; Result IsUnintendedHomeButtonInputProtectionEnabled(Core::HID::NpadIdType npad_id, bool& is_enabled) const; @@ -239,10 +218,6 @@ public: void ApplyNpadSystemCommonPolicy(); - static bool IsNpadIdValid(Core::HID::NpadIdType npad_id); - static Result IsDeviceHandleValid(const Core::HID::VibrationDeviceHandle& device_handle); - static Result VerifyValidSixAxisSensorHandle( - const Core::HID::SixAxisSensorHandle& device_handle); AppletDetailedUiType GetAppletDetailedUiType(Core::HID::NpadIdType npad_id); private: @@ -302,29 +277,6 @@ private: }; static_assert(sizeof(NPadGenericState) == 0x28, "NPadGenericState is an invalid size"); - // This is nn::hid::SixAxisSensorAttribute - struct SixAxisSensorAttribute { - union { - u32 raw{}; - BitField<0, 1, u32> is_connected; - BitField<1, 1, u32> is_interpolated; - }; - }; - static_assert(sizeof(SixAxisSensorAttribute) == 4, "SixAxisSensorAttribute is an invalid size"); - - // This is nn::hid::SixAxisSensorState - struct SixAxisSensorState { - s64 delta_time{}; - s64 sampling_number{}; - Common::Vec3f accel{}; - Common::Vec3f gyro{}; - Common::Vec3f rotation{}; - std::array orientation{}; - SixAxisSensorAttribute attribute{}; - INSERT_PADDING_BYTES(4); // Reserved - }; - static_assert(sizeof(SixAxisSensorState) == 0x60, "SixAxisSensorState is an invalid size"); - // This is nn::hid::server::NpadGcTriggerState struct NpadGcTriggerState { s64 sampling_number{}; @@ -444,12 +396,12 @@ private: Lifo joy_right_lifo{}; Lifo palma_lifo{}; Lifo system_ext_lifo{}; - Lifo sixaxis_fullkey_lifo{}; - Lifo sixaxis_handheld_lifo{}; - Lifo sixaxis_dual_left_lifo{}; - Lifo sixaxis_dual_right_lifo{}; - Lifo sixaxis_left_lifo{}; - Lifo sixaxis_right_lifo{}; + Lifo sixaxis_fullkey_lifo{}; + Lifo sixaxis_handheld_lifo{}; + Lifo sixaxis_dual_left_lifo{}; + Lifo sixaxis_dual_right_lifo{}; + Lifo sixaxis_left_lifo{}; + Lifo sixaxis_right_lifo{}; DeviceType device_type{}; INSERT_PADDING_BYTES(0x4); // Reserved NPadSystemProperties system_properties{}; @@ -483,16 +435,6 @@ private: std::chrono::steady_clock::time_point last_vibration_timepoint{}; }; - struct SixaxisParameters { - bool is_fusion_enabled{true}; - bool unaltered_passtrough{false}; - Core::HID::SixAxisSensorFusionParameters fusion{}; - Core::HID::SixAxisSensorCalibrationParameter calibration{}; - Core::HID::SixAxisSensorIcInformation ic_information{}; - Core::HID::GyroscopeZeroDriftMode gyroscope_zero_drift_mode{ - Core::HID::GyroscopeZeroDriftMode::Standard}; - }; - struct NpadControllerData { Kernel::KEvent* styleset_changed_event{}; NpadInternalState* shared_memory = nullptr; @@ -506,27 +448,10 @@ private: bool is_dual_left_connected{true}; bool is_dual_right_connected{true}; - // Motion parameters - bool sixaxis_at_rest{true}; - bool sixaxis_sensor_enabled{true}; - SixaxisParameters sixaxis_fullkey{}; - SixaxisParameters sixaxis_handheld{}; - SixaxisParameters sixaxis_dual_left{}; - SixaxisParameters sixaxis_dual_right{}; - SixaxisParameters sixaxis_left{}; - SixaxisParameters sixaxis_right{}; - SixaxisParameters sixaxis_unknown{}; - // Current pad state NPadGenericState npad_pad_state{}; NPadGenericState npad_libnx_state{}; NpadGcTriggerState npad_trigger_state{}; - SixAxisSensorState sixaxis_fullkey_state{}; - SixAxisSensorState sixaxis_handheld_state{}; - SixAxisSensorState sixaxis_dual_left_state{}; - SixAxisSensorState sixaxis_dual_right_state{}; - SixAxisSensorState sixaxis_left_lifo_state{}; - SixAxisSensorState sixaxis_right_lifo_state{}; int callback_key{}; }; @@ -536,14 +461,14 @@ private: void RequestPadStateUpdate(Core::HID::NpadIdType npad_id); void WriteEmptyEntry(NpadInternalState* npad); - NpadControllerData& GetControllerFromHandle( - const Core::HID::SixAxisSensorHandle& device_handle); - const NpadControllerData& GetControllerFromHandle( - const Core::HID::SixAxisSensorHandle& device_handle) const; NpadControllerData& GetControllerFromHandle( const Core::HID::VibrationDeviceHandle& device_handle); const NpadControllerData& GetControllerFromHandle( const Core::HID::VibrationDeviceHandle& device_handle) const; + NpadControllerData& GetControllerFromHandle( + const Core::HID::SixAxisSensorHandle& device_handle); + const NpadControllerData& GetControllerFromHandle( + const Core::HID::SixAxisSensorHandle& device_handle) const; NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id); const NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) const; @@ -551,9 +476,6 @@ private: const Core::HID::SixAxisSensorHandle& device_handle); const Core::HID::SixAxisSensorProperties& GetSixaxisProperties( const Core::HID::SixAxisSensorHandle& device_handle) const; - SixaxisParameters& GetSixaxisState(const Core::HID::SixAxisSensorHandle& device_handle); - const SixaxisParameters& GetSixaxisState( - const Core::HID::SixAxisSensorHandle& device_handle) const; std::atomic press_state{}; diff --git a/src/core/hle/service/hid/controllers/palma.cpp b/src/core/hle/service/hid/controllers/palma.cpp index 51a18335f..588ff9d62 100644 --- a/src/core/hle/service/hid/controllers/palma.cpp +++ b/src/core/hle/service/hid/controllers/palma.cpp @@ -12,35 +12,35 @@ namespace Service::HID { -Controller_Palma::Controller_Palma(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_, - KernelHelpers::ServiceContext& service_context_) +Palma::Palma(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_, + KernelHelpers::ServiceContext& service_context_) : ControllerBase{hid_core_}, service_context{service_context_} { controller = hid_core.GetEmulatedController(Core::HID::NpadIdType::Other); operation_complete_event = service_context.CreateEvent("hid:PalmaOperationCompleteEvent"); } -Controller_Palma::~Controller_Palma() { +Palma::~Palma() { service_context.CloseEvent(operation_complete_event); }; -void Controller_Palma::OnInit() {} +void Palma::OnInit() {} -void Controller_Palma::OnRelease() {} +void Palma::OnRelease() {} -void Controller_Palma::OnUpdate(const Core::Timing::CoreTiming& core_timing) { +void Palma::OnUpdate(const Core::Timing::CoreTiming& core_timing) { if (!IsControllerActivated()) { return; } } -Result Controller_Palma::GetPalmaConnectionHandle(Core::HID::NpadIdType npad_id, - PalmaConnectionHandle& handle) { +Result Palma::GetPalmaConnectionHandle(Core::HID::NpadIdType npad_id, + PalmaConnectionHandle& handle) { active_handle.npad_id = npad_id; handle = active_handle; return ResultSuccess; } -Result Controller_Palma::InitializePalma(const PalmaConnectionHandle& handle) { +Result Palma::InitializePalma(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -48,7 +48,7 @@ Result Controller_Palma::InitializePalma(const PalmaConnectionHandle& handle) { return ResultSuccess; } -Kernel::KReadableEvent& Controller_Palma::AcquirePalmaOperationCompleteEvent( +Kernel::KReadableEvent& Palma::AcquirePalmaOperationCompleteEvent( const PalmaConnectionHandle& handle) const { if (handle.npad_id != active_handle.npad_id) { LOG_ERROR(Service_HID, "Invalid npad id {}", handle.npad_id); @@ -56,9 +56,9 @@ Kernel::KReadableEvent& Controller_Palma::AcquirePalmaOperationCompleteEvent( return operation_complete_event->GetReadableEvent(); } -Result Controller_Palma::GetPalmaOperationInfo(const PalmaConnectionHandle& handle, - PalmaOperationType& operation_type, - PalmaOperationData& data) const { +Result Palma::GetPalmaOperationInfo(const PalmaConnectionHandle& handle, + PalmaOperationType& operation_type, + PalmaOperationData& data) const { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -67,8 +67,7 @@ Result Controller_Palma::GetPalmaOperationInfo(const PalmaConnectionHandle& hand return ResultSuccess; } -Result Controller_Palma::PlayPalmaActivity(const PalmaConnectionHandle& handle, - u64 palma_activity) { +Result Palma::PlayPalmaActivity(const PalmaConnectionHandle& handle, u64 palma_activity) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -79,8 +78,7 @@ Result Controller_Palma::PlayPalmaActivity(const PalmaConnectionHandle& handle, return ResultSuccess; } -Result Controller_Palma::SetPalmaFrModeType(const PalmaConnectionHandle& handle, - PalmaFrModeType fr_mode_) { +Result Palma::SetPalmaFrModeType(const PalmaConnectionHandle& handle, PalmaFrModeType fr_mode_) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -88,7 +86,7 @@ Result Controller_Palma::SetPalmaFrModeType(const PalmaConnectionHandle& handle, return ResultSuccess; } -Result Controller_Palma::ReadPalmaStep(const PalmaConnectionHandle& handle) { +Result Palma::ReadPalmaStep(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -99,25 +97,25 @@ Result Controller_Palma::ReadPalmaStep(const PalmaConnectionHandle& handle) { return ResultSuccess; } -Result Controller_Palma::EnablePalmaStep(const PalmaConnectionHandle& handle, bool is_enabled) { +Result Palma::EnablePalmaStep(const PalmaConnectionHandle& handle, bool is_enabled) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } return ResultSuccess; } -Result Controller_Palma::ResetPalmaStep(const PalmaConnectionHandle& handle) { +Result Palma::ResetPalmaStep(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } return ResultSuccess; } -void Controller_Palma::ReadPalmaApplicationSection() {} +void Palma::ReadPalmaApplicationSection() {} -void Controller_Palma::WritePalmaApplicationSection() {} +void Palma::WritePalmaApplicationSection() {} -Result Controller_Palma::ReadPalmaUniqueCode(const PalmaConnectionHandle& handle) { +Result Palma::ReadPalmaUniqueCode(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -128,7 +126,7 @@ Result Controller_Palma::ReadPalmaUniqueCode(const PalmaConnectionHandle& handle return ResultSuccess; } -Result Controller_Palma::SetPalmaUniqueCodeInvalid(const PalmaConnectionHandle& handle) { +Result Palma::SetPalmaUniqueCodeInvalid(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -139,10 +137,9 @@ Result Controller_Palma::SetPalmaUniqueCodeInvalid(const PalmaConnectionHandle& return ResultSuccess; } -void Controller_Palma::WritePalmaActivityEntry() {} +void Palma::WritePalmaActivityEntry() {} -Result Controller_Palma::WritePalmaRgbLedPatternEntry(const PalmaConnectionHandle& handle, - u64 unknown) { +Result Palma::WritePalmaRgbLedPatternEntry(const PalmaConnectionHandle& handle, u64 unknown) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -153,8 +150,8 @@ Result Controller_Palma::WritePalmaRgbLedPatternEntry(const PalmaConnectionHandl return ResultSuccess; } -Result Controller_Palma::WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWaveSet wave, - Common::ProcessAddress t_mem, u64 size) { +Result Palma::WritePalmaWaveEntry(const PalmaConnectionHandle& handle, PalmaWaveSet wave, + Common::ProcessAddress t_mem, u64 size) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -165,8 +162,8 @@ Result Controller_Palma::WritePalmaWaveEntry(const PalmaConnectionHandle& handle return ResultSuccess; } -Result Controller_Palma::SetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle, - s32 database_id_version_) { +Result Palma::SetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle, + s32 database_id_version_) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -178,8 +175,7 @@ Result Controller_Palma::SetPalmaDataBaseIdentificationVersion(const PalmaConnec return ResultSuccess; } -Result Controller_Palma::GetPalmaDataBaseIdentificationVersion( - const PalmaConnectionHandle& handle) { +Result Palma::GetPalmaDataBaseIdentificationVersion(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -191,26 +187,26 @@ Result Controller_Palma::GetPalmaDataBaseIdentificationVersion( return ResultSuccess; } -void Controller_Palma::SuspendPalmaFeature() {} +void Palma::SuspendPalmaFeature() {} -Result Controller_Palma::GetPalmaOperationResult(const PalmaConnectionHandle& handle) const { +Result Palma::GetPalmaOperationResult(const PalmaConnectionHandle& handle) const { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } return operation.result; } -void Controller_Palma::ReadPalmaPlayLog() {} +void Palma::ReadPalmaPlayLog() {} -void Controller_Palma::ResetPalmaPlayLog() {} +void Palma::ResetPalmaPlayLog() {} -void Controller_Palma::SetIsPalmaAllConnectable(bool is_all_connectable) { +void Palma::SetIsPalmaAllConnectable(bool is_all_connectable) { // If true controllers are able to be paired is_connectable = is_all_connectable; } -void Controller_Palma::SetIsPalmaPairedConnectable() {} +void Palma::SetIsPalmaPairedConnectable() {} -Result Controller_Palma::PairPalma(const PalmaConnectionHandle& handle) { +Result Palma::PairPalma(const PalmaConnectionHandle& handle) { if (handle.npad_id != active_handle.npad_id) { return InvalidPalmaHandle; } @@ -218,14 +214,14 @@ Result Controller_Palma::PairPalma(const PalmaConnectionHandle& handle) { return ResultSuccess; } -void Controller_Palma::SetPalmaBoostMode(bool boost_mode) {} +void Palma::SetPalmaBoostMode(bool boost_mode) {} -void Controller_Palma::CancelWritePalmaWaveEntry() {} +void Palma::CancelWritePalmaWaveEntry() {} -void Controller_Palma::EnablePalmaBoostMode() {} +void Palma::EnablePalmaBoostMode() {} -void Controller_Palma::GetPalmaBluetoothAddress() {} +void Palma::GetPalmaBluetoothAddress() {} -void Controller_Palma::SetDisallowedPalmaConnection() {} +void Palma::SetDisallowedPalmaConnection() {} } // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/palma.h b/src/core/hle/service/hid/controllers/palma.h index a0491a819..a6047f36a 100644 --- a/src/core/hle/service/hid/controllers/palma.h +++ b/src/core/hle/service/hid/controllers/palma.h @@ -23,7 +23,7 @@ class EmulatedController; } // namespace Core::HID namespace Service::HID { -class Controller_Palma final : public ControllerBase { +class Palma final : public ControllerBase { public: using PalmaOperationData = std::array; @@ -97,9 +97,9 @@ public: static_assert(sizeof(PalmaConnectionHandle) == 0x8, "PalmaConnectionHandle has incorrect size."); - explicit Controller_Palma(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_, - KernelHelpers::ServiceContext& service_context_); - ~Controller_Palma() override; + explicit Palma(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_, + KernelHelpers::ServiceContext& service_context_); + ~Palma() override; // Called when the controller is initialized void OnInit() override; diff --git a/src/core/hle/service/hid/controllers/seven_six_axis.cpp b/src/core/hle/service/hid/controllers/seven_six_axis.cpp new file mode 100644 index 000000000..495568484 --- /dev/null +++ b/src/core/hle/service/hid/controllers/seven_six_axis.cpp @@ -0,0 +1,66 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include +#include "common/common_types.h" +#include "core/core.h" +#include "core/core_timing.h" +#include "core/frontend/emu_window.h" +#include "core/hid/emulated_console.h" +#include "core/hid/emulated_devices.h" +#include "core/hid/hid_core.h" +#include "core/hle/service/hid/controllers/seven_six_axis.h" +#include "core/memory.h" + +namespace Service::HID { +SevenSixAxis::SevenSixAxis(Core::System& system_) + : ControllerBase{system_.HIDCore()}, system{system_} { + console = hid_core.GetEmulatedConsole(); +} + +SevenSixAxis::~SevenSixAxis() = default; + +void SevenSixAxis::OnInit() {} +void SevenSixAxis::OnRelease() {} + +void SevenSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + if (!IsControllerActivated() || transfer_memory == 0) { + seven_sixaxis_lifo.buffer_count = 0; + seven_sixaxis_lifo.buffer_tail = 0; + return; + } + + const auto& last_entry = seven_sixaxis_lifo.ReadCurrentEntry().state; + next_seven_sixaxis_state.sampling_number = last_entry.sampling_number + 1; + + const auto motion_status = console->GetMotion(); + last_global_timestamp = core_timing.GetGlobalTimeNs().count(); + + // This value increments every time the switch goes to sleep + next_seven_sixaxis_state.unknown = 1; + next_seven_sixaxis_state.timestamp = last_global_timestamp - last_saved_timestamp; + next_seven_sixaxis_state.accel = motion_status.accel; + next_seven_sixaxis_state.gyro = motion_status.gyro; + next_seven_sixaxis_state.quaternion = { + { + motion_status.quaternion.xyz.y, + motion_status.quaternion.xyz.x, + -motion_status.quaternion.w, + }, + -motion_status.quaternion.xyz.z, + }; + + seven_sixaxis_lifo.WriteNextEntry(next_seven_sixaxis_state); + system.ApplicationMemory().WriteBlock(transfer_memory, &seven_sixaxis_lifo, + sizeof(seven_sixaxis_lifo)); +} + +void SevenSixAxis::SetTransferMemoryAddress(Common::ProcessAddress t_mem) { + transfer_memory = t_mem; +} + +void SevenSixAxis::ResetTimestamp() { + last_saved_timestamp = last_global_timestamp; +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/seven_six_axis.h b/src/core/hle/service/hid/controllers/seven_six_axis.h new file mode 100644 index 000000000..40e3f5d12 --- /dev/null +++ b/src/core/hle/service/hid/controllers/seven_six_axis.h @@ -0,0 +1,65 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "common/common_types.h" +#include "common/quaternion.h" +#include "common/typed_address.h" +#include "core/hle/service/hid/controllers/controller_base.h" +#include "core/hle/service/hid/ring_lifo.h" + +namespace Core { +class System; +} // namespace Core + +namespace Core::HID { +class EmulatedConsole; +} // namespace Core::HID + +namespace Service::HID { +class SevenSixAxis final : public ControllerBase { +public: + explicit SevenSixAxis(Core::System& system_); + ~SevenSixAxis() override; + + // Called when the controller is initialized + void OnInit() override; + + // When the controller is released + void OnRelease() override; + + // When the controller is requesting an update for the shared memory + void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; + + // Called on InitializeSevenSixAxisSensor + void SetTransferMemoryAddress(Common::ProcessAddress t_mem); + + // Called on ResetSevenSixAxisSensorTimestamp + void ResetTimestamp(); + +private: + struct SevenSixAxisState { + INSERT_PADDING_WORDS(2); // unused + u64 timestamp{}; + u64 sampling_number{}; + u64 unknown{}; + Common::Vec3f accel{}; + Common::Vec3f gyro{}; + Common::Quaternion quaternion{}; + }; + static_assert(sizeof(SevenSixAxisState) == 0x48, "SevenSixAxisState is an invalid size"); + + Lifo seven_sixaxis_lifo{}; + static_assert(sizeof(seven_sixaxis_lifo) == 0xA70, "SevenSixAxisState is an invalid size"); + + u64 last_saved_timestamp{}; + u64 last_global_timestamp{}; + + SevenSixAxisState next_seven_sixaxis_state{}; + Common::ProcessAddress transfer_memory{}; + Core::HID::EmulatedConsole* console = nullptr; + + Core::System& system; +}; +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/six_axis.cpp b/src/core/hle/service/hid/controllers/six_axis.cpp new file mode 100644 index 000000000..3d24a5c04 --- /dev/null +++ b/src/core/hle/service/hid/controllers/six_axis.cpp @@ -0,0 +1,413 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "common/common_types.h" +#include "core/core_timing.h" +#include "core/hid/emulated_controller.h" +#include "core/hid/hid_core.h" +#include "core/hle/service/hid/controllers/npad.h" +#include "core/hle/service/hid/controllers/six_axis.h" +#include "core/hle/service/hid/errors.h" +#include "core/hle/service/hid/hid_util.h" + +namespace Service::HID { + +SixAxis::SixAxis(Core::HID::HIDCore& hid_core_, std::shared_ptr npad_) + : ControllerBase{hid_core_}, npad{npad_} { + for (std::size_t i = 0; i < controller_data.size(); ++i) { + auto& controller = controller_data[i]; + controller.device = hid_core.GetEmulatedControllerByIndex(i); + } +} + +SixAxis::~SixAxis() = default; + +void SixAxis::OnInit() {} +void SixAxis::OnRelease() {} + +void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) { + if (!IsControllerActivated()) { + return; + } + + for (std::size_t i = 0; i < controller_data.size(); ++i) { + auto& controller = controller_data[i]; + + const auto npad_id = IndexToNpadIdType(i); + const auto& controller_type = controller.device->GetNpadStyleIndex(); + + if (controller_type == Core::HID::NpadStyleIndex::None || + !controller.device->IsConnected()) { + continue; + } + + const auto& motion_state = controller.device->GetMotions(); + auto& sixaxis_fullkey_state = controller.sixaxis_fullkey_state; + auto& sixaxis_handheld_state = controller.sixaxis_handheld_state; + auto& sixaxis_dual_left_state = controller.sixaxis_dual_left_state; + auto& sixaxis_dual_right_state = controller.sixaxis_dual_right_state; + auto& sixaxis_left_lifo_state = controller.sixaxis_left_lifo_state; + auto& sixaxis_right_lifo_state = controller.sixaxis_right_lifo_state; + + auto& sixaxis_fullkey_lifo = npad->GetSixAxisFullkeyLifo(npad_id); + auto& sixaxis_handheld_lifo = npad->GetSixAxisHandheldLifo(npad_id); + auto& sixaxis_dual_left_lifo = npad->GetSixAxisDualLeftLifo(npad_id); + auto& sixaxis_dual_right_lifo = npad->GetSixAxisDualRightLifo(npad_id); + auto& sixaxis_left_lifo = npad->GetSixAxisLeftLifo(npad_id); + auto& sixaxis_right_lifo = npad->GetSixAxisRightLifo(npad_id); + + // Clear previous state + sixaxis_fullkey_state = {}; + sixaxis_handheld_state = {}; + sixaxis_dual_left_state = {}; + sixaxis_dual_right_state = {}; + sixaxis_left_lifo_state = {}; + sixaxis_right_lifo_state = {}; + + if (controller.sixaxis_sensor_enabled && Settings::values.motion_enabled.GetValue()) { + controller.sixaxis_at_rest = true; + for (std::size_t e = 0; e < motion_state.size(); ++e) { + controller.sixaxis_at_rest = + controller.sixaxis_at_rest && motion_state[e].is_at_rest; + } + } + + const auto set_motion_state = [&](Core::HID::SixAxisSensorState& state, + const Core::HID::ControllerMotion& hid_state) { + using namespace std::literals::chrono_literals; + static constexpr Core::HID::SixAxisSensorState default_motion_state = { + .delta_time = std::chrono::nanoseconds(5ms).count(), + .accel = {0, 0, -1.0f}, + .orientation = + { + Common::Vec3f{1.0f, 0, 0}, + Common::Vec3f{0, 1.0f, 0}, + Common::Vec3f{0, 0, 1.0f}, + }, + .attribute = {1}, + }; + if (!controller.sixaxis_sensor_enabled) { + state = default_motion_state; + return; + } + if (!Settings::values.motion_enabled.GetValue()) { + state = default_motion_state; + return; + } + state.attribute.is_connected.Assign(1); + state.delta_time = std::chrono::nanoseconds(5ms).count(); + state.accel = hid_state.accel; + state.gyro = hid_state.gyro; + state.rotation = hid_state.rotation; + state.orientation = hid_state.orientation; + }; + + switch (controller_type) { + case Core::HID::NpadStyleIndex::None: + ASSERT(false); + break; + case Core::HID::NpadStyleIndex::ProController: + set_motion_state(sixaxis_fullkey_state, motion_state[0]); + break; + case Core::HID::NpadStyleIndex::Handheld: + set_motion_state(sixaxis_handheld_state, motion_state[0]); + break; + case Core::HID::NpadStyleIndex::JoyconDual: + set_motion_state(sixaxis_dual_left_state, motion_state[0]); + set_motion_state(sixaxis_dual_right_state, motion_state[1]); + break; + case Core::HID::NpadStyleIndex::JoyconLeft: + set_motion_state(sixaxis_left_lifo_state, motion_state[0]); + break; + case Core::HID::NpadStyleIndex::JoyconRight: + set_motion_state(sixaxis_right_lifo_state, motion_state[1]); + break; + case Core::HID::NpadStyleIndex::Pokeball: + using namespace std::literals::chrono_literals; + set_motion_state(sixaxis_fullkey_state, motion_state[0]); + sixaxis_fullkey_state.delta_time = std::chrono::nanoseconds(15ms).count(); + break; + default: + break; + } + + sixaxis_fullkey_state.sampling_number = + sixaxis_fullkey_lifo.ReadCurrentEntry().state.sampling_number + 1; + sixaxis_handheld_state.sampling_number = + sixaxis_handheld_lifo.ReadCurrentEntry().state.sampling_number + 1; + sixaxis_dual_left_state.sampling_number = + sixaxis_dual_left_lifo.ReadCurrentEntry().state.sampling_number + 1; + sixaxis_dual_right_state.sampling_number = + sixaxis_dual_right_lifo.ReadCurrentEntry().state.sampling_number + 1; + sixaxis_left_lifo_state.sampling_number = + sixaxis_left_lifo.ReadCurrentEntry().state.sampling_number + 1; + sixaxis_right_lifo_state.sampling_number = + sixaxis_right_lifo.ReadCurrentEntry().state.sampling_number + 1; + + if (IndexToNpadIdType(i) == Core::HID::NpadIdType::Handheld) { + // This buffer only is updated on handheld on HW + sixaxis_handheld_lifo.WriteNextEntry(sixaxis_handheld_state); + } else { + // Handheld doesn't update this buffer on HW + sixaxis_fullkey_lifo.WriteNextEntry(sixaxis_fullkey_state); + } + + sixaxis_dual_left_lifo.WriteNextEntry(sixaxis_dual_left_state); + sixaxis_dual_right_lifo.WriteNextEntry(sixaxis_dual_right_state); + sixaxis_left_lifo.WriteNextEntry(sixaxis_left_lifo_state); + sixaxis_right_lifo.WriteNextEntry(sixaxis_right_lifo_state); + } +} + +Result SixAxis::SetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::GyroscopeZeroDriftMode drift_mode) { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + auto& sixaxis = GetSixaxisState(sixaxis_handle); + auto& controller = GetControllerFromHandle(sixaxis_handle); + sixaxis.gyroscope_zero_drift_mode = drift_mode; + controller.device->SetGyroscopeZeroDriftMode(drift_mode); + + return ResultSuccess; +} + +Result SixAxis::GetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::GyroscopeZeroDriftMode& drift_mode) const { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + const auto& sixaxis = GetSixaxisState(sixaxis_handle); + drift_mode = sixaxis.gyroscope_zero_drift_mode; + + return ResultSuccess; +} + +Result SixAxis::IsSixAxisSensorAtRest(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + bool& is_at_rest) const { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + const auto& controller = GetControllerFromHandle(sixaxis_handle); + is_at_rest = controller.sixaxis_at_rest; + return ResultSuccess; +} + +Result SixAxis::LoadSixAxisSensorCalibrationParameter( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::SixAxisSensorCalibrationParameter& calibration) const { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + // TODO: Request this data to the controller. On error return 0xd8ca + const auto& sixaxis = GetSixaxisState(sixaxis_handle); + calibration = sixaxis.calibration; + return ResultSuccess; +} + +Result SixAxis::GetSixAxisSensorIcInformation( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::SixAxisSensorIcInformation& ic_information) const { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + // TODO: Request this data to the controller. On error return 0xd8ca + const auto& sixaxis = GetSixaxisState(sixaxis_handle); + ic_information = sixaxis.ic_information; + return ResultSuccess; +} + +Result SixAxis::EnableSixAxisSensorUnalteredPassthrough( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool is_enabled) { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + auto& sixaxis = GetSixaxisState(sixaxis_handle); + sixaxis.unaltered_passtrough = is_enabled; + return ResultSuccess; +} + +Result SixAxis::IsSixAxisSensorUnalteredPassthroughEnabled( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_enabled) const { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + const auto& sixaxis = GetSixaxisState(sixaxis_handle); + is_enabled = sixaxis.unaltered_passtrough; + return ResultSuccess; +} + +Result SixAxis::SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + bool sixaxis_status) { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + auto& controller = GetControllerFromHandle(sixaxis_handle); + controller.sixaxis_sensor_enabled = sixaxis_status; + return ResultSuccess; +} + +Result SixAxis::IsSixAxisSensorFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + bool& is_fusion_enabled) const { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + const auto& sixaxis = GetSixaxisState(sixaxis_handle); + is_fusion_enabled = sixaxis.is_fusion_enabled; + + return ResultSuccess; +} +Result SixAxis::SetSixAxisFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + bool is_fusion_enabled) { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + auto& sixaxis = GetSixaxisState(sixaxis_handle); + sixaxis.is_fusion_enabled = is_fusion_enabled; + + return ResultSuccess; +} + +Result SixAxis::SetSixAxisFusionParameters( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters) { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + const auto param1 = sixaxis_fusion_parameters.parameter1; + if (param1 < 0.0f || param1 > 1.0f) { + return InvalidSixAxisFusionRange; + } + + auto& sixaxis = GetSixaxisState(sixaxis_handle); + sixaxis.fusion = sixaxis_fusion_parameters; + + return ResultSuccess; +} + +Result SixAxis::GetSixAxisFusionParameters( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::SixAxisSensorFusionParameters& parameters) const { + const auto is_valid = IsSixaxisHandleValid(sixaxis_handle); + if (is_valid.IsError()) { + LOG_ERROR(Service_HID, "Invalid handle, error_code={}", is_valid.raw); + return is_valid; + } + + const auto& sixaxis = GetSixaxisState(sixaxis_handle); + parameters = sixaxis.fusion; + + return ResultSuccess; +} + +SixAxis::SixaxisParameters& SixAxis::GetSixaxisState( + const Core::HID::SixAxisSensorHandle& sixaxis_handle) { + auto& controller = GetControllerFromHandle(sixaxis_handle); + switch (sixaxis_handle.npad_type) { + case Core::HID::NpadStyleIndex::ProController: + case Core::HID::NpadStyleIndex::Pokeball: + return controller.sixaxis_fullkey; + case Core::HID::NpadStyleIndex::Handheld: + return controller.sixaxis_handheld; + case Core::HID::NpadStyleIndex::JoyconDual: + if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) { + return controller.sixaxis_dual_left; + } + return controller.sixaxis_dual_right; + case Core::HID::NpadStyleIndex::JoyconLeft: + return controller.sixaxis_left; + case Core::HID::NpadStyleIndex::JoyconRight: + return controller.sixaxis_right; + default: + return controller.sixaxis_unknown; + } +} + +const SixAxis::SixaxisParameters& SixAxis::GetSixaxisState( + const Core::HID::SixAxisSensorHandle& sixaxis_handle) const { + const auto& controller = GetControllerFromHandle(sixaxis_handle); + switch (sixaxis_handle.npad_type) { + case Core::HID::NpadStyleIndex::ProController: + case Core::HID::NpadStyleIndex::Pokeball: + return controller.sixaxis_fullkey; + case Core::HID::NpadStyleIndex::Handheld: + return controller.sixaxis_handheld; + case Core::HID::NpadStyleIndex::JoyconDual: + if (sixaxis_handle.device_index == Core::HID::DeviceIndex::Left) { + return controller.sixaxis_dual_left; + } + return controller.sixaxis_dual_right; + case Core::HID::NpadStyleIndex::JoyconLeft: + return controller.sixaxis_left; + case Core::HID::NpadStyleIndex::JoyconRight: + return controller.sixaxis_right; + default: + return controller.sixaxis_unknown; + } +} + +SixAxis::NpadControllerData& SixAxis::GetControllerFromHandle( + const Core::HID::SixAxisSensorHandle& device_handle) { + const auto npad_id = static_cast(device_handle.npad_id); + return GetControllerFromNpadIdType(npad_id); +} + +const SixAxis::NpadControllerData& SixAxis::GetControllerFromHandle( + const Core::HID::SixAxisSensorHandle& device_handle) const { + const auto npad_id = static_cast(device_handle.npad_id); + return GetControllerFromNpadIdType(npad_id); +} + +SixAxis::NpadControllerData& SixAxis::GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) { + if (!IsNpadIdValid(npad_id)) { + LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); + npad_id = Core::HID::NpadIdType::Player1; + } + const auto npad_index = NpadIdTypeToIndex(npad_id); + return controller_data[npad_index]; +} + +const SixAxis::NpadControllerData& SixAxis::GetControllerFromNpadIdType( + Core::HID::NpadIdType npad_id) const { + if (!IsNpadIdValid(npad_id)) { + LOG_ERROR(Service_HID, "Invalid NpadIdType npad_id:{}", npad_id); + npad_id = Core::HID::NpadIdType::Player1; + } + const auto npad_index = NpadIdTypeToIndex(npad_id); + return controller_data[npad_index]; +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/six_axis.h b/src/core/hle/service/hid/controllers/six_axis.h new file mode 100644 index 000000000..4c4f5dc7b --- /dev/null +++ b/src/core/hle/service/hid/controllers/six_axis.h @@ -0,0 +1,111 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "common/common_types.h" +#include "core/hid/hid_types.h" +#include "core/hle/service/hid/controllers/controller_base.h" +#include "core/hle/service/hid/ring_lifo.h" + +namespace Core::HID { +class EmulatedController; +} // namespace Core::HID + +namespace Service::HID { +class NPad; + +class SixAxis final : public ControllerBase { +public: + explicit SixAxis(Core::HID::HIDCore& hid_core_, std::shared_ptr npad_); + ~SixAxis() override; + + // Called when the controller is initialized + void OnInit() override; + + // When the controller is released + void OnRelease() override; + + // When the controller is requesting an update for the shared memory + void OnUpdate(const Core::Timing::CoreTiming& core_timing) override; + + Result SetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::GyroscopeZeroDriftMode drift_mode); + Result GetGyroscopeZeroDriftMode(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::GyroscopeZeroDriftMode& drift_mode) const; + Result IsSixAxisSensorAtRest(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + bool& is_at_rest) const; + Result EnableSixAxisSensorUnalteredPassthrough( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool is_enabled); + Result IsSixAxisSensorUnalteredPassthroughEnabled( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, bool& is_enabled) const; + Result LoadSixAxisSensorCalibrationParameter( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::SixAxisSensorCalibrationParameter& calibration) const; + Result GetSixAxisSensorIcInformation( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::SixAxisSensorIcInformation& ic_information) const; + Result SetSixAxisEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + bool sixaxis_status); + Result IsSixAxisSensorFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + bool& is_fusion_enabled) const; + Result SetSixAxisFusionEnabled(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + bool is_fusion_enabled); + Result SetSixAxisFusionParameters( + const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::SixAxisSensorFusionParameters sixaxis_fusion_parameters); + Result GetSixAxisFusionParameters(const Core::HID::SixAxisSensorHandle& sixaxis_handle, + Core::HID::SixAxisSensorFusionParameters& parameters) const; + +private: + static constexpr std::size_t NPAD_COUNT = 10; + + struct SixaxisParameters { + bool is_fusion_enabled{true}; + bool unaltered_passtrough{false}; + Core::HID::SixAxisSensorFusionParameters fusion{}; + Core::HID::SixAxisSensorCalibrationParameter calibration{}; + Core::HID::SixAxisSensorIcInformation ic_information{}; + Core::HID::GyroscopeZeroDriftMode gyroscope_zero_drift_mode{ + Core::HID::GyroscopeZeroDriftMode::Standard}; + }; + + struct NpadControllerData { + Core::HID::EmulatedController* device = nullptr; + + // Motion parameters + bool sixaxis_at_rest{true}; + bool sixaxis_sensor_enabled{true}; + SixaxisParameters sixaxis_fullkey{}; + SixaxisParameters sixaxis_handheld{}; + SixaxisParameters sixaxis_dual_left{}; + SixaxisParameters sixaxis_dual_right{}; + SixaxisParameters sixaxis_left{}; + SixaxisParameters sixaxis_right{}; + SixaxisParameters sixaxis_unknown{}; + + // Current pad state + Core::HID::SixAxisSensorState sixaxis_fullkey_state{}; + Core::HID::SixAxisSensorState sixaxis_handheld_state{}; + Core::HID::SixAxisSensorState sixaxis_dual_left_state{}; + Core::HID::SixAxisSensorState sixaxis_dual_right_state{}; + Core::HID::SixAxisSensorState sixaxis_left_lifo_state{}; + Core::HID::SixAxisSensorState sixaxis_right_lifo_state{}; + int callback_key{}; + }; + + SixaxisParameters& GetSixaxisState(const Core::HID::SixAxisSensorHandle& device_handle); + const SixaxisParameters& GetSixaxisState( + const Core::HID::SixAxisSensorHandle& device_handle) const; + + NpadControllerData& GetControllerFromHandle( + const Core::HID::SixAxisSensorHandle& device_handle); + const NpadControllerData& GetControllerFromHandle( + const Core::HID::SixAxisSensorHandle& device_handle) const; + NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id); + const NpadControllerData& GetControllerFromNpadIdType(Core::HID::NpadIdType npad_id) const; + + std::shared_ptr npad; + std::array controller_data{}; +}; +} // namespace Service::HID diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp index 3ef91df4b..3bcf0ee9f 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.cpp +++ b/src/core/hle/service/hid/controllers/touchscreen.cpp @@ -15,8 +15,7 @@ namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x400; -Controller_Touchscreen::Controller_Touchscreen(Core::HID::HIDCore& hid_core_, - u8* raw_shared_memory_) +TouchScreen::TouchScreen(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) : ControllerBase{hid_core_} { static_assert(SHARED_MEMORY_OFFSET + sizeof(TouchSharedMemory) < shared_memory_size, "TouchSharedMemory is bigger than the shared memory"); @@ -25,13 +24,13 @@ Controller_Touchscreen::Controller_Touchscreen(Core::HID::HIDCore& hid_core_, console = hid_core.GetEmulatedConsole(); } -Controller_Touchscreen::~Controller_Touchscreen() = default; +TouchScreen::~TouchScreen() = default; -void Controller_Touchscreen::OnInit() {} +void TouchScreen::OnInit() {} -void Controller_Touchscreen::OnRelease() {} +void TouchScreen::OnRelease() {} -void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) { +void TouchScreen::OnUpdate(const Core::Timing::CoreTiming& core_timing) { shared_memory->touch_screen_lifo.timestamp = core_timing.GetGlobalTimeNs().count(); if (!IsControllerActivated()) { diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h index dd00921fd..cd342ce91 100644 --- a/src/core/hle/service/hid/controllers/touchscreen.h +++ b/src/core/hle/service/hid/controllers/touchscreen.h @@ -14,10 +14,10 @@ class EmulatedConsole; } // namespace Core::HID namespace Service::HID { -class Controller_Touchscreen final : public ControllerBase { +class TouchScreen final : public ControllerBase { public: - explicit Controller_Touchscreen(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); - ~Controller_Touchscreen() override; + explicit TouchScreen(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); + ~TouchScreen() override; // Called when the controller is initialized void OnInit() override; diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp index 62119e2c5..0aaed1fa7 100644 --- a/src/core/hle/service/hid/controllers/xpad.cpp +++ b/src/core/hle/service/hid/controllers/xpad.cpp @@ -10,20 +10,19 @@ namespace Service::HID { constexpr std::size_t SHARED_MEMORY_OFFSET = 0x3C00; -Controller_XPad::Controller_XPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) - : ControllerBase{hid_core_} { +XPad::XPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_) : ControllerBase{hid_core_} { static_assert(SHARED_MEMORY_OFFSET + sizeof(XpadSharedMemory) < shared_memory_size, "XpadSharedMemory is bigger than the shared memory"); shared_memory = std::construct_at( reinterpret_cast(raw_shared_memory_ + SHARED_MEMORY_OFFSET)); } -Controller_XPad::~Controller_XPad() = default; +XPad::~XPad() = default; -void Controller_XPad::OnInit() {} +void XPad::OnInit() {} -void Controller_XPad::OnRelease() {} +void XPad::OnRelease() {} -void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { +void XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing) { if (!IsControllerActivated()) { shared_memory->basic_xpad_lifo.buffer_count = 0; shared_memory->basic_xpad_lifo.buffer_tail = 0; diff --git a/src/core/hle/service/hid/controllers/xpad.h b/src/core/hle/service/hid/controllers/xpad.h index d01dee5fc..9e63a317a 100644 --- a/src/core/hle/service/hid/controllers/xpad.h +++ b/src/core/hle/service/hid/controllers/xpad.h @@ -10,10 +10,10 @@ #include "core/hle/service/hid/ring_lifo.h" namespace Service::HID { -class Controller_XPad final : public ControllerBase { +class XPad final : public ControllerBase { public: - explicit Controller_XPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); - ~Controller_XPad() override; + explicit XPad(Core::HID::HIDCore& hid_core_, u8* raw_shared_memory_); + ~XPad() override; // Called when the controller is initialized void OnInit() override; diff --git a/src/core/hle/service/hid/hid_server.cpp b/src/core/hle/service/hid/hid_server.cpp index 9caed6541..583142e35 100644 --- a/src/core/hle/service/hid/hid_server.cpp +++ b/src/core/hle/service/hid/hid_server.cpp @@ -12,11 +12,12 @@ #include "core/hle/service/hid/errors.h" #include "core/hle/service/hid/hid_firmware_settings.h" #include "core/hle/service/hid/hid_server.h" +#include "core/hle/service/hid/hid_util.h" #include "core/hle/service/hid/resource_manager.h" #include "core/hle/service/ipc_helpers.h" #include "core/memory.h" -#include "core/hle/service/hid/controllers/console_sixaxis.h" +#include "core/hle/service/hid/controllers/console_six_axis.h" #include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/hid/controllers/debug_pad.h" #include "core/hle/service/hid/controllers/gesture.h" @@ -24,9 +25,9 @@ #include "core/hle/service/hid/controllers/mouse.h" #include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/palma.h" -#include "core/hle/service/hid/controllers/stubbed.h" +#include "core/hle/service/hid/controllers/seven_six_axis.h" +#include "core/hle/service/hid/controllers/six_axis.h" #include "core/hle/service/hid/controllers/touchscreen.h" -#include "core/hle/service/hid/controllers/xpad.h" namespace Service::HID { @@ -50,8 +51,7 @@ private: const auto vibration_device_handle{rp.PopRaw()}; if (resource_manager != nullptr) { - resource_manager->GetController(HidController::NPad) - .InitializeVibrationDevice(vibration_device_handle); + resource_manager->GetNpad()->InitializeVibrationDevice(vibration_device_handle); } LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}", @@ -235,15 +235,14 @@ void IHidServer::ActivateDebugPad(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); Result result = ResultSuccess; - auto& debug_pad = - GetResourceManager()->GetController(HidController::DebugPad); + auto debug_pad = GetResourceManager()->GetDebugPad(); if (!firmware_settings->IsDeviceManaged()) { - result = debug_pad.Activate(); + result = debug_pad->Activate(); } if (result.IsSuccess()) { - result = debug_pad.Activate(applet_resource_user_id); + result = debug_pad->Activate(applet_resource_user_id); } IPC::ResponseBuilder rb{ctx, 2}; @@ -257,15 +256,14 @@ void IHidServer::ActivateTouchScreen(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); Result result = ResultSuccess; - auto& touch_screen = - GetResourceManager()->GetController(HidController::Touchscreen); + auto touch_screen = GetResourceManager()->GetTouchScreen(); if (!firmware_settings->IsDeviceManaged()) { - result = touch_screen.Activate(); + result = touch_screen->Activate(); } if (result.IsSuccess()) { - result = touch_screen.Activate(applet_resource_user_id); + result = touch_screen->Activate(applet_resource_user_id); } IPC::ResponseBuilder rb{ctx, 2}; @@ -279,14 +277,14 @@ void IHidServer::ActivateMouse(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); Result result = ResultSuccess; - auto& mouse = GetResourceManager()->GetController(HidController::Mouse); + auto mouse = GetResourceManager()->GetMouse(); if (!firmware_settings->IsDeviceManaged()) { - result = mouse.Activate(); + result = mouse->Activate(); } if (result.IsSuccess()) { - result = mouse.Activate(applet_resource_user_id); + result = mouse->Activate(applet_resource_user_id); } IPC::ResponseBuilder rb{ctx, 2}; @@ -300,15 +298,14 @@ void IHidServer::ActivateKeyboard(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); Result result = ResultSuccess; - auto& keyboard = - GetResourceManager()->GetController(HidController::Keyboard); + auto keyboard = GetResourceManager()->GetKeyboard(); if (!firmware_settings->IsDeviceManaged()) { - result = keyboard.Activate(); + result = keyboard->Activate(); } if (result.IsSuccess()) { - result = keyboard.Activate(applet_resource_user_id); + result = keyboard->Activate(applet_resource_user_id); } IPC::ResponseBuilder rb{ctx, 2}; @@ -502,8 +499,8 @@ void IHidServer::StartSixAxisSensor(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.SetSixAxisEnabled(parameters.sixaxis_handle, true); + auto six_axis = GetResourceManager()->GetSixAxis(); + const auto result = six_axis->SetSixAxisEnabled(parameters.sixaxis_handle, true); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", @@ -525,8 +522,8 @@ void IHidServer::StopSixAxisSensor(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.SetSixAxisEnabled(parameters.sixaxis_handle, false); + auto six_axis = GetResourceManager()->GetSixAxis(); + const auto result = six_axis->SetSixAxisEnabled(parameters.sixaxis_handle, false); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", @@ -549,9 +546,9 @@ void IHidServer::IsSixAxisSensorFusionEnabled(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; bool is_enabled{}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); + auto six_axis = GetResourceManager()->GetSixAxis(); const auto result = - controller.IsSixAxisSensorFusionEnabled(parameters.sixaxis_handle, is_enabled); + six_axis->IsSixAxisSensorFusionEnabled(parameters.sixaxis_handle, is_enabled); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", @@ -575,9 +572,9 @@ void IHidServer::EnableSixAxisSensorFusion(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.SetSixAxisFusionEnabled(parameters.sixaxis_handle, - parameters.enable_sixaxis_sensor_fusion); + auto six_axis = GetResourceManager()->GetSixAxis(); + const auto result = six_axis->SetSixAxisFusionEnabled(parameters.sixaxis_handle, + parameters.enable_sixaxis_sensor_fusion); LOG_DEBUG(Service_HID, "called, enable_sixaxis_sensor_fusion={}, npad_type={}, npad_id={}, " @@ -602,9 +599,9 @@ void IHidServer::SetSixAxisSensorFusionParameters(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); + auto six_axis = GetResourceManager()->GetSixAxis(); const auto result = - controller.SetSixAxisFusionParameters(parameters.sixaxis_handle, parameters.sixaxis_fusion); + six_axis->SetSixAxisFusionParameters(parameters.sixaxis_handle, parameters.sixaxis_fusion); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, parameter1={}, " @@ -629,10 +626,9 @@ void IHidServer::GetSixAxisSensorFusionParameters(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; Core::HID::SixAxisSensorFusionParameters fusion_parameters{}; - const auto& controller = - GetResourceManager()->GetController(HidController::NPad); + auto six_axis = GetResourceManager()->GetSixAxis(); const auto result = - controller.GetSixAxisFusionParameters(parameters.sixaxis_handle, fusion_parameters); + six_axis->GetSixAxisFusionParameters(parameters.sixaxis_handle, fusion_parameters); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", @@ -660,10 +656,10 @@ void IHidServer::ResetSixAxisSensorFusionParameters(HLERequestContext& ctx) { .parameter1 = 0.03f, .parameter2 = 0.4f, }; - auto& controller = GetResourceManager()->GetController(HidController::NPad); + auto six_axis = GetResourceManager()->GetSixAxis(); const auto result1 = - controller.SetSixAxisFusionParameters(parameters.sixaxis_handle, fusion_parameters); - const auto result2 = controller.SetSixAxisFusionEnabled(parameters.sixaxis_handle, true); + six_axis->SetSixAxisFusionParameters(parameters.sixaxis_handle, fusion_parameters); + const auto result2 = six_axis->SetSixAxisFusionEnabled(parameters.sixaxis_handle, true); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", @@ -684,8 +680,8 @@ void IHidServer::SetGyroscopeZeroDriftMode(HLERequestContext& ctx) { const auto drift_mode{rp.PopEnum()}; const auto applet_resource_user_id{rp.Pop()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.SetGyroscopeZeroDriftMode(sixaxis_handle, drift_mode); + auto six_axis = GetResourceManager()->GetSixAxis(); + const auto result = six_axis->SetGyroscopeZeroDriftMode(sixaxis_handle, drift_mode); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, drift_mode={}, " @@ -709,8 +705,8 @@ void IHidServer::GetGyroscopeZeroDriftMode(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; auto drift_mode{Core::HID::GyroscopeZeroDriftMode::Standard}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.GetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); + auto six_axis = GetResourceManager()->GetSixAxis(); + const auto result = six_axis->GetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", @@ -734,8 +730,8 @@ void IHidServer::ResetGyroscopeZeroDriftMode(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; const auto drift_mode{Core::HID::GyroscopeZeroDriftMode::Standard}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.SetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); + auto six_axis = GetResourceManager()->GetSixAxis(); + const auto result = six_axis->SetGyroscopeZeroDriftMode(parameters.sixaxis_handle, drift_mode); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", @@ -758,8 +754,8 @@ void IHidServer::IsSixAxisSensorAtRest(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; bool is_at_rest{}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - controller.IsSixAxisSensorAtRest(parameters.sixaxis_handle, is_at_rest); + auto six_axis = GetResourceManager()->GetSixAxis(); + six_axis->IsSixAxisSensorAtRest(parameters.sixaxis_handle, is_at_rest); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", @@ -783,9 +779,9 @@ void IHidServer::IsFirmwareUpdateAvailableForSixAxisSensor(HLERequestContext& ct const auto parameters{rp.PopRaw()}; bool is_firmware_available{}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - controller.IsFirmwareUpdateAvailableForSixAxisSensor(parameters.sixaxis_handle, - is_firmware_available); + auto controller = GetResourceManager()->GetNpad(); + controller->IsFirmwareUpdateAvailableForSixAxisSensor(parameters.sixaxis_handle, + is_firmware_available); LOG_WARNING( Service_HID, @@ -809,9 +805,9 @@ void IHidServer::EnableSixAxisSensorUnalteredPassthrough(HLERequestContext& ctx) const auto parameters{rp.PopRaw()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.EnableSixAxisSensorUnalteredPassthrough( - parameters.sixaxis_handle, parameters.enabled); + auto six_axis = GetResourceManager()->GetSixAxis(); + const auto result = six_axis->EnableSixAxisSensorUnalteredPassthrough(parameters.sixaxis_handle, + parameters.enabled); LOG_DEBUG(Service_HID, "(STUBBED) called, enabled={}, npad_type={}, npad_id={}, device_index={}, " @@ -836,8 +832,8 @@ void IHidServer::IsSixAxisSensorUnalteredPassthroughEnabled(HLERequestContext& c const auto parameters{rp.PopRaw()}; bool is_unaltered_sisxaxis_enabled{}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.IsSixAxisSensorUnalteredPassthroughEnabled( + auto six_axis = GetResourceManager()->GetSixAxis(); + const auto result = six_axis->IsSixAxisSensorUnalteredPassthroughEnabled( parameters.sixaxis_handle, is_unaltered_sisxaxis_enabled); LOG_DEBUG( @@ -863,9 +859,9 @@ void IHidServer::LoadSixAxisSensorCalibrationParameter(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; Core::HID::SixAxisSensorCalibrationParameter calibration{}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); + auto six_axis = GetResourceManager()->GetSixAxis(); const auto result = - controller.LoadSixAxisSensorCalibrationParameter(parameters.sixaxis_handle, calibration); + six_axis->LoadSixAxisSensorCalibrationParameter(parameters.sixaxis_handle, calibration); LOG_WARNING( Service_HID, @@ -893,9 +889,9 @@ void IHidServer::GetSixAxisSensorIcInformation(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; Core::HID::SixAxisSensorIcInformation ic_information{}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); + auto six_axis = GetResourceManager()->GetSixAxis(); const auto result = - controller.GetSixAxisSensorIcInformation(parameters.sixaxis_handle, ic_information); + six_axis->GetSixAxisSensorIcInformation(parameters.sixaxis_handle, ic_information); LOG_WARNING( Service_HID, @@ -922,9 +918,9 @@ void IHidServer::ResetIsSixAxisSensorDeviceNewlyAssigned(HLERequestContext& ctx) const auto parameters{rp.PopRaw()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); + auto controller = GetResourceManager()->GetNpad(); const auto result = - controller.ResetIsSixAxisSensorDeviceNewlyAssigned(parameters.sixaxis_handle); + controller->ResetIsSixAxisSensorDeviceNewlyAssigned(parameters.sixaxis_handle); LOG_WARNING( Service_HID, @@ -951,15 +947,15 @@ void IHidServer::ActivateGesture(HLERequestContext& ctx) { parameters.basic_gesture_id, parameters.applet_resource_user_id); Result result = ResultSuccess; - auto& gesture = GetResourceManager()->GetController(HidController::Gesture); + auto gesture = GetResourceManager()->GetGesture(); if (!firmware_settings->IsDeviceManaged()) { - result = gesture.Activate(); + result = gesture->Activate(); } if (result.IsSuccess()) { // TODO: Use gesture id here - result = gesture.Activate(parameters.applet_resource_user_id); + result = gesture->Activate(parameters.applet_resource_user_id); } IPC::ResponseBuilder rb{ctx, 2}; @@ -977,9 +973,7 @@ void IHidServer::SetSupportedNpadStyleSet(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - GetResourceManager() - ->GetController(HidController::NPad) - .SetSupportedStyleSet({parameters.supported_styleset}); + GetResourceManager()->GetNpad()->SetSupportedStyleSet({parameters.supported_styleset}); LOG_DEBUG(Service_HID, "called, supported_styleset={}, applet_resource_user_id={}", parameters.supported_styleset, parameters.applet_resource_user_id); @@ -996,19 +990,14 @@ void IHidServer::GetSupportedNpadStyleSet(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); - rb.PushEnum(GetResourceManager() - ->GetController(HidController::NPad) - .GetSupportedStyleSet() - .raw); + rb.PushEnum(GetResourceManager()->GetNpad()->GetSupportedStyleSet().raw); } void IHidServer::SetSupportedNpadIdType(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - const auto result = GetResourceManager() - ->GetController(HidController::NPad) - .SetSupportedNpadIdTypes(ctx.ReadBuffer()); + const auto result = GetResourceManager()->GetNpad()->SetSupportedNpadIdTypes(ctx.ReadBuffer()); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); @@ -1022,10 +1011,10 @@ void IHidServer::ActivateNpad(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); - auto& npad = GetResourceManager()->GetController(HidController::NPad); + auto npad = GetResourceManager()->GetNpad(); // TODO: npad->SetRevision(applet_resource_user_id, NpadRevision::Revision0); - const Result result = npad.Activate(applet_resource_user_id); + const Result result = npad->Activate(applet_resource_user_id); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -1059,15 +1048,12 @@ void IHidServer::AcquireNpadStyleSetUpdateEventHandle(HLERequestContext& ctx) { parameters.npad_id, parameters.applet_resource_user_id, parameters.unknown); // Games expect this event to be signaled after calling this function - GetResourceManager() - ->GetController(HidController::NPad) - .SignalStyleSetChangedEvent(parameters.npad_id); + GetResourceManager()->GetNpad()->SignalStyleSetChangedEvent(parameters.npad_id); IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(ResultSuccess); - rb.PushCopyObjects(GetResourceManager() - ->GetController(HidController::NPad) - .GetStyleSetChangedEvent(parameters.npad_id)); + rb.PushCopyObjects( + GetResourceManager()->GetNpad()->GetStyleSetChangedEvent(parameters.npad_id)); } void IHidServer::DisconnectNpad(HLERequestContext& ctx) { @@ -1081,8 +1067,8 @@ void IHidServer::DisconnectNpad(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - controller.DisconnectNpad(parameters.npad_id); + auto controller = GetResourceManager()->GetNpad(); + controller->DisconnectNpad(parameters.npad_id); LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, parameters.applet_resource_user_id); @@ -1096,8 +1082,8 @@ void IHidServer::GetPlayerLedPattern(HLERequestContext& ctx) { const auto npad_id{rp.PopEnum()}; Core::HID::LedPattern pattern{0, 0, 0, 0}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.GetLedPattern(npad_id, pattern); + auto controller = GetResourceManager()->GetNpad(); + const auto result = controller->GetLedPattern(npad_id, pattern); LOG_DEBUG(Service_HID, "called, npad_id={}", npad_id); @@ -1109,7 +1095,7 @@ void IHidServer::GetPlayerLedPattern(HLERequestContext& ctx) { void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; struct Parameters { - Controller_NPad::NpadRevision revision; + NPad::NpadRevision revision; INSERT_PADDING_WORDS_NOINIT(1); u64 applet_resource_user_id; }; @@ -1120,10 +1106,10 @@ void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, revision={}, applet_resource_user_id={}", parameters.revision, parameters.applet_resource_user_id); - auto& npad = GetResourceManager()->GetController(HidController::NPad); + auto npad = GetResourceManager()->GetNpad(); // TODO: npad->SetRevision(applet_resource_user_id, revision); - const auto result = npad.Activate(parameters.applet_resource_user_id); + const auto result = npad->Activate(parameters.applet_resource_user_id); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -1132,11 +1118,9 @@ void IHidServer::ActivateNpadWithRevision(HLERequestContext& ctx) { void IHidServer::SetNpadJoyHoldType(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - const auto hold_type{rp.PopEnum()}; + const auto hold_type{rp.PopEnum()}; - GetResourceManager() - ->GetController(HidController::NPad) - .SetHoldType(hold_type); + GetResourceManager()->GetNpad()->SetHoldType(hold_type); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, hold_type={}", applet_resource_user_id, hold_type); @@ -1153,8 +1137,7 @@ void IHidServer::GetNpadJoyHoldType(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); - rb.PushEnum( - GetResourceManager()->GetController(HidController::NPad).GetHoldType()); + rb.PushEnum(GetResourceManager()->GetNpad()->GetHoldType()); } void IHidServer::SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx) { @@ -1169,10 +1152,9 @@ void IHidServer::SetNpadJoyAssignmentModeSingleByDefault(HLERequestContext& ctx) const auto parameters{rp.PopRaw()}; Core::HID::NpadIdType new_npad_id{}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - controller.SetNpadMode(new_npad_id, parameters.npad_id, - Controller_NPad::NpadJoyDeviceType::Left, - Controller_NPad::NpadJoyAssignmentMode::Single); + auto controller = GetResourceManager()->GetNpad(); + controller->SetNpadMode(new_npad_id, parameters.npad_id, NPad::NpadJoyDeviceType::Left, + NPad::NpadJoyAssignmentMode::Single); LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, parameters.applet_resource_user_id); @@ -1187,16 +1169,16 @@ void IHidServer::SetNpadJoyAssignmentModeSingle(HLERequestContext& ctx) { Core::HID::NpadIdType npad_id; INSERT_PADDING_WORDS_NOINIT(1); u64 applet_resource_user_id; - Controller_NPad::NpadJoyDeviceType npad_joy_device_type; + NPad::NpadJoyDeviceType npad_joy_device_type; }; static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); const auto parameters{rp.PopRaw()}; Core::HID::NpadIdType new_npad_id{}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - controller.SetNpadMode(new_npad_id, parameters.npad_id, parameters.npad_joy_device_type, - Controller_NPad::NpadJoyAssignmentMode::Single); + auto controller = GetResourceManager()->GetNpad(); + controller->SetNpadMode(new_npad_id, parameters.npad_id, parameters.npad_joy_device_type, + NPad::NpadJoyAssignmentMode::Single); LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}", parameters.npad_id, parameters.applet_resource_user_id, @@ -1218,9 +1200,8 @@ void IHidServer::SetNpadJoyAssignmentModeDual(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; Core::HID::NpadIdType new_npad_id{}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - controller.SetNpadMode(new_npad_id, parameters.npad_id, {}, - Controller_NPad::NpadJoyAssignmentMode::Dual); + auto controller = GetResourceManager()->GetNpad(); + controller->SetNpadMode(new_npad_id, parameters.npad_id, {}, NPad::NpadJoyAssignmentMode::Dual); LOG_DEBUG(Service_HID, "called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, parameters.applet_resource_user_id); // Spams a lot when controller applet is open @@ -1235,8 +1216,8 @@ void IHidServer::MergeSingleJoyAsDualJoy(HLERequestContext& ctx) { const auto npad_id_2{rp.PopEnum()}; const auto applet_resource_user_id{rp.Pop()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.MergeSingleJoyAsDualJoy(npad_id_1, npad_id_2); + auto controller = GetResourceManager()->GetNpad(); + const auto result = controller->MergeSingleJoyAsDualJoy(npad_id_1, npad_id_2); LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}", npad_id_1, npad_id_2, applet_resource_user_id); @@ -1249,9 +1230,7 @@ void IHidServer::StartLrAssignmentMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager() - ->GetController(HidController::NPad) - .StartLRAssignmentMode(); + GetResourceManager()->GetNpad()->StartLRAssignmentMode(); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); @@ -1263,9 +1242,7 @@ void IHidServer::StopLrAssignmentMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager() - ->GetController(HidController::NPad) - .StopLRAssignmentMode(); + GetResourceManager()->GetNpad()->StopLRAssignmentMode(); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); @@ -1276,11 +1253,9 @@ void IHidServer::StopLrAssignmentMode(HLERequestContext& ctx) { void IHidServer::SetNpadHandheldActivationMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - const auto activation_mode{rp.PopEnum()}; + const auto activation_mode{rp.PopEnum()}; - GetResourceManager() - ->GetController(HidController::NPad) - .SetNpadHandheldActivationMode(activation_mode); + GetResourceManager()->GetNpad()->SetNpadHandheldActivationMode(activation_mode); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}, activation_mode={}", applet_resource_user_id, activation_mode); @@ -1297,9 +1272,7 @@ void IHidServer::GetNpadHandheldActivationMode(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); - rb.PushEnum(GetResourceManager() - ->GetController(HidController::NPad) - .GetNpadHandheldActivationMode()); + rb.PushEnum(GetResourceManager()->GetNpad()->GetNpadHandheldActivationMode()); } void IHidServer::SwapNpadAssignment(HLERequestContext& ctx) { @@ -1308,8 +1281,8 @@ void IHidServer::SwapNpadAssignment(HLERequestContext& ctx) { const auto npad_id_2{rp.PopEnum()}; const auto applet_resource_user_id{rp.Pop()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.SwapNpadAssignment(npad_id_1, npad_id_2); + auto controller = GetResourceManager()->GetNpad(); + const auto result = controller->SwapNpadAssignment(npad_id_1, npad_id_2); LOG_DEBUG(Service_HID, "called, npad_id_1={}, npad_id_2={}, applet_resource_user_id={}", npad_id_1, npad_id_2, applet_resource_user_id); @@ -1330,9 +1303,9 @@ void IHidServer::IsUnintendedHomeButtonInputProtectionEnabled(HLERequestContext& const auto parameters{rp.PopRaw()}; bool is_enabled = false; - auto& controller = GetResourceManager()->GetController(HidController::NPad); + auto controller = GetResourceManager()->GetNpad(); const auto result = - controller.IsUnintendedHomeButtonInputProtectionEnabled(parameters.npad_id, is_enabled); + controller->IsUnintendedHomeButtonInputProtectionEnabled(parameters.npad_id, is_enabled); LOG_WARNING(Service_HID, "(STUBBED) called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, parameters.applet_resource_user_id); @@ -1354,8 +1327,8 @@ void IHidServer::EnableUnintendedHomeButtonInputProtection(HLERequestContext& ct const auto parameters{rp.PopRaw()}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); - const auto result = controller.SetUnintendedHomeButtonInputProtectionEnabled( + auto controller = GetResourceManager()->GetNpad(); + const auto result = controller->SetUnintendedHomeButtonInputProtectionEnabled( parameters.is_enabled, parameters.npad_id); LOG_DEBUG(Service_HID, @@ -1372,17 +1345,17 @@ void IHidServer::SetNpadJoyAssignmentModeSingleWithDestination(HLERequestContext Core::HID::NpadIdType npad_id; INSERT_PADDING_WORDS_NOINIT(1); u64 applet_resource_user_id; - Controller_NPad::NpadJoyDeviceType npad_joy_device_type; + NPad::NpadJoyDeviceType npad_joy_device_type; }; static_assert(sizeof(Parameters) == 0x18, "Parameters has incorrect size."); const auto parameters{rp.PopRaw()}; Core::HID::NpadIdType new_npad_id{}; - auto& controller = GetResourceManager()->GetController(HidController::NPad); + auto controller = GetResourceManager()->GetNpad(); const auto is_reassigned = - controller.SetNpadMode(new_npad_id, parameters.npad_id, parameters.npad_joy_device_type, - Controller_NPad::NpadJoyAssignmentMode::Single); + controller->SetNpadMode(new_npad_id, parameters.npad_id, parameters.npad_joy_device_type, + NPad::NpadJoyAssignmentMode::Single); LOG_INFO(Service_HID, "called, npad_id={}, applet_resource_user_id={}, npad_joy_device_type={}", parameters.npad_id, parameters.applet_resource_user_id, @@ -1405,9 +1378,8 @@ void IHidServer::SetNpadAnalogStickUseCenterClamp(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - GetResourceManager() - ->GetController(HidController::NPad) - .SetAnalogStickUseCenterClamp(parameters.analog_stick_use_center_clamp); + GetResourceManager()->GetNpad()->SetAnalogStickUseCenterClamp( + parameters.analog_stick_use_center_clamp); LOG_WARNING(Service_HID, "(STUBBED) called, analog_stick_use_center_clamp={}, applet_resource_user_id={}", @@ -1451,8 +1423,7 @@ void IHidServer::ClearNpadCaptureButtonAssignment(HLERequestContext& ctx) { void IHidServer::GetVibrationDeviceInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto vibration_device_handle{rp.PopRaw()}; - const auto& controller = - GetResourceManager()->GetController(HidController::NPad); + const auto controller = GetResourceManager()->GetNpad(); Core::HID::VibrationDeviceInfo vibration_device_info; bool check_device_index = false; @@ -1496,7 +1467,7 @@ void IHidServer::GetVibrationDeviceInfo(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, vibration_device_type={}, vibration_device_position={}", vibration_device_info.type, vibration_device_info.position); - const auto result = controller.IsDeviceHandleValid(vibration_device_handle); + const auto result = IsVibrationHandleValid(vibration_device_handle); if (result.IsError()) { IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -1520,9 +1491,8 @@ void IHidServer::SendVibrationValue(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - GetResourceManager() - ->GetController(HidController::NPad) - .VibrateController(parameters.vibration_device_handle, parameters.vibration_value); + GetResourceManager()->GetNpad()->VibrateController(parameters.vibration_device_handle, + parameters.vibration_value); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}", @@ -1553,9 +1523,8 @@ void IHidServer::GetActualVibrationValue(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 6}; rb.Push(ResultSuccess); - rb.PushRaw(GetResourceManager() - ->GetController(HidController::NPad) - .GetLastVibration(parameters.vibration_device_handle)); + rb.PushRaw( + GetResourceManager()->GetNpad()->GetLastVibration(parameters.vibration_device_handle)); } void IHidServer::CreateActiveVibrationDeviceList(HLERequestContext& ctx) { @@ -1606,9 +1575,7 @@ void IHidServer::SendVibrationValues(HLERequestContext& ctx) { auto vibration_values = std::span( reinterpret_cast(vibration_data.data()), vibration_count); - GetResourceManager() - ->GetController(HidController::NPad) - .VibrateControllers(vibration_device_handles, vibration_values); + GetResourceManager()->GetNpad()->VibrateControllers(vibration_device_handles, vibration_values); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); @@ -1662,9 +1629,8 @@ void IHidServer::SendVibrationGcErmCommand(HLERequestContext& ctx) { } }(); - GetResourceManager() - ->GetController(HidController::NPad) - .VibrateController(parameters.vibration_device_handle, vibration_value); + GetResourceManager()->GetNpad()->VibrateController(parameters.vibration_device_handle, + vibration_value); LOG_DEBUG(Service_HID, "called, npad_type={}, npad_id={}, device_index={}, applet_resource_user_id={}, " @@ -1688,9 +1654,8 @@ void IHidServer::GetActualVibrationGcErmCommand(HLERequestContext& ctx) { const auto parameters{rp.PopRaw()}; - const auto last_vibration = GetResourceManager() - ->GetController(HidController::NPad) - .GetLastVibration(parameters.vibration_device_handle); + const auto last_vibration = + GetResourceManager()->GetNpad()->GetLastVibration(parameters.vibration_device_handle); const auto gc_erm_command = [last_vibration] { if (last_vibration.low_amplitude != 0.0f || last_vibration.high_amplitude != 0.0f) { @@ -1725,9 +1690,7 @@ void IHidServer::BeginPermitVibrationSession(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager() - ->GetController(HidController::NPad) - .SetPermitVibrationSession(true); + GetResourceManager()->GetNpad()->SetPermitVibrationSession(true); LOG_DEBUG(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); @@ -1736,9 +1699,7 @@ void IHidServer::BeginPermitVibrationSession(HLERequestContext& ctx) { } void IHidServer::EndPermitVibrationSession(HLERequestContext& ctx) { - GetResourceManager() - ->GetController(HidController::NPad) - .SetPermitVibrationSession(false); + GetResourceManager()->GetNpad()->SetPermitVibrationSession(false); LOG_DEBUG(Service_HID, "called"); @@ -1765,9 +1726,8 @@ void IHidServer::IsVibrationDeviceMounted(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); - rb.Push(GetResourceManager() - ->GetController(HidController::NPad) - .IsVibrationDeviceMounted(parameters.vibration_device_handle)); + rb.Push(GetResourceManager()->GetNpad()->IsVibrationDeviceMounted( + parameters.vibration_device_handle)); } void IHidServer::ActivateConsoleSixAxisSensor(HLERequestContext& ctx) { @@ -1777,15 +1737,14 @@ void IHidServer::ActivateConsoleSixAxisSensor(HLERequestContext& ctx) { LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); Result result = ResultSuccess; - auto console_sixaxis = GetResourceManager()->GetController( - HidController::ConsoleSixAxisSensor); + auto console_sixaxis = GetResourceManager()->GetConsoleSixAxis(); if (!firmware_settings->IsDeviceManaged()) { - result = console_sixaxis.Activate(); + result = console_sixaxis->Activate(); } if (result.IsSuccess()) { - result = console_sixaxis.Activate(applet_resource_user_id); + result = console_sixaxis->Activate(applet_resource_user_id); } IPC::ResponseBuilder rb{ctx, 2}; @@ -1839,15 +1798,14 @@ void IHidServer::ActivateSevenSixAxisSensor(HLERequestContext& ctx) { LOG_INFO(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); Result result = ResultSuccess; - auto console_sixaxis = GetResourceManager()->GetController( - HidController::ConsoleSixAxisSensor); + auto seven_sixaxis = GetResourceManager()->GetSevenSixAxis(); if (!firmware_settings->IsDeviceManaged()) { - result = console_sixaxis.Activate(); + result = seven_sixaxis->Activate(); } if (result.IsSuccess()) { - console_sixaxis.Activate(applet_resource_user_id); + seven_sixaxis->Activate(applet_resource_user_id); } IPC::ResponseBuilder rb{ctx, 2}; @@ -1911,13 +1869,10 @@ void IHidServer::InitializeSevenSixAxisSensor(HLERequestContext& ctx) { ASSERT_MSG(t_mem_2->GetSize() == 0x7F000, "t_mem_2 has incorrect size"); // Activate console six axis controller - GetResourceManager() - ->GetController(HidController::ConsoleSixAxisSensor) - .Activate(); + GetResourceManager()->GetConsoleSixAxis()->Activate(); + GetResourceManager()->GetSevenSixAxis()->Activate(); - GetResourceManager() - ->GetController(HidController::ConsoleSixAxisSensor) - .SetTransferMemoryAddress(t_mem_1->GetSourceAddress()); + GetResourceManager()->GetSevenSixAxis()->SetTransferMemoryAddress(t_mem_1->GetSourceAddress()); LOG_WARNING(Service_HID, "called, t_mem_1_handle=0x{:08X}, t_mem_2_handle=0x{:08X}, " @@ -1943,9 +1898,7 @@ void IHidServer::ResetSevenSixAxisSensorTimestamp(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - GetResourceManager() - ->GetController(HidController::ConsoleSixAxisSensor) - .ResetTimestamp(); + GetResourceManager()->GetSevenSixAxis()->ResetTimestamp(); LOG_WARNING(Service_HID, "called, applet_resource_user_id={}", applet_resource_user_id); @@ -1977,9 +1930,9 @@ void IHidServer::GetPalmaConnectionHandle(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called, npad_id={}, applet_resource_user_id={}", parameters.npad_id, parameters.applet_resource_user_id); - Controller_Palma::PalmaConnectionHandle handle; - auto& controller = GetResourceManager()->GetController(HidController::Palma); - const auto result = controller.GetPalmaConnectionHandle(parameters.npad_id, handle); + Palma::PalmaConnectionHandle handle; + auto controller = GetResourceManager()->GetPalma(); + const auto result = controller->GetPalmaConnectionHandle(parameters.npad_id, handle); IPC::ResponseBuilder rb{ctx, 4}; rb.Push(result); @@ -1988,12 +1941,12 @@ void IHidServer::GetPalmaConnectionHandle(HLERequestContext& ctx) { void IHidServer::InitializePalma(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - auto& controller = GetResourceManager()->GetController(HidController::Palma); - const auto result = controller.InitializePalma(connection_handle); + auto controller = GetResourceManager()->GetPalma(); + const auto result = controller->InitializePalma(connection_handle); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -2001,27 +1954,27 @@ void IHidServer::InitializePalma(HLERequestContext& ctx) { void IHidServer::AcquirePalmaOperationCompleteEvent(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - auto& controller = GetResourceManager()->GetController(HidController::Palma); + auto controller = GetResourceManager()->GetPalma(); IPC::ResponseBuilder rb{ctx, 2, 1}; rb.Push(ResultSuccess); - rb.PushCopyObjects(controller.AcquirePalmaOperationCompleteEvent(connection_handle)); + rb.PushCopyObjects(controller->AcquirePalmaOperationCompleteEvent(connection_handle)); } void IHidServer::GetPalmaOperationInfo(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - Controller_Palma::PalmaOperationType operation_type; - Controller_Palma::PalmaOperationData data; - auto& controller = GetResourceManager()->GetController(HidController::Palma); - const auto result = controller.GetPalmaOperationInfo(connection_handle, operation_type, data); + Palma::PalmaOperationType operation_type; + Palma::PalmaOperationData data; + auto controller = GetResourceManager()->GetPalma(); + const auto result = controller->GetPalmaOperationInfo(connection_handle, operation_type, data); if (result.IsError()) { IPC::ResponseBuilder rb{ctx, 2}; @@ -2036,14 +1989,14 @@ void IHidServer::GetPalmaOperationInfo(HLERequestContext& ctx) { void IHidServer::PlayPalmaActivity(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; const auto palma_activity{rp.Pop()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, palma_activity={}", connection_handle.npad_id, palma_activity); - auto& controller = GetResourceManager()->GetController(HidController::Palma); - const auto result = controller.PlayPalmaActivity(connection_handle, palma_activity); + auto controller = GetResourceManager()->GetPalma(); + const auto result = controller->PlayPalmaActivity(connection_handle, palma_activity); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -2051,14 +2004,14 @@ void IHidServer::PlayPalmaActivity(HLERequestContext& ctx) { void IHidServer::SetPalmaFrModeType(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - const auto fr_mode{rp.PopEnum()}; + const auto connection_handle{rp.PopRaw()}; + const auto fr_mode{rp.PopEnum()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, fr_mode={}", connection_handle.npad_id, fr_mode); - auto& controller = GetResourceManager()->GetController(HidController::Palma); - const auto result = controller.SetPalmaFrModeType(connection_handle, fr_mode); + auto controller = GetResourceManager()->GetPalma(); + const auto result = controller->SetPalmaFrModeType(connection_handle, fr_mode); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -2066,12 +2019,12 @@ void IHidServer::SetPalmaFrModeType(HLERequestContext& ctx) { void IHidServer::ReadPalmaStep(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - auto& controller = GetResourceManager()->GetController(HidController::Palma); - const auto result = controller.ReadPalmaStep(connection_handle); + auto controller = GetResourceManager()->GetPalma(); + const auto result = controller->ReadPalmaStep(connection_handle); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -2082,7 +2035,7 @@ void IHidServer::EnablePalmaStep(HLERequestContext& ctx) { struct Parameters { bool is_enabled; INSERT_PADDING_WORDS_NOINIT(1); - Controller_Palma::PalmaConnectionHandle connection_handle; + Palma::PalmaConnectionHandle connection_handle; }; static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); @@ -2091,9 +2044,9 @@ void IHidServer::EnablePalmaStep(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, is_enabled={}", parameters.connection_handle.npad_id, parameters.is_enabled); - auto& controller = GetResourceManager()->GetController(HidController::Palma); + auto controller = GetResourceManager()->GetPalma(); const auto result = - controller.EnablePalmaStep(parameters.connection_handle, parameters.is_enabled); + controller->EnablePalmaStep(parameters.connection_handle, parameters.is_enabled); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -2101,12 +2054,12 @@ void IHidServer::EnablePalmaStep(HLERequestContext& ctx) { void IHidServer::ResetPalmaStep(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - auto& controller = GetResourceManager()->GetController(HidController::Palma); - const auto result = controller.ResetPalmaStep(connection_handle); + auto controller = GetResourceManager()->GetPalma(); + const auto result = controller->ResetPalmaStep(connection_handle); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -2128,13 +2081,11 @@ void IHidServer::WritePalmaApplicationSection(HLERequestContext& ctx) { void IHidServer::ReadPalmaUniqueCode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - GetResourceManager() - ->GetController(HidController::Palma) - .ReadPalmaUniqueCode(connection_handle); + GetResourceManager()->GetPalma()->ReadPalmaUniqueCode(connection_handle); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -2142,13 +2093,11 @@ void IHidServer::ReadPalmaUniqueCode(HLERequestContext& ctx) { void IHidServer::SetPalmaUniqueCodeInvalid(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - GetResourceManager() - ->GetController(HidController::Palma) - .SetPalmaUniqueCodeInvalid(connection_handle); + GetResourceManager()->GetPalma()->SetPalmaUniqueCodeInvalid(connection_handle); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -2163,7 +2112,7 @@ void IHidServer::WritePalmaActivityEntry(HLERequestContext& ctx) { void IHidServer::WritePalmaRgbLedPatternEntry(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; const auto unknown{rp.Pop()}; [[maybe_unused]] const auto buffer = ctx.ReadBuffer(); @@ -2171,9 +2120,7 @@ void IHidServer::WritePalmaRgbLedPatternEntry(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, unknown={}", connection_handle.npad_id, unknown); - GetResourceManager() - ->GetController(HidController::Palma) - .WritePalmaRgbLedPatternEntry(connection_handle, unknown); + GetResourceManager()->GetPalma()->WritePalmaRgbLedPatternEntry(connection_handle, unknown); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -2181,8 +2128,8 @@ void IHidServer::WritePalmaRgbLedPatternEntry(HLERequestContext& ctx) { void IHidServer::WritePalmaWaveEntry(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; - const auto wave_set{rp.PopEnum()}; + const auto connection_handle{rp.PopRaw()}; + const auto wave_set{rp.PopEnum()}; const auto unknown{rp.Pop()}; const auto t_mem_size{rp.Pop()}; const auto t_mem_handle{ctx.GetCopyHandle(0)}; @@ -2207,9 +2154,8 @@ void IHidServer::WritePalmaWaveEntry(HLERequestContext& ctx) { "t_mem_handle=0x{:08X}, t_mem_size={}, size={}", connection_handle.npad_id, wave_set, unknown, t_mem_handle, t_mem_size, size); - GetResourceManager() - ->GetController(HidController::Palma) - .WritePalmaWaveEntry(connection_handle, wave_set, t_mem->GetSourceAddress(), t_mem_size); + GetResourceManager()->GetPalma()->WritePalmaWaveEntry(connection_handle, wave_set, + t_mem->GetSourceAddress(), t_mem_size); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -2220,7 +2166,7 @@ void IHidServer::SetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx) { struct Parameters { s32 database_id_version; INSERT_PADDING_WORDS_NOINIT(1); - Controller_Palma::PalmaConnectionHandle connection_handle; + Palma::PalmaConnectionHandle connection_handle; }; static_assert(sizeof(Parameters) == 0x10, "Parameters has incorrect size."); @@ -2229,10 +2175,8 @@ void IHidServer::SetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}, database_id_version={}", parameters.connection_handle.npad_id, parameters.database_id_version); - GetResourceManager() - ->GetController(HidController::Palma) - .SetPalmaDataBaseIdentificationVersion(parameters.connection_handle, - parameters.database_id_version); + GetResourceManager()->GetPalma()->SetPalmaDataBaseIdentificationVersion( + parameters.connection_handle, parameters.database_id_version); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -2240,13 +2184,11 @@ void IHidServer::SetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx) { void IHidServer::GetPalmaDataBaseIdentificationVersion(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - GetResourceManager() - ->GetController(HidController::Palma) - .GetPalmaDataBaseIdentificationVersion(connection_handle); + GetResourceManager()->GetPalma()->GetPalmaDataBaseIdentificationVersion(connection_handle); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -2261,13 +2203,12 @@ void IHidServer::SuspendPalmaFeature(HLERequestContext& ctx) { void IHidServer::GetPalmaOperationResult(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - const auto result = GetResourceManager() - ->GetController(HidController::Palma) - .GetPalmaOperationResult(connection_handle); + const auto result = + GetResourceManager()->GetPalma()->GetPalmaOperationResult(connection_handle); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -2302,9 +2243,7 @@ void IHidServer::SetIsPalmaAllConnectable(HLERequestContext& ctx) { "(STUBBED) called, is_palma_all_connectable={},applet_resource_user_id={}", parameters.is_palma_all_connectable, parameters.applet_resource_user_id); - GetResourceManager() - ->GetController(HidController::Palma) - .SetIsPalmaAllConnectable(parameters.is_palma_all_connectable); + GetResourceManager()->GetPalma()->SetIsPalmaAllConnectable(parameters.is_palma_all_connectable); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -2319,13 +2258,11 @@ void IHidServer::SetIsPalmaPairedConnectable(HLERequestContext& ctx) { void IHidServer::PairPalma(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const auto connection_handle{rp.PopRaw()}; + const auto connection_handle{rp.PopRaw()}; LOG_WARNING(Service_HID, "(STUBBED) called, connection_handle={}", connection_handle.npad_id); - GetResourceManager() - ->GetController(HidController::Palma) - .PairPalma(connection_handle); + GetResourceManager()->GetPalma()->PairPalma(connection_handle); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -2337,9 +2274,7 @@ void IHidServer::SetPalmaBoostMode(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "(STUBBED) called, palma_boost_mode={}", palma_boost_mode); - GetResourceManager() - ->GetController(HidController::Palma) - .SetPalmaBoostMode(palma_boost_mode); + GetResourceManager()->GetPalma()->SetPalmaBoostMode(palma_boost_mode); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -2376,11 +2311,9 @@ void IHidServer::SetDisallowedPalmaConnection(HLERequestContext& ctx) { void IHidServer::SetNpadCommunicationMode(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto applet_resource_user_id{rp.Pop()}; - const auto communication_mode{rp.PopEnum()}; + const auto communication_mode{rp.PopEnum()}; - GetResourceManager() - ->GetController(HidController::NPad) - .SetNpadCommunicationMode(communication_mode); + GetResourceManager()->GetNpad()->SetNpadCommunicationMode(communication_mode); LOG_WARNING(Service_HID, "(STUBBED) called, applet_resource_user_id={}, communication_mode={}", applet_resource_user_id, communication_mode); @@ -2396,9 +2329,7 @@ void IHidServer::GetNpadCommunicationMode(HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 4}; rb.Push(ResultSuccess); - rb.PushEnum(GetResourceManager() - ->GetController(HidController::NPad) - .GetNpadCommunicationMode()); + rb.PushEnum(GetResourceManager()->GetNpad()->GetNpadCommunicationMode()); } void IHidServer::SetTouchScreenConfiguration(HLERequestContext& ctx) { diff --git a/src/core/hle/service/hid/hid_system_server.cpp b/src/core/hle/service/hid/hid_system_server.cpp index 6f1902ee5..b56d0347a 100644 --- a/src/core/hle/service/hid/hid_system_server.cpp +++ b/src/core/hle/service/hid/hid_system_server.cpp @@ -16,206 +16,206 @@ IHidSystemServer::IHidSystemServer(Core::System& system_, std::shared_ptrGetController(HidController::NPad) - .ApplyNpadSystemCommonPolicy(); + GetResourceManager()->GetNpad()->ApplyNpadSystemCommonPolicy(); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -273,9 +271,7 @@ void IHidSystemServer::GetLastActiveNpad(HLERequestContext& ctx) { void IHidSystemServer::ApplyNpadSystemCommonPolicyFull(HLERequestContext& ctx) { LOG_WARNING(Service_HID, "called"); - GetResourceManager() - ->GetController(HidController::NPad) - .ApplyNpadSystemCommonPolicy(); + GetResourceManager()->GetNpad()->ApplyNpadSystemCommonPolicy(); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -304,10 +300,7 @@ void IHidSystemServer::GetMaskedSupportedNpadStyleSet(HLERequestContext& ctx) { LOG_INFO(Service_HID, "(STUBBED) called"); Core::HID::NpadStyleSet supported_styleset = - GetResourceManager() - ->GetController(HidController::NPad) - .GetSupportedStyleSet() - .raw; + GetResourceManager()->GetNpad()->GetSupportedStyleSet().raw; IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); @@ -320,10 +313,7 @@ void IHidSystemServer::SetSupportedNpadStyleSetAll(HLERequestContext& ctx) { LOG_INFO(Service_HID, "(STUBBED) called"); Core::HID::NpadStyleSet supported_styleset = - GetResourceManager() - ->GetController(HidController::NPad) - .GetSupportedStyleSet() - .raw; + GetResourceManager()->GetNpad()->GetSupportedStyleSet().raw; IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); @@ -337,10 +327,8 @@ void IHidSystemServer::GetAppletDetailedUiType(HLERequestContext& ctx) { LOG_DEBUG(Service_HID, "called, npad_id_type={}", npad_id_type); // Spams a lot when controller applet is running - const Service::HID::Controller_NPad::AppletDetailedUiType detailed_ui_type = - GetResourceManager() - ->GetController(HidController::NPad) - .GetAppletDetailedUiType(npad_id_type); + const NPad::AppletDetailedUiType detailed_ui_type = + GetResourceManager()->GetNpad()->GetAppletDetailedUiType(npad_id_type); IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); diff --git a/src/core/hle/service/hid/hid_util.h b/src/core/hle/service/hid/hid_util.h new file mode 100644 index 000000000..b87cc10e3 --- /dev/null +++ b/src/core/hle/service/hid/hid_util.h @@ -0,0 +1,146 @@ +// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "core/hid/hid_types.h" +#include "core/hle/service/hid/errors.h" + +namespace Service::HID { + +constexpr bool IsNpadIdValid(const Core::HID::NpadIdType npad_id) { + switch (npad_id) { + case Core::HID::NpadIdType::Player1: + case Core::HID::NpadIdType::Player2: + case Core::HID::NpadIdType::Player3: + case Core::HID::NpadIdType::Player4: + case Core::HID::NpadIdType::Player5: + case Core::HID::NpadIdType::Player6: + case Core::HID::NpadIdType::Player7: + case Core::HID::NpadIdType::Player8: + case Core::HID::NpadIdType::Other: + case Core::HID::NpadIdType::Handheld: + return true; + default: + return false; + } +} + +constexpr Result IsSixaxisHandleValid(const Core::HID::SixAxisSensorHandle& handle) { + const auto npad_id = IsNpadIdValid(static_cast(handle.npad_id)); + const bool device_index = handle.device_index < Core::HID::DeviceIndex::MaxDeviceIndex; + + if (!npad_id) { + return InvalidNpadId; + } + if (!device_index) { + return NpadDeviceIndexOutOfRange; + } + + return ResultSuccess; +} + +constexpr Result IsVibrationHandleValid(const Core::HID::VibrationDeviceHandle& handle) { + switch (handle.npad_type) { + case Core::HID::NpadStyleIndex::ProController: + case Core::HID::NpadStyleIndex::Handheld: + case Core::HID::NpadStyleIndex::JoyconDual: + case Core::HID::NpadStyleIndex::JoyconLeft: + case Core::HID::NpadStyleIndex::JoyconRight: + case Core::HID::NpadStyleIndex::GameCube: + case Core::HID::NpadStyleIndex::N64: + case Core::HID::NpadStyleIndex::SystemExt: + case Core::HID::NpadStyleIndex::System: + // These support vibration + break; + default: + return VibrationInvalidStyleIndex; + } + + if (!IsNpadIdValid(static_cast(handle.npad_id))) { + return VibrationInvalidNpadId; + } + + if (handle.device_index >= Core::HID::DeviceIndex::MaxDeviceIndex) { + return VibrationDeviceIndexOutOfRange; + } + + return ResultSuccess; +} + +/// Converts a Core::HID::NpadIdType to an array index. +constexpr size_t NpadIdTypeToIndex(Core::HID::NpadIdType npad_id_type) { + switch (npad_id_type) { + case Core::HID::NpadIdType::Player1: + return 0; + case Core::HID::NpadIdType::Player2: + return 1; + case Core::HID::NpadIdType::Player3: + return 2; + case Core::HID::NpadIdType::Player4: + return 3; + case Core::HID::NpadIdType::Player5: + return 4; + case Core::HID::NpadIdType::Player6: + return 5; + case Core::HID::NpadIdType::Player7: + return 6; + case Core::HID::NpadIdType::Player8: + return 7; + case Core::HID::NpadIdType::Handheld: + return 8; + case Core::HID::NpadIdType::Other: + return 9; + default: + return 8; + } +} + +/// Converts an array index to a Core::HID::NpadIdType +constexpr Core::HID::NpadIdType IndexToNpadIdType(size_t index) { + switch (index) { + case 0: + return Core::HID::NpadIdType::Player1; + case 1: + return Core::HID::NpadIdType::Player2; + case 2: + return Core::HID::NpadIdType::Player3; + case 3: + return Core::HID::NpadIdType::Player4; + case 4: + return Core::HID::NpadIdType::Player5; + case 5: + return Core::HID::NpadIdType::Player6; + case 6: + return Core::HID::NpadIdType::Player7; + case 7: + return Core::HID::NpadIdType::Player8; + case 8: + return Core::HID::NpadIdType::Handheld; + case 9: + return Core::HID::NpadIdType::Other; + default: + return Core::HID::NpadIdType::Invalid; + } +} + +constexpr Core::HID::NpadStyleSet GetStylesetByIndex(std::size_t index) { + switch (index) { + case 0: + return Core::HID::NpadStyleSet::Fullkey; + case 1: + return Core::HID::NpadStyleSet::Handheld; + case 2: + return Core::HID::NpadStyleSet::JoyDual; + case 3: + return Core::HID::NpadStyleSet::JoyLeft; + case 4: + return Core::HID::NpadStyleSet::JoyRight; + case 5: + return Core::HID::NpadStyleSet::Palma; + default: + return Core::HID::NpadStyleSet::None; + } +} + +} // namespace Service::HID diff --git a/src/core/hle/service/hid/irs.cpp b/src/core/hle/service/hid/irs.cpp index d383a266d..39b9a4474 100644 --- a/src/core/hle/service/hid/irs.cpp +++ b/src/core/hle/service/hid/irs.cpp @@ -12,6 +12,7 @@ #include "core/hle/kernel/k_transfer_memory.h" #include "core/hle/kernel/kernel.h" #include "core/hle/service/hid/errors.h" +#include "core/hle/service/hid/hid_util.h" #include "core/hle/service/hid/irs.h" #include "core/hle/service/hid/irsensor/clustering_processor.h" #include "core/hle/service/hid/irsensor/image_transfer_processor.h" @@ -320,7 +321,7 @@ void IRS::GetNpadIrCameraHandle(HLERequestContext& ctx) { } Core::IrSensor::IrCameraHandle camera_handle{ - .npad_id = static_cast(NpadIdTypeToIndex(npad_id)), + .npad_id = static_cast(HID::NpadIdTypeToIndex(npad_id)), .npad_type = Core::HID::NpadStyleIndex::None, }; @@ -545,7 +546,7 @@ void IRS::ActivateIrsensorWithFunctionLevel(HLERequestContext& ctx) { Result IRS::IsIrCameraHandleValid(const Core::IrSensor::IrCameraHandle& camera_handle) const { if (camera_handle.npad_id > - static_cast(NpadIdTypeToIndex(Core::HID::NpadIdType::Handheld))) { + static_cast(HID::NpadIdTypeToIndex(Core::HID::NpadIdType::Handheld))) { return InvalidIrCameraHandle; } if (camera_handle.npad_type != Core::HID::NpadStyleIndex::None) { diff --git a/src/core/hle/service/hid/resource_manager.cpp b/src/core/hle/service/hid/resource_manager.cpp index d6f42c646..e76d4eea9 100644 --- a/src/core/hle/service/hid/resource_manager.cpp +++ b/src/core/hle/service/hid/resource_manager.cpp @@ -9,14 +9,15 @@ #include "core/hle/service/hid/resource_manager.h" #include "core/hle/service/ipc_helpers.h" -#include "core/hle/service/hid/controllers/console_sixaxis.h" -#include "core/hle/service/hid/controllers/controller_base.h" +#include "core/hle/service/hid/controllers/console_six_axis.h" #include "core/hle/service/hid/controllers/debug_pad.h" #include "core/hle/service/hid/controllers/gesture.h" #include "core/hle/service/hid/controllers/keyboard.h" #include "core/hle/service/hid/controllers/mouse.h" #include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/palma.h" +#include "core/hle/service/hid/controllers/seven_six_axis.h" +#include "core/hle/service/hid/controllers/six_axis.h" #include "core/hle/service/hid/controllers/stubbed.h" #include "core/hle/service/hid/controllers/touchscreen.h" #include "core/hle/service/hid/controllers/xpad.h" @@ -42,76 +43,132 @@ void ResourceManager::Initialize() { } u8* shared_memory = system.Kernel().GetHidSharedMem().GetPointer(); - MakeController(HidController::DebugPad, shared_memory); - MakeController(HidController::Touchscreen, shared_memory); - MakeController(HidController::Mouse, shared_memory); - MakeController(HidController::Keyboard, shared_memory); - MakeController(HidController::XPad, shared_memory); - MakeController(HidController::HomeButton, shared_memory); - MakeController(HidController::SleepButton, shared_memory); - MakeController(HidController::CaptureButton, shared_memory); - MakeController(HidController::InputDetector, shared_memory); - MakeController(HidController::UniquePad, shared_memory); - MakeControllerWithServiceContext(HidController::NPad, shared_memory); - MakeController(HidController::Gesture, shared_memory); - MakeController(HidController::ConsoleSixAxisSensor, shared_memory); - MakeController(HidController::DebugMouse, shared_memory); - MakeControllerWithServiceContext(HidController::Palma, shared_memory); + debug_pad = std::make_shared(system.HIDCore(), shared_memory); + mouse = std::make_shared(system.HIDCore(), shared_memory); + debug_mouse = std::make_shared(system.HIDCore(), shared_memory); + keyboard = std::make_shared(system.HIDCore(), shared_memory); + unique_pad = std::make_shared(system.HIDCore(), shared_memory); + npad = std::make_shared(system.HIDCore(), shared_memory, service_context); + gesture = std::make_shared(system.HIDCore(), shared_memory); + touch_screen = std::make_shared(system.HIDCore(), shared_memory); + xpad = std::make_shared(system.HIDCore(), shared_memory); + + palma = std::make_shared(system.HIDCore(), shared_memory, service_context); + + home_button = std::make_shared(system.HIDCore(), shared_memory); + sleep_button = std::make_shared(system.HIDCore(), shared_memory); + capture_button = std::make_shared(system.HIDCore(), shared_memory); + + six_axis = std::make_shared(system.HIDCore(), npad); + console_six_axis = std::make_shared(system.HIDCore(), shared_memory); + seven_six_axis = std::make_shared(system); + + home_button->SetCommonHeaderOffset(0x4C00); + sleep_button->SetCommonHeaderOffset(0x4E00); + capture_button->SetCommonHeaderOffset(0x5000); + unique_pad->SetCommonHeaderOffset(0x5A00); + debug_mouse->SetCommonHeaderOffset(0x3DC00); // Homebrew doesn't try to activate some controllers, so we activate them by default - GetController(HidController::NPad).Activate(); - GetController(HidController::Touchscreen).Activate(); - - GetController(HidController::HomeButton).SetCommonHeaderOffset(0x4C00); - GetController(HidController::SleepButton).SetCommonHeaderOffset(0x4E00); - GetController(HidController::CaptureButton).SetCommonHeaderOffset(0x5000); - GetController(HidController::InputDetector).SetCommonHeaderOffset(0x5200); - GetController(HidController::UniquePad).SetCommonHeaderOffset(0x5A00); - GetController(HidController::DebugMouse).SetCommonHeaderOffset(0x3DC00); + npad->Activate(); + six_axis->Activate(); + touch_screen->Activate(); system.HIDCore().ReloadInputDevices(); is_initialized = true; } +std::shared_ptr ResourceManager::GetCaptureButton() const { + return capture_button; +} + +std::shared_ptr ResourceManager::GetConsoleSixAxis() const { + return console_six_axis; +} + +std::shared_ptr ResourceManager::GetDebugMouse() const { + return debug_mouse; +} + +std::shared_ptr ResourceManager::GetDebugPad() const { + return debug_pad; +} + +std::shared_ptr ResourceManager::GetGesture() const { + return gesture; +} + +std::shared_ptr ResourceManager::GetHomeButton() const { + return home_button; +} + +std::shared_ptr ResourceManager::GetKeyboard() const { + return keyboard; +} + +std::shared_ptr ResourceManager::GetMouse() const { + return mouse; +} + +std::shared_ptr ResourceManager::GetNpad() const { + return npad; +} + +std::shared_ptr ResourceManager::GetPalma() const { + return palma; +} + +std::shared_ptr ResourceManager::GetSevenSixAxis() const { + return seven_six_axis; +} + +std::shared_ptr ResourceManager::GetSixAxis() const { + return six_axis; +} + +std::shared_ptr ResourceManager::GetSleepButton() const { + return sleep_button; +} + +std::shared_ptr ResourceManager::GetTouchScreen() const { + return touch_screen; +} + +std::shared_ptr ResourceManager::GetUniquePad() const { + return unique_pad; +} void ResourceManager::UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { auto& core_timing = system.CoreTiming(); - - for (const auto& controller : controllers) { - // Keyboard has it's own update event - if (controller == controllers[static_cast(HidController::Keyboard)]) { - continue; - } - // Mouse has it's own update event - if (controller == controllers[static_cast(HidController::Mouse)]) { - continue; - } - // Npad has it's own update event - if (controller == controllers[static_cast(HidController::NPad)]) { - continue; - } - controller->OnUpdate(core_timing); - } + debug_pad->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); + capture_button->OnUpdate(core_timing); + xpad->OnUpdate(core_timing); } void ResourceManager::UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { auto& core_timing = system.CoreTiming(); - - controllers[static_cast(HidController::NPad)]->OnUpdate(core_timing); + npad->OnUpdate(core_timing); } void ResourceManager::UpdateMouseKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { auto& core_timing = system.CoreTiming(); - - controllers[static_cast(HidController::Mouse)]->OnUpdate(core_timing); - controllers[static_cast(HidController::Keyboard)]->OnUpdate(core_timing); + mouse->OnUpdate(core_timing); + debug_mouse->OnUpdate(core_timing); + keyboard->OnUpdate(core_timing); } void ResourceManager::UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late) { auto& core_timing = system.CoreTiming(); - - controllers[static_cast(HidController::NPad)]->OnMotionUpdate(core_timing); + six_axis->OnUpdate(core_timing); + seven_six_axis->OnUpdate(core_timing); + console_six_axis->OnUpdate(core_timing); } IAppletResource::IAppletResource(Core::System& system_, std::shared_ptr resource) diff --git a/src/core/hle/service/hid/resource_manager.h b/src/core/hle/service/hid/resource_manager.h index 34dbf36bc..2b6a9b5e6 100644 --- a/src/core/hle/service/hid/resource_manager.h +++ b/src/core/hle/service/hid/resource_manager.h @@ -3,10 +3,6 @@ #pragma once -#include - -#include "core/core.h" -#include "core/hle/service/hid/controllers/controller_base.h" #include "core/hle/service/kernel_helpers.h" #include "core/hle/service/service.h" @@ -14,74 +10,85 @@ namespace Core::Timing { struct EventType; } -namespace Core::HID { -class HIDCore; -} - namespace Service::HID { +class Controller_Stubbed; +class ConsoleSixAxis; +class DebugPad; +class Gesture; +class Keyboard; +class Mouse; +class NPad; +class Palma; +class SevenSixAxis; +class SixAxis; +class TouchScreen; +class XPad; + +using CaptureButton = Controller_Stubbed; +using DebugMouse = Controller_Stubbed; +using HomeButton = Controller_Stubbed; +using SleepButton = Controller_Stubbed; +using UniquePad = Controller_Stubbed; -enum class HidController : std::size_t { - DebugPad, - Touchscreen, - Mouse, - Keyboard, - XPad, - HomeButton, - SleepButton, - CaptureButton, - InputDetector, - UniquePad, - NPad, - Gesture, - ConsoleSixAxisSensor, - DebugMouse, - Palma, - - MaxControllers, -}; class ResourceManager { + public: explicit ResourceManager(Core::System& system_); ~ResourceManager(); - template - T& GetController(HidController controller) { - return static_cast(*controllers[static_cast(controller)]); - } - - template - const T& GetController(HidController controller) const { - return static_cast(*controllers[static_cast(controller)]); - } - void Initialize(); + std::shared_ptr GetCaptureButton() const; + std::shared_ptr GetConsoleSixAxis() const; + std::shared_ptr GetDebugMouse() const; + std::shared_ptr GetDebugPad() const; + std::shared_ptr GetGesture() const; + std::shared_ptr GetHomeButton() const; + std::shared_ptr GetKeyboard() const; + std::shared_ptr GetMouse() const; + std::shared_ptr GetNpad() const; + std::shared_ptr GetPalma() const; + std::shared_ptr GetSevenSixAxis() const; + std::shared_ptr GetSixAxis() const; + std::shared_ptr GetSleepButton() const; + std::shared_ptr GetTouchScreen() const; + std::shared_ptr GetUniquePad() const; + void UpdateControllers(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); void UpdateNpad(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); void UpdateMouseKeyboard(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); void UpdateMotion(std::uintptr_t user_data, std::chrono::nanoseconds ns_late); private: - template - void MakeController(HidController controller, u8* shared_memory) { - if constexpr (std::is_constructible_v) { - controllers[static_cast(controller)] = - std::make_unique(system, shared_memory); - } else { - controllers[static_cast(controller)] = - std::make_unique(system.HIDCore(), shared_memory); - } - } - - template - void MakeControllerWithServiceContext(HidController controller, u8* shared_memory) { - controllers[static_cast(controller)] = - std::make_unique(system.HIDCore(), shared_memory, service_context); - } - bool is_initialized{false}; - std::array, static_cast(HidController::MaxControllers)> - controllers{}; + + std::shared_ptr capture_button = nullptr; + std::shared_ptr console_six_axis = nullptr; + std::shared_ptr debug_mouse = nullptr; + std::shared_ptr debug_pad = nullptr; + std::shared_ptr gesture = nullptr; + std::shared_ptr home_button = nullptr; + std::shared_ptr keyboard = nullptr; + std::shared_ptr mouse = nullptr; + std::shared_ptr npad = nullptr; + std::shared_ptr palma = nullptr; + std::shared_ptr seven_six_axis = nullptr; + std::shared_ptr six_axis = nullptr; + std::shared_ptr sleep_button = nullptr; + std::shared_ptr touch_screen = nullptr; + std::shared_ptr unique_pad = nullptr; + std::shared_ptr xpad = nullptr; + + // TODO: Create these resources + // std::shared_ptr audio_control = nullptr; + // std::shared_ptr button_config = nullptr; + // std::shared_ptr config = nullptr; + // std::shared_ptr connection = nullptr; + // std::shared_ptr custom_config = nullptr; + // std::shared_ptr digitizer = nullptr; + // std::shared_ptr hdls = nullptr; + // std::shared_ptr play_report = nullptr; + // std::shared_ptr rail = nullptr; Core::System& system; KernelHelpers::ServiceContext service_context; diff --git a/src/core/hle/service/nfc/common/device_manager.cpp b/src/core/hle/service/nfc/common/device_manager.cpp index a71d26157..ad534177d 100644 --- a/src/core/hle/service/nfc/common/device_manager.cpp +++ b/src/core/hle/service/nfc/common/device_manager.cpp @@ -7,6 +7,7 @@ #include "core/core.h" #include "core/hid/hid_types.h" #include "core/hle/kernel/k_event.h" +#include "core/hle/service/hid/hid_util.h" #include "core/hle/service/ipc_helpers.h" #include "core/hle/service/nfc/common/device.h" #include "core/hle/service/nfc/common/device_manager.h" @@ -24,7 +25,7 @@ DeviceManager::DeviceManager(Core::System& system_, KernelHelpers::ServiceContex for (u32 device_index = 0; device_index < devices.size(); device_index++) { devices[device_index] = - std::make_shared(Core::HID::IndexToNpadIdType(device_index), system, + std::make_shared(HID::IndexToNpadIdType(device_index), system, service_context, availability_change_event); } diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp index da140c01c..db30ba598 100644 --- a/src/core/memory/cheat_engine.cpp +++ b/src/core/memory/cheat_engine.cpp @@ -68,10 +68,7 @@ u64 StandardVmCallbacks::HidKeysDown() { return 0; } - const auto press_state = - applet_resource - ->GetController(Service::HID::HidController::NPad) - .GetAndResetPressState(); + const auto press_state = applet_resource->GetNpad()->GetAndResetPressState(); return static_cast(press_state & HID::NpadButton::All); } -- cgit v1.2.3