diff options
| author | 2014-09-03 18:12:58 -0700 | |
|---|---|---|
| committer | 2014-09-11 22:43:42 -0700 | |
| commit | 4a94ec934ab1a2216f94e3fcc46f5dde1d6e2f02 (patch) | |
| tree | 2588f0c6051c9a5e3f23057d2953c35a854dbc43 /src/core/hle/service/hid.cpp | |
| parent | Created structure for PAD. (diff) | |
| download | yuzu-4a94ec934ab1a2216f94e3fcc46f5dde1d6e2f02.tar.gz yuzu-4a94ec934ab1a2216f94e3fcc46f5dde1d6e2f02.tar.xz yuzu-4a94ec934ab1a2216f94e3fcc46f5dde1d6e2f02.zip | |
Initial HID PAD work, with GLFW only.
Diffstat (limited to 'src/core/hle/service/hid.cpp')
| -rw-r--r-- | src/core/hle/service/hid.cpp | 134 |
1 files changed, 127 insertions, 7 deletions
diff --git a/src/core/hle/service/hid.cpp b/src/core/hle/service/hid.cpp index 6a4895c90..1ef39fced 100644 --- a/src/core/hle/service/hid.cpp +++ b/src/core/hle/service/hid.cpp | |||
| @@ -16,6 +16,121 @@ namespace HID_User { | |||
| 16 | 16 | ||
| 17 | Handle g_shared_mem = 0; ///< Handle to shared memory region designated to HID_User service | 17 | Handle g_shared_mem = 0; ///< Handle to shared memory region designated to HID_User service |
| 18 | 18 | ||
| 19 | // Event handles | ||
| 20 | Handle g_event_pad_or_touch_1 = 0; | ||
| 21 | Handle g_event_pad_or_touch_2 = 0; | ||
| 22 | Handle g_event_accelerometer = 0; | ||
| 23 | Handle g_event_gyroscope = 0; | ||
| 24 | Handle g_event_debug_pad = 0; | ||
| 25 | |||
| 26 | // Next PAD state update information | ||
| 27 | PADState g_next_state = {{0}}; | ||
| 28 | u32 g_next_index = 0; | ||
| 29 | s16 g_next_circle_x = 0; | ||
| 30 | s16 g_next_circle_y = 0; | ||
| 31 | |||
| 32 | /** Gets a pointer to the PADData structure inside HID shared memory | ||
| 33 | */ | ||
| 34 | static inline PADData* GetPADData() { | ||
| 35 | if (0 == g_shared_mem) | ||
| 36 | return nullptr; | ||
| 37 | |||
| 38 | return reinterpret_cast<PADData*>(Kernel::GetSharedMemoryPointer(g_shared_mem, 0)); | ||
| 39 | } | ||
| 40 | |||
| 41 | /** Circle PAD from keys. | ||
| 42 | * | ||
| 43 | * This is implemented as "pushed all the way to an edge (max) or centered (0)". | ||
| 44 | * | ||
| 45 | * Indicate the circle pad is pushed completely to the edge in 1 of 8 directions. | ||
| 46 | */ | ||
| 47 | void UpdateNextCirclePADState() { | ||
| 48 | static const s16 max_value = 0x9C; | ||
| 49 | g_next_circle_x = g_next_state.circle_left ? -max_value : 0x0; | ||
| 50 | g_next_circle_x += g_next_state.circle_right ? max_value : 0x0; | ||
| 51 | g_next_circle_y = g_next_state.circle_down ? -max_value : 0x0; | ||
| 52 | g_next_circle_y += g_next_state.circle_up ? max_value : 0x0; | ||
| 53 | } | ||
| 54 | |||
| 55 | /** Sets a PAD state (button or button combo) as pressed | ||
| 56 | */ | ||
| 57 | void PADButtonPress(PADState pad_state) { | ||
| 58 | g_next_state.hex |= pad_state.hex; | ||
| 59 | UpdateNextCirclePADState(); | ||
| 60 | } | ||
| 61 | |||
| 62 | /** Sets a PAD state (button or button combo) as released | ||
| 63 | */ | ||
| 64 | void PADButtonRelease(PADState pad_state) { | ||
| 65 | g_next_state.hex &= ~pad_state.hex; | ||
| 66 | UpdateNextCirclePADState(); | ||
| 67 | } | ||
| 68 | |||
| 69 | /** Called after all PAD changes to be included in this update have been made, | ||
| 70 | * including both PAD key changes and analog circle PAD changes. | ||
| 71 | */ | ||
| 72 | void PADUpdateComplete() { | ||
| 73 | PADData* pad_data = GetPADData(); | ||
| 74 | |||
| 75 | // Update PADData struct | ||
| 76 | pad_data->current_state.hex = g_next_state.hex; | ||
| 77 | pad_data->index = g_next_index; | ||
| 78 | g_next_index = (g_next_index + 1) % pad_data->entries.size(); | ||
| 79 | |||
| 80 | // Get the previous PAD state | ||
| 81 | u32 last_entry_index = (pad_data->index - 1) % pad_data->entries.size(); | ||
| 82 | PADState old_state = pad_data->entries[last_entry_index].current_state; | ||
| 83 | |||
| 84 | // Compute bitmask with 1s for bits different from the old state | ||
| 85 | PADState changed; | ||
| 86 | changed.hex = (g_next_state.hex ^ old_state.hex); | ||
| 87 | |||
| 88 | // Compute what was added | ||
| 89 | PADState additions; | ||
| 90 | additions.hex = changed.hex & g_next_state.hex; | ||
| 91 | |||
| 92 | // Compute what was removed | ||
| 93 | PADState removals; | ||
| 94 | removals.hex = changed.hex & old_state.hex; | ||
| 95 | |||
| 96 | // Get the current PAD entry | ||
| 97 | PADDataEntry* current_pad_entry = &pad_data->entries[pad_data->index]; | ||
| 98 | |||
| 99 | // Update entry properties | ||
| 100 | current_pad_entry->current_state.hex = g_next_state.hex; | ||
| 101 | current_pad_entry->delta_additions.hex = additions.hex; | ||
| 102 | current_pad_entry->delta_removals.hex = removals.hex; | ||
| 103 | |||
| 104 | // Set circle PAD | ||
| 105 | current_pad_entry->circle_pad_x = g_next_circle_x; | ||
| 106 | current_pad_entry->circle_pad_y = g_next_circle_y; | ||
| 107 | |||
| 108 | // If we just updated index 0, provide a new timestamp | ||
| 109 | if (pad_data->index == 0) { | ||
| 110 | pad_data->index_reset_ticks_previous = pad_data->index_reset_ticks; | ||
| 111 | pad_data->index_reset_ticks = (s64)Core::g_app_core->GetTicks(); | ||
| 112 | } | ||
| 113 | |||
| 114 | // Signal both handles when there's an update to PAD or touch | ||
| 115 | Kernel::SignalEvent(g_event_pad_or_touch_1); | ||
| 116 | Kernel::SignalEvent(g_event_pad_or_touch_2); | ||
| 117 | } | ||
| 118 | |||
| 119 | |||
| 120 | // TODO(peachum): | ||
| 121 | // Add a method for setting analog input from joystick device for the circle PAD. | ||
| 122 | // | ||
| 123 | // This method should: | ||
| 124 | // * Be called after both PADButton<Press, Release>(). | ||
| 125 | // * Be called before PADUpdateComplete() | ||
| 126 | // * Set current PADEntry.circle_pad_<axis> using analog data | ||
| 127 | // * Set PadData.raw_circle_pad_data | ||
| 128 | // * Set PadData.current_state.circle_right = 1 if current PADEntry.circle_pad_x >= 41 | ||
| 129 | // * Set PadData.current_state.circle_up = 1 if current PADEntry.circle_pad_y >= 41 | ||
| 130 | // * Set PadData.current_state.circle_left = 1 if current PADEntry.circle_pad_x <= -41 | ||
| 131 | // * Set PadData.current_state.circle_right = 1 if current PADEntry.circle_pad_y <= -41 | ||
| 132 | |||
| 133 | |||
| 19 | /** | 134 | /** |
| 20 | * HID_User::GetIPCHandles service function | 135 | * HID_User::GetIPCHandles service function |
| 21 | * Inputs: | 136 | * Inputs: |
| @@ -35,11 +150,11 @@ void GetIPCHandles(Service::Interface* self) { | |||
| 35 | 150 | ||
| 36 | cmd_buff[1] = 0; // No error | 151 | cmd_buff[1] = 0; // No error |
| 37 | cmd_buff[3] = g_shared_mem; | 152 | cmd_buff[3] = g_shared_mem; |
| 38 | cmd_buff[4] = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventA"); | 153 | cmd_buff[4] = g_event_pad_or_touch_1; |
| 39 | cmd_buff[5] = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventB"); | 154 | cmd_buff[5] = g_event_pad_or_touch_2; |
| 40 | cmd_buff[6] = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventC"); | 155 | cmd_buff[6] = g_event_accelerometer; |
| 41 | cmd_buff[7] = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventGyroscope"); | 156 | cmd_buff[7] = g_event_gyroscope; |
| 42 | cmd_buff[8] = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventD"); | 157 | cmd_buff[8] = g_event_debug_pad; |
| 43 | 158 | ||
| 44 | DEBUG_LOG(KERNEL, "called"); | 159 | DEBUG_LOG(KERNEL, "called"); |
| 45 | } | 160 | } |
| @@ -58,14 +173,19 @@ const Interface::FunctionInfo FunctionTable[] = { | |||
| 58 | }; | 173 | }; |
| 59 | 174 | ||
| 60 | 175 | ||
| 61 | |||
| 62 | |||
| 63 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 176 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 64 | // Interface class | 177 | // Interface class |
| 65 | 178 | ||
| 66 | Interface::Interface() { | 179 | Interface::Interface() { |
| 67 | g_shared_mem = Kernel::CreateSharedMemory("HID_User:SharedMem"); // Create shared memory object | 180 | g_shared_mem = Kernel::CreateSharedMemory("HID_User:SharedMem"); // Create shared memory object |
| 68 | 181 | ||
| 182 | // Create event handles | ||
| 183 | g_event_pad_or_touch_1 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventPADOrTouch1"); | ||
| 184 | g_event_pad_or_touch_2 = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventPADOrTouch2"); | ||
| 185 | g_event_accelerometer = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventAccelerometer"); | ||
| 186 | g_event_gyroscope = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventGyroscope"); | ||
| 187 | g_event_debug_pad = Kernel::CreateEvent(RESETTYPE_ONESHOT, "HID_User:EventDebugPAD"); | ||
| 188 | |||
| 69 | Register(FunctionTable, ARRAY_SIZE(FunctionTable)); | 189 | Register(FunctionTable, ARRAY_SIZE(FunctionTable)); |
| 70 | } | 190 | } |
| 71 | 191 | ||