diff options
author | Manna Harbour <51143715+manna-harbour@users.noreply.github.com> | 2020-04-09 18:29:27 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-09 01:29:27 -0700 |
commit | 07c75feba3f2c0b4baf1c230750483004e502020 (patch) | |
tree | b07e03f3463b06077e9bfbfe6170fa3c67a2a1bd | |
parent | b5aa5e4338750f6a7d969a30b2fe96f0f5382405 (diff) |
Add PS2_MOUSE_ROTATE to compensate for device orientation (#8650)
* Add PS2_MOUSE_ROTATE to compensate for device orientation
* fixup! Add PS2_MOUSE_ROTATE to compensate for device orientation
* Reformat with IndentPPDirectives: AfterHash as per #6316
-rw-r--r-- | docs/feature_ps2_mouse.md | 19 | ||||
-rw-r--r-- | tmk_core/protocol/ps2_mouse.c | 15 |
2 files changed, 34 insertions, 0 deletions
diff --git a/docs/feature_ps2_mouse.md b/docs/feature_ps2_mouse.md index ce072fbe93..c1bd8bff50 100644 --- a/docs/feature_ps2_mouse.md +++ b/docs/feature_ps2_mouse.md @@ -266,6 +266,25 @@ To reverse the scroll axes you can put: into config.h. +### Rotate Mouse Axes :id=rotate-mouse-axes + +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 90 /* Compensate for West-facing device orientation. */ +``` + ### 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 aa3a307ebf..a0e52bc7c3 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) { |