diff options
| author | 2015-01-21 18:36:46 -0500 | |
|---|---|---|
| committer | 2015-01-21 18:36:46 -0500 | |
| commit | 0c7498545f7f9beeb7e8070e1a1955a8d6f40bb6 (patch) | |
| tree | 9eaedc4e6d764f3436a45ba05e79f16fec1ff299 /src/core | |
| parent | Merge pull request #429 from Kingcom/titlebar (diff) | |
| parent | Added HID_SPVR service and split HID_U implementation into service/hid/hid.xxx (diff) | |
| download | yuzu-0c7498545f7f9beeb7e8070e1a1955a8d6f40bb6.tar.gz yuzu-0c7498545f7f9beeb7e8070e1a1955a8d6f40bb6.tar.xz yuzu-0c7498545f7f9beeb7e8070e1a1955a8d6f40bb6.zip | |
Merge pull request #491 from archshift/hidspvr
Added HID_SPVR service and split HID_U implementation into hle/service/hid/hid.xxx
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/CMakeLists.txt | 8 | ||||
| -rw-r--r-- | src/core/hle/hle.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 138 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.h (renamed from src/core/hle/service/hid_user.h) | 37 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid_spvr.cpp | 38 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid_spvr.h | 23 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid_user.cpp | 75 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid_user.h | 29 | ||||
| -rw-r--r-- | src/core/hle/service/hid_user.cpp | 197 | ||||
| -rw-r--r-- | src/core/hle/service/service.cpp | 4 |
10 files changed, 333 insertions, 219 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 0fc8bf318..ee4238d2e 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -53,7 +53,9 @@ set(SRCS | |||
| 53 | hle/service/fs/archive.cpp | 53 | hle/service/fs/archive.cpp |
| 54 | hle/service/fs/fs_user.cpp | 54 | hle/service/fs/fs_user.cpp |
| 55 | hle/service/gsp_gpu.cpp | 55 | hle/service/gsp_gpu.cpp |
| 56 | hle/service/hid_user.cpp | 56 | hle/service/hid/hid.cpp |
| 57 | hle/service/hid/hid_user.cpp | ||
| 58 | hle/service/hid/hid_spvr.cpp | ||
| 57 | hle/service/http_c.cpp | 59 | hle/service/http_c.cpp |
| 58 | hle/service/ir_rst.cpp | 60 | hle/service/ir_rst.cpp |
| 59 | hle/service/ir_u.cpp | 61 | hle/service/ir_u.cpp |
| @@ -150,7 +152,9 @@ set(HEADERS | |||
| 150 | hle/service/fs/archive.h | 152 | hle/service/fs/archive.h |
| 151 | hle/service/fs/fs_user.h | 153 | hle/service/fs/fs_user.h |
| 152 | hle/service/gsp_gpu.h | 154 | hle/service/gsp_gpu.h |
| 153 | hle/service/hid_user.h | 155 | hle/service/hid/hid.h |
| 156 | hle/service/hid/hid_spvr.h | ||
| 157 | hle/service/hid/hid_user.h | ||
| 154 | hle/service/http_c.h | 158 | hle/service/http_c.h |
| 155 | hle/service/ir_rst.h | 159 | hle/service/ir_rst.h |
| 156 | hle/service/ir_u.h | 160 | hle/service/ir_u.h |
diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index 11570c8b4..5a2edeb4a 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp | |||
| @@ -12,6 +12,7 @@ | |||
| 12 | #include "core/hle/service/service.h" | 12 | #include "core/hle/service/service.h" |
| 13 | #include "core/hle/service/fs/archive.h" | 13 | #include "core/hle/service/fs/archive.h" |
| 14 | #include "core/hle/service/cfg/cfg.h" | 14 | #include "core/hle/service/cfg/cfg.h" |
| 15 | #include "core/hle/service/hid/hid.h" | ||
| 15 | 16 | ||
| 16 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 17 | 18 | ||
| @@ -70,6 +71,7 @@ void Init() { | |||
| 70 | Service::Init(); | 71 | Service::Init(); |
| 71 | Service::FS::ArchiveInit(); | 72 | Service::FS::ArchiveInit(); |
| 72 | Service::CFG::CFGInit(); | 73 | Service::CFG::CFGInit(); |
| 74 | Service::HID::HIDInit(); | ||
| 73 | 75 | ||
| 74 | RegisterAllModules(); | 76 | RegisterAllModules(); |
| 75 | 77 | ||
| @@ -79,6 +81,7 @@ void Init() { | |||
| 79 | } | 81 | } |
| 80 | 82 | ||
| 81 | void Shutdown() { | 83 | void Shutdown() { |
| 84 | Service::HID::HIDShutdown(); | ||
| 82 | Service::CFG::CFGShutdown(); | 85 | Service::CFG::CFGShutdown(); |
| 83 | Service::FS::ArchiveShutdown(); | 86 | Service::FS::ArchiveShutdown(); |
| 84 | Service::Shutdown(); | 87 | Service::Shutdown(); |
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp new file mode 100644 index 000000000..5abcb2596 --- /dev/null +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -0,0 +1,138 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "core/hle/service/hid/hid.h" | ||
| 6 | |||
| 7 | #include "core/arm/arm_interface.h" | ||
| 8 | #include "core/hle/kernel/event.h" | ||
| 9 | #include "core/hle/kernel/shared_memory.h" | ||
| 10 | #include "core/hle/hle.h" | ||
| 11 | |||
| 12 | namespace Service { | ||
| 13 | namespace HID { | ||
| 14 | |||
| 15 | Handle g_shared_mem = 0; | ||
| 16 | |||
| 17 | Handle g_event_pad_or_touch_1 = 0; | ||
| 18 | Handle g_event_pad_or_touch_2 = 0; | ||
| 19 | Handle g_event_accelerometer = 0; | ||
| 20 | Handle g_event_gyroscope = 0; | ||
| 21 | Handle g_event_debug_pad = 0; | ||
| 22 | |||
| 23 | // Next Pad state update information | ||
| 24 | static PadState next_state = {{0}}; | ||
| 25 | static u32 next_index = 0; | ||
| 26 | static s16 next_circle_x = 0; | ||
| 27 | static s16 next_circle_y = 0; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * Gets a pointer to the PadData structure inside HID shared memory | ||
| 31 | */ | ||
| 32 | static inline PadData* GetPadData() { | ||
| 33 | return reinterpret_cast<PadData*>(Kernel::GetSharedMemoryPointer(g_shared_mem, 0).ValueOr(nullptr)); | ||
| 34 | } | ||
| 35 | |||
| 36 | /** | ||
| 37 | * Circle Pad from keys. | ||
| 38 | * | ||
| 39 | * This is implemented as "pushed all the way to an edge (max) or centered (0)". | ||
| 40 | * | ||
| 41 | * Indicate the circle pad is pushed completely to the edge in 1 of 8 directions. | ||
| 42 | */ | ||
| 43 | static void UpdateNextCirclePadState() { | ||
| 44 | static const s16 max_value = 0x9C; | ||
| 45 | next_circle_x = next_state.circle_left ? -max_value : 0x0; | ||
| 46 | next_circle_x += next_state.circle_right ? max_value : 0x0; | ||
| 47 | next_circle_y = next_state.circle_down ? -max_value : 0x0; | ||
| 48 | next_circle_y += next_state.circle_up ? max_value : 0x0; | ||
| 49 | } | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Sets a Pad state (button or button combo) as pressed | ||
| 53 | */ | ||
| 54 | void PadButtonPress(const PadState& pad_state) { | ||
| 55 | next_state.hex |= pad_state.hex; | ||
| 56 | UpdateNextCirclePadState(); | ||
| 57 | } | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Sets a Pad state (button or button combo) as released | ||
| 61 | */ | ||
| 62 | void PadButtonRelease(const PadState& pad_state) { | ||
| 63 | next_state.hex &= ~pad_state.hex; | ||
| 64 | UpdateNextCirclePadState(); | ||
| 65 | } | ||
| 66 | |||
| 67 | /** | ||
| 68 | * Called after all Pad changes to be included in this update have been made, | ||
| 69 | * including both Pad key changes and analog circle Pad changes. | ||
| 70 | */ | ||
| 71 | void PadUpdateComplete() { | ||
| 72 | PadData* pad_data = GetPadData(); | ||
| 73 | |||
| 74 | if (pad_data == nullptr) { | ||
| 75 | return; | ||
| 76 | } | ||
| 77 | |||
| 78 | // Update PadData struct | ||
| 79 | pad_data->current_state.hex = next_state.hex; | ||
| 80 | pad_data->index = next_index; | ||
| 81 | next_index = (next_index + 1) % pad_data->entries.size(); | ||
| 82 | |||
| 83 | // Get the previous Pad state | ||
| 84 | u32 last_entry_index = (pad_data->index - 1) % pad_data->entries.size(); | ||
| 85 | PadState old_state = pad_data->entries[last_entry_index].current_state; | ||
| 86 | |||
| 87 | // Compute bitmask with 1s for bits different from the old state | ||
| 88 | PadState changed; | ||
| 89 | changed.hex = (next_state.hex ^ old_state.hex); | ||
| 90 | |||
| 91 | // Compute what was added | ||
| 92 | PadState additions; | ||
| 93 | additions.hex = changed.hex & next_state.hex; | ||
| 94 | |||
| 95 | // Compute what was removed | ||
| 96 | PadState removals; | ||
| 97 | removals.hex = changed.hex & old_state.hex; | ||
| 98 | |||
| 99 | // Get the current Pad entry | ||
| 100 | PadDataEntry* current_pad_entry = &pad_data->entries[pad_data->index]; | ||
| 101 | |||
| 102 | // Update entry properties | ||
| 103 | current_pad_entry->current_state.hex = next_state.hex; | ||
| 104 | current_pad_entry->delta_additions.hex = additions.hex; | ||
| 105 | current_pad_entry->delta_removals.hex = removals.hex; | ||
| 106 | |||
| 107 | // Set circle Pad | ||
| 108 | current_pad_entry->circle_pad_x = next_circle_x; | ||
| 109 | current_pad_entry->circle_pad_y = next_circle_y; | ||
| 110 | |||
| 111 | // If we just updated index 0, provide a new timestamp | ||
| 112 | if (pad_data->index == 0) { | ||
| 113 | pad_data->index_reset_ticks_previous = pad_data->index_reset_ticks; | ||
| 114 | pad_data->index_reset_ticks = (s64)Core::g_app_core->GetTicks(); | ||
| 115 | } | ||
| 116 | |||
| 117 | // Signal both handles when there's an update to Pad or touch | ||
| 118 | Kernel::SignalEvent(g_event_pad_or_touch_1); | ||
| 119 | Kernel::SignalEvent(g_event_pad_or_touch_2); | ||
| 120 | } | ||
| 121 | |||
| 122 | void HIDInit() { | ||
| 123 | g_shared_mem = Kernel::CreateSharedMemory("HID:SharedMem"); // Create shared memory object | ||
| 124 | |||
| 125 | // Create event handles | ||
| 126 | g_event_pad_or_touch_1 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID:EventPadOrTouch1"); | ||
| 127 | g_event_pad_or_touch_2 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID:EventPadOrTouch2"); | ||
| 128 | g_event_accelerometer = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID:EventAccelerometer"); | ||
| 129 | g_event_gyroscope = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID:EventGyroscope"); | ||
| 130 | g_event_debug_pad = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID:EventDebugPad"); | ||
| 131 | } | ||
| 132 | |||
| 133 | void HIDShutdown() { | ||
| 134 | |||
| 135 | } | ||
| 136 | |||
| 137 | } | ||
| 138 | } | ||
diff --git a/src/core/hle/service/hid_user.h b/src/core/hle/service/hid/hid.h index 5b96dda60..73cdaa527 100644 --- a/src/core/hle/service/hid_user.h +++ b/src/core/hle/service/hid/hid.h | |||
| @@ -1,19 +1,26 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | 1 | // Copyright 2015 Citra Emulator Project |
| 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 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "core/hle/service/service.h" | 7 | #include <array> |
| 8 | |||
| 9 | #include "core/hle/kernel/kernel.h" | ||
| 8 | #include "common/bit_field.h" | 10 | #include "common/bit_field.h" |
| 9 | 11 | ||
| 10 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 12 | namespace Service { |
| 11 | // Namespace HID_User | 13 | namespace HID { |
| 12 | 14 | ||
| 13 | // This service is used for interfacing to physical user controls. | 15 | // Handle to shared memory region designated to HID_User service |
| 14 | // Uses include game pad controls, touchscreen, accelerometers, gyroscopes, and debug pad. | 16 | extern Handle g_shared_mem; |
| 15 | 17 | ||
| 16 | namespace HID_User { | 18 | // Event handles |
| 19 | extern Handle g_event_pad_or_touch_1; | ||
| 20 | extern Handle g_event_pad_or_touch_2; | ||
| 21 | extern Handle g_event_accelerometer; | ||
| 22 | extern Handle g_event_gyroscope; | ||
| 23 | extern Handle g_event_debug_pad; | ||
| 17 | 24 | ||
| 18 | /** | 25 | /** |
| 19 | * Structure of a Pad controller state. | 26 | * Structure of a Pad controller state. |
| @@ -97,16 +104,8 @@ void PadButtonPress(const PadState& pad_state); | |||
| 97 | void PadButtonRelease(const PadState& pad_state); | 104 | void PadButtonRelease(const PadState& pad_state); |
| 98 | void PadUpdateComplete(); | 105 | void PadUpdateComplete(); |
| 99 | 106 | ||
| 100 | /** | 107 | void HIDInit(); |
| 101 | * HID service interface. | 108 | void HIDShutdown(); |
| 102 | */ | ||
| 103 | class Interface : public Service::Interface { | ||
| 104 | public: | ||
| 105 | Interface(); | ||
| 106 | |||
| 107 | std::string GetPortName() const override { | ||
| 108 | return "hid:USER"; | ||
| 109 | } | ||
| 110 | }; | ||
| 111 | 109 | ||
| 112 | } // namespace | 110 | } |
| 111 | } | ||
diff --git a/src/core/hle/service/hid/hid_spvr.cpp b/src/core/hle/service/hid/hid_spvr.cpp new file mode 100644 index 000000000..76c40b659 --- /dev/null +++ b/src/core/hle/service/hid/hid_spvr.cpp | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/log.h" | ||
| 6 | #include "core/hle/hle.h" | ||
| 7 | #include "core/hle/service/hid/hid_spvr.h" | ||
| 8 | |||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 10 | // Namespace HID_SPVR | ||
| 11 | |||
| 12 | namespace HID_User { | ||
| 13 | extern void GetIPCHandles(Service::Interface* self); | ||
| 14 | } | ||
| 15 | |||
| 16 | namespace HID_SPVR { | ||
| 17 | |||
| 18 | const Interface::FunctionInfo FunctionTable[] = { | ||
| 19 | {0x000A0000, HID_User::GetIPCHandles, "GetIPCHandles"}, | ||
| 20 | {0x000B0000, nullptr, "StartAnalogStickCalibration"}, | ||
| 21 | {0x000E0000, nullptr, "GetAnalogStickCalibrateParam"}, | ||
| 22 | {0x00110000, nullptr, "EnableAccelerometer"}, | ||
| 23 | {0x00120000, nullptr, "DisableAccelerometer"}, | ||
| 24 | {0x00130000, nullptr, "EnableGyroscopeLow"}, | ||
| 25 | {0x00140000, nullptr, "DisableGyroscopeLow"}, | ||
| 26 | {0x00150000, nullptr, "GetGyroscopeLowRawToDpsCoefficient"}, | ||
| 27 | {0x00160000, nullptr, "GetGyroscopeLowCalibrateParam"}, | ||
| 28 | {0x00170000, nullptr, "GetSoundVolume"}, | ||
| 29 | }; | ||
| 30 | |||
| 31 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 32 | // Interface class | ||
| 33 | |||
| 34 | Interface::Interface() { | ||
| 35 | Register(FunctionTable, ARRAY_SIZE(FunctionTable)); | ||
| 36 | } | ||
| 37 | |||
| 38 | } // namespace | ||
diff --git a/src/core/hle/service/hid/hid_spvr.h b/src/core/hle/service/hid/hid_spvr.h new file mode 100644 index 000000000..53ddc8569 --- /dev/null +++ b/src/core/hle/service/hid/hid_spvr.h | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/hle/service/service.h" | ||
| 8 | |||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 10 | // Namespace HID_SPVR | ||
| 11 | |||
| 12 | namespace HID_SPVR { | ||
| 13 | |||
| 14 | class Interface : public Service::Interface { | ||
| 15 | public: | ||
| 16 | Interface(); | ||
| 17 | |||
| 18 | std::string GetPortName() const override { | ||
| 19 | return "hid:SPVR"; | ||
| 20 | } | ||
| 21 | }; | ||
| 22 | |||
| 23 | } // namespace | ||
diff --git a/src/core/hle/service/hid/hid_user.cpp b/src/core/hle/service/hid/hid_user.cpp new file mode 100644 index 000000000..3a6275707 --- /dev/null +++ b/src/core/hle/service/hid/hid_user.cpp | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/log.h" | ||
| 6 | |||
| 7 | #include "core/hle/hle.h" | ||
| 8 | #include "core/hle/service/hid/hid.h" | ||
| 9 | #include "hid_user.h" | ||
| 10 | |||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 12 | // Namespace HID_User | ||
| 13 | |||
| 14 | namespace HID_User { | ||
| 15 | |||
| 16 | |||
| 17 | // TODO(peachum): | ||
| 18 | // Add a method for setting analog input from joystick device for the circle Pad. | ||
| 19 | // | ||
| 20 | // This method should: | ||
| 21 | // * Be called after both PadButton<Press, Release>(). | ||
| 22 | // * Be called before PadUpdateComplete() | ||
| 23 | // * Set current PadEntry.circle_pad_<axis> using analog data | ||
| 24 | // * Set PadData.raw_circle_pad_data | ||
| 25 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_x >= 41 | ||
| 26 | // * Set PadData.current_state.circle_up = 1 if current PadEntry.circle_pad_y >= 41 | ||
| 27 | // * Set PadData.current_state.circle_left = 1 if current PadEntry.circle_pad_x <= -41 | ||
| 28 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_y <= -41 | ||
| 29 | |||
| 30 | |||
| 31 | /** | ||
| 32 | * HID_User::GetIPCHandles service function | ||
| 33 | * Inputs: | ||
| 34 | * None | ||
| 35 | * Outputs: | ||
| 36 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 37 | * 2 : Unused | ||
| 38 | * 3 : Handle to HID_User shared memory | ||
| 39 | * 4 : Event signaled by HID_User | ||
| 40 | * 5 : Event signaled by HID_User | ||
| 41 | * 6 : Event signaled by HID_User | ||
| 42 | * 7 : Gyroscope event | ||
| 43 | * 8 : Event signaled by HID_User | ||
| 44 | */ | ||
| 45 | void GetIPCHandles(Service::Interface* self) { | ||
| 46 | u32* cmd_buff = Kernel::GetCommandBuffer(); | ||
| 47 | |||
| 48 | cmd_buff[1] = 0; // No error | ||
| 49 | cmd_buff[3] = Service::HID::g_shared_mem; | ||
| 50 | cmd_buff[4] = Service::HID::g_event_pad_or_touch_1; | ||
| 51 | cmd_buff[5] = Service::HID::g_event_pad_or_touch_2; | ||
| 52 | cmd_buff[6] = Service::HID::g_event_accelerometer; | ||
| 53 | cmd_buff[7] = Service::HID::g_event_gyroscope; | ||
| 54 | cmd_buff[8] = Service::HID::g_event_debug_pad; | ||
| 55 | } | ||
| 56 | |||
| 57 | const Interface::FunctionInfo FunctionTable[] = { | ||
| 58 | {0x000A0000, GetIPCHandles, "GetIPCHandles"}, | ||
| 59 | {0x00110000, nullptr, "EnableAccelerometer"}, | ||
| 60 | {0x00120000, nullptr, "DisableAccelerometer"}, | ||
| 61 | {0x00130000, nullptr, "EnableGyroscopeLow"}, | ||
| 62 | {0x00140000, nullptr, "DisableGyroscopeLow"}, | ||
| 63 | {0x00150000, nullptr, "GetGyroscopeLowRawToDpsCoefficient"}, | ||
| 64 | {0x00160000, nullptr, "GetGyroscopeLowCalibrateParam"}, | ||
| 65 | {0x00170000, nullptr, "GetSoundVolume"}, | ||
| 66 | }; | ||
| 67 | |||
| 68 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 69 | // Interface class | ||
| 70 | |||
| 71 | Interface::Interface() { | ||
| 72 | Register(FunctionTable, ARRAY_SIZE(FunctionTable)); | ||
| 73 | } | ||
| 74 | |||
| 75 | } // namespace | ||
diff --git a/src/core/hle/service/hid/hid_user.h b/src/core/hle/service/hid/hid_user.h new file mode 100644 index 000000000..1d9929e67 --- /dev/null +++ b/src/core/hle/service/hid/hid_user.h | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/hle/service/service.h" | ||
| 8 | |||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 10 | // Namespace HID_User | ||
| 11 | |||
| 12 | // This service is used for interfacing to physical user controls. | ||
| 13 | // Uses include game pad controls, touchscreen, accelerometers, gyroscopes, and debug pad. | ||
| 14 | |||
| 15 | namespace HID_User { | ||
| 16 | |||
| 17 | /** | ||
| 18 | * HID service interface. | ||
| 19 | */ | ||
| 20 | class Interface : public Service::Interface { | ||
| 21 | public: | ||
| 22 | Interface(); | ||
| 23 | |||
| 24 | std::string GetPortName() const override { | ||
| 25 | return "hid:USER"; | ||
| 26 | } | ||
| 27 | }; | ||
| 28 | |||
| 29 | } // namespace | ||
diff --git a/src/core/hle/service/hid_user.cpp b/src/core/hle/service/hid_user.cpp deleted file mode 100644 index 1403b1de9..000000000 --- a/src/core/hle/service/hid_user.cpp +++ /dev/null | |||
| @@ -1,197 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/log.h" | ||
| 6 | |||
| 7 | #include "core/arm/arm_interface.h" | ||
| 8 | #include "core/hle/hle.h" | ||
| 9 | #include "core/hle/kernel/event.h" | ||
| 10 | #include "core/hle/kernel/shared_memory.h" | ||
| 11 | #include "hid_user.h" | ||
| 12 | |||
| 13 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 14 | // Namespace HID_User | ||
| 15 | |||
| 16 | namespace HID_User { | ||
| 17 | |||
| 18 | // Handle to shared memory region designated to HID_User service | ||
| 19 | static Handle shared_mem = 0; | ||
| 20 | |||
| 21 | // Event handles | ||
| 22 | static Handle event_pad_or_touch_1 = 0; | ||
| 23 | static Handle event_pad_or_touch_2 = 0; | ||
| 24 | static Handle event_accelerometer = 0; | ||
| 25 | static Handle event_gyroscope = 0; | ||
| 26 | static Handle event_debug_pad = 0; | ||
| 27 | |||
| 28 | // Next Pad state update information | ||
| 29 | static PadState next_state = {{0}}; | ||
| 30 | static u32 next_index = 0; | ||
| 31 | static s16 next_circle_x = 0; | ||
| 32 | static s16 next_circle_y = 0; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * Gets a pointer to the PadData structure inside HID shared memory | ||
| 36 | */ | ||
| 37 | static inline PadData* GetPadData() { | ||
| 38 | return reinterpret_cast<PadData*>(Kernel::GetSharedMemoryPointer(shared_mem, 0).ValueOr(nullptr)); | ||
| 39 | } | ||
| 40 | |||
| 41 | /** | ||
| 42 | * Circle Pad from keys. | ||
| 43 | * | ||
| 44 | * This is implemented as "pushed all the way to an edge (max) or centered (0)". | ||
| 45 | * | ||
| 46 | * Indicate the circle pad is pushed completely to the edge in 1 of 8 directions. | ||
| 47 | */ | ||
| 48 | static void UpdateNextCirclePadState() { | ||
| 49 | static const s16 max_value = 0x9C; | ||
| 50 | next_circle_x = next_state.circle_left ? -max_value : 0x0; | ||
| 51 | next_circle_x += next_state.circle_right ? max_value : 0x0; | ||
| 52 | next_circle_y = next_state.circle_down ? -max_value : 0x0; | ||
| 53 | next_circle_y += next_state.circle_up ? max_value : 0x0; | ||
| 54 | } | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Sets a Pad state (button or button combo) as pressed | ||
| 58 | */ | ||
| 59 | void PadButtonPress(const PadState& pad_state) { | ||
| 60 | next_state.hex |= pad_state.hex; | ||
| 61 | UpdateNextCirclePadState(); | ||
| 62 | } | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Sets a Pad state (button or button combo) as released | ||
| 66 | */ | ||
| 67 | void PadButtonRelease(const PadState& pad_state) { | ||
| 68 | next_state.hex &= ~pad_state.hex; | ||
| 69 | UpdateNextCirclePadState(); | ||
| 70 | } | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Called after all Pad changes to be included in this update have been made, | ||
| 74 | * including both Pad key changes and analog circle Pad changes. | ||
| 75 | */ | ||
| 76 | void PadUpdateComplete() { | ||
| 77 | PadData* pad_data = GetPadData(); | ||
| 78 | |||
| 79 | if (pad_data == nullptr) { | ||
| 80 | return; | ||
| 81 | } | ||
| 82 | |||
| 83 | // Update PadData struct | ||
| 84 | pad_data->current_state.hex = next_state.hex; | ||
| 85 | pad_data->index = next_index; | ||
| 86 | next_index = (next_index + 1) % pad_data->entries.size(); | ||
| 87 | |||
| 88 | // Get the previous Pad state | ||
| 89 | u32 last_entry_index = (pad_data->index - 1) % pad_data->entries.size(); | ||
| 90 | PadState old_state = pad_data->entries[last_entry_index].current_state; | ||
| 91 | |||
| 92 | // Compute bitmask with 1s for bits different from the old state | ||
| 93 | PadState changed; | ||
| 94 | changed.hex = (next_state.hex ^ old_state.hex); | ||
| 95 | |||
| 96 | // Compute what was added | ||
| 97 | PadState additions; | ||
| 98 | additions.hex = changed.hex & next_state.hex; | ||
| 99 | |||
| 100 | // Compute what was removed | ||
| 101 | PadState removals; | ||
| 102 | removals.hex = changed.hex & old_state.hex; | ||
| 103 | |||
| 104 | // Get the current Pad entry | ||
| 105 | PadDataEntry* current_pad_entry = &pad_data->entries[pad_data->index]; | ||
| 106 | |||
| 107 | // Update entry properties | ||
| 108 | current_pad_entry->current_state.hex = next_state.hex; | ||
| 109 | current_pad_entry->delta_additions.hex = additions.hex; | ||
| 110 | current_pad_entry->delta_removals.hex = removals.hex; | ||
| 111 | |||
| 112 | // Set circle Pad | ||
| 113 | current_pad_entry->circle_pad_x = next_circle_x; | ||
| 114 | current_pad_entry->circle_pad_y = next_circle_y; | ||
| 115 | |||
| 116 | // If we just updated index 0, provide a new timestamp | ||
| 117 | if (pad_data->index == 0) { | ||
| 118 | pad_data->index_reset_ticks_previous = pad_data->index_reset_ticks; | ||
| 119 | pad_data->index_reset_ticks = (s64)Core::g_app_core->GetTicks(); | ||
| 120 | } | ||
| 121 | |||
| 122 | // Signal both handles when there's an update to Pad or touch | ||
| 123 | Kernel::SignalEvent(event_pad_or_touch_1); | ||
| 124 | Kernel::SignalEvent(event_pad_or_touch_2); | ||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | // TODO(peachum): | ||
| 129 | // Add a method for setting analog input from joystick device for the circle Pad. | ||
| 130 | // | ||
| 131 | // This method should: | ||
| 132 | // * Be called after both PadButton<Press, Release>(). | ||
| 133 | // * Be called before PadUpdateComplete() | ||
| 134 | // * Set current PadEntry.circle_pad_<axis> using analog data | ||
| 135 | // * Set PadData.raw_circle_pad_data | ||
| 136 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_x >= 41 | ||
| 137 | // * Set PadData.current_state.circle_up = 1 if current PadEntry.circle_pad_y >= 41 | ||
| 138 | // * Set PadData.current_state.circle_left = 1 if current PadEntry.circle_pad_x <= -41 | ||
| 139 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_y <= -41 | ||
| 140 | |||
| 141 | |||
| 142 | /** | ||
| 143 | * HID_User::GetIPCHandles service function | ||
| 144 | * Inputs: | ||
| 145 | * None | ||
| 146 | * Outputs: | ||
| 147 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 148 | * 2 : Unused | ||
| 149 | * 3 : Handle to HID_User shared memory | ||
| 150 | * 4 : Event signaled by HID_User | ||
| 151 | * 5 : Event signaled by HID_User | ||
| 152 | * 6 : Event signaled by HID_User | ||
| 153 | * 7 : Gyroscope event | ||
| 154 | * 8 : Event signaled by HID_User | ||
| 155 | */ | ||
| 156 | static void GetIPCHandles(Service::Interface* self) { | ||
| 157 | u32* cmd_buff = Kernel::GetCommandBuffer(); | ||
| 158 | |||
| 159 | cmd_buff[1] = 0; // No error | ||
| 160 | cmd_buff[3] = shared_mem; | ||
| 161 | cmd_buff[4] = event_pad_or_touch_1; | ||
| 162 | cmd_buff[5] = event_pad_or_touch_2; | ||
| 163 | cmd_buff[6] = event_accelerometer; | ||
| 164 | cmd_buff[7] = event_gyroscope; | ||
| 165 | cmd_buff[8] = event_debug_pad; | ||
| 166 | } | ||
| 167 | |||
| 168 | const Interface::FunctionInfo FunctionTable[] = { | ||
| 169 | {0x000A0000, GetIPCHandles, "GetIPCHandles"}, | ||
| 170 | {0x000B0000, nullptr, "StartAnalogStickCalibration"}, | ||
| 171 | {0x000E0000, nullptr, "GetAnalogStickCalibrateParam"}, | ||
| 172 | {0x00110000, nullptr, "EnableAccelerometer"}, | ||
| 173 | {0x00120000, nullptr, "DisableAccelerometer"}, | ||
| 174 | {0x00130000, nullptr, "EnableGyroscopeLow"}, | ||
| 175 | {0x00140000, nullptr, "DisableGyroscopeLow"}, | ||
| 176 | {0x00150000, nullptr, "GetGyroscopeLowRawToDpsCoefficient"}, | ||
| 177 | {0x00160000, nullptr, "GetGyroscopeLowCalibrateParam"}, | ||
| 178 | {0x00170000, nullptr, "GetSoundVolume"}, | ||
| 179 | }; | ||
| 180 | |||
| 181 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 182 | // Interface class | ||
| 183 | |||
| 184 | Interface::Interface() { | ||
| 185 | shared_mem = Kernel::CreateSharedMemory("HID_User:SharedMem"); // Create shared memory object | ||
| 186 | |||
| 187 | // Create event handles | ||
| 188 | event_pad_or_touch_1 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventPadOrTouch1"); | ||
| 189 | event_pad_or_touch_2 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventPadOrTouch2"); | ||
| 190 | event_accelerometer = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventAccelerometer"); | ||
| 191 | event_gyroscope = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventGyroscope"); | ||
| 192 | event_debug_pad = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventDebugPad"); | ||
| 193 | |||
| 194 | Register(FunctionTable, ARRAY_SIZE(FunctionTable)); | ||
| 195 | } | ||
| 196 | |||
| 197 | } // namespace | ||
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 446ed5164..b685fc905 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -24,7 +24,8 @@ | |||
| 24 | #include "core/hle/service/fs/fs_user.h" | 24 | #include "core/hle/service/fs/fs_user.h" |
| 25 | #include "core/hle/service/frd_u.h" | 25 | #include "core/hle/service/frd_u.h" |
| 26 | #include "core/hle/service/gsp_gpu.h" | 26 | #include "core/hle/service/gsp_gpu.h" |
| 27 | #include "core/hle/service/hid_user.h" | 27 | #include "core/hle/service/hid/hid_spvr.h" |
| 28 | #include "core/hle/service/hid/hid_user.h" | ||
| 28 | #include "core/hle/service/http_c.h" | 29 | #include "core/hle/service/http_c.h" |
| 29 | #include "core/hle/service/ir_rst.h" | 30 | #include "core/hle/service/ir_rst.h" |
| 30 | #include "core/hle/service/ir_u.h" | 31 | #include "core/hle/service/ir_u.h" |
| @@ -101,6 +102,7 @@ void Init() { | |||
| 101 | g_manager->AddService(new FRD_U::Interface); | 102 | g_manager->AddService(new FRD_U::Interface); |
| 102 | g_manager->AddService(new FS::FSUserInterface); | 103 | g_manager->AddService(new FS::FSUserInterface); |
| 103 | g_manager->AddService(new GSP_GPU::Interface); | 104 | g_manager->AddService(new GSP_GPU::Interface); |
| 105 | g_manager->AddService(new HID_SPVR::Interface); | ||
| 104 | g_manager->AddService(new HID_User::Interface); | 106 | g_manager->AddService(new HID_User::Interface); |
| 105 | g_manager->AddService(new HTTP_C::Interface); | 107 | g_manager->AddService(new HTTP_C::Interface); |
| 106 | g_manager->AddService(new IR_RST::Interface); | 108 | g_manager->AddService(new IR_RST::Interface); |