summaryrefslogtreecommitdiff
path: root/quantum
diff options
context:
space:
mode:
authorDasky <32983009+daskygit@users.noreply.github.com>2024-10-25 18:11:51 +0100
committerGitHub <noreply@github.com>2024-10-25 18:11:51 +0100
commitf5b495e06e257796a9be845f47bfc375fece81f8 (patch)
tree3772da6b18ad610df774269d3542c6fb660b812c /quantum
parent5c85271e48b4f2be7da47d1728ad1ddb95364ad7 (diff)
Move pointing device driver code (#24445)
Co-authored-by: Drashna Jaelre <drashna@live.com>
Diffstat (limited to 'quantum')
-rw-r--r--quantum/pointing_device/pointing_device.c41
-rw-r--r--quantum/pointing_device/pointing_device.h18
-rw-r--r--quantum/pointing_device/pointing_device_drivers.c514
-rw-r--r--quantum/split_common/transactions.c10
4 files changed, 46 insertions, 537 deletions
diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c
index 7d3be9e524..cac2875fc8 100644
--- a/quantum/pointing_device/pointing_device.c
+++ b/quantum/pointing_device/pointing_device.c
@@ -79,7 +79,28 @@ uint16_t pointing_device_get_shared_cpi(void) {
79static report_mouse_t local_mouse_report = {}; 79static report_mouse_t local_mouse_report = {};
80static bool pointing_device_force_send = false; 80static bool pointing_device_force_send = false;
81 81
82extern const pointing_device_driver_t pointing_device_driver; 82#define POINTING_DEVICE_DRIVER_CONCAT(name) name##_pointing_device_driver
83#define POINTING_DEVICE_DRIVER(name) POINTING_DEVICE_DRIVER_CONCAT(name)
84
85#ifdef POINTING_DEVICE_DRIVER_custom
86__attribute__((weak)) void pointing_device_driver_init(void) {}
87__attribute__((weak)) report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) {
88 return mouse_report;
89}
90__attribute__((weak)) uint16_t pointing_device_driver_get_cpi(void) {
91 return 0;
92}
93__attribute__((weak)) void pointing_device_driver_set_cpi(uint16_t cpi) {}
94
95const pointing_device_driver_t custom_pointing_device_driver = {
96 .init = pointing_device_driver_init,
97 .get_report = pointing_device_driver_get_report,
98 .get_cpi = pointing_device_driver_get_cpi,
99 .set_cpi = pointing_device_driver_set_cpi,
100};
101#endif
102
103const pointing_device_driver_t *pointing_device_driver = &POINTING_DEVICE_DRIVER(POINTING_DEVICE_DRIVER_NAME);
83 104
84/** 105/**
85 * @brief Keyboard level code pointing device initialisation 106 * @brief Keyboard level code pointing device initialisation
@@ -146,7 +167,7 @@ __attribute__((weak)) void pointing_device_init(void) {
146 if ((POINTING_DEVICE_THIS_SIDE)) 167 if ((POINTING_DEVICE_THIS_SIDE))
147#endif 168#endif
148 { 169 {
149 pointing_device_driver.init(); 170 pointing_device_driver->init();
150#ifdef POINTING_DEVICE_MOTION_PIN 171#ifdef POINTING_DEVICE_MOTION_PIN
151# ifdef POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW 172# ifdef POINTING_DEVICE_MOTION_PIN_ACTIVE_LOW
152 gpio_set_pin_input_high(POINTING_DEVICE_MOTION_PIN); 173 gpio_set_pin_input_high(POINTING_DEVICE_MOTION_PIN);
@@ -258,15 +279,15 @@ __attribute__((weak)) bool pointing_device_task(void) {
258# if defined(POINTING_DEVICE_COMBINED) 279# if defined(POINTING_DEVICE_COMBINED)
259 static uint8_t old_buttons = 0; 280 static uint8_t old_buttons = 0;
260 local_mouse_report.buttons = old_buttons; 281 local_mouse_report.buttons = old_buttons;
261 local_mouse_report = pointing_device_driver.get_report(local_mouse_report); 282 local_mouse_report = pointing_device_driver->get_report(local_mouse_report);
262 old_buttons = local_mouse_report.buttons; 283 old_buttons = local_mouse_report.buttons;
263# elif defined(POINTING_DEVICE_LEFT) || defined(POINTING_DEVICE_RIGHT) 284# elif defined(POINTING_DEVICE_LEFT) || defined(POINTING_DEVICE_RIGHT)
264 local_mouse_report = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_report(local_mouse_report) : shared_mouse_report; 285 local_mouse_report = POINTING_DEVICE_THIS_SIDE ? pointing_device_driver->get_report(local_mouse_report) : shared_mouse_report;
265# else 286# else
266# error "You need to define the side(s) the pointing device is on. POINTING_DEVICE_COMBINED / POINTING_DEVICE_LEFT / POINTING_DEVICE_RIGHT" 287# error "You need to define the side(s) the pointing device is on. POINTING_DEVICE_COMBINED / POINTING_DEVICE_LEFT / POINTING_DEVICE_RIGHT"
267# endif 288# endif
268#else 289#else
269 local_mouse_report = pointing_device_driver.get_report(local_mouse_report); 290 local_mouse_report = pointing_device_driver->get_report(local_mouse_report);
270#endif // defined(SPLIT_POINTING_ENABLE) 291#endif // defined(SPLIT_POINTING_ENABLE)
271 292
272#ifdef POINTING_DEVICE_MOTION_PIN 293#ifdef POINTING_DEVICE_MOTION_PIN
@@ -331,9 +352,9 @@ void pointing_device_set_report(report_mouse_t mouse_report) {
331 */ 352 */
332uint16_t pointing_device_get_cpi(void) { 353uint16_t pointing_device_get_cpi(void) {
333#if defined(SPLIT_POINTING_ENABLE) 354#if defined(SPLIT_POINTING_ENABLE)
334 return POINTING_DEVICE_THIS_SIDE ? pointing_device_driver.get_cpi() : shared_cpi; 355 return POINTING_DEVICE_THIS_SIDE ? pointing_device_driver->get_cpi() : shared_cpi;
335#else 356#else
336 return pointing_device_driver.get_cpi(); 357 return pointing_device_driver->get_cpi();
337#endif 358#endif
338} 359}
339 360
@@ -347,12 +368,12 @@ uint16_t pointing_device_get_cpi(void) {
347void pointing_device_set_cpi(uint16_t cpi) { 368void pointing_device_set_cpi(uint16_t cpi) {
348#if defined(SPLIT_POINTING_ENABLE) 369#if defined(SPLIT_POINTING_ENABLE)
349 if (POINTING_DEVICE_THIS_SIDE) { 370 if (POINTING_DEVICE_THIS_SIDE) {
350 pointing_device_driver.set_cpi(cpi); 371 pointing_device_driver->set_cpi(cpi);
351 } else { 372 } else {
352 shared_cpi = cpi; 373 shared_cpi = cpi;
353 } 374 }
354#else 375#else
355 pointing_device_driver.set_cpi(cpi); 376 pointing_device_driver->set_cpi(cpi);
356#endif 377#endif
357} 378}
358 379
@@ -370,7 +391,7 @@ void pointing_device_set_cpi(uint16_t cpi) {
370void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { 391void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) {
371 bool local = (is_keyboard_left() == left); 392 bool local = (is_keyboard_left() == left);
372 if (local) { 393 if (local) {
373 pointing_device_driver.set_cpi(cpi); 394 pointing_device_driver->set_cpi(cpi);
374 } else { 395 } else {
375 shared_cpi = cpi; 396 shared_cpi = cpi;
376 } 397 }
diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h
index b0f8533d6d..72188c977d 100644
--- a/quantum/pointing_device/pointing_device.h
+++ b/quantum/pointing_device/pointing_device.h
@@ -21,6 +21,13 @@ 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
24typedef struct {
25 void (*init)(void);
26 report_mouse_t (*get_report)(report_mouse_t mouse_report);
27 void (*set_cpi)(uint16_t);
28 uint16_t (*get_cpi)(void);
29} pointing_device_driver_t;
30
24#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE 31#ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
25# include "pointing_device_auto_mouse.h" 32# include "pointing_device_auto_mouse.h"
26#endif 33#endif
@@ -44,7 +51,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
44# include "drivers/sensors/azoteq_iqs5xx.h" 51# include "drivers/sensors/azoteq_iqs5xx.h"
45#elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi) 52#elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
46# include "drivers/sensors/cirque_pinnacle.h" 53# include "drivers/sensors/cirque_pinnacle.h"
47# include "drivers/sensors/cirque_pinnacle_gestures.h"
48# include "pointing_device_gestures.h" 54# include "pointing_device_gestures.h"
49#elif defined(POINTING_DEVICE_DRIVER_paw3204) 55#elif defined(POINTING_DEVICE_DRIVER_paw3204)
50# include "drivers/sensors/paw3204.h" 56# include "drivers/sensors/paw3204.h"
@@ -74,13 +80,6 @@ uint16_t pointing_device_driver_get_cpi(void);
74void pointing_device_driver_set_cpi(uint16_t cpi); 80void pointing_device_driver_set_cpi(uint16_t cpi);
75#endif 81#endif
76 82
77typedef struct {
78 void (*init)(void);
79 report_mouse_t (*get_report)(report_mouse_t mouse_report);
80 void (*set_cpi)(uint16_t);
81 uint16_t (*get_cpi)(void);
82} pointing_device_driver_t;
83
84typedef enum { 83typedef enum {
85 POINTING_DEVICE_BUTTON1, 84 POINTING_DEVICE_BUTTON1,
86 POINTING_DEVICE_BUTTON2, 85 POINTING_DEVICE_BUTTON2,
@@ -112,6 +111,9 @@ typedef int32_t hv_clamp_range_t;
112typedef int16_t hv_clamp_range_t; 111typedef int16_t hv_clamp_range_t;
113#endif 112#endif
114 113
114#define CONSTRAIN_HID(amt) ((amt) < INT8_MIN ? INT8_MIN : ((amt) > INT8_MAX ? INT8_MAX : (amt)))
115#define CONSTRAIN_HID_XY(amt) ((amt) < XY_REPORT_MIN ? XY_REPORT_MIN : ((amt) > XY_REPORT_MAX ? XY_REPORT_MAX : (amt)))
116
115void pointing_device_init(void); 117void pointing_device_init(void);
116bool pointing_device_task(void); 118bool pointing_device_task(void);
117bool pointing_device_send(void); 119bool pointing_device_send(void);
diff --git a/quantum/pointing_device/pointing_device_drivers.c b/quantum/pointing_device/pointing_device_drivers.c
deleted file mode 100644
index 6cbe427401..0000000000
--- a/quantum/pointing_device/pointing_device_drivers.c
+++ /dev/null
@@ -1,514 +0,0 @@
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 "pointing_device_internal.h"
21#include "debug.h"
22#include "wait.h"
23#include "timer.h"
24#include <stddef.h>
25
26#define CONSTRAIN_HID(amt) ((amt) < INT8_MIN ? INT8_MIN : ((amt) > INT8_MAX ? INT8_MAX : (amt)))
27#define CONSTRAIN_HID_XY(amt) ((amt) < XY_REPORT_MIN ? XY_REPORT_MIN : ((amt) > XY_REPORT_MAX ? XY_REPORT_MAX : (amt)))
28
29// get_report functions should probably be moved to their respective drivers.
30
31#if defined(POINTING_DEVICE_DRIVER_adns5050)
32report_mouse_t adns5050_get_report(report_mouse_t mouse_report) {
33 report_adns5050_t data = adns5050_read_burst();
34
35 if (data.dx != 0 || data.dy != 0) {
36 pd_dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
37 mouse_report.x = (mouse_xy_report_t)data.dx;
38 mouse_report.y = (mouse_xy_report_t)data.dy;
39 }
40
41 return mouse_report;
42}
43
44// clang-format off
45const pointing_device_driver_t pointing_device_driver = {
46 .init = adns5050_init,
47 .get_report = adns5050_get_report,
48 .set_cpi = adns5050_set_cpi,
49 .get_cpi = adns5050_get_cpi,
50};
51// clang-format on
52
53#elif defined(POINTING_DEVICE_DRIVER_pmw3320)
54report_mouse_t pmw3320_get_report(report_mouse_t mouse_report) {
55 report_pmw3320_t data = pmw3320_read_burst();
56
57 if (data.dx != 0 || data.dy != 0) {
58 pd_dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
59 mouse_report.x = (mouse_xy_report_t)data.dx;
60 mouse_report.y = (mouse_xy_report_t)data.dy;
61 }
62
63 return mouse_report;
64}
65
66// clang-format off
67const pointing_device_driver_t pointing_device_driver = {
68 .init = pmw3320_init,
69 .get_report = pmw3320_get_report,
70 .set_cpi = pmw3320_set_cpi,
71 .get_cpi = pmw3320_get_cpi,
72};
73// clang-format on
74
75#elif defined(POINTING_DEVICE_DRIVER_adns9800)
76
77report_mouse_t adns9800_get_report_driver(report_mouse_t mouse_report) {
78 report_adns9800_t sensor_report = adns9800_get_report();
79
80 mouse_report.x = CONSTRAIN_HID_XY(sensor_report.x);
81 mouse_report.y = CONSTRAIN_HID_XY(sensor_report.y);
82
83 return mouse_report;
84}
85
86// clang-format off
87const pointing_device_driver_t pointing_device_driver = {
88 .init = adns9800_init,
89 .get_report = adns9800_get_report_driver,
90 .set_cpi = adns9800_set_cpi,
91 .get_cpi = adns9800_get_cpi
92};
93// clang-format on
94
95#elif defined(POINTING_DEVICE_DRIVER_analog_joystick)
96report_mouse_t analog_joystick_get_report(report_mouse_t mouse_report) {
97 report_analog_joystick_t data = analog_joystick_read();
98
99 pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y);
100
101 mouse_report.x = data.x;
102 mouse_report.y = data.y;
103
104 mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, data.button, POINTING_DEVICE_BUTTON1);
105
106 return mouse_report;
107}
108
109// clang-format off
110const pointing_device_driver_t pointing_device_driver = {
111 .init = analog_joystick_init,
112 .get_report = analog_joystick_get_report,
113 .set_cpi = NULL,
114 .get_cpi = NULL
115};
116// clang-format on
117
118#elif defined(POINTING_DEVICE_DRIVER_azoteq_iqs5xx)
119
120static i2c_status_t azoteq_iqs5xx_init_status = 1;
121
122void azoteq_iqs5xx_init(void) {
123 i2c_init();
124 azoteq_iqs5xx_wake();
125 azoteq_iqs5xx_reset_suspend(true, false, true);
126 wait_ms(100);
127 azoteq_iqs5xx_wake();
128 if (azoteq_iqs5xx_get_product() != AZOTEQ_IQS5XX_UNKNOWN) {
129 azoteq_iqs5xx_setup_resolution();
130 azoteq_iqs5xx_init_status = azoteq_iqs5xx_set_report_rate(AZOTEQ_IQS5XX_REPORT_RATE, AZOTEQ_IQS5XX_ACTIVE, false);
131 azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_event_mode(false, false);
132 azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_reati(true, false);
133# if defined(AZOTEQ_IQS5XX_ROTATION_90)
134 azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(false, true, true, true, false);
135# elif defined(AZOTEQ_IQS5XX_ROTATION_180)
136 azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(true, true, false, true, false);
137# elif defined(AZOTEQ_IQS5XX_ROTATION_270)
138 azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(true, false, true, true, false);
139# else
140 azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_xy_config(false, false, false, true, false);
141# endif
142 azoteq_iqs5xx_init_status |= azoteq_iqs5xx_set_gesture_config(true);
143 wait_ms(AZOTEQ_IQS5XX_REPORT_RATE + 1);
144 }
145};
146
147report_mouse_t azoteq_iqs5xx_get_report(report_mouse_t mouse_report) {
148 report_mouse_t temp_report = {0};
149 static uint8_t previous_button_state = 0;
150 static uint8_t read_error_count = 0;
151
152 if (azoteq_iqs5xx_init_status == I2C_STATUS_SUCCESS) {
153 azoteq_iqs5xx_base_data_t base_data = {0};
154# if !defined(POINTING_DEVICE_MOTION_PIN)
155 azoteq_iqs5xx_wake();
156# endif
157 i2c_status_t status = azoteq_iqs5xx_get_base_data(&base_data);
158 bool ignore_movement = false;
159
160 if (status == I2C_STATUS_SUCCESS) {
161 // pd_dprintf("IQS5XX - previous cycle time: %d \n", base_data.previous_cycle_time);
162 read_error_count = 0;
163 if (base_data.gesture_events_0.single_tap || base_data.gesture_events_0.press_and_hold) {
164 pd_dprintf("IQS5XX - Single tap/hold.\n");
165 temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON1);
166 } else if (base_data.gesture_events_1.two_finger_tap) {
167 pd_dprintf("IQS5XX - Two finger tap.\n");
168 temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON2);
169 } else if (base_data.gesture_events_0.swipe_x_neg) {
170 pd_dprintf("IQS5XX - X-.\n");
171 temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON4);
172 ignore_movement = true;
173 } else if (base_data.gesture_events_0.swipe_x_pos) {
174 pd_dprintf("IQS5XX - X+.\n");
175 temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON5);
176 ignore_movement = true;
177 } else if (base_data.gesture_events_0.swipe_y_neg) {
178 pd_dprintf("IQS5XX - Y-.\n");
179 temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON6);
180 ignore_movement = true;
181 } else if (base_data.gesture_events_0.swipe_y_pos) {
182 pd_dprintf("IQS5XX - Y+.\n");
183 temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON3);
184 ignore_movement = true;
185 } else if (base_data.gesture_events_1.zoom) {
186 if (AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l) < 0) {
187 pd_dprintf("IQS5XX - Zoom out.\n");
188 temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON7);
189 } else if (AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l) > 0) {
190 pd_dprintf("IQS5XX - Zoom in.\n");
191 temp_report.buttons = pointing_device_handle_buttons(temp_report.buttons, true, POINTING_DEVICE_BUTTON8);
192 }
193 } else if (base_data.gesture_events_1.scroll) {
194 pd_dprintf("IQS5XX - Scroll.\n");
195 temp_report.h = CONSTRAIN_HID(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l));
196 temp_report.v = CONSTRAIN_HID(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.y.h, base_data.y.l));
197 }
198 if (base_data.number_of_fingers == 1 && !ignore_movement) {
199 temp_report.x = CONSTRAIN_HID_XY(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.x.h, base_data.x.l));
200 temp_report.y = CONSTRAIN_HID_XY(AZOTEQ_IQS5XX_COMBINE_H_L_BYTES(base_data.y.h, base_data.y.l));
201 }
202
203 previous_button_state = temp_report.buttons;
204
205 } else {
206 if (read_error_count > 10) {
207 read_error_count = 0;
208 previous_button_state = 0;
209 } else {
210 read_error_count++;
211 }
212 temp_report.buttons = previous_button_state;
213 pd_dprintf("IQS5XX - get report failed: %d \n", status);
214 }
215 } else {
216 pd_dprintf("IQS5XX - Init failed: %d \n", azoteq_iqs5xx_init_status);
217 }
218
219 return temp_report;
220}
221
222// clang-format off
223const pointing_device_driver_t pointing_device_driver = {
224 .init = azoteq_iqs5xx_init,
225 .get_report = azoteq_iqs5xx_get_report,
226 .set_cpi = azoteq_iqs5xx_set_cpi,
227 .get_cpi = azoteq_iqs5xx_get_cpi
228};
229// clang-format on
230
231#elif defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_i2c) || defined(POINTING_DEVICE_DRIVER_cirque_pinnacle_spi)
232# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
233static bool cursor_glide_enable = true;
234
235static cursor_glide_context_t glide = {.config = {
236 .coef = 102, /* Good default friction coef */
237 .interval = 10, /* 100sps */
238 .trigger_px = 10, /* Default threshold in case of hover, set to 0 if you'd like */
239 }};
240
241void cirque_pinnacle_enable_cursor_glide(bool enable) {
242 cursor_glide_enable = enable;
243}
244
245void cirque_pinnacle_configure_cursor_glide(float trigger_px) {
246 glide.config.trigger_px = trigger_px;
247}
248# endif
249
250# if CIRQUE_PINNACLE_POSITION_MODE
251
252# ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
253static bool is_touch_down;
254
255bool auto_mouse_activation(report_mouse_t mouse_report) {
256 return is_touch_down || mouse_report.x != 0 || mouse_report.y != 0 || mouse_report.h != 0 || mouse_report.v != 0 || mouse_report.buttons;
257}
258# endif
259
260report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
261 uint16_t scale = cirque_pinnacle_get_scale();
262 pinnacle_data_t touchData = cirque_pinnacle_read_data();
263 mouse_xy_report_t report_x = 0, report_y = 0;
264 static uint16_t x = 0, y = 0, last_scale = 0;
265
266# if defined(CIRQUE_PINNACLE_TAP_ENABLE)
267 mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1);
268# endif
269# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
270 cursor_glide_t glide_report = {0};
271
272 if (cursor_glide_enable) {
273 glide_report = cursor_glide_check(&glide);
274 }
275# endif
276
277 if (!touchData.valid) {
278# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
279 if (cursor_glide_enable && glide_report.valid) {
280 report_x = glide_report.dx;
281 report_y = glide_report.dy;
282 goto mouse_report_update;
283 }
284# endif
285 return mouse_report;
286 }
287
288 if (touchData.touchDown) {
289 pd_dprintf("cirque_pinnacle touchData x=%4d y=%4d z=%2d\n", touchData.xValue, touchData.yValue, touchData.zValue);
290 }
291
292# ifdef POINTING_DEVICE_AUTO_MOUSE_ENABLE
293 is_touch_down = touchData.touchDown;
294# endif
295
296 // Scale coordinates to arbitrary X, Y resolution
297 cirque_pinnacle_scale_data(&touchData, scale, scale);
298
299 if (!cirque_pinnacle_gestures(&mouse_report, touchData)) {
300 if (last_scale && scale == last_scale && x && y && touchData.xValue && touchData.yValue) {
301 report_x = CONSTRAIN_HID_XY((int16_t)(touchData.xValue - x));
302 report_y = CONSTRAIN_HID_XY((int16_t)(touchData.yValue - y));
303 }
304 x = touchData.xValue;
305 y = touchData.yValue;
306 last_scale = scale;
307
308# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
309 if (cursor_glide_enable) {
310 if (touchData.touchDown) {
311 cursor_glide_update(&glide, report_x, report_y, touchData.zValue);
312 } else if (!glide_report.valid) {
313 glide_report = cursor_glide_start(&glide);
314 if (glide_report.valid) {
315 report_x = glide_report.dx;
316 report_y = glide_report.dy;
317 }
318 }
319 }
320# endif
321 }
322
323# ifdef POINTING_DEVICE_GESTURES_CURSOR_GLIDE_ENABLE
324mouse_report_update:
325# endif
326 mouse_report.x = report_x;
327 mouse_report.y = report_y;
328
329 return mouse_report;
330}
331
332uint16_t cirque_pinnacle_get_cpi(void) {
333 return CIRQUE_PINNACLE_PX_TO_INCH(cirque_pinnacle_get_scale());
334}
335void cirque_pinnacle_set_cpi(uint16_t cpi) {
336 cirque_pinnacle_set_scale(CIRQUE_PINNACLE_INCH_TO_PX(cpi));
337}
338
339// clang-format off
340const pointing_device_driver_t pointing_device_driver = {
341 .init = cirque_pinnacle_init,
342 .get_report = cirque_pinnacle_get_report,
343 .set_cpi = cirque_pinnacle_set_cpi,
344 .get_cpi = cirque_pinnacle_get_cpi
345};
346// clang-format on
347# else
348report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
349 pinnacle_data_t touchData = cirque_pinnacle_read_data();
350
351 // Scale coordinates to arbitrary X, Y resolution
352 cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale());
353
354 if (touchData.valid) {
355 mouse_report.buttons = touchData.buttons;
356 mouse_report.x = CONSTRAIN_HID_XY(touchData.xDelta);
357 mouse_report.y = CONSTRAIN_HID_XY(touchData.yDelta);
358 mouse_report.v = touchData.wheelCount;
359 }
360 return mouse_report;
361}
362
363// clang-format off
364const pointing_device_driver_t pointing_device_driver = {
365 .init = cirque_pinnacle_init,
366 .get_report = cirque_pinnacle_get_report,
367 .set_cpi = cirque_pinnacle_set_scale,
368 .get_cpi = cirque_pinnacle_get_scale
369};
370// clang-format on
371# endif
372
373#elif defined(POINTING_DEVICE_DRIVER_paw3204)
374
375report_mouse_t paw3204_get_report(report_mouse_t mouse_report) {
376 report_paw3204_t data = paw3204_read();
377 if (data.isMotion) {
378 pd_dprintf("Raw ] X: %d, Y: %d\n", data.x, data.y);
379
380 mouse_report.x = data.x;
381 mouse_report.y = data.y;
382 }
383
384 return mouse_report;
385}
386const pointing_device_driver_t pointing_device_driver = {
387 .init = paw3204_init,
388 .get_report = paw3204_get_report,
389 .set_cpi = paw3204_set_cpi,
390 .get_cpi = paw3204_get_cpi,
391};
392#elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball)
393
394mouse_xy_report_t pimoroni_trackball_adapt_values(xy_clamp_range_t* offset) {
395 if (*offset > XY_REPORT_MAX) {
396 *offset -= XY_REPORT_MAX;
397 return (mouse_xy_report_t)XY_REPORT_MAX;
398 } else if (*offset < XY_REPORT_MIN) {
399 *offset += XY_REPORT_MAX;
400 return (mouse_xy_report_t)XY_REPORT_MIN;
401 } else {
402 mouse_xy_report_t temp_return = *offset;
403 *offset = 0;
404 return temp_return;
405 }
406}
407
408report_mouse_t pimoroni_trackball_get_report(report_mouse_t mouse_report) {
409 static uint16_t debounce = 0;
410 static uint8_t error_count = 0;
411 pimoroni_data_t pimoroni_data = {0};
412 static xy_clamp_range_t x_offset = 0, y_offset = 0;
413
414 if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT) {
415 i2c_status_t status = read_pimoroni_trackball(&pimoroni_data);
416
417 if (status == I2C_STATUS_SUCCESS) {
418 error_count = 0;
419
420 if (!(pimoroni_data.click & 128)) {
421 mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, false, POINTING_DEVICE_BUTTON1);
422 if (!debounce) {
423 x_offset += pimoroni_trackball_get_offsets(pimoroni_data.right, pimoroni_data.left, PIMORONI_TRACKBALL_SCALE);
424 y_offset += pimoroni_trackball_get_offsets(pimoroni_data.down, pimoroni_data.up, PIMORONI_TRACKBALL_SCALE);
425 mouse_report.x = pimoroni_trackball_adapt_values(&x_offset);
426 mouse_report.y = pimoroni_trackball_adapt_values(&y_offset);
427 } else {
428 debounce--;
429 }
430 } else {
431 mouse_report.buttons = pointing_device_handle_buttons(mouse_report.buttons, true, POINTING_DEVICE_BUTTON1);
432 debounce = PIMORONI_TRACKBALL_DEBOUNCE_CYCLES;
433 }
434 } else {
435 error_count++;
436 }
437 }
438 return mouse_report;
439}
440
441// clang-format off
442const pointing_device_driver_t pointing_device_driver = {
443 .init = pimoroni_trackball_device_init,
444 .get_report = pimoroni_trackball_get_report,
445 .set_cpi = pimoroni_trackball_set_cpi,
446 .get_cpi = pimoroni_trackball_get_cpi
447};
448// clang-format on
449
450#elif defined(POINTING_DEVICE_DRIVER_pmw3360) || defined(POINTING_DEVICE_DRIVER_pmw3389)
451static void pmw33xx_init_wrapper(void) {
452 pmw33xx_init(0);
453}
454
455static void pmw33xx_set_cpi_wrapper(uint16_t cpi) {
456 pmw33xx_set_cpi(0, cpi);
457}
458
459static uint16_t pmw33xx_get_cpi_wrapper(void) {
460 return pmw33xx_get_cpi(0);
461}
462
463report_mouse_t pmw33xx_get_report(report_mouse_t mouse_report) {
464 pmw33xx_report_t report = pmw33xx_read_burst(0);
465 static bool in_motion = false;
466
467 if (report.motion.b.is_lifted) {
468 return mouse_report;
469 }
470
471 if (!report.motion.b.is_motion) {
472 in_motion = false;
473 return mouse_report;
474 }
475
476 if (!in_motion) {
477 in_motion = true;
478 pd_dprintf("PWM3360 (0): starting motion\n");
479 }
480
481 mouse_report.x = CONSTRAIN_HID_XY(report.delta_x);
482 mouse_report.y = CONSTRAIN_HID_XY(report.delta_y);
483 return mouse_report;
484}
485
486// clang-format off
487const pointing_device_driver_t pointing_device_driver = {
488 .init = pmw33xx_init_wrapper,
489 .get_report = pmw33xx_get_report,
490 .set_cpi = pmw33xx_set_cpi_wrapper,
491 .get_cpi = pmw33xx_get_cpi_wrapper
492};
493// clang-format on
494
495#else
496__attribute__((weak)) void pointing_device_driver_init(void) {}
497__attribute__((weak)) report_mouse_t pointing_device_driver_get_report(report_mouse_t mouse_report) {
498 return mouse_report;
499}
500__attribute__((weak)) uint16_t pointing_device_driver_get_cpi(void) {
501 return 0;
502}
503__attribute__((weak)) void pointing_device_driver_set_cpi(uint16_t cpi) {}
504
505// clang-format off
506const pointing_device_driver_t pointing_device_driver = {
507 .init = pointing_device_driver_init,
508 .get_report = pointing_device_driver_get_report,
509 .get_cpi = pointing_device_driver_get_cpi,
510 .set_cpi = pointing_device_driver_set_cpi
511};
512// clang-format on
513
514#endif
diff --git a/quantum/split_common/transactions.c b/quantum/split_common/transactions.c
index 6c1aeb284d..f66b2ad89f 100644
--- a/quantum/split_common/transactions.c
+++ b/quantum/split_common/transactions.c
@@ -733,7 +733,7 @@ static bool pointing_handlers_master(matrix_row_t master_matrix[], matrix_row_t
733 return okay; 733 return okay;
734} 734}
735 735
736extern const pointing_device_driver_t pointing_device_driver; 736extern const pointing_device_driver_t *pointing_device_driver;
737 737
738static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) { 738static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t slave_matrix[]) {
739# if defined(POINTING_DEVICE_LEFT) 739# if defined(POINTING_DEVICE_LEFT)
@@ -753,18 +753,18 @@ static void pointing_handlers_slave(matrix_row_t master_matrix[], matrix_row_t s
753 last_exec = timer_read32(); 753 last_exec = timer_read32();
754# endif 754# endif
755 755
756 uint16_t temp_cpi = !pointing_device_driver.get_cpi ? 0 : pointing_device_driver.get_cpi(); // check for NULL 756 uint16_t temp_cpi = !pointing_device_driver->get_cpi ? 0 : pointing_device_driver->get_cpi(); // check for NULL
757 757
758 split_shared_memory_lock(); 758 split_shared_memory_lock();
759 split_slave_pointing_sync_t pointing; 759 split_slave_pointing_sync_t pointing;
760 memcpy(&pointing, &split_shmem->pointing, sizeof(split_slave_pointing_sync_t)); 760 memcpy(&pointing, &split_shmem->pointing, sizeof(split_slave_pointing_sync_t));
761 split_shared_memory_unlock(); 761 split_shared_memory_unlock();
762 762
763 if (pointing.cpi && pointing.cpi != temp_cpi && pointing_device_driver.set_cpi) { 763 if (pointing.cpi && pointing.cpi != temp_cpi && pointing_device_driver->set_cpi) {
764 pointing_device_driver.set_cpi(pointing.cpi); 764 pointing_device_driver->set_cpi(pointing.cpi);
765 } 765 }
766 766
767 pointing.report = pointing_device_driver.get_report((report_mouse_t){0}); 767 pointing.report = pointing_device_driver->get_report((report_mouse_t){0});
768 // Now update the checksum given that the pointing has been written to 768 // Now update the checksum given that the pointing has been written to
769 pointing.checksum = crc8(&pointing.report, sizeof(report_mouse_t)); 769 pointing.checksum = crc8(&pointing.report, sizeof(report_mouse_t));
770 770