diff options
| author | Drashna Jaelre <drashna@live.com> | 2021-11-14 22:03:24 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-14 22:03:24 -0800 |
| commit | 56e3f06a26851976e559aacf7a096c61403304be (patch) | |
| tree | 1e9ec98ad239fdd241e77ac4c4822fc2721a9cea /quantum/pointing_device.c | |
| parent | 462c3a615113e84ac3ca837a5caeb928c0ec8505 (diff) | |
| download | qmk_firmware-56e3f06a26851976e559aacf7a096c61403304be.tar.gz qmk_firmware-56e3f06a26851976e559aacf7a096c61403304be.zip | |
Rework and expand Pointing Device support (#14343)
Co-authored-by: Dasky <32983009+daskygit@users.noreply.github.com>
Diffstat (limited to 'quantum/pointing_device.c')
| -rw-r--r-- | quantum/pointing_device.c | 123 |
1 files changed, 90 insertions, 33 deletions
diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c index 09d889f69..feeb2b316 100644 --- a/quantum/pointing_device.c +++ b/quantum/pointing_device.c | |||
| @@ -1,34 +1,56 @@ | |||
| 1 | /* | 1 | /* Copyright 2017 Joshua Broekhuijsen <snipeye+qmk@gmail.com> |
| 2 | Copyright 2017 Joshua Broekhuijsen <snipeye+qmk@gmail.com> | 2 | * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> |
| 3 | 3 | * Copyright 2021 Dasky (@daskygit) | |
| 4 | This program is free software: you can redistribute it and/or modify | 4 | * |
| 5 | it under the terms of the GNU General Public License as published by | 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | the Free Software Foundation, either version 2 of the License, or | 6 | * it under the terms of the GNU General Public License as published by |
| 7 | (at your option) any later version. | 7 | * the Free Software Foundation, either version 2 of the License, or |
| 8 | 8 | * (at your option) any later version. | |
| 9 | This program is distributed in the hope that it will be useful, | 9 | * |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | * This program is distributed in the hope that it will be useful, |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | GNU General Public License for more details. | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | 13 | * GNU General Public License for more details. | |
| 14 | You should have received a copy of the GNU General Public License | 14 | * |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 15 | * You should have received a copy of the GNU General Public License |
| 16 | */ | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | 17 | */ | |
| 18 | #include <stdint.h> | 18 | |
| 19 | #include "report.h" | ||
| 20 | #include "host.h" | ||
| 21 | #include "timer.h" | ||
| 22 | #include "print.h" | ||
| 23 | #include "debug.h" | ||
| 24 | #include "pointing_device.h" | 19 | #include "pointing_device.h" |
| 20 | #ifdef MOUSEKEY_ENABLE | ||
| 21 | # include "mousekey.h" | ||
| 22 | #endif | ||
| 23 | #if (defined(POINTING_DEVICE_ROTATION_90) + defined(POINTING_DEVICE_ROTATION_180) + defined(POINTING_DEVICE_ROTATION_270)) > 1 | ||
| 24 | # error More than one rotation selected. This is not supported. | ||
| 25 | #endif | ||
| 25 | 26 | ||
| 26 | static report_mouse_t mouseReport = {}; | 27 | static report_mouse_t mouseReport = {}; |
| 27 | 28 | ||
| 28 | __attribute__((weak)) bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old) { return (new.buttons != old.buttons) || (new.x&& new.x != old.x) || (new.y&& new.y != old.y) || (new.h&& new.h != old.h) || (new.v&& new.v != old.v); } | 29 | extern const pointing_device_driver_t pointing_device_driver; |
| 30 | |||
| 31 | __attribute__((weak)) bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old) { return memcmp(&new, &old, sizeof(new)); } | ||
| 32 | |||
| 33 | __attribute__((weak)) void pointing_device_init_kb(void) {} | ||
| 34 | __attribute__((weak)) void pointing_device_init_user(void) {} | ||
| 35 | __attribute__((weak)) report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { return pointing_device_task_user(mouse_report); } | ||
| 36 | __attribute__((weak)) report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { return mouse_report; } | ||
| 37 | |||
| 38 | __attribute__((weak)) uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button) { | ||
| 39 | if (pressed) { | ||
| 40 | buttons |= 1 << (button); | ||
| 41 | } else { | ||
| 42 | buttons &= ~(1 << (button)); | ||
| 43 | } | ||
| 44 | return buttons; | ||
| 45 | } | ||
| 29 | 46 | ||
| 30 | __attribute__((weak)) void pointing_device_init(void) { | 47 | __attribute__((weak)) void pointing_device_init(void) { |
| 31 | // initialize device, if that needs to be done. | 48 | pointing_device_driver.init(); |
| 49 | #ifdef POINTING_DEVICE_MOTION_PIN | ||
| 50 | setPinInputHigh(POINTING_DEVICE_MOTION_PIN); | ||
| 51 | #endif | ||
| 52 | pointing_device_init_kb(); | ||
| 53 | pointing_device_init_user(); | ||
| 32 | } | 54 | } |
| 33 | 55 | ||
| 34 | __attribute__((weak)) void pointing_device_send(void) { | 56 | __attribute__((weak)) void pointing_device_send(void) { |
| @@ -43,20 +65,55 @@ __attribute__((weak)) void pointing_device_send(void) { | |||
| 43 | mouseReport.y = 0; | 65 | mouseReport.y = 0; |
| 44 | mouseReport.v = 0; | 66 | mouseReport.v = 0; |
| 45 | mouseReport.h = 0; | 67 | mouseReport.h = 0; |
| 46 | old_report = mouseReport; | 68 | |
| 69 | memcpy(&old_report, &mouseReport, sizeof(mouseReport)); | ||
| 47 | } | 70 | } |
| 48 | 71 | ||
| 49 | __attribute__((weak)) void pointing_device_task(void) { | 72 | __attribute__((weak)) void pointing_device_task(void) { |
| 50 | // gather info and put it in: | 73 | // Gather report info |
| 51 | // mouseReport.x = 127 max -127 min | 74 | #ifdef POINTING_DEVICE_MOTION_PIN |
| 52 | // mouseReport.y = 127 max -127 min | 75 | if (!readPin(POINTING_DEVICE_MOTION_PIN)) |
| 53 | // mouseReport.v = 127 max -127 min (scroll vertical) | 76 | #endif |
| 54 | // mouseReport.h = 127 max -127 min (scroll horizontal) | 77 | mouseReport = pointing_device_driver.get_report(mouseReport); |
| 55 | // mouseReport.buttons = 0x1F (decimal 31, binary 00011111) max (bitmask for mouse buttons 1-5, 1 is rightmost, 5 is leftmost) 0x00 min | 78 | |
| 56 | // send the report | 79 | // Support rotation of the sensor data |
| 80 | #if defined(POINTING_DEVICE_ROTATION_90) || defined(POINTING_DEVICE_ROTATION_180) || defined(POINTING_DEVICE_ROTATION_270) | ||
| 81 | int8_t x = mouseReport.x, y = mouseReport.y; | ||
| 82 | # if defined(POINTING_DEVICE_ROTATION_90) | ||
| 83 | mouseReport.x = y; | ||
| 84 | mouseReport.y = -x; | ||
| 85 | # elif defined(POINTING_DEVICE_ROTATION_180) | ||
| 86 | mouseReport.x = -x; | ||
| 87 | mouseReport.y = -y; | ||
| 88 | # elif defined(POINTING_DEVICE_ROTATION_270) | ||
| 89 | mouseReport.x = -y; | ||
| 90 | mouseReport.y = x; | ||
| 91 | # else | ||
| 92 | # error "How the heck did you get here?!" | ||
| 93 | # endif | ||
| 94 | #endif | ||
| 95 | // Support Inverting the X and Y Axises | ||
| 96 | #if defined(POINTING_DEVICE_INVERT_X) | ||
| 97 | mouseReport.x = -mouseReport.x; | ||
| 98 | #endif | ||
| 99 | #if defined(POINTING_DEVICE_INVERT_Y) | ||
| 100 | mouseReport.y = -mouseReport.y; | ||
| 101 | #endif | ||
| 102 | |||
| 103 | // allow kb to intercept and modify report | ||
| 104 | mouseReport = pointing_device_task_kb(mouseReport); | ||
| 105 | // combine with mouse report to ensure that the combined is sent correctly | ||
| 106 | #ifdef MOUSEKEY_ENABLE | ||
| 107 | report_mouse_t mousekey_report = mousekey_get_report(); | ||
| 108 | mouseReport.buttons = mouseReport.buttons | mousekey_report.buttons; | ||
| 109 | #endif | ||
| 57 | pointing_device_send(); | 110 | pointing_device_send(); |
| 58 | } | 111 | } |
| 59 | 112 | ||
| 60 | report_mouse_t pointing_device_get_report(void) { return mouseReport; } | 113 | report_mouse_t pointing_device_get_report(void) { return mouseReport; } |
| 61 | 114 | ||
| 62 | void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = newMouseReport; } | 115 | void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = newMouseReport; } |
| 116 | |||
| 117 | uint16_t pointing_device_get_cpi(void) { return pointing_device_driver.get_cpi(); } | ||
| 118 | |||
| 119 | void pointing_device_set_cpi(uint16_t cpi) { pointing_device_driver.set_cpi(cpi); } | ||
