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 | |
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')
-rw-r--r-- | quantum/pointing_device.c | 123 | ||||
-rw-r--r-- | quantum/pointing_device.h | 59 | ||||
-rw-r--r-- | quantum/pointing_device_drivers.c | 262 | ||||
-rw-r--r-- | quantum/quantum.c | 4 | ||||
-rw-r--r-- | quantum/quantum.h | 4 |
5 files changed, 419 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); } | ||
diff --git a/quantum/pointing_device.h b/quantum/pointing_device.h index 56a542d54..5106c2666 100644 --- a/quantum/pointing_device.h +++ b/quantum/pointing_device.h | |||
@@ -21,9 +21,68 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
21 | #include "host.h" | 21 | #include "host.h" |
22 | #include "report.h" | 22 | #include "report.h" |
23 | 23 | ||
24 | #if defined(POINTING_DEVICE_DRIVER_adns5050) | ||
25 | # include "drivers/sensors/adns5050.h" | ||
26 | #elif defined(POINTING_DEVICE_DRIVER_adns9800) | ||
27 | # include "spi_master.h" | ||
28 | # include "drivers/sensors/adns9800.h" | ||
29 | #elif defined(POINTING_DEVICE_DRIVER_analog_joystick) | ||
30 | # include "analog.h" | ||
31 | # include "drivers/sensors/analog_joystick.h" | ||
32 | #elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi) | ||
33 | # include "drivers/sensors/cirque_pinnacle.h" | ||
34 | #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball) | ||
35 | # include "i2c_master.h" | ||
36 | # include "drivers/sensors/pimoroni_trackball.h" | ||
37 | // support for legacy pimoroni defines | ||
38 | # ifdef PIMORONI_TRACKBALL_INVERT_X | ||
39 | # define POINTING_DEVICE_INVERT_X | ||
40 | # endif | ||
41 | # ifdef PIMORONI_TRACKBALL_INVERT_Y | ||
42 | # define POINTING_DEVICE_INVERT_Y | ||
43 | # endif | ||
44 | # ifdef PIMORONI_TRACKBALL_ROTATE | ||
45 | # define POINTING_DEVICE_ROTATION_90 | ||
46 | # endif | ||
47 | #elif defined(POINTING_DEVICE_DRIVER_pmw3360) | ||
48 | # include "spi_master.h" | ||
49 | # include "drivers/sensors/pmw3360.h" | ||
50 | #else | ||
51 | void pointing_device_driver_init(void); | ||
52 | report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report); | ||
53 | uint16_t pointing_device_driver_get_cpi(void); | ||
54 | void pointing_device_driver_set_cpi(uint16_t cpi); | ||
55 | #endif | ||
56 | |||
57 | typedef struct { | ||
58 | void (*init)(void); | ||
59 | report_mouse_t (*get_report)(report_mouse_t mouse_report); | ||
60 | void (*set_cpi)(uint16_t); | ||
61 | uint16_t (*get_cpi)(void); | ||
62 | } pointing_device_driver_t; | ||
63 | |||
64 | typedef enum { | ||
65 | POINTING_DEVICE_BUTTON1, | ||
66 | POINTING_DEVICE_BUTTON2, | ||
67 | POINTING_DEVICE_BUTTON3, | ||
68 | POINTING_DEVICE_BUTTON4, | ||
69 | POINTING_DEVICE_BUTTON5, | ||
70 | POINTING_DEVICE_BUTTON6, | ||
71 | POINTING_DEVICE_BUTTON7, | ||
72 | POINTING_DEVICE_BUTTON8, | ||
73 | } pointing_device_buttons_t; | ||
74 | |||
24 | void pointing_device_init(void); | 75 | void pointing_device_init(void); |
25 | void pointing_device_task(void); | 76 | void pointing_device_task(void); |
26 | void pointing_device_send(void); | 77 | void pointing_device_send(void); |
27 | report_mouse_t pointing_device_get_report(void); | 78 | report_mouse_t pointing_device_get_report(void); |
28 | void pointing_device_set_report(report_mouse_t newMouseReport); | 79 | void pointing_device_set_report(report_mouse_t newMouseReport); |
29 | bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old); | 80 | bool has_mouse_report_changed(report_mouse_t new, report_mouse_t old); |
81 | uint16_t pointing_device_get_cpi(void); | ||
82 | void pointing_device_set_cpi(uint16_t cpi); | ||
83 | |||
84 | void pointing_device_init_kb(void); | ||
85 | void pointing_device_init_user(void); | ||
86 | report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report); | ||
87 | report_mouse_t pointing_device_task_user(report_mouse_t mouse_report); | ||
88 | uint8_t pointing_device_handle_buttons(uint8_t buttons, bool pressed, pointing_device_buttons_t button); | ||
diff --git a/quantum/pointing_device_drivers.c b/quantum/pointing_device_drivers.c new file mode 100644 index 000000000..9ad5e76ba --- /dev/null +++ b/quantum/pointing_device_drivers.c | |||
@@ -0,0 +1,262 @@ | |||
1 | /* Copyright 2017 Joshua Broekhuijsen <snipeye+qmk@gmail.com> | ||
2 | * Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> | ||
3 | * Copyright 2021 Dasky (@daskygit) | ||
4 | * | ||
5 | * This program is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation, either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | #include "pointing_device.h" | ||
20 | #include "debug.h" | ||
21 | #include "wait.h" | ||
22 | #include "timer.h" | ||
23 | #include <stddef.h> | ||
24 | |||
25 | // hid mouse reports cannot exceed -127 to 127, so constrain to that value | ||
26 | #define constrain_hid(amt) ((amt) < -127 ? -127 : ((amt) > 127 ? 127 : (amt))) | ||
27 | |||
28 | // get_report functions should probably be moved to their respective drivers. | ||
29 | #if defined(POINTING_DEVICE_DRIVER_adns5050) | ||
30 | report_mouse_t adns5050_get_report(report_mouse_t mouse_report) { | ||
31 | report_adns5050_t data = adns5050_read_burst(); | ||
32 | |||
33 | if (data.dx != 0 || data.dy != 0) { | ||
34 | # ifdef CONSOLE_ENABLE | ||
35 | if (debug_mouse) dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy); | ||
36 | # endif | ||
37 | |||
38 | mouse_report.x = data.dx; | ||
39 | mouse_report.y = data.dy; | ||
40 | } | ||
41 | |||
42 | return mouse_report; | ||
43 | } | ||
44 | |||
45 | // clang-format off | ||
46 | const pointing_device_driver_t pointing_device_driver = { | ||
47 | .init = adns5050_init, | ||
48 | .get_report = adns5050_get_report, | ||
49 | .set_cpi = adns5050_set_cpi, | ||
50 | .get_cpi = adns5050_get_cpi, | ||
51 | }; | ||
52 | // clang-format on | ||
53 | #elif defined(POINTING_DEVICE_DRIVER_adns9800) | ||
54 | |||
55 | report_mouse_t adns9800_get_report_driver(report_mouse_t mouse_report) { | ||
56 | report_adns9800_t sensor_report = adns9800_get_report(); | ||
57 | |||
58 | int8_t clamped_x = constrain_hid(sensor_report.x); | ||
59 | int8_t clamped_y = constrain_hid(sensor_report.y); | ||
60 | |||
61 | mouse_report.x = clamped_x; | ||
62 | mouse_report.y = clamped_y; | ||
63 | |||
64 | return mouse_report; | ||
65 | } | ||
66 | |||
67 | // clang-format off | ||
68 | const pointing_device_driver_t pointing_device_driver = { | ||
69 | .init = adns9800_init, | ||
70 | .get_report = adns9800_get_report_driver, | ||
71 | .set_cpi = adns9800_set_cpi, | ||
72 | .get_cpi = adns9800_get_cpi | ||
73 | }; | ||
74 | // clang-format on | ||
75 | #elif defined(POINTING_DEVICE_DRIVER_analog_joystick) | ||
76 | report_mouse_t analog_joystick_get_report(report_mouse_t mouse_report) { | ||
77 | report_analog_joystick_t data = analog_joystick_read(); | ||
78 | |||
79 | # ifdef CONSOLE_ENABLE | ||
80 | if (debug_mouse) dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y); | ||
81 | # endif | ||
82 | |||
83 | mouse_report.x = data.x; | ||
84 | mouse_report.y = data.y; | ||
85 | |||
86 | mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, data.button, POINTING_DEVICE_BUTTON1); | ||
87 | |||
88 | return mouse_report; | ||
89 | } | ||
90 | |||
91 | // clang-format off | ||
92 | const pointing_device_driver_t pointing_device_driver = { | ||
93 | .init = analog_joystick_init, | ||
94 | .get_report = analog_joystick_get_report, | ||
95 | .set_cpi = NULL, | ||
96 | .get_cpi = NULL | ||
97 | }; | ||
98 | // clang-format on | ||
99 | #elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi) | ||
100 | # ifndef CIRQUE_PINNACLE_TAPPING_TERM | ||
101 | # ifdef TAPPING_TERM_PER_KEY | ||
102 | # include "action.h" | ||
103 | # include "action_tapping.h" | ||
104 | # define CIRQUE_PINNACLE_TAPPING_TERM get_tapping_term(KC_BTN1, NULL) | ||
105 | # else | ||
106 | # ifdef TAPPING_TERM | ||
107 | # define CIRQUE_PINNACLE_TAPPING_TERM TAPPING_TERM | ||
108 | # else | ||
109 | # define CIRQUE_PINNACLE_TAPPING_TERM 200 | ||
110 | # endif | ||
111 | # endif | ||
112 | # endif | ||
113 | # ifndef CIRQUE_PINNACLE_TOUCH_DEBOUNCE | ||
114 | # define CIRQUE_PINNACLE_TOUCH_DEBOUNCE (CIRQUE_PINNACLE_TAPPING_TERM * 8) | ||
115 | # endif | ||
116 | |||
117 | report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) { | ||
118 | pinnacle_data_t touchData = cirque_pinnacle_read_data(); | ||
119 | static uint16_t x = 0, y = 0, mouse_timer = 0; | ||
120 | int8_t report_x = 0, report_y = 0; | ||
121 | static bool is_z_down = false; | ||
122 | |||
123 | cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale()); // Scale coordinates to arbitrary X, Y resolution | ||
124 | |||
125 | if (x && y && touchData.xValue && touchData.yValue) { | ||
126 | report_x = (int8_t)(touchData.xValue - x); | ||
127 | report_y = (int8_t)(touchData.yValue - y); | ||
128 | } | ||
129 | x = touchData.xValue; | ||
130 | y = touchData.yValue; | ||
131 | |||
132 | if ((bool)touchData.zValue != is_z_down) { | ||
133 | is_z_down = (bool)touchData.zValue; | ||
134 | if (!touchData.zValue) { | ||
135 | if (timer_elapsed(mouse_timer) < CIRQUE_PINNACLE_TAPPING_TERM && mouse_timer != 0) { | ||
136 | mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, true, POINTING_DEVICE_BUTTON1); | ||
137 | pointing_device_set_report(mouse_report); | ||
138 | pointing_device_send(); | ||
139 | # if TAP_CODE_DELAY > 0 | ||
140 | wait_ms(TAP_CODE_DELAY); | ||
141 | # endif | ||
142 | mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1); | ||
143 | pointing_device_set_report(mouse_report); | ||
144 | pointing_device_send(); | ||
145 | } | ||
146 | } | ||
147 | mouse_timer = timer_read(); | ||
148 | } | ||
149 | if (timer_elapsed(mouse_timer) > (CIRQUE_PINNACLE_TOUCH_DEBOUNCE)) { | ||
150 | mouse_timer = 0; | ||
151 | } | ||
152 | mouse_report.x = report_x; | ||
153 | mouse_report.y = report_y; | ||
154 | |||
155 | return mouse_report; | ||
156 | } | ||
157 | |||
158 | // clang-format off | ||
159 | const pointing_device_driver_t pointing_device_driver = { | ||
160 | .init = cirque_pinnacle_init, | ||
161 | .get_report = cirque_pinnacle_get_report, | ||
162 | .set_cpi = cirque_pinnacle_set_scale, | ||
163 | .get_cpi = cirque_pinnacle_get_scale | ||
164 | }; | ||
165 | // clang-format on | ||
166 | |||
167 | #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball) | ||
168 | report_mouse_t pimorono_trackball_get_report(report_mouse_t mouse_report) { | ||
169 | static fast_timer_t throttle = 0; | ||
170 | static uint16_t debounce = 0; | ||
171 | static uint8_t error_count = 0; | ||
172 | pimoroni_data_t pimoroni_data = {0}; | ||
173 | static int16_t x_offset = 0, y_offset = 0; | ||
174 | |||
175 | if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT && timer_elapsed_fast(throttle) >= PIMORONI_TRACKBALL_INTERVAL_MS) { | ||
176 | i2c_status_t status = read_pimoroni_trackball(&pimoroni_data); | ||
177 | |||
178 | if (status == I2C_STATUS_SUCCESS) { | ||
179 | error_count = 0; | ||
180 | |||
181 | if (!(pimoroni_data.click & 128)) { | ||
182 | mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1); | ||
183 | if (!debounce) { | ||
184 | x_offset += pimoroni_trackball_get_offsets(pimoroni_data.right, pimoroni_data.left, PIMORONI_TRACKBALL_SCALE); | ||
185 | y_offset += pimoroni_trackball_get_offsets(pimoroni_data.down, pimoroni_data.up, PIMORONI_TRACKBALL_SCALE); | ||
186 | pimoroni_trackball_adapt_values(&mouse_report.x, &x_offset); | ||
187 | pimoroni_trackball_adapt_values(&mouse_report.y, &y_offset); | ||
188 | } else { | ||
189 | debounce--; | ||
190 | } | ||
191 | } else { | ||
192 | mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, true, POINTING_DEVICE_BUTTON1); | ||
193 | debounce = PIMORONI_TRACKBALL_DEBOUNCE_CYCLES; | ||
194 | } | ||
195 | } else { | ||
196 | error_count++; | ||
197 | } | ||
198 | throttle = timer_read_fast(); | ||
199 | } | ||
200 | return mouse_report; | ||
201 | } | ||
202 | |||
203 | // clang-format off | ||
204 | const pointing_device_driver_t pointing_device_driver = { | ||
205 | .init = pimironi_trackball_device_init, | ||
206 | .get_report = pimorono_trackball_get_report, | ||
207 | .set_cpi = NULL, | ||
208 | .get_cpi = NULL | ||
209 | }; | ||
210 | // clang-format on | ||
211 | #elif defined(POINTING_DEVICE_DRIVER_pmw3360) | ||
212 | |||
213 | static void init(void) { pmw3360_init(); } | ||
214 | |||
215 | report_mouse_t pmw3360_get_report(report_mouse_t mouse_report) { | ||
216 | report_pmw3360_t data = pmw3360_read_burst(); | ||
217 | static uint16_t MotionStart = 0; // Timer for accel, 0 is resting state | ||
218 | |||
219 | if (data.isOnSurface && data.isMotion) { | ||
220 | // Reset timer if stopped moving | ||
221 | if (!data.isMotion) { | ||
222 | if (MotionStart != 0) MotionStart = 0; | ||
223 | return mouse_report; | ||
224 | } | ||
225 | |||
226 | // Set timer if new motion | ||
227 | if ((MotionStart == 0) && data.isMotion) { | ||
228 | # ifdef CONSOLE_ENABLE | ||
229 | if (debug_mouse) dprintf("Starting motion.\n"); | ||
230 | # endif | ||
231 | MotionStart = timer_read(); | ||
232 | } | ||
233 | mouse_report.x = constrain_hid(data.dx); | ||
234 | mouse_report.y = constrain_hid(data.dy); | ||
235 | } | ||
236 | |||
237 | return mouse_report; | ||
238 | } | ||
239 | |||
240 | // clang-format off | ||
241 | const pointing_device_driver_t pointing_device_driver = { | ||
242 | .init = init, | ||
243 | .get_report = pmw3360_get_report, | ||
244 | .set_cpi = pmw3360_set_cpi, | ||
245 | .get_cpi = pmw3360_get_cpi | ||
246 | }; | ||
247 | // clang-format on | ||
248 | #else | ||
249 | __attribute__((weak)) void pointing_device_driver_init(void) {} | ||
250 | __attribute__((weak)) report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) { return mouse_report; } | ||
251 | __attribute__((weak)) uint16_t pointing_device_driver_get_cpi(void) { return 0; } | ||
252 | __attribute__((weak)) void pointing_device_driver_set_cpi(uint16_t cpi) {} | ||
253 | |||
254 | // clang-format off | ||
255 | const pointing_device_driver_t pointing_device_driver = { | ||
256 | .init = pointing_device_driver_init, | ||
257 | .get_report = pointing_device_driver_get_report, | ||
258 | .get_cpi = pointing_device_driver_get_cpi, | ||
259 | .set_cpi = pointing_device_driver_set_cpi | ||
260 | }; | ||
261 | // clang-format on | ||
262 | #endif | ||
diff --git a/quantum/quantum.c b/quantum/quantum.c index 0eca329f0..c7a3bb197 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
@@ -531,6 +531,10 @@ void suspend_power_down_quantum(void) { | |||
531 | # ifdef ST7565_ENABLE | 531 | # ifdef ST7565_ENABLE |
532 | st7565_off(); | 532 | st7565_off(); |
533 | # endif | 533 | # endif |
534 | # if defined(POINTING_DEVICE_ENABLE) | ||
535 | // run to ensure scanning occurs while suspended | ||
536 | pointing_device_task(); | ||
537 | # endif | ||
534 | #endif | 538 | #endif |
535 | } | 539 | } |
536 | 540 | ||
diff --git a/quantum/quantum.h b/quantum/quantum.h index 9250f5acc..e6015adbe 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h | |||
@@ -204,6 +204,10 @@ extern layer_state_t layer_state; | |||
204 | # include "encoder.h" | 204 | # include "encoder.h" |
205 | #endif | 205 | #endif |
206 | 206 | ||
207 | #ifdef POINTING_DEVICE_ENABLE | ||
208 | # include "pointing_device.h" | ||
209 | #endif | ||
210 | |||
207 | // For tri-layer | 211 | // For tri-layer |
208 | void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); | 212 | void update_tri_layer(uint8_t layer1, uint8_t layer2, uint8_t layer3); |
209 | layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3); | 213 | layer_state_t update_tri_layer_state(layer_state_t state, uint8_t layer1, uint8_t layer2, uint8_t layer3); |