summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar wwylele2017-05-07 21:53:27 +0300
committerGravatar wwylele2017-05-07 21:53:27 +0300
commitf9fdaafa0496e3aae894719d2e3aad62f8bd698c (patch)
tree1c0867503180de21b18df0ab41b55498259ab89d /src/core
parentir: implement new 3ds HID via ir:rst (diff)
downloadyuzu-f9fdaafa0496e3aae894719d2e3aad62f8bd698c.tar.gz
yuzu-f9fdaafa0496e3aae894719d2e3aad62f8bd698c.tar.xz
yuzu-f9fdaafa0496e3aae894719d2e3aad62f8bd698c.zip
fixup!ir: implement new 3ds HID via ir:rst
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/service/ir/ir_rst.cpp63
1 files changed, 32 insertions, 31 deletions
diff --git a/src/core/hle/service/ir/ir_rst.cpp b/src/core/hle/service/ir/ir_rst.cpp
index b22f6548c..53807cd91 100644
--- a/src/core/hle/service/ir/ir_rst.cpp
+++ b/src/core/hle/service/ir/ir_rst.cpp
@@ -17,15 +17,15 @@ namespace Service {
17namespace IR { 17namespace IR {
18 18
19union PadState { 19union PadState {
20 u32 hex; 20 u32_le hex;
21 21
22 BitField<14, 1, u32> zl; 22 BitField<14, 1, u32_le> zl;
23 BitField<15, 1, u32> zr; 23 BitField<15, 1, u32_le> zr;
24 24
25 BitField<24, 1, u32> c_stick_right; 25 BitField<24, 1, u32_le> c_stick_right;
26 BitField<25, 1, u32> c_stick_left; 26 BitField<25, 1, u32_le> c_stick_left;
27 BitField<26, 1, u32> c_stick_up; 27 BitField<26, 1, u32_le> c_stick_up;
28 BitField<27, 1, u32> c_stick_down; 28 BitField<27, 1, u32_le> c_stick_down;
29}; 29};
30 30
31struct PadDataEntry { 31struct PadDataEntry {
@@ -33,14 +33,14 @@ struct PadDataEntry {
33 PadState delta_additions; 33 PadState delta_additions;
34 PadState delta_removals; 34 PadState delta_removals;
35 35
36 s16 c_stick_x; 36 s16_le c_stick_x;
37 s16 c_stick_y; 37 s16_le c_stick_y;
38}; 38};
39 39
40struct SharedMem { 40struct SharedMem {
41 u64 index_reset_ticks; ///< CPU tick count for when HID module updated entry index 0 41 u64_le index_reset_ticks; ///< CPU tick count for when HID module updated entry index 0
42 u64 index_reset_ticks_previous; ///< Previous `index_reset_ticks` 42 u64_le index_reset_ticks_previous; ///< Previous `index_reset_ticks`
43 u32 index; 43 u32_le index;
44 INSERT_PADDING_WORDS(1); 44 INSERT_PADDING_WORDS(1);
45 std::array<PadDataEntry, 8> entries; ///< Last 8 pad entries 45 std::array<PadDataEntry, 8> entries; ///< Last 8 pad entries
46}; 46};
@@ -50,26 +50,26 @@ static_assert(sizeof(SharedMem) == 0x98, "SharedMem has wrong size!");
50static Kernel::SharedPtr<Kernel::Event> update_event; 50static Kernel::SharedPtr<Kernel::Event> update_event;
51static Kernel::SharedPtr<Kernel::SharedMemory> shared_memory; 51static Kernel::SharedPtr<Kernel::SharedMemory> shared_memory;
52static u32 next_pad_index; 52static u32 next_pad_index;
53static int update_callback; 53static int update_callback_id;
54static std::unique_ptr<Input::ButtonDevice> zl; 54static std::unique_ptr<Input::ButtonDevice> zl_button;
55static std::unique_ptr<Input::ButtonDevice> zr; 55static std::unique_ptr<Input::ButtonDevice> zr_button;
56static std::unique_ptr<Input::AnalogDevice> c_stick; 56static std::unique_ptr<Input::AnalogDevice> c_stick;
57static std::atomic<bool> is_device_reload_pending; 57static std::atomic<bool> is_device_reload_pending;
58static bool raw_c_stick; 58static bool raw_c_stick;
59static int update_period; 59static int update_period;
60 60
61static void LoadInputDevices() { 61static void LoadInputDevices() {
62 zl = Input::CreateDevice<Input::ButtonDevice>( 62 zl_button = Input::CreateDevice<Input::ButtonDevice>(
63 Settings::values.buttons[Settings::NativeButton::ZL]); 63 Settings::values.buttons[Settings::NativeButton::ZL]);
64 zr = Input::CreateDevice<Input::ButtonDevice>( 64 zr_button = Input::CreateDevice<Input::ButtonDevice>(
65 Settings::values.buttons[Settings::NativeButton::ZR]); 65 Settings::values.buttons[Settings::NativeButton::ZR]);
66 c_stick = Input::CreateDevice<Input::AnalogDevice>( 66 c_stick = Input::CreateDevice<Input::AnalogDevice>(
67 Settings::values.analogs[Settings::NativeAnalog::CStick]); 67 Settings::values.analogs[Settings::NativeAnalog::CStick]);
68} 68}
69 69
70static void UnloadInputDevices() { 70static void UnloadInputDevices() {
71 zl = nullptr; 71 zl_button = nullptr;
72 zr = nullptr; 72 zr_button = nullptr;
73 c_stick = nullptr; 73 c_stick = nullptr;
74} 74}
75 75
@@ -80,15 +80,15 @@ static void UpdateCallback(u64 userdata, int cycles_late) {
80 LoadInputDevices(); 80 LoadInputDevices();
81 81
82 PadState state; 82 PadState state;
83 state.zl.Assign(zl->GetStatus()); 83 state.zl.Assign(zl_button->GetStatus());
84 state.zr.Assign(zr->GetStatus()); 84 state.zr.Assign(zr_button->GetStatus());
85 85
86 // Get current c-stick position and update c-stick direction 86 // Get current c-stick position and update c-stick direction
87 float c_stick_x_f, c_stick_y_f; 87 float c_stick_x_f, c_stick_y_f;
88 std::tie(c_stick_x_f, c_stick_y_f) = c_stick->GetStatus(); 88 std::tie(c_stick_x_f, c_stick_y_f) = c_stick->GetStatus();
89 constexpr int MAX_CSTICK_POS = 0x9C; // Max value for a c-stick position 89 constexpr int MAX_CSTICK_RADIUS = 0x9C; // Max value for a c-stick radius
90 const s16 c_stick_x = static_cast<s16>(c_stick_x_f * MAX_CSTICK_POS); 90 const s16 c_stick_x = static_cast<s16>(c_stick_x_f * MAX_CSTICK_RADIUS);
91 const s16 c_stick_y = static_cast<s16>(c_stick_y_f * MAX_CSTICK_POS); 91 const s16 c_stick_y = static_cast<s16>(c_stick_y_f * MAX_CSTICK_RADIUS);
92 92
93 if (!raw_c_stick) { 93 if (!raw_c_stick) {
94 const HID::DirectionState direction = HID::GetStickDirectionState(c_stick_x, c_stick_y); 94 const HID::DirectionState direction = HID::GetStickDirectionState(c_stick_x, c_stick_y);
@@ -129,7 +129,7 @@ static void UpdateCallback(u64 userdata, int cycles_late) {
129 update_event->Signal(); 129 update_event->Signal();
130 130
131 // Reschedule recurrent event 131 // Reschedule recurrent event
132 CoreTiming::ScheduleEvent(msToCycles(update_period) - cycles_late, update_callback); 132 CoreTiming::ScheduleEvent(msToCycles(update_period) - cycles_late, update_callback_id);
133} 133}
134 134
135/** 135/**
@@ -164,23 +164,23 @@ static void Initialize(Interface* self) {
164 164
165 next_pad_index = 0; 165 next_pad_index = 0;
166 is_device_reload_pending.store(true); 166 is_device_reload_pending.store(true);
167 CoreTiming::ScheduleEvent(msToCycles(update_period), update_callback); 167 CoreTiming::ScheduleEvent(msToCycles(update_period), update_callback_id);
168 168
169 IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); 169 IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
170 rb.Push(RESULT_SUCCESS); 170 rb.Push(RESULT_SUCCESS);
171 171
172 LOG_INFO(Service_IR, "called. update_period=%d, raw_c_stick=%d", update_period, raw_c_stick); 172 LOG_DEBUG(Service_IR, "called. update_period=%d, raw_c_stick=%d", update_period, raw_c_stick);
173} 173}
174 174
175static void Shutdown(Interface* self) { 175static void Shutdown(Interface* self) {
176 IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x03, 1, 0); 176 IPC::RequestParser rp(Kernel::GetCommandBuffer(), 0x03, 1, 0);
177 177
178 CoreTiming::UnscheduleEvent(update_callback, 0); 178 CoreTiming::UnscheduleEvent(update_callback_id, 0);
179 UnloadInputDevices(); 179 UnloadInputDevices();
180 180
181 IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); 181 IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
182 rb.Push(RESULT_SUCCESS); 182 rb.Push(RESULT_SUCCESS);
183 LOG_INFO(Service_IR, "called"); 183 LOG_DEBUG(Service_IR, "called");
184} 184}
185 185
186const Interface::FunctionInfo FunctionTable[] = { 186const Interface::FunctionInfo FunctionTable[] = {
@@ -195,14 +195,15 @@ IR_RST_Interface::IR_RST_Interface() {
195} 195}
196 196
197void InitRST() { 197void InitRST() {
198 // Note: these two kernel objects are available before Initialize service function is called.
199 using namespace Kernel; 198 using namespace Kernel;
199 // Note: these two kernel objects are even available before Initialize service function is
200 // called.
200 shared_memory = 201 shared_memory =
201 SharedMemory::Create(nullptr, 0x1000, MemoryPermission::ReadWrite, MemoryPermission::Read, 202 SharedMemory::Create(nullptr, 0x1000, MemoryPermission::ReadWrite, MemoryPermission::Read,
202 0, MemoryRegion::BASE, "IRRST:SharedMemory"); 203 0, MemoryRegion::BASE, "IRRST:SharedMemory");
203 update_event = Event::Create(ResetType::OneShot, "IRRST:UpdateEvent"); 204 update_event = Event::Create(ResetType::OneShot, "IRRST:UpdateEvent");
204 205
205 update_callback = CoreTiming::RegisterEvent("IRRST:UpdateCallBack", UpdateCallback); 206 update_callback_id = CoreTiming::RegisterEvent("IRRST:UpdateCallBack", UpdateCallback);
206} 207}
207 208
208void ShutdownRST() { 209void ShutdownRST() {