From 56e36e4935d0e14e75bf78052afe916d5573df9f Mon Sep 17 00:00:00 2001 From: Manna Harbour <51143715+manna-harbour@users.noreply.github.com> Date: Thu, 2 Apr 2020 10:31:04 +1100 Subject: [PATCH 1/3] Add PS2_MOUSE_ROTATE to compensate for device orientation --- docs/feature_ps2_mouse.md | 9 +++++++++ tmk_core/protocol/ps2_mouse.c | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index ce072fbe935e..2b0b49eb3936 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -266,6 +266,15 @@ To reverse the scroll axes you can put: into config.h. +### Rotate Mouse Axes :id=rotate-mouse-axes + +Rotate the X and Y axes by 90, 180, or 270 degrees to compensate for device +orientation: + +```c +#define PS2_MOUSE_ROTATE 270 /* trackpoint module rotated clockwise 90 degrees */ +``` + ### Debug Settings :id=debug-settings To debug the mouse, add `debug_mouse = true` or enable via bootmagic. diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c index aa3a307ebfab..6362af247601 100644 --- a/tmk_core/protocol/ps2_mouse.c +++ b/tmk_core/protocol/ps2_mouse.c @@ -157,6 +157,21 @@ static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report) // invert coordinate of y to conform to USB HID mouse mouse_report->y = -mouse_report->y; #endif + +#ifdef PS2_MOUSE_ROTATE + int8_t x = mouse_report->x; + int8_t y = mouse_report->y; +#if PS2_MOUSE_ROTATE == 90 + mouse_report->x = y; + mouse_report->y = -x; +#elif PS2_MOUSE_ROTATE == 180 + mouse_report->x = -x; + mouse_report->y = -y; +#elif PS2_MOUSE_ROTATE == 270 + mouse_report->x = -y; + mouse_report->y = x; +#endif +#endif } static inline void ps2_mouse_clear_report(report_mouse_t *mouse_report) { From 1ade0d3471c2aa5a971178c95e85b3f7913c187c Mon Sep 17 00:00:00 2001 From: Manna Harbour <51143715+manna-harbour@users.noreply.github.com> Date: Mon, 6 Apr 2020 10:46:19 +1000 Subject: [PATCH 2/3] fixup! Add PS2_MOUSE_ROTATE to compensate for device orientation --- docs/feature_ps2_mouse.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index 2b0b49eb3936..c1bd8bff50a8 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -268,11 +268,21 @@ into config.h. ### Rotate Mouse Axes :id=rotate-mouse-axes -Rotate the X and Y axes by 90, 180, or 270 degrees to compensate for device -orientation: +Transform the output of the device with a clockwise rotation of 90, 180, or 270 +degrees. +When compensating for device orientation, rotate the output the same amount in +the opposite direction. E.g. if the normal device orientation is considered to +be North-facing, compensate as follows: + +```c +#define PS2_MOUSE_ROTATE 270 /* Compensate for East-facing device orientation. */ +``` +```c +#define PS2_MOUSE_ROTATE 180 /* Compensate for South-facing device orientation. */ +``` ```c -#define PS2_MOUSE_ROTATE 270 /* trackpoint module rotated clockwise 90 degrees */ +#define PS2_MOUSE_ROTATE 90 /* Compensate for West-facing device orientation. */ ``` ### Debug Settings :id=debug-settings From bceaabc4146f1f03434f1c9bec4d676387f8530f Mon Sep 17 00:00:00 2001 From: Manna Harbour <51143715+manna-harbour@users.noreply.github.com> Date: Mon, 6 Apr 2020 12:16:32 +1000 Subject: [PATCH 3/3] Reformat with IndentPPDirectives: AfterHash as per #6316 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Konstantin Đorđević --- tmk_core/protocol/ps2_mouse.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tmk_core/protocol/ps2_mouse.c b/tmk_core/protocol/ps2_mouse.c index 6362af247601..a0e52bc7c3a5 100644 --- a/tmk_core/protocol/ps2_mouse.c +++ b/tmk_core/protocol/ps2_mouse.c @@ -161,16 +161,16 @@ static inline void ps2_mouse_convert_report_to_hid(report_mouse_t *mouse_report) #ifdef PS2_MOUSE_ROTATE int8_t x = mouse_report->x; int8_t y = mouse_report->y; -#if PS2_MOUSE_ROTATE == 90 +# if PS2_MOUSE_ROTATE == 90 mouse_report->x = y; mouse_report->y = -x; -#elif PS2_MOUSE_ROTATE == 180 +# elif PS2_MOUSE_ROTATE == 180 mouse_report->x = -x; mouse_report->y = -y; -#elif PS2_MOUSE_ROTATE == 270 +# elif PS2_MOUSE_ROTATE == 270 mouse_report->x = -y; mouse_report->y = x; -#endif +# endif #endif }