Skip to content

Commit

Permalink
Add PS2_MOUSE_ROTATE to compensate for device orientation (qmk#8650)
Browse files Browse the repository at this point in the history
* 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 qmk#6316
  • Loading branch information
manna-harbour authored Apr 9, 2020
1 parent f369069 commit 06740f4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/feature_ps2_mouse.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions tmk_core/protocol/ps2_mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 06740f4

Please sign in to comment.