diff options
| author | 2014-10-28 23:08:37 -0400 | |
|---|---|---|
| committer | 2014-10-29 15:55:51 -0400 | |
| commit | 38df9e96dd39604273a7a3508abb5e2b302b79cd (patch) | |
| tree | 56e092b84815ba02b3d6918524405f25f4c2f251 /src/core/hle/service/hid.cpp | |
| parent | Merge pull request #151 from archshift/dyncom-enabled (diff) | |
| download | yuzu-38df9e96dd39604273a7a3508abb5e2b302b79cd.tar.gz yuzu-38df9e96dd39604273a7a3508abb5e2b302b79cd.tar.xz yuzu-38df9e96dd39604273a7a3508abb5e2b302b79cd.zip | |
Renamed souce files of services to match port names
Diffstat (limited to 'src/core/hle/service/hid.cpp')
| -rw-r--r-- | src/core/hle/service/hid.cpp | 205 |
1 files changed, 0 insertions, 205 deletions
diff --git a/src/core/hle/service/hid.cpp b/src/core/hle/service/hid.cpp deleted file mode 100644 index ef38a5603..000000000 --- a/src/core/hle/service/hid.cpp +++ /dev/null | |||
| @@ -1,205 +0,0 @@ | |||
| 1 | // Copyright 2014 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 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/kernel/event.h" | ||
| 9 | #include "core/hle/kernel/shared_memory.h" | ||
| 10 | #include "core/hle/service/hid.h" | ||
| 11 | |||
| 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 13 | // Namespace HID_User | ||
| 14 | |||
| 15 | namespace HID_User { | ||
| 16 | |||
| 17 | // Handle to shared memory region designated to HID_User service | ||
| 18 | static Handle shared_mem = 0; | ||
| 19 | |||
| 20 | // Event handles | ||
| 21 | static Handle event_pad_or_touch_1 = 0; | ||
| 22 | static Handle event_pad_or_touch_2 = 0; | ||
| 23 | static Handle event_accelerometer = 0; | ||
| 24 | static Handle event_gyroscope = 0; | ||
| 25 | static Handle event_debug_pad = 0; | ||
| 26 | |||
| 27 | // Next Pad state update information | ||
| 28 | static PadState next_state = {{0}}; | ||
| 29 | static u32 next_index = 0; | ||
| 30 | static s16 next_circle_x = 0; | ||
| 31 | static s16 next_circle_y = 0; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * Gets a pointer to the PadData structure inside HID shared memory | ||
| 35 | */ | ||
| 36 | static inline PadData* GetPadData() { | ||
| 37 | if (0 == shared_mem) | ||
| 38 | return nullptr; | ||
| 39 | |||
| 40 | return reinterpret_cast<PadData*>(Kernel::GetSharedMemoryPointer(shared_mem, 0)); | ||
| 41 | } | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Circle Pad from keys. | ||
| 45 | * | ||
| 46 | * This is implemented as "pushed all the way to an edge (max) or centered (0)". | ||
| 47 | * | ||
| 48 | * Indicate the circle pad is pushed completely to the edge in 1 of 8 directions. | ||
| 49 | */ | ||
| 50 | void UpdateNextCirclePadState() { | ||
| 51 | static const s16 max_value = 0x9C; | ||
| 52 | next_circle_x = next_state.circle_left ? -max_value : 0x0; | ||
| 53 | next_circle_x += next_state.circle_right ? max_value : 0x0; | ||
| 54 | next_circle_y = next_state.circle_down ? -max_value : 0x0; | ||
| 55 | next_circle_y += next_state.circle_up ? max_value : 0x0; | ||
| 56 | } | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Sets a Pad state (button or button combo) as pressed | ||
| 60 | */ | ||
| 61 | void PadButtonPress(PadState pad_state) { | ||
| 62 | next_state.hex |= pad_state.hex; | ||
| 63 | UpdateNextCirclePadState(); | ||
| 64 | } | ||
| 65 | |||
| 66 | /** | ||
| 67 | * Sets a Pad state (button or button combo) as released | ||
| 68 | */ | ||
| 69 | void PadButtonRelease(PadState pad_state) { | ||
| 70 | next_state.hex &= ~pad_state.hex; | ||
| 71 | UpdateNextCirclePadState(); | ||
| 72 | } | ||
| 73 | |||
| 74 | /** | ||
| 75 | * Called after all Pad changes to be included in this update have been made, | ||
| 76 | * including both Pad key changes and analog circle Pad changes. | ||
| 77 | */ | ||
| 78 | void PadUpdateComplete() { | ||
| 79 | PadData* pad_data = GetPadData(); | ||
| 80 | |||
| 81 | if (pad_data == nullptr) { | ||
| 82 | return; | ||
| 83 | } | ||
| 84 | |||
| 85 | // Update PadData struct | ||
| 86 | pad_data->current_state.hex = next_state.hex; | ||
| 87 | pad_data->index = next_index; | ||
| 88 | next_index = (next_index + 1) % pad_data->entries.size(); | ||
| 89 | |||
| 90 | // Get the previous Pad state | ||
| 91 | u32 last_entry_index = (pad_data->index - 1) % pad_data->entries.size(); | ||
| 92 | PadState old_state = pad_data->entries[last_entry_index].current_state; | ||
| 93 | |||
| 94 | // Compute bitmask with 1s for bits different from the old state | ||
| 95 | PadState changed; | ||
| 96 | changed.hex = (next_state.hex ^ old_state.hex); | ||
| 97 | |||
| 98 | // Compute what was added | ||
| 99 | PadState additions; | ||
| 100 | additions.hex = changed.hex & next_state.hex; | ||
| 101 | |||
| 102 | // Compute what was removed | ||
| 103 | PadState removals; | ||
| 104 | removals.hex = changed.hex & old_state.hex; | ||
| 105 | |||
| 106 | // Get the current Pad entry | ||
| 107 | PadDataEntry* current_pad_entry = &pad_data->entries[pad_data->index]; | ||
| 108 | |||
| 109 | // Update entry properties | ||
| 110 | current_pad_entry->current_state.hex = next_state.hex; | ||
| 111 | current_pad_entry->delta_additions.hex = additions.hex; | ||
| 112 | current_pad_entry->delta_removals.hex = removals.hex; | ||
| 113 | |||
| 114 | // Set circle Pad | ||
| 115 | current_pad_entry->circle_pad_x = next_circle_x; | ||
| 116 | current_pad_entry->circle_pad_y = next_circle_y; | ||
| 117 | |||
| 118 | // If we just updated index 0, provide a new timestamp | ||
| 119 | if (pad_data->index == 0) { | ||
| 120 | pad_data->index_reset_ticks_previous = pad_data->index_reset_ticks; | ||
| 121 | pad_data->index_reset_ticks = (s64)Core::g_app_core->GetTicks(); | ||
| 122 | } | ||
| 123 | |||
| 124 | // Signal both handles when there's an update to Pad or touch | ||
| 125 | Kernel::SignalEvent(event_pad_or_touch_1); | ||
| 126 | Kernel::SignalEvent(event_pad_or_touch_2); | ||
| 127 | } | ||
| 128 | |||
| 129 | |||
| 130 | // TODO(peachum): | ||
| 131 | // Add a method for setting analog input from joystick device for the circle Pad. | ||
| 132 | // | ||
| 133 | // This method should: | ||
| 134 | // * Be called after both PadButton<Press, Release>(). | ||
| 135 | // * Be called before PadUpdateComplete() | ||
| 136 | // * Set current PadEntry.circle_pad_<axis> using analog data | ||
| 137 | // * Set PadData.raw_circle_pad_data | ||
| 138 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_x >= 41 | ||
| 139 | // * Set PadData.current_state.circle_up = 1 if current PadEntry.circle_pad_y >= 41 | ||
| 140 | // * Set PadData.current_state.circle_left = 1 if current PadEntry.circle_pad_x <= -41 | ||
| 141 | // * Set PadData.current_state.circle_right = 1 if current PadEntry.circle_pad_y <= -41 | ||
| 142 | |||
| 143 | |||
| 144 | /** | ||
| 145 | * HID_User::GetIPCHandles service function | ||
| 146 | * Inputs: | ||
| 147 | * None | ||
| 148 | * Outputs: | ||
| 149 | * 1 : Result of function, 0 on success, otherwise error code | ||
| 150 | * 2 : Unused | ||
| 151 | * 3 : Handle to HID_User shared memory | ||
| 152 | * 4 : Event signaled by HID_User | ||
| 153 | * 5 : Event signaled by HID_User | ||
| 154 | * 6 : Event signaled by HID_User | ||
| 155 | * 7 : Gyroscope event | ||
| 156 | * 8 : Event signaled by HID_User | ||
| 157 | */ | ||
| 158 | void GetIPCHandles(Service::Interface* self) { | ||
| 159 | u32* cmd_buff = Service::GetCommandBuffer(); | ||
| 160 | |||
| 161 | cmd_buff[1] = 0; // No error | ||
| 162 | cmd_buff[3] = shared_mem; | ||
| 163 | cmd_buff[4] = event_pad_or_touch_1; | ||
| 164 | cmd_buff[5] = event_pad_or_touch_2; | ||
| 165 | cmd_buff[6] = event_accelerometer; | ||
| 166 | cmd_buff[7] = event_gyroscope; | ||
| 167 | cmd_buff[8] = event_debug_pad; | ||
| 168 | |||
| 169 | DEBUG_LOG(KERNEL, "called"); | ||
| 170 | } | ||
| 171 | |||
| 172 | const Interface::FunctionInfo FunctionTable[] = { | ||
| 173 | {0x000A0000, GetIPCHandles, "GetIPCHandles"}, | ||
| 174 | {0x000B0000, nullptr, "StartAnalogStickCalibration"}, | ||
| 175 | {0x000E0000, nullptr, "GetAnalogStickCalibrateParam"}, | ||
| 176 | {0x00110000, nullptr, "EnableAccelerometer"}, | ||
| 177 | {0x00120000, nullptr, "DisableAccelerometer"}, | ||
| 178 | {0x00130000, nullptr, "EnableGyroscopeLow"}, | ||
| 179 | {0x00140000, nullptr, "DisableGyroscopeLow"}, | ||
| 180 | {0x00150000, nullptr, "GetGyroscopeLowRawToDpsCoefficient"}, | ||
| 181 | {0x00160000, nullptr, "GetGyroscopeLowCalibrateParam"}, | ||
| 182 | {0x00170000, nullptr, "GetSoundVolume"}, | ||
| 183 | }; | ||
| 184 | |||
| 185 | |||
| 186 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 187 | // Interface class | ||
| 188 | |||
| 189 | Interface::Interface() { | ||
| 190 | shared_mem = Kernel::CreateSharedMemory("HID_User:SharedMem"); // Create shared memory object | ||
| 191 | |||
| 192 | // Create event handles | ||
| 193 | event_pad_or_touch_1 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventPadOrTouch1"); | ||
| 194 | event_pad_or_touch_2 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventPadOrTouch2"); | ||
| 195 | event_accelerometer = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventAccelerometer"); | ||
| 196 | event_gyroscope = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventGyroscope"); | ||
| 197 | event_debug_pad = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventDebugPad"); | ||
| 198 | |||
| 199 | Register(FunctionTable, ARRAY_SIZE(FunctionTable)); | ||
| 200 | } | ||
| 201 | |||
| 202 | Interface::~Interface() { | ||
| 203 | } | ||
| 204 | |||
| 205 | } // namespace | ||