From 83a66dd701789761c118c7e105327a1b6166ed13 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 8 Mar 2015 00:12:47 -0500 Subject: HID: Refactored shared memory decoding for touchpad support. --- src/core/hle/service/hid/hid.h | 46 +++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 12 deletions(-) (limited to 'src/core/hle/service/hid/hid.h') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 9c6e86f77..6318d1d53 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -65,7 +65,7 @@ struct PadState { }; /** - * Structure of a single entry in the PadData's Pad state history array. + * Structure of a single entry of Pad state history within HID shared memory */ struct PadDataEntry { PadState current_state; @@ -77,22 +77,44 @@ struct PadDataEntry { }; /** - * Structure of all data related to the 3DS Pad. + * Structure of a single entry of touch state history within HID shared memory */ -struct PadData { - s64 index_reset_ticks; - s64 index_reset_ticks_previous; - u32 index; // the index of the last updated Pad state history element +struct TouchDataEntry { + u16 x; + u16 y; + u32 data_valid; +}; + +/** + * Structure of data stored in HID shared memory + */ +struct SharedMem { + // Offset 0x0 : "PAD" data, this is used for buttons and the circle pad + struct { + s64 index_reset_ticks; + s64 index_reset_ticks_previous; + u32 index; // Index of the last updated pad state history element + + INSERT_PADDING_BYTES(0x8); + + PadState current_state; // Same as entries[index].current_state + u32 raw_circle_pad_data; + + INSERT_PADDING_BYTES(0x4); - u32 pad1; - u32 pad2; + std::array entries; // Pad state history + } pad; - PadState current_state; // same as entries[index].current_state - u32 raw_circle_pad_data; + // Offset 0xA8 : Touchpad data, this is used for touchpad input + struct { + s64 index_reset_ticks; + s64 index_reset_ticks_previous; + u32 index; // Index of the last updated touch state history element - u32 pad3; + INSERT_PADDING_BYTES(0xC); - std::array entries; // Pad state history + std::array entries; + } touch; }; // Pre-defined PadStates for single button presses -- cgit v1.2.3 From 3229b048d9b4f16433fb1c5d623e6b79bc1a2d93 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 8 Mar 2015 00:13:49 -0500 Subject: HID: Moved some docstrings to the header. --- src/core/hle/service/hid/hid.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/core/hle/service/hid/hid.h') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 6318d1d53..cd6263243 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -162,9 +162,22 @@ const PadState PAD_CIRCLE_DOWN = {{1u << 31}}; */ void GetIPCHandles(Interface* self); -// Methods for updating the HID module's state +/** + * Sets a Pad state (button or button combo) as pressed + * @param pad_state PadState data indicating which buttons have been pressed + */ void PadButtonPress(const PadState& pad_state); + +/** + * Sets a Pad state (button or button combo) as released + * @param pad_state PadState data indicating which buttons have been released + */ void PadButtonRelease(const PadState& pad_state); + +/** + * Called after all Pad changes to be included in this update have been made, including both Pad + * key changes and analog circle Pad changes. + */ void PadUpdateComplete(); void HIDInit(); -- cgit v1.2.3 From 1a904ded40c87c41c404cfe5e74722c0a6554926 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 8 Mar 2015 03:05:56 -0400 Subject: HID: Added functions to emulate the touchpad. --- src/core/hle/service/hid/hid.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/core/hle/service/hid/hid.h') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index cd6263243..f2affb5c5 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -180,6 +180,19 @@ void PadButtonRelease(const PadState& pad_state); */ void PadUpdateComplete(); +/** + * Signal that the touchpad has been pressed + * @param x Touchpad x-coordinate in bottom screen pixels (between 0 and 320) + * @param y Touchpad y-coordinate in bottom screen pixels (between 0 and 240) + */ +void TouchPress(u16 x, u16 y); + +/// Signal that touchpad has been released +void TouchRelease(); + +/// Signal that touchpad updates have been completed +void TouchUpdateComplete(); + void HIDInit(); void HIDShutdown(); -- cgit v1.2.3 From e9b9f1842be5afa794f03e2a0fa29d49cfca2601 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 8 Mar 2015 21:21:25 -0400 Subject: HID: Added static asserts to check register position in shared memory. --- src/core/hle/service/hid/hid.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/core/hle/service/hid/hid.h') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index f2affb5c5..e4665a43c 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -89,7 +89,7 @@ struct TouchDataEntry { * Structure of data stored in HID shared memory */ struct SharedMem { - // Offset 0x0 : "PAD" data, this is used for buttons and the circle pad + // "Pad data, this is used for buttons and the circle pad struct { s64 index_reset_ticks; s64 index_reset_ticks_previous; @@ -105,7 +105,7 @@ struct SharedMem { std::array entries; // Pad state history } pad; - // Offset 0xA8 : Touchpad data, this is used for touchpad input + // Touchpad data, this is used for touchpad input struct { s64 index_reset_ticks; s64 index_reset_ticks_previous; @@ -117,6 +117,20 @@ struct SharedMem { } touch; }; +// TODO: MSVC does not support using offsetof() on non-static data members even though this +// is technically allowed since C++11. This macro should be enabled once MSVC adds +// support for that. +#ifndef _MSC_VER +#define ASSERT_REG_POSITION(field_name, position) \ + static_assert(offsetof(SharedMem, field_name) == position * 4, \ + "Field "#field_name" has invalid position") + +ASSERT_REG_POSITION(pad.index_reset_ticks, 0x0); +ASSERT_REG_POSITION(touch.index_reset_ticks, 0x2A); + +#undef ASSERT_REG_POSITION +#endif // !defined(_MSC_VER) + // Pre-defined PadStates for single button presses const PadState PAD_NONE = {{0}}; const PadState PAD_A = {{1u << 0}}; -- cgit v1.2.3 From 432aa1044c12b9b2ac9815c6ab41917ac971a616 Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 8 Mar 2015 21:28:23 -0400 Subject: HID: Changed TouchDataEntry `valid` to a BitField and added some doc strings. --- src/core/hle/service/hid/hid.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/core/hle/service/hid/hid.h') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index e4665a43c..7fdf5828a 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -80,9 +80,9 @@ struct PadDataEntry { * Structure of a single entry of touch state history within HID shared memory */ struct TouchDataEntry { - u16 x; - u16 y; - u32 data_valid; + u16 x; ///< Y-coordinate of a touchpad press on the lower screen + u16 y; ///< X-coordinate of a touchpad press on the lower screen + BitField<0,7,u32> valid; ///< Set to 1 when this entry contains actual X/Y data, otherwise 0 }; /** -- cgit v1.2.3 From d61b26b79f889603a084e148626bba3c267cf75f Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 9 Mar 2015 00:14:59 -0400 Subject: HID: Complete refactor of pad/touch input to fix threading issues. --- src/core/hle/service/hid/hid.h | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) (limited to 'src/core/hle/service/hid/hid.h') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 7fdf5828a..063f06858 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -176,38 +176,13 @@ const PadState PAD_CIRCLE_DOWN = {{1u << 31}}; */ void GetIPCHandles(Interface* self); -/** - * Sets a Pad state (button or button combo) as pressed - * @param pad_state PadState data indicating which buttons have been pressed - */ -void PadButtonPress(const PadState& pad_state); - -/** - * Sets a Pad state (button or button combo) as released - * @param pad_state PadState data indicating which buttons have been released - */ -void PadButtonRelease(const PadState& pad_state); - -/** - * Called after all Pad changes to be included in this update have been made, including both Pad - * key changes and analog circle Pad changes. - */ -void PadUpdateComplete(); - -/** - * Signal that the touchpad has been pressed - * @param x Touchpad x-coordinate in bottom screen pixels (between 0 and 320) - * @param y Touchpad y-coordinate in bottom screen pixels (between 0 and 240) - */ -void TouchPress(u16 x, u16 y); - -/// Signal that touchpad has been released -void TouchRelease(); - -/// Signal that touchpad updates have been completed -void TouchUpdateComplete(); +/// Checks for user input updates +void HIDUpdate(); +/// Initialize HID service void HIDInit(); + +/// Shutdown HID service void HIDShutdown(); } -- cgit v1.2.3 From 85cbccb1d3110c934ccf0edddf86a03fa692f27b Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 9 Mar 2015 23:03:24 -0400 Subject: HID: Added additional variable comments and some code cleanups. --- src/core/hle/service/hid/hid.h | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) (limited to 'src/core/hle/service/hid/hid.h') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 063f06858..03971d3c7 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -80,40 +80,45 @@ struct PadDataEntry { * Structure of a single entry of touch state history within HID shared memory */ struct TouchDataEntry { - u16 x; ///< Y-coordinate of a touchpad press on the lower screen - u16 y; ///< X-coordinate of a touchpad press on the lower screen - BitField<0,7,u32> valid; ///< Set to 1 when this entry contains actual X/Y data, otherwise 0 + u16 x; ///< Y-coordinate of a touchpad press on the lower screen + u16 y; ///< X-coordinate of a touchpad press on the lower screen + BitField<0, 7, u32> valid; ///< Set to 1 when this entry contains actual X/Y data, otherwise 0 }; /** * Structure of data stored in HID shared memory */ struct SharedMem { - // "Pad data, this is used for buttons and the circle pad + /// Pad data, this is used for buttons and the circle pad struct { - s64 index_reset_ticks; - s64 index_reset_ticks_previous; - u32 index; // Index of the last updated pad state history element + s64 index_reset_ticks; ///< CPU tick count for when HID module updated entry index 0 + s64 index_reset_ticks_previous; ///< Previous `index_reset_ticks` + u32 index; ///< Index of the last updated pad state entry - INSERT_PADDING_BYTES(0x8); + INSERT_PADDING_WORDS(0x2); - PadState current_state; // Same as entries[index].current_state - u32 raw_circle_pad_data; + PadState current_state; ///< Current state of the pad buttons - INSERT_PADDING_BYTES(0x4); + // TODO(bunnei): Implement `raw_circle_pad_data` field + u32 raw_circle_pad_data; ///< Raw (analog) circle pad data, before being converted - std::array entries; // Pad state history + INSERT_PADDING_WORDS(0x1); + + std::array entries; ///< Last 8 pad entries } pad; - // Touchpad data, this is used for touchpad input + /// Touchpad data, this is used for touchpad input struct { - s64 index_reset_ticks; - s64 index_reset_ticks_previous; - u32 index; // Index of the last updated touch state history element + s64 index_reset_ticks; ///< CPU tick count for when HID module updated entry index 0 + s64 index_reset_ticks_previous; ///< Previous `index_reset_ticks` + u32 index; ///< Index of the last updated touch entry + + INSERT_PADDING_WORDS(0x1); - INSERT_PADDING_BYTES(0xC); + // TODO(bunnei): Implement `raw_entry` field + TouchDataEntry raw_entry; ///< Raw (analog) touch data, before being converted - std::array entries; + std::array entries; ///< Last 8 touch entries, in pixel coordinates } touch; }; -- cgit v1.2.3 From e79c27f1e04031e08a14db9517fe6b06647c65b1 Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 9 Mar 2015 23:38:52 -0400 Subject: HID: Removed unnecessary global variables. --- src/core/hle/service/hid/hid.h | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/core/hle/service/hid/hid.h') diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 03971d3c7..0946cf660 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -18,16 +18,6 @@ namespace Kernel { namespace Service { namespace HID { -// Handle to shared memory region designated to HID_User service -extern Kernel::SharedPtr g_shared_mem; - -// Event handles -extern Kernel::SharedPtr g_event_pad_or_touch_1; -extern Kernel::SharedPtr g_event_pad_or_touch_2; -extern Kernel::SharedPtr g_event_accelerometer; -extern Kernel::SharedPtr g_event_gyroscope; -extern Kernel::SharedPtr g_event_debug_pad; - /** * Structure of a Pad controller state. */ -- cgit v1.2.3