aboutsummaryrefslogtreecommitdiff
path: root/quantum/pointing_device.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/pointing_device.c')
-rw-r--r--quantum/pointing_device.c124
1 files changed, 91 insertions, 33 deletions
diff --git a/quantum/pointing_device.c b/quantum/pointing_device.c
index 09d889f69..2fefdb67b 100644
--- a/quantum/pointing_device.c
+++ b/quantum/pointing_device.c
@@ -1,34 +1,57 @@
1/* 1/* Copyright 2017 Joshua Broekhuijsen <snipeye+qmk@gmail.com>
2Copyright 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)
4This program is free software: you can redistribute it and/or modify 4 *
5it 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
6the 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.
9This program is distributed in the hope that it will be useful, 9 *
10but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * This program is distributed in the hope that it will be useful,
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12GNU 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.
14You should have received a copy of the GNU General Public License 14 *
15along 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#include <string.h>
21#ifdef MOUSEKEY_ENABLE
22# include "mousekey.h"
23#endif
24#if (defined(POINTING_DEVICE_ROTATION_90) + defined(POINTING_DEVICE_ROTATION_180) + defined(POINTING_DEVICE_ROTATION_270)) > 1
25# error More than one rotation selected. This is not supported.
26#endif
25 27
26static report_mouse_t mouseReport = {}; 28static report_mouse_t mouseReport = {};
27 29
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); } 30extern const pointing_device_driver_t pointing_device_driver;
31
32__attribute__((weak)) bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old) { return memcmp(&new, &old, sizeof(new)); }
33
34__attribute__((weak)) void pointing_device_init_kb(void) {}
35__attribute__((weak)) void pointing_device_init_user(void) {}
36__attribute__((weak)) report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { return pointing_device_task_user(mouse_report); }
37__attribute__((weak)) report_mouse_t pointing_device_task_user(report_mouse_t mouse_report) { return mouse_report; }
38
39__attribute__((weak)) uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button) {
40 if (pressed) {
41 buttons |= 1 << (button);
42 } else {
43 buttons &= ~(1 << (button));
44 }
45 return buttons;
46}
29 47
30__attribute__((weak)) void pointing_device_init(void) { 48__attribute__((weak)) void pointing_device_init(void) {
31 // initialize device, if that needs to be done. 49 pointing_device_driver.init();
50#ifdef POINTING_DEVICE_MOTION_PIN
51 setPinInputHigh(POINTING_DEVICE_MOTION_PIN);
52#endif
53 pointing_device_init_kb();
54 pointing_device_init_user();
32} 55}
33 56
34__attribute__((weak)) void pointing_device_send(void) { 57__attribute__((weak)) void pointing_device_send(void) {
@@ -43,20 +66,55 @@ __attribute__((weak)) void pointing_device_send(void) {
43 mouseReport.y = 0; 66 mouseReport.y = 0;
44 mouseReport.v = 0; 67 mouseReport.v = 0;
45 mouseReport.h = 0; 68 mouseReport.h = 0;
46 old_report = mouseReport; 69
70 memcpy(&old_report, &mouseReport, sizeof(mouseReport));
47} 71}
48 72
49__attribute__((weak)) void pointing_device_task(void) { 73__attribute__((weak)) void pointing_device_task(void) {
50 // gather info and put it in: 74 // Gather report info
51 // mouseReport.x = 127 max -127 min 75#ifdef POINTING_DEVICE_MOTION_PIN
52 // mouseReport.y = 127 max -127 min 76 if (!readPin(POINTING_DEVICE_MOTION_PIN))
53 // mouseReport.v = 127 max -127 min (scroll vertical) 77#endif
54 // mouseReport.h = 127 max -127 min (scroll horizontal) 78 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 79
56 // send the report 80 // Support rotation of the sensor data
81#if defined(POINTING_DEVICE_ROTATION_90) || defined(POINTING_DEVICE_ROTATION_180) || defined(POINTING_DEVICE_ROTATION_270)
82 int8_t x = mouseReport.x, y = mouseReport.y;
83# if defined(POINTING_DEVICE_ROTATION_90)
84 mouseReport.x = y;
85 mouseReport.y = -x;
86# elif defined(POINTING_DEVICE_ROTATION_180)
87 mouseReport.x = -x;
88 mouseReport.y = -y;
89# elif defined(POINTING_DEVICE_ROTATION_270)
90 mouseReport.x = -y;
91 mouseReport.y = x;
92# else
93# error "How the heck did you get here?!"
94# endif
95#endif
96 // Support Inverting the X and Y Axises
97#if defined(POINTING_DEVICE_INVERT_X)
98 mouseReport.x = -mouseReport.x;
99#endif
100#if defined(POINTING_DEVICE_INVERT_Y)
101 mouseReport.y = -mouseReport.y;
102#endif
103
104 // allow kb to intercept and modify report
105 mouseReport = pointing_device_task_kb(mouseReport);
106 // combine with mouse report to ensure that the combined is sent correctly
107#ifdef MOUSEKEY_ENABLE
108 report_mouse_t mousekey_report = mousekey_get_report();
109 mouseReport.buttons = mouseReport.buttons | mousekey_report.buttons;
110#endif
57 pointing_device_send(); 111 pointing_device_send();
58} 112}
59 113
60report_mouse_t pointing_device_get_report(void) { return mouseReport; } 114report_mouse_t pointing_device_get_report(void) { return mouseReport; }
61 115
62void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = newMouseReport; } 116void pointing_device_set_report(report_mouse_t newMouseReport) { mouseReport = newMouseReport; }
117
118uint16_t pointing_device_get_cpi(void) { return pointing_device_driver.get_cpi(); }
119
120void pointing_device_set_cpi(uint16_t cpi) { pointing_device_driver.set_cpi(cpi); }