summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/core/frontend/input.h6
-rw-r--r--src/core/hle/service/hid/hid.cpp45
-rw-r--r--src/core/hle/service/hid/hid.h3
-rw-r--r--src/core/settings.cpp3
-rw-r--r--src/core/settings.h44
5 files changed, 100 insertions, 1 deletions
diff --git a/src/core/frontend/input.h b/src/core/frontend/input.h
index a0c51df0c..63e64ac67 100644
--- a/src/core/frontend/input.h
+++ b/src/core/frontend/input.h
@@ -94,4 +94,10 @@ std::unique_ptr<InputDeviceType> CreateDevice(const std::string& params) {
94 return pair->second->Create(package); 94 return pair->second->Create(package);
95} 95}
96 96
97/**
98 * A button device is an input device that returns bool as status.
99 * true for pressed; false for released.
100 */
101using ButtonDevice = InputDevice<bool>;
102
97} // namespace Input 103} // namespace Input
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index fb3acb507..0da731418 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -2,10 +2,14 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm>
6#include <atomic>
5#include <cmath> 7#include <cmath>
8#include <memory>
6#include "common/logging/log.h" 9#include "common/logging/log.h"
7#include "core/core_timing.h" 10#include "core/core_timing.h"
8#include "core/frontend/emu_window.h" 11#include "core/frontend/emu_window.h"
12#include "core/frontend/input.h"
9#include "core/hle/kernel/event.h" 13#include "core/hle/kernel/event.h"
10#include "core/hle/kernel/shared_memory.h" 14#include "core/hle/kernel/shared_memory.h"
11#include "core/hle/service/hid/hid.h" 15#include "core/hle/service/hid/hid.h"
@@ -44,6 +48,10 @@ constexpr u64 pad_update_ticks = BASE_CLOCK_RATE_ARM11 / 234;
44constexpr u64 accelerometer_update_ticks = BASE_CLOCK_RATE_ARM11 / 104; 48constexpr u64 accelerometer_update_ticks = BASE_CLOCK_RATE_ARM11 / 104;
45constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE_ARM11 / 101; 49constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE_ARM11 / 101;
46 50
51static std::atomic<bool> is_device_reload_pending;
52static std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID>
53 buttons;
54
47static PadState GetCirclePadDirectionState(s16 circle_pad_x, s16 circle_pad_y) { 55static PadState GetCirclePadDirectionState(s16 circle_pad_x, s16 circle_pad_y) {
48 // 30 degree and 60 degree are angular thresholds for directions 56 // 30 degree and 60 degree are angular thresholds for directions
49 constexpr float TAN30 = 0.577350269f; 57 constexpr float TAN30 = 0.577350269f;
@@ -74,10 +82,38 @@ static PadState GetCirclePadDirectionState(s16 circle_pad_x, s16 circle_pad_y) {
74 return state; 82 return state;
75} 83}
76 84
85static void LoadInputDevices() {
86 std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN,
87 Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END,
88 buttons.begin(), Input::CreateDevice<Input::ButtonDevice>);
89}
90
91static void UnloadInputDevices() {
92 for (auto& button : buttons) {
93 button.reset();
94 }
95}
96
77static void UpdatePadCallback(u64 userdata, int cycles_late) { 97static void UpdatePadCallback(u64 userdata, int cycles_late) {
78 SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer()); 98 SharedMem* mem = reinterpret_cast<SharedMem*>(shared_mem->GetPointer());
79 99
80 PadState state = VideoCore::g_emu_window->GetPadState(); 100 if (is_device_reload_pending.exchange(false))
101 LoadInputDevices();
102
103 PadState state;
104 using namespace Settings::NativeButton;
105 state.a.Assign(buttons[A - BUTTON_HID_BEGIN]->GetStatus());
106 state.b.Assign(buttons[B - BUTTON_HID_BEGIN]->GetStatus());
107 state.x.Assign(buttons[X - BUTTON_HID_BEGIN]->GetStatus());
108 state.y.Assign(buttons[Y - BUTTON_HID_BEGIN]->GetStatus());
109 state.right.Assign(buttons[Right - BUTTON_HID_BEGIN]->GetStatus());
110 state.left.Assign(buttons[Left - BUTTON_HID_BEGIN]->GetStatus());
111 state.up.Assign(buttons[Up - BUTTON_HID_BEGIN]->GetStatus());
112 state.down.Assign(buttons[Down - BUTTON_HID_BEGIN]->GetStatus());
113 state.l.Assign(buttons[L - BUTTON_HID_BEGIN]->GetStatus());
114 state.r.Assign(buttons[R - BUTTON_HID_BEGIN]->GetStatus());
115 state.start.Assign(buttons[Start - BUTTON_HID_BEGIN]->GetStatus());
116 state.select.Assign(buttons[Select - BUTTON_HID_BEGIN]->GetStatus());
81 117
82 // Get current circle pad position and update circle pad direction 118 // Get current circle pad position and update circle pad direction
83 s16 circle_pad_x, circle_pad_y; 119 s16 circle_pad_x, circle_pad_y;
@@ -313,6 +349,8 @@ void Init() {
313 AddService(new HID_U_Interface); 349 AddService(new HID_U_Interface);
314 AddService(new HID_SPVR_Interface); 350 AddService(new HID_SPVR_Interface);
315 351
352 is_device_reload_pending.store(true);
353
316 using Kernel::MemoryPermission; 354 using Kernel::MemoryPermission;
317 shared_mem = 355 shared_mem =
318 SharedMemory::Create(nullptr, 0x1000, MemoryPermission::ReadWrite, MemoryPermission::Read, 356 SharedMemory::Create(nullptr, 0x1000, MemoryPermission::ReadWrite, MemoryPermission::Read,
@@ -350,6 +388,11 @@ void Shutdown() {
350 event_accelerometer = nullptr; 388 event_accelerometer = nullptr;
351 event_gyroscope = nullptr; 389 event_gyroscope = nullptr;
352 event_debug_pad = nullptr; 390 event_debug_pad = nullptr;
391 UnloadInputDevices();
392}
393
394void ReloadInputDevices() {
395 is_device_reload_pending.store(true);
353} 396}
354 397
355} // namespace HID 398} // namespace HID
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index c7f4ee138..b828abe4b 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -297,5 +297,8 @@ void Init();
297 297
298/// Shutdown HID service 298/// Shutdown HID service
299void Shutdown(); 299void Shutdown();
300
301/// Reload input devices. Used when input configuration changed
302void ReloadInputDevices();
300} 303}
301} 304}
diff --git a/src/core/settings.cpp b/src/core/settings.cpp
index 3a32b70aa..a598f9f2f 100644
--- a/src/core/settings.cpp
+++ b/src/core/settings.cpp
@@ -4,6 +4,7 @@
4 4
5#include "audio_core/audio_core.h" 5#include "audio_core/audio_core.h"
6#include "core/gdbstub/gdbstub.h" 6#include "core/gdbstub/gdbstub.h"
7#include "core/hle/service/hid/hid.h"
7#include "settings.h" 8#include "settings.h"
8#include "video_core/video_core.h" 9#include "video_core/video_core.h"
9 10
@@ -29,6 +30,8 @@ void Apply() {
29 30
30 AudioCore::SelectSink(values.sink_id); 31 AudioCore::SelectSink(values.sink_id);
31 AudioCore::EnableStretching(values.enable_audio_stretching); 32 AudioCore::EnableStretching(values.enable_audio_stretching);
33
34 Service::HID::ReloadInputDevices();
32} 35}
33 36
34} // namespace 37} // namespace
diff --git a/src/core/settings.h b/src/core/settings.h
index b6c75531f..dba57bd6c 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -69,6 +69,48 @@ static const std::array<Values, NUM_INPUTS> All = {{
69}}; 69}};
70} 70}
71 71
72namespace NativeButton {
73enum Values {
74 A,
75 B,
76 X,
77 Y,
78 Up,
79 Down,
80 Left,
81 Right,
82 L,
83 R,
84 Start,
85 Select,
86
87 ZL,
88 ZR,
89
90 Home,
91
92 NumButtons,
93};
94
95constexpr int BUTTON_HID_BEGIN = A;
96constexpr int BUTTON_IR_BEGIN = ZL;
97constexpr int BUTTON_NS_BEGIN = Home;
98
99constexpr int BUTTON_HID_END = BUTTON_IR_BEGIN;
100constexpr int BUTTON_IR_END = BUTTON_NS_BEGIN;
101constexpr int BUTTON_NS_END = NumButtons;
102
103constexpr int NUM_BUTTONS_HID = BUTTON_HID_END - BUTTON_HID_BEGIN;
104constexpr int NUM_BUTTONS_IR = BUTTON_IR_END - BUTTON_IR_BEGIN;
105constexpr int NUM_BUTTONS_NS = BUTTON_NS_END - BUTTON_NS_BEGIN;
106
107static const std::array<const char*, NumButtons> mapping = {{
108 "button_a", "button_b", "button_x", "button_y", "button_up", "button_down", "button_left",
109 "button_right", "button_l", "button_r", "button_start", "button_select", "button_zl",
110 "button_zr", "button_home",
111}};
112} // namespace NativeButton
113
72struct Values { 114struct Values {
73 // CheckNew3DS 115 // CheckNew3DS
74 bool is_new_3ds; 116 bool is_new_3ds;
@@ -77,6 +119,8 @@ struct Values {
77 std::array<int, NativeInput::NUM_INPUTS> input_mappings; 119 std::array<int, NativeInput::NUM_INPUTS> input_mappings;
78 float pad_circle_modifier_scale; 120 float pad_circle_modifier_scale;
79 121
122 std::array<std::string, NativeButton::NumButtons> buttons;
123
80 // Core 124 // Core
81 bool use_cpu_jit; 125 bool use_cpu_jit;
82 126