aboutsummaryrefslogtreecommitdiff
path: root/keyboards/handwired/tractyl_manuform/tm_sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/handwired/tractyl_manuform/tm_sync.c')
-rw-r--r--keyboards/handwired/tractyl_manuform/tm_sync.c111
1 files changed, 102 insertions, 9 deletions
diff --git a/keyboards/handwired/tractyl_manuform/tm_sync.c b/keyboards/handwired/tractyl_manuform/tm_sync.c
index 4739af1e7..733f09a22 100644
--- a/keyboards/handwired/tractyl_manuform/tm_sync.c
+++ b/keyboards/handwired/tractyl_manuform/tm_sync.c
@@ -14,19 +14,29 @@
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */ 15 */
16 16
17#include "tractyl_manuform.h" 17#include QMK_KEYBOARD_H
18#include "pointing_device.h"
18#include "transactions.h" 19#include "transactions.h"
19#include <string.h> 20#include <string.h>
21#ifdef MOUSEKEY_ENABLE
22# include "mousekey.h"
23#endif
20 24
21kb_config_data_t kb_config; 25// typedef struct {
22kb_mouse_report_t sync_mouse_report; 26// uint16_t device_cpi;
27// } kb_config_data_t;
28
29kb_config_data_t kb_config;
30static report_mouse_t shared_mouse_report;
31extern const pointing_device_driver_t pointing_device_driver;
23 32
24void kb_pointer_sync_handler(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) { 33void kb_pointer_sync_handler(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
25 if (target2initiator_buffer_size == sizeof(sync_mouse_report)) { 34 shared_mouse_report = pointing_device_driver.get_report(shared_mouse_report);
26 memcpy(target2initiator_buffer, &sync_mouse_report, sizeof(sync_mouse_report)); 35 memcpy(target2initiator_buffer, &shared_mouse_report, sizeof(report_mouse_t));
27 } 36 shared_mouse_report.x = 0;
28 sync_mouse_report.x = 0; 37 shared_mouse_report.y = 0;
29 sync_mouse_report.y = 0; 38 shared_mouse_report.h = 0;
39 shared_mouse_report.v = 0;
30} 40}
31 41
32void kb_config_sync_handler(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) { 42void kb_config_sync_handler(uint8_t initiator2target_buffer_size, const void* initiator2target_buffer, uint8_t target2initiator_buffer_size, void* target2initiator_buffer) {
@@ -38,12 +48,15 @@ void kb_config_sync_handler(uint8_t initiator2target_buffer_size, const void* in
38 // Check if the state values are different 48 // Check if the state values are different
39 if (cpi != kb_config.device_cpi) { 49 if (cpi != kb_config.device_cpi) {
40 cpi = kb_config.device_cpi; 50 cpi = kb_config.device_cpi;
51 if (!is_keyboard_left()) {
52 pointing_device_set_cpi(cpi);
53 }
41 } 54 }
42} 55}
43 56
44void keyboard_pre_init_sync(void) { 57void keyboard_pre_init_sync(void) {
45 memset(&kb_config, 0, sizeof(kb_config)); 58 memset(&kb_config, 0, sizeof(kb_config));
46 memset(&sync_mouse_report, 0, sizeof(sync_mouse_report)); 59 memset(&shared_mouse_report, 0, sizeof(shared_mouse_report));
47} 60}
48 61
49void keyboard_post_init_sync(void) { 62void keyboard_post_init_sync(void) {
@@ -84,3 +97,83 @@ void trackball_set_cpi(uint16_t cpi) {
84 pointing_device_set_cpi(cpi); 97 pointing_device_set_cpi(cpi);
85 } 98 }
86} 99}
100
101void pointing_device_task(void) {
102 if (!is_keyboard_master()) {
103 return;
104 }
105
106#if defined(POINTING_DEVICE_TASK_THROTTLE)
107 static uint32_t last_exec = 0;
108 if (timer_elapsed32(last_exec) < 1) {
109 return;
110 }
111 last_exec = timer_read32();
112#endif
113
114 report_mouse_t local_report = pointing_device_get_report();
115
116 // Gather report info
117#ifdef POINTING_DEVICE_MOTION_PIN
118 if (!readPin(POINTING_DEVICE_MOTION_PIN))
119#endif
120#if defined(POINTING_DEVICE_COMBINED)
121 local_report = pointing_device_driver.get_report(local_report);
122 transaction_rpc_recv(RPC_ID_POINTER_STATE_SYNC, sizeof(report_mouse_t), &shared_mouse_report);
123 local_report.x = local_report.x | shared_mouse_report.x;
124 local_report.y = local_report.y | shared_mouse_report.y;
125 local_report.h = local_report.h | shared_mouse_report.h;
126 local_report.v = local_report.v | shared_mouse_report.v;
127#elif defined(POINTING_DEVICE_LEFT)
128 if (is_keyboard_left()) {
129 local_report = pointing_device_driver.get_report(local_report);
130 } else {
131 transaction_rpc_recv(RPC_ID_POINTER_STATE_SYNC, sizeof(report_mouse_t), &local_report);
132 }
133#elif defined(POINTING_DEVICE_RIGHT)
134 if (!is_keyboard_left()) {
135 local_report = pointing_device_driver.get_report(local_report);
136 } else {
137 transaction_rpc_recv(RPC_ID_POINTER_STATE_SYNC, sizeof(report_mouse_t), &local_report);
138 }
139#else
140# error "You need to define the side(s) the pointing device is on. POINTING_DEVICE_COMBINED / POINTING_DEVICE_LEFT / POINTING_DEVICE_RIGHT"
141#endif
142
143 // Support rotation of the sensor data
144#if defined(POINTING_DEVICE_ROTATION_90) || defined(POINTING_DEVICE_ROTATION_180) || defined(POINTING_DEVICE_ROTATION_270)
145 int8_t x = local_report.x, y = local_report.y;
146# if defined(POINTING_DEVICE_ROTATION_90)
147 local_report.x = y;
148 local_report.y = -x;
149# elif defined(POINTING_DEVICE_ROTATION_180)
150 local_report.x = -x;
151 local_report.y = -y;
152# elif defined(POINTING_DEVICE_ROTATION_270)
153 local_report.x = -y;
154 local_report.y = x;
155# else
156# error "How the heck did you get here?!"
157# endif
158#endif
159 // Support Inverting the X and Y Axises
160#if defined(POINTING_DEVICE_INVERT_X)
161 local_report.x = -local_report.x;
162#endif
163#if defined(POINTING_DEVICE_INVERT_Y)
164 local_report.y = -local_report.y;
165#endif
166
167 // allow kb to intercept and modify report
168 local_report = pointing_device_task_kb(local_report);
169 // combine with mouse report to ensure that the combined is sent correctly
170#ifdef MOUSEKEY_ENABLE
171 report_mouse_t mousekey_report = mousekey_get_report();
172 local_report.buttons = local_report.buttons | mousekey_report.buttons;
173#endif
174#if defined(POINTING_DEVICE_COMBINED)
175 local_report.buttons = local_report.buttons | shared_mouse_report.buttons;
176#endif
177 pointing_device_set_report(local_report);
178 pointing_device_send();
179}