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 /keyboards/ploopyco | |
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 'keyboards/ploopyco')
-rw-r--r-- | keyboards/ploopyco/mouse/mouse.c | 117 | ||||
-rw-r--r-- | keyboards/ploopyco/mouse/mouse.h | 6 | ||||
-rw-r--r-- | keyboards/ploopyco/mouse/rules.mk | 5 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball/rules.mk | 5 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball/trackball.c | 105 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball/trackball.h | 6 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball_mini/config.h | 6 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c | 2 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball_mini/rules.mk | 6 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball_mini/trackball_mini.c | 108 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball_mini/trackball_mini.h | 5 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball_nano/config.h | 6 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball_nano/keymaps/maddie/keymap.c | 22 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball_nano/rules.mk | 7 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball_nano/trackball_nano.c | 116 | ||||
-rw-r--r-- | keyboards/ploopyco/trackball_nano/trackball_nano.h | 13 |
16 files changed, 113 insertions, 422 deletions
diff --git a/keyboards/ploopyco/mouse/mouse.c b/keyboards/ploopyco/mouse/mouse.c index 0bf96a20f..1b00ef3b7 100644 --- a/keyboards/ploopyco/mouse/mouse.c +++ b/keyboards/ploopyco/mouse/mouse.c | |||
@@ -31,7 +31,8 @@ | |||
31 | # define OPT_SCALE 1 // Multiplier for wheel | 31 | # define OPT_SCALE 1 // Multiplier for wheel |
32 | #endif | 32 | #endif |
33 | #ifndef PLOOPY_DPI_OPTIONS | 33 | #ifndef PLOOPY_DPI_OPTIONS |
34 | # define PLOOPY_DPI_OPTIONS { 1200, 1600, 2400 } | 34 | # define PLOOPY_DPI_OPTIONS \ |
35 | { 1200, 1600, 2400 } | ||
35 | # ifndef PLOOPY_DPI_DEFAULT | 36 | # ifndef PLOOPY_DPI_DEFAULT |
36 | # define PLOOPY_DPI_DEFAULT 1 | 37 | # define PLOOPY_DPI_DEFAULT 1 |
37 | # endif | 38 | # endif |
@@ -40,10 +41,10 @@ | |||
40 | # define PLOOPY_DPI_DEFAULT 0 | 41 | # define PLOOPY_DPI_DEFAULT 0 |
41 | #endif | 42 | #endif |
42 | #ifndef PLOOPY_DRAGSCROLL_DPI | 43 | #ifndef PLOOPY_DRAGSCROLL_DPI |
43 | # define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll | 44 | # define PLOOPY_DRAGSCROLL_DPI 100 // Fixed-DPI Drag Scroll |
44 | #endif | 45 | #endif |
45 | #ifndef PLOOPY_DRAGSCROLL_MULTIPLIER | 46 | #ifndef PLOOPY_DRAGSCROLL_MULTIPLIER |
46 | # define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll | 47 | # define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll |
47 | #endif | 48 | #endif |
48 | 49 | ||
49 | keyboard_config_t keyboard_config; | 50 | keyboard_config_t keyboard_config; |
@@ -65,13 +66,7 @@ uint8_t OptLowPin = OPT_ENC1; | |||
65 | bool debug_encoder = false; | 66 | bool debug_encoder = false; |
66 | bool is_drag_scroll = false; | 67 | bool is_drag_scroll = false; |
67 | 68 | ||
68 | __attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) { | 69 | void process_wheel(report_mouse_t* mouse_report) { |
69 | mouse_report->h = h; | ||
70 | mouse_report->v = v; | ||
71 | } | ||
72 | |||
73 | __attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) { | ||
74 | // TODO: Replace this with interrupt driven code, polling is S L O W | ||
75 | // Lovingly ripped from the Ploopy Source | 70 | // Lovingly ripped from the Ploopy Source |
76 | 71 | ||
77 | // If the mouse wheel was just released, do not scroll. | 72 | // If the mouse wheel was just released, do not scroll. |
@@ -99,56 +94,25 @@ __attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) { | |||
99 | int dir = opt_encoder_handler(p1, p2); | 94 | int dir = opt_encoder_handler(p1, p2); |
100 | 95 | ||
101 | if (dir == 0) return; | 96 | if (dir == 0) return; |
102 | process_wheel_user(mouse_report, mouse_report->h, (int)(mouse_report->v + (dir * OPT_SCALE))); | 97 | mouse_report->v = (int8_t)(dir * OPT_SCALE); |
103 | } | ||
104 | |||
105 | __attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) { | ||
106 | mouse_report->x = x; | ||
107 | mouse_report->y = y; | ||
108 | } | 98 | } |
109 | 99 | ||
110 | __attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) { | 100 | __attribute__((weak)) report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { |
111 | report_pmw_t data = pmw_read_burst(); | 101 | process_wheel(&mouse_report); |
112 | if (data.isOnSurface && data.isMotion) { | ||
113 | // Reset timer if stopped moving | ||
114 | if (!data.isMotion) { | ||
115 | if (MotionStart != 0) MotionStart = 0; | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | // Set timer if new motion | ||
120 | if ((MotionStart == 0) && data.isMotion) { | ||
121 | if (debug_mouse) dprintf("Starting motion.\n"); | ||
122 | MotionStart = timer_read(); | ||
123 | } | ||
124 | 102 | ||
125 | if (debug_mouse) { | 103 | if (is_drag_scroll) { |
126 | dprintf("Delt] d: %d t: %u\n", abs(data.dx) + abs(data.dy), MotionStart); | 104 | mouse_report.h = mouse_report.x; |
127 | } | 105 | #ifdef PLOOPY_DRAGSCROLL_INVERT |
128 | if (debug_mouse) { | 106 | // Invert vertical scroll direction |
129 | dprintf("Pre ] X: %d, Y: %d\n", data.dx, data.dy); | 107 | mouse_report.v = -mouse_report.y; |
130 | } | ||
131 | #if defined(PROFILE_LINEAR) | ||
132 | float scale = float(timer_elaspsed(MotionStart)) / 1000.0; | ||
133 | data.dx *= scale; | ||
134 | data.dy *= scale; | ||
135 | #elif defined(PROFILE_INVERSE) | ||
136 | // TODO | ||
137 | #else | 108 | #else |
138 | // no post processing | 109 | mouse_report.v = mouse_report.y; |
139 | #endif | 110 | #endif |
140 | // apply multiplier | 111 | mouse_report.x = 0; |
141 | // data.dx *= mouse_multiplier; | 112 | mouse_report.y = 0; |
142 | // data.dy *= mouse_multiplier; | ||
143 | |||
144 | // Wrap to HID size | ||
145 | data.dx = constrain(data.dx, -127, 127); | ||
146 | data.dy = constrain(data.dy, -127, 127); | ||
147 | if (debug_mouse) dprintf("Cons] X: %d, Y: %d\n", data.dx, data.dy); | ||
148 | // dprintf("Elapsed:%u, X: %f Y: %\n", i, pgm_read_byte(firmware_data+i)); | ||
149 | |||
150 | process_mouse_user(mouse_report, data.dx, data.dy); | ||
151 | } | 113 | } |
114 | |||
115 | return pointing_device_task_user(mouse_report); | ||
152 | } | 116 | } |
153 | 117 | ||
154 | bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | 118 | bool process_record_kb(uint16_t keycode, keyrecord_t* record) { |
@@ -169,7 +133,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | |||
169 | if (keycode == DPI_CONFIG && record->event.pressed) { | 133 | if (keycode == DPI_CONFIG && record->event.pressed) { |
170 | keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; | 134 | keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; |
171 | eeconfig_update_kb(keyboard_config.raw); | 135 | eeconfig_update_kb(keyboard_config.raw); |
172 | pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); | 136 | pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]); |
173 | } | 137 | } |
174 | 138 | ||
175 | if (keycode == DRAG_SCROLL) { | 139 | if (keycode == DRAG_SCROLL) { |
@@ -180,9 +144,9 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | |||
180 | is_drag_scroll ^= 1; | 144 | is_drag_scroll ^= 1; |
181 | } | 145 | } |
182 | #ifdef PLOOPY_DRAGSCROLL_FIXED | 146 | #ifdef PLOOPY_DRAGSCROLL_FIXED |
183 | pmw_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]); | 147 | pointing_device_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]); |
184 | #else | 148 | #else |
185 | pmw_set_cpi(is_drag_scroll ? (dpi_array[keyboard_config.dpi_config] * PLOOPY_DRAGSCROLL_MULTIPLIER) : dpi_array[keyboard_config.dpi_config]); | 149 | pointing_device_set_cpi(is_drag_scroll ? (dpi_array[keyboard_config.dpi_config] * PLOOPY_DRAGSCROLL_MULTIPLIER) : dpi_array[keyboard_config.dpi_config]); |
186 | #endif | 150 | #endif |
187 | } | 151 | } |
188 | 152 | ||
@@ -194,11 +158,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | |||
194 | #ifndef MOUSEKEY_ENABLE | 158 | #ifndef MOUSEKEY_ENABLE |
195 | if (IS_MOUSEKEY_BUTTON(keycode)) { | 159 | if (IS_MOUSEKEY_BUTTON(keycode)) { |
196 | report_mouse_t currentReport = pointing_device_get_report(); | 160 | report_mouse_t currentReport = pointing_device_get_report(); |
197 | if (record->event.pressed) { | 161 | currentReport.buttons = pointing_device_handle_buttons(currentReport.buttons, record->event.pressed, keycode - KC_MS_BTN1); |
198 | currentReport.buttons |= 1 << (keycode - KC_MS_BTN1); | ||
199 | } else { | ||
200 | currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1)); | ||
201 | } | ||
202 | pointing_device_set_report(currentReport); | 162 | pointing_device_set_report(currentReport); |
203 | pointing_device_send(); | 163 | pointing_device_send(); |
204 | } | 164 | } |
@@ -240,35 +200,12 @@ void keyboard_pre_init_kb(void) { | |||
240 | keyboard_pre_init_user(); | 200 | keyboard_pre_init_user(); |
241 | } | 201 | } |
242 | 202 | ||
243 | void pointing_device_init(void) { | 203 | void pointing_device_init_kb(void) { |
244 | // initialize ball sensor | 204 | pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]); |
245 | pmw_spi_init(); | ||
246 | // initialize the scroll wheel's optical encoder | 205 | // initialize the scroll wheel's optical encoder |
247 | opt_encoder_init(); | 206 | opt_encoder_init(); |
248 | } | 207 | } |
249 | 208 | ||
250 | |||
251 | void pointing_device_task(void) { | ||
252 | report_mouse_t mouse_report = pointing_device_get_report(); | ||
253 | process_wheel(&mouse_report); | ||
254 | process_mouse(&mouse_report); | ||
255 | |||
256 | if (is_drag_scroll) { | ||
257 | mouse_report.h = mouse_report.x; | ||
258 | #ifdef PLOOPY_DRAGSCROLL_INVERT | ||
259 | // Invert vertical scroll direction | ||
260 | mouse_report.v = -mouse_report.y; | ||
261 | #else | ||
262 | mouse_report.v = mouse_report.y; | ||
263 | #endif | ||
264 | mouse_report.x = 0; | ||
265 | mouse_report.y = 0; | ||
266 | } | ||
267 | |||
268 | pointing_device_set_report(mouse_report); | ||
269 | pointing_device_send(); | ||
270 | } | ||
271 | |||
272 | void eeconfig_init_kb(void) { | 209 | void eeconfig_init_kb(void) { |
273 | keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; | 210 | keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; |
274 | eeconfig_update_kb(keyboard_config.raw); | 211 | eeconfig_update_kb(keyboard_config.raw); |
@@ -284,9 +221,3 @@ void matrix_init_kb(void) { | |||
284 | } | 221 | } |
285 | matrix_init_user(); | 222 | matrix_init_user(); |
286 | } | 223 | } |
287 | |||
288 | void keyboard_post_init_kb(void) { | ||
289 | pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); | ||
290 | |||
291 | keyboard_post_init_user(); | ||
292 | } | ||
diff --git a/keyboards/ploopyco/mouse/mouse.h b/keyboards/ploopyco/mouse/mouse.h index d11aa5e9a..ee5982713 100644 --- a/keyboards/ploopyco/mouse/mouse.h +++ b/keyboards/ploopyco/mouse/mouse.h | |||
@@ -19,11 +19,8 @@ | |||
19 | #pragma once | 19 | #pragma once |
20 | 20 | ||
21 | #include "quantum.h" | 21 | #include "quantum.h" |
22 | #include "spi_master.h" | ||
23 | #include "drivers/sensors/pmw3360.h" | ||
24 | #include "analog.h" | 22 | #include "analog.h" |
25 | #include "opt_encoder.h" | 23 | #include "opt_encoder.h" |
26 | #include "pointing_device.h" | ||
27 | 24 | ||
28 | // Sensor defs | 25 | // Sensor defs |
29 | #define OPT_ENC1 F0 | 26 | #define OPT_ENC1 F0 |
@@ -31,10 +28,7 @@ | |||
31 | #define OPT_ENC1_MUX 0 | 28 | #define OPT_ENC1_MUX 0 |
32 | #define OPT_ENC2_MUX 4 | 29 | #define OPT_ENC2_MUX 4 |
33 | 30 | ||
34 | void process_mouse(report_mouse_t* mouse_report); | ||
35 | void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y); | ||
36 | void process_wheel(report_mouse_t* mouse_report); | 31 | void process_wheel(report_mouse_t* mouse_report); |
37 | void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v); | ||
38 | 32 | ||
39 | #define LAYOUT(BLL, BL, BM, BR, BRR, BF, BB, BDPI) \ | 33 | #define LAYOUT(BLL, BL, BM, BR, BRR, BF, BB, BDPI) \ |
40 | { {BL, BM, BR, BF, BB, BRR, BLL, BDPI}, } | 34 | { {BL, BM, BR, BF, BB, BRR, BLL, BDPI}, } |
diff --git a/keyboards/ploopyco/mouse/rules.mk b/keyboards/ploopyco/mouse/rules.mk index c02afa00c..45cb38901 100644 --- a/keyboards/ploopyco/mouse/rules.mk +++ b/keyboards/ploopyco/mouse/rules.mk | |||
@@ -22,7 +22,8 @@ BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | |||
22 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow | 22 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow |
23 | AUDIO_ENABLE = no # Audio output | 23 | AUDIO_ENABLE = no # Audio output |
24 | POINTING_DEVICE_ENABLE = yes | 24 | POINTING_DEVICE_ENABLE = yes |
25 | POINTING_DEVICE_DRIVER = pmw3360 | ||
25 | MOUSEKEY_ENABLE = yes # Mouse keys | 26 | MOUSEKEY_ENABLE = yes # Mouse keys |
26 | 27 | ||
27 | QUANTUM_LIB_SRC += analog.c spi_master.c | 28 | QUANTUM_LIB_SRC += analog.c |
28 | SRC += drivers/sensors/pmw3360.c opt_encoder.c | 29 | SRC += opt_encoder.c |
diff --git a/keyboards/ploopyco/trackball/rules.mk b/keyboards/ploopyco/trackball/rules.mk index af9bc7d4c..d11858152 100644 --- a/keyboards/ploopyco/trackball/rules.mk +++ b/keyboards/ploopyco/trackball/rules.mk | |||
@@ -19,9 +19,10 @@ BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | |||
19 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow | 19 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow |
20 | AUDIO_ENABLE = no # Audio output | 20 | AUDIO_ENABLE = no # Audio output |
21 | POINTING_DEVICE_ENABLE = yes | 21 | POINTING_DEVICE_ENABLE = yes |
22 | POINTING_DEVICE_DRIVER = pmw3360 | ||
22 | MOUSEKEY_ENABLE = yes # Mouse keys | 23 | MOUSEKEY_ENABLE = yes # Mouse keys |
23 | 24 | ||
24 | QUANTUM_LIB_SRC += analog.c spi_master.c | 25 | QUANTUM_LIB_SRC += analog.c |
25 | SRC += drivers/sensors/pmw3360.c opt_encoder.c | 26 | SRC += opt_encoder.c |
26 | 27 | ||
27 | DEFAULT_FOLDER = ploopyco/trackball/rev1_005 | 28 | DEFAULT_FOLDER = ploopyco/trackball/rev1_005 |
diff --git a/keyboards/ploopyco/trackball/trackball.c b/keyboards/ploopyco/trackball/trackball.c index 719020997..e2a6e4ed5 100644 --- a/keyboards/ploopyco/trackball/trackball.c +++ b/keyboards/ploopyco/trackball/trackball.c | |||
@@ -65,12 +65,7 @@ uint8_t OptLowPin = OPT_ENC1; | |||
65 | bool debug_encoder = false; | 65 | bool debug_encoder = false; |
66 | bool is_drag_scroll = false; | 66 | bool is_drag_scroll = false; |
67 | 67 | ||
68 | __attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) { | 68 | void process_wheel(report_mouse_t* mouse_report) { |
69 | mouse_report->h = h; | ||
70 | mouse_report->v = v; | ||
71 | } | ||
72 | |||
73 | __attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) { | ||
74 | // TODO: Replace this with interrupt driven code, polling is S L O W | 69 | // TODO: Replace this with interrupt driven code, polling is S L O W |
75 | // Lovingly ripped from the Ploopy Source | 70 | // Lovingly ripped from the Ploopy Source |
76 | 71 | ||
@@ -99,56 +94,25 @@ __attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) { | |||
99 | int dir = opt_encoder_handler(p1, p2); | 94 | int dir = opt_encoder_handler(p1, p2); |
100 | 95 | ||
101 | if (dir == 0) return; | 96 | if (dir == 0) return; |
102 | process_wheel_user(mouse_report, mouse_report->h, (int)(mouse_report->v + (dir * OPT_SCALE))); | 97 | mouse_report->v = (int8_t)(dir * OPT_SCALE); |
103 | } | 98 | } |
104 | 99 | ||
105 | __attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) { | 100 | report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { |
106 | mouse_report->x = x; | 101 | process_wheel(&mouse_report); |
107 | mouse_report->y = y; | ||
108 | } | ||
109 | |||
110 | __attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) { | ||
111 | report_pmw_t data = pmw_read_burst(); | ||
112 | if (data.isOnSurface && data.isMotion) { | ||
113 | // Reset timer if stopped moving | ||
114 | if (!data.isMotion) { | ||
115 | if (MotionStart != 0) MotionStart = 0; | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | // Set timer if new motion | ||
120 | if ((MotionStart == 0) && data.isMotion) { | ||
121 | if (debug_mouse) dprintf("Starting motion.\n"); | ||
122 | MotionStart = timer_read(); | ||
123 | } | ||
124 | 102 | ||
125 | if (debug_mouse) { | 103 | if (is_drag_scroll) { |
126 | dprintf("Delt] d: %d t: %u\n", abs(data.dx) + abs(data.dy), MotionStart); | 104 | mouse_report.h = mouse_report.x; |
127 | } | 105 | #ifdef PLOOPY_DRAGSCROLL_INVERT |
128 | if (debug_mouse) { | 106 | // Invert vertical scroll direction |
129 | dprintf("Pre ] X: %d, Y: %d\n", data.dx, data.dy); | 107 | mouse_report.v = -mouse_report.y; |
130 | } | ||
131 | #if defined(PROFILE_LINEAR) | ||
132 | float scale = float(timer_elaspsed(MotionStart)) / 1000.0; | ||
133 | data.dx *= scale; | ||
134 | data.dy *= scale; | ||
135 | #elif defined(PROFILE_INVERSE) | ||
136 | // TODO | ||
137 | #else | 108 | #else |
138 | // no post processing | 109 | mouse_report.v = mouse_report.y; |
139 | #endif | 110 | #endif |
140 | // apply multiplier | 111 | mouse_report.x = 0; |
141 | // data.dx *= mouse_multiplier; | 112 | mouse_report.y = 0; |
142 | // data.dy *= mouse_multiplier; | ||
143 | |||
144 | // Wrap to HID size | ||
145 | data.dx = constrain(data.dx, -127, 127); | ||
146 | data.dy = constrain(data.dy, -127, 127); | ||
147 | if (debug_mouse) dprintf("Cons] X: %d, Y: %d\n", data.dx, data.dy); | ||
148 | // dprintf("Elapsed:%u, X: %f Y: %\n", i, pgm_read_byte(firmware_data+i)); | ||
149 | |||
150 | process_mouse_user(mouse_report, data.dx, -data.dy); | ||
151 | } | 113 | } |
114 | |||
115 | return pointing_device_task_user(mouse_report); | ||
152 | } | 116 | } |
153 | 117 | ||
154 | bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | 118 | bool process_record_kb(uint16_t keycode, keyrecord_t* record) { |
@@ -169,7 +133,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | |||
169 | if (keycode == DPI_CONFIG && record->event.pressed) { | 133 | if (keycode == DPI_CONFIG && record->event.pressed) { |
170 | keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; | 134 | keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; |
171 | eeconfig_update_kb(keyboard_config.raw); | 135 | eeconfig_update_kb(keyboard_config.raw); |
172 | pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); | 136 | pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]); |
173 | } | 137 | } |
174 | 138 | ||
175 | if (keycode == DRAG_SCROLL) { | 139 | if (keycode == DRAG_SCROLL) { |
@@ -180,9 +144,9 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | |||
180 | is_drag_scroll ^= 1; | 144 | is_drag_scroll ^= 1; |
181 | } | 145 | } |
182 | #ifdef PLOOPY_DRAGSCROLL_FIXED | 146 | #ifdef PLOOPY_DRAGSCROLL_FIXED |
183 | pmw_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]); | 147 | pointing_device_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]); |
184 | #else | 148 | #else |
185 | pmw_set_cpi(is_drag_scroll ? (dpi_array[keyboard_config.dpi_config] * PLOOPY_DRAGSCROLL_MULTIPLIER) : dpi_array[keyboard_config.dpi_config]); | 149 | pointing_device_set_cpi(is_drag_scroll ? (dpi_array[keyboard_config.dpi_config] * PLOOPY_DRAGSCROLL_MULTIPLIER) : dpi_array[keyboard_config.dpi_config]); |
186 | #endif | 150 | #endif |
187 | } | 151 | } |
188 | 152 | ||
@@ -194,11 +158,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | |||
194 | #ifndef MOUSEKEY_ENABLE | 158 | #ifndef MOUSEKEY_ENABLE |
195 | if (IS_MOUSEKEY_BUTTON(keycode)) { | 159 | if (IS_MOUSEKEY_BUTTON(keycode)) { |
196 | report_mouse_t currentReport = pointing_device_get_report(); | 160 | report_mouse_t currentReport = pointing_device_get_report(); |
197 | if (record->event.pressed) { | 161 | currentReport.buttons = pointing_device_handle_buttons(record->event.pressed, keycode - KC_MS_BTN1); |
198 | currentReport.buttons |= 1 << (keycode - KC_MS_BTN1); | ||
199 | } else { | ||
200 | currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1)); | ||
201 | } | ||
202 | pointing_device_set_report(currentReport); | 162 | pointing_device_set_report(currentReport); |
203 | pointing_device_send(); | 163 | pointing_device_send(); |
204 | } | 164 | } |
@@ -239,35 +199,12 @@ void keyboard_pre_init_kb(void) { | |||
239 | keyboard_pre_init_user(); | 199 | keyboard_pre_init_user(); |
240 | } | 200 | } |
241 | 201 | ||
242 | void pointing_device_init(void) { | 202 | void pointing_device_init_kb(void) { |
243 | // initialize ball sensor | 203 | pmw3360_set_cpi(dpi_array[keyboard_config.dpi_config]); |
244 | pmw_spi_init(); | ||
245 | // initialize the scroll wheel's optical encoder | 204 | // initialize the scroll wheel's optical encoder |
246 | opt_encoder_init(); | 205 | opt_encoder_init(); |
247 | } | 206 | } |
248 | 207 | ||
249 | |||
250 | void pointing_device_task(void) { | ||
251 | report_mouse_t mouse_report = pointing_device_get_report(); | ||
252 | process_wheel(&mouse_report); | ||
253 | process_mouse(&mouse_report); | ||
254 | |||
255 | if (is_drag_scroll) { | ||
256 | mouse_report.h = mouse_report.x; | ||
257 | #ifdef PLOOPY_DRAGSCROLL_INVERT | ||
258 | // Invert vertical scroll direction | ||
259 | mouse_report.v = -mouse_report.y; | ||
260 | #else | ||
261 | mouse_report.v = mouse_report.y; | ||
262 | #endif | ||
263 | mouse_report.x = 0; | ||
264 | mouse_report.y = 0; | ||
265 | } | ||
266 | |||
267 | pointing_device_set_report(mouse_report); | ||
268 | pointing_device_send(); | ||
269 | } | ||
270 | |||
271 | void eeconfig_init_kb(void) { | 208 | void eeconfig_init_kb(void) { |
272 | keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; | 209 | keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; |
273 | eeconfig_update_kb(keyboard_config.raw); | 210 | eeconfig_update_kb(keyboard_config.raw); |
@@ -285,7 +222,7 @@ void matrix_init_kb(void) { | |||
285 | } | 222 | } |
286 | 223 | ||
287 | void keyboard_post_init_kb(void) { | 224 | void keyboard_post_init_kb(void) { |
288 | pmw_set_cpi(dpi_array[keyboard_config.dpi_config]); | 225 | pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]); |
289 | 226 | ||
290 | keyboard_post_init_user(); | 227 | keyboard_post_init_user(); |
291 | } | 228 | } |
diff --git a/keyboards/ploopyco/trackball/trackball.h b/keyboards/ploopyco/trackball/trackball.h index 70f5d83b1..52d955325 100644 --- a/keyboards/ploopyco/trackball/trackball.h +++ b/keyboards/ploopyco/trackball/trackball.h | |||
@@ -19,11 +19,8 @@ | |||
19 | #pragma once | 19 | #pragma once |
20 | 20 | ||
21 | #include "quantum.h" | 21 | #include "quantum.h" |
22 | #include "spi_master.h" | ||
23 | #include "drivers/sensors/pmw3360.h" | ||
24 | #include "analog.h" | 22 | #include "analog.h" |
25 | #include "opt_encoder.h" | 23 | #include "opt_encoder.h" |
26 | #include "pointing_device.h" | ||
27 | #if defined(KEYBOARD_ploopyco_trackball_rev1) | 24 | #if defined(KEYBOARD_ploopyco_trackball_rev1) |
28 | # include "rev1.h" | 25 | # include "rev1.h" |
29 | #elif defined(KEYBOARD_ploopyco_trackball_rev1_005) | 26 | #elif defined(KEYBOARD_ploopyco_trackball_rev1_005) |
@@ -36,10 +33,7 @@ | |||
36 | #define OPT_ENC1_MUX 0 | 33 | #define OPT_ENC1_MUX 0 |
37 | #define OPT_ENC2_MUX 4 | 34 | #define OPT_ENC2_MUX 4 |
38 | 35 | ||
39 | void process_mouse(report_mouse_t* mouse_report); | ||
40 | void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y); | ||
41 | void process_wheel(report_mouse_t* mouse_report); | 36 | void process_wheel(report_mouse_t* mouse_report); |
42 | void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v); | ||
43 | 37 | ||
44 | #define LAYOUT(BL, BM, BR, BF, BB) \ | 38 | #define LAYOUT(BL, BM, BR, BF, BB) \ |
45 | { {BL, BM, BR, BF, BB}, } | 39 | { {BL, BM, BR, BF, BB}, } |
diff --git a/keyboards/ploopyco/trackball_mini/config.h b/keyboards/ploopyco/trackball_mini/config.h index f76a6eb2c..52d7390ca 100644 --- a/keyboards/ploopyco/trackball_mini/config.h +++ b/keyboards/ploopyco/trackball_mini/config.h | |||
@@ -56,3 +56,9 @@ | |||
56 | 56 | ||
57 | // If board has a debug LED, you can enable it by defining this | 57 | // If board has a debug LED, you can enable it by defining this |
58 | // #define DEBUG_LED_PIN F7 | 58 | // #define DEBUG_LED_PIN F7 |
59 | |||
60 | #define ADNS5050_SCLK_PIN B7 | ||
61 | #define ADNS5050_SDIO_PIN C6 | ||
62 | #define ADNS5050_CS_PIN B4 | ||
63 | |||
64 | #define POINTING_DEVICE_ROTATION_90 | ||
diff --git a/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c b/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c index 7784bc855..7eb973216 100644 --- a/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c +++ b/keyboards/ploopyco/trackball_mini/keymaps/drag_scroll/keymap.c | |||
@@ -44,7 +44,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |||
44 | // to only scroll in one direction, if you wanted, as well. In fact, | 44 | // to only scroll in one direction, if you wanted, as well. In fact, |
45 | // there is no reason that you need to send this to the mouse report. | 45 | // there is no reason that you need to send this to the mouse report. |
46 | // You could have it register a key, instead. | 46 | // You could have it register a key, instead. |
47 | void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) { | 47 | void process_mouse_user(report_mouse_t* mouse_report, int8_t x, int8_t y) { |
48 | if (is_drag_scroll) { | 48 | if (is_drag_scroll) { |
49 | mouse_report->h = x; | 49 | mouse_report->h = x; |
50 | mouse_report->v = y; | 50 | mouse_report->v = y; |
diff --git a/keyboards/ploopyco/trackball_mini/rules.mk b/keyboards/ploopyco/trackball_mini/rules.mk index 07a6889cb..8d76c9b3d 100644 --- a/keyboards/ploopyco/trackball_mini/rules.mk +++ b/keyboards/ploopyco/trackball_mini/rules.mk | |||
@@ -1,9 +1,6 @@ | |||
1 | # MCU name | 1 | # MCU name |
2 | MCU = atmega32u4 | 2 | MCU = atmega32u4 |
3 | 3 | ||
4 | # Processor frequency | ||
5 | F_CPU = 16000000 | ||
6 | |||
7 | # Bootloader selection | 4 | # Bootloader selection |
8 | BOOTLOADER = atmel-dfu | 5 | BOOTLOADER = atmel-dfu |
9 | 6 | ||
@@ -22,9 +19,10 @@ BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | |||
22 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow | 19 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow |
23 | AUDIO_ENABLE = no # Audio output | 20 | AUDIO_ENABLE = no # Audio output |
24 | POINTING_DEVICE_ENABLE = yes | 21 | POINTING_DEVICE_ENABLE = yes |
22 | POINTING_DEVICE_DRIVER = adns5050 | ||
25 | MOUSEKEY_ENABLE = no # Mouse keys | 23 | MOUSEKEY_ENABLE = no # Mouse keys |
26 | 24 | ||
27 | QUANTUM_LIB_SRC += analog.c | 25 | QUANTUM_LIB_SRC += analog.c |
28 | SRC += drivers/sensors/adns5050.c opt_encoder.c | 26 | SRC += opt_encoder.c |
29 | 27 | ||
30 | DEFAULT_FOLDER = ploopyco/trackball_mini/rev1_001 | 28 | DEFAULT_FOLDER = ploopyco/trackball_mini/rev1_001 |
diff --git a/keyboards/ploopyco/trackball_mini/trackball_mini.c b/keyboards/ploopyco/trackball_mini/trackball_mini.c index b50850b54..2158a8f48 100644 --- a/keyboards/ploopyco/trackball_mini/trackball_mini.c +++ b/keyboards/ploopyco/trackball_mini/trackball_mini.c | |||
@@ -37,20 +37,17 @@ | |||
37 | # define OPT_SCALE 1 // Multiplier for wheel | 37 | # define OPT_SCALE 1 // Multiplier for wheel |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | #define PLOOPY_DPI_OPTIONS { CPI375, CPI750, CPI1375 } | 40 | #define PLOOPY_DPI_OPTIONS \ |
41 | { 375, 750, 1375 } | ||
41 | #define PLOOPY_DPI_DEFAULT 2 | 42 | #define PLOOPY_DPI_DEFAULT 2 |
42 | 43 | ||
43 | #ifndef PLOOPY_DRAGSCROLL_DPI | 44 | #ifndef PLOOPY_DRAGSCROLL_DPI |
44 | # define PLOOPY_DRAGSCROLL_DPI CPI375 // Fixed-DPI Drag Scroll | 45 | # define PLOOPY_DRAGSCROLL_DPI 375 // Fixed-DPI Drag Scroll |
45 | #endif | 46 | #endif |
46 | #ifndef PLOOPY_DRAGSCROLL_MULTIPLIER | 47 | #ifndef PLOOPY_DRAGSCROLL_MULTIPLIER |
47 | # define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll | 48 | # define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll |
48 | #endif | 49 | #endif |
49 | 50 | ||
50 | // Transformation constants for delta-X and delta-Y | ||
51 | const static float ADNS_X_TRANSFORM = -1.0; | ||
52 | const static float ADNS_Y_TRANSFORM = 1.0; | ||
53 | |||
54 | keyboard_config_t keyboard_config; | 51 | keyboard_config_t keyboard_config; |
55 | uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; | 52 | uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; |
56 | #define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) | 53 | #define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) |
@@ -70,12 +67,7 @@ uint8_t OptLowPin = OPT_ENC1; | |||
70 | bool debug_encoder = false; | 67 | bool debug_encoder = false; |
71 | bool is_drag_scroll = false; | 68 | bool is_drag_scroll = false; |
72 | 69 | ||
73 | __attribute__((weak)) void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v) { | 70 | void process_wheel(report_mouse_t* mouse_report) { |
74 | mouse_report->h = h; | ||
75 | mouse_report->v = v; | ||
76 | } | ||
77 | |||
78 | __attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) { | ||
79 | // If the mouse wheel was just released, do not scroll. | 71 | // If the mouse wheel was just released, do not scroll. |
80 | if (timer_elapsed(lastMidClick) < SCROLL_BUTT_DEBOUNCE) | 72 | if (timer_elapsed(lastMidClick) < SCROLL_BUTT_DEBOUNCE) |
81 | return; | 73 | return; |
@@ -103,33 +95,31 @@ __attribute__((weak)) void process_wheel(report_mouse_t* mouse_report) { | |||
103 | if (dir == 0) | 95 | if (dir == 0) |
104 | return; | 96 | return; |
105 | 97 | ||
106 | process_wheel_user(mouse_report, mouse_report->h, (int)(mouse_report->v + (dir * OPT_SCALE))); | 98 | mouse_report->v = (int8_t)(dir * OPT_SCALE); |
107 | } | 99 | } |
108 | 100 | ||
109 | __attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) { | 101 | void pointing_device_init_kb(void) { |
110 | mouse_report->x = x; | 102 | opt_encoder_init(); |
111 | mouse_report->y = y; | ||
112 | } | ||
113 | |||
114 | __attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) { | ||
115 | report_adns_t data = adns_read_burst(); | ||
116 | |||
117 | if (data.dx != 0 || data.dy != 0) { | ||
118 | if (debug_mouse) | ||
119 | dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy); | ||
120 | 103 | ||
121 | // Apply delta-X and delta-Y transformations. | 104 | // set the DPI. |
122 | // x and y are swapped | 105 | pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]); |
123 | // the sensor is rotated | 106 | } |
124 | // by 90 degrees | ||
125 | float xt = (float) data.dy * ADNS_X_TRANSFORM; | ||
126 | float yt = (float) data.dx * ADNS_Y_TRANSFORM; | ||
127 | 107 | ||
128 | int16_t xti = (int16_t)xt; | 108 | report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { |
129 | int16_t yti = (int16_t)yt; | ||
130 | 109 | ||
131 | process_mouse_user(mouse_report, xti, yti); | 110 | if (is_drag_scroll) { |
111 | mouse_report.h = mouse_report.x; | ||
112 | #ifdef PLOOPY_DRAGSCROLL_INVERT | ||
113 | // Invert vertical scroll direction | ||
114 | mouse_report.v = -mouse_report.y; | ||
115 | #else | ||
116 | mouse_report.v = mouse_report.y; | ||
117 | #endif | ||
118 | mouse_report.x = 0; | ||
119 | mouse_report.y = 0; | ||
132 | } | 120 | } |
121 | |||
122 | return pointing_device_task_user(mouse_report); | ||
133 | } | 123 | } |
134 | 124 | ||
135 | bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | 125 | bool process_record_kb(uint16_t keycode, keyrecord_t* record) { |
@@ -147,7 +137,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | |||
147 | if (keycode == DPI_CONFIG && record->event.pressed) { | 137 | if (keycode == DPI_CONFIG && record->event.pressed) { |
148 | keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; | 138 | keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; |
149 | eeconfig_update_kb(keyboard_config.raw); | 139 | eeconfig_update_kb(keyboard_config.raw); |
150 | adns_set_cpi(dpi_array[keyboard_config.dpi_config]); | 140 | pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]); |
151 | } | 141 | } |
152 | 142 | ||
153 | if (keycode == DRAG_SCROLL) { | 143 | if (keycode == DRAG_SCROLL) { |
@@ -157,7 +147,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | |||
157 | { | 147 | { |
158 | is_drag_scroll ^= 1; | 148 | is_drag_scroll ^= 1; |
159 | } | 149 | } |
160 | adns_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]); | 150 | pointing_device_set_cpi(is_drag_scroll ? PLOOPY_DRAGSCROLL_DPI : dpi_array[keyboard_config.dpi_config]); |
161 | } | 151 | } |
162 | 152 | ||
163 | /* If Mousekeys is disabled, then use handle the mouse button | 153 | /* If Mousekeys is disabled, then use handle the mouse button |
@@ -168,11 +158,7 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | |||
168 | #ifndef MOUSEKEY_ENABLE | 158 | #ifndef MOUSEKEY_ENABLE |
169 | if (IS_MOUSEKEY_BUTTON(keycode)) { | 159 | if (IS_MOUSEKEY_BUTTON(keycode)) { |
170 | report_mouse_t currentReport = pointing_device_get_report(); | 160 | report_mouse_t currentReport = pointing_device_get_report(); |
171 | if (record->event.pressed) { | 161 | currentReport.buttons = pointing_device_handle_buttons(currentReport.buttons, record->event.pressed, keycode - KC_MS_BTN1); |
172 | currentReport.buttons |= 1 << (keycode - KC_MS_BTN1); | ||
173 | } else { | ||
174 | currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1)); | ||
175 | } | ||
176 | pointing_device_set_report(currentReport); | 162 | pointing_device_set_report(currentReport); |
177 | pointing_device_send(); | 163 | pointing_device_send(); |
178 | } | 164 | } |
@@ -207,48 +193,6 @@ void keyboard_pre_init_kb(void) { | |||
207 | keyboard_pre_init_user(); | 193 | keyboard_pre_init_user(); |
208 | } | 194 | } |
209 | 195 | ||
210 | void pointing_device_init(void) { | ||
211 | adns_init(); | ||
212 | opt_encoder_init(); | ||
213 | |||
214 | // reboot the adns. | ||
215 | // if the adns hasn't initialized yet, this is harmless. | ||
216 | adns_write_reg(REG_CHIP_RESET, 0x5a); | ||
217 | |||
218 | // wait maximum time before adns is ready. | ||
219 | // this ensures that the adns is actuall ready after reset. | ||
220 | wait_ms(55); | ||
221 | |||
222 | // read a burst from the adns and then discard it. | ||
223 | // gets the adns ready for write commands | ||
224 | // (for example, setting the dpi). | ||
225 | adns_read_burst(); | ||
226 | |||
227 | // set the DPI. | ||
228 | adns_set_cpi(dpi_array[keyboard_config.dpi_config]); | ||
229 | } | ||
230 | |||
231 | void pointing_device_task(void) { | ||
232 | report_mouse_t mouse_report = pointing_device_get_report(); | ||
233 | process_wheel(&mouse_report); | ||
234 | process_mouse(&mouse_report); | ||
235 | |||
236 | if (is_drag_scroll) { | ||
237 | mouse_report.h = mouse_report.x; | ||
238 | #ifdef PLOOPY_DRAGSCROLL_INVERT | ||
239 | // Invert vertical scroll direction | ||
240 | mouse_report.v = -mouse_report.y; | ||
241 | #else | ||
242 | mouse_report.v = mouse_report.y; | ||
243 | #endif | ||
244 | mouse_report.x = 0; | ||
245 | mouse_report.y = 0; | ||
246 | } | ||
247 | |||
248 | pointing_device_set_report(mouse_report); | ||
249 | pointing_device_send(); | ||
250 | } | ||
251 | |||
252 | void eeconfig_init_kb(void) { | 196 | void eeconfig_init_kb(void) { |
253 | keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; | 197 | keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; |
254 | eeconfig_update_kb(keyboard_config.raw); | 198 | eeconfig_update_kb(keyboard_config.raw); |
diff --git a/keyboards/ploopyco/trackball_mini/trackball_mini.h b/keyboards/ploopyco/trackball_mini/trackball_mini.h index 7bcb02a94..fc86fe776 100644 --- a/keyboards/ploopyco/trackball_mini/trackball_mini.h +++ b/keyboards/ploopyco/trackball_mini/trackball_mini.h | |||
@@ -20,10 +20,8 @@ | |||
20 | #pragma once | 20 | #pragma once |
21 | 21 | ||
22 | #include "quantum.h" | 22 | #include "quantum.h" |
23 | #include "drivers/sensors/adns5050.h" | ||
24 | #include "analog.h" | 23 | #include "analog.h" |
25 | #include "opt_encoder.h" | 24 | #include "opt_encoder.h" |
26 | #include "pointing_device.h" | ||
27 | 25 | ||
28 | // Sensor defs | 26 | // Sensor defs |
29 | #define OPT_ENC1 F0 | 27 | #define OPT_ENC1 F0 |
@@ -31,10 +29,7 @@ | |||
31 | #define OPT_ENC1_MUX 0 | 29 | #define OPT_ENC1_MUX 0 |
32 | #define OPT_ENC2_MUX 4 | 30 | #define OPT_ENC2_MUX 4 |
33 | 31 | ||
34 | void process_mouse(report_mouse_t* mouse_report); | ||
35 | void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y); | ||
36 | void process_wheel(report_mouse_t* mouse_report); | 32 | void process_wheel(report_mouse_t* mouse_report); |
37 | void process_wheel_user(report_mouse_t* mouse_report, int16_t h, int16_t v); | ||
38 | 33 | ||
39 | #define LAYOUT(BL, BM, BR, BF, BB) \ | 34 | #define LAYOUT(BL, BM, BR, BF, BB) \ |
40 | { {BL, BM, BR, BF, BB}, } | 35 | { {BL, BM, BR, BF, BB}, } |
diff --git a/keyboards/ploopyco/trackball_nano/config.h b/keyboards/ploopyco/trackball_nano/config.h index 7450f5574..7d109db99 100644 --- a/keyboards/ploopyco/trackball_nano/config.h +++ b/keyboards/ploopyco/trackball_nano/config.h | |||
@@ -45,3 +45,9 @@ | |||
45 | a polling rate as possible. */ | 45 | a polling rate as possible. */ |
46 | #define USB_POLLING_INTERVAL_MS 1 | 46 | #define USB_POLLING_INTERVAL_MS 1 |
47 | #define USB_MAX_POWER_CONSUMPTION 100 | 47 | #define USB_MAX_POWER_CONSUMPTION 100 |
48 | |||
49 | #define ADNS5050_SCLK_PIN B7 | ||
50 | #define ADNS5050_SDIO_PIN C6 | ||
51 | #define ADNS5050_CS_PIN B4 | ||
52 | |||
53 | #define POINTING_DEVICE_ROTATION_90 | ||
diff --git a/keyboards/ploopyco/trackball_nano/keymaps/maddie/keymap.c b/keyboards/ploopyco/trackball_nano/keymaps/maddie/keymap.c index 6f568ecf5..9e33db378 100644 --- a/keyboards/ploopyco/trackball_nano/keymaps/maddie/keymap.c +++ b/keyboards/ploopyco/trackball_nano/keymaps/maddie/keymap.c | |||
@@ -21,14 +21,14 @@ | |||
21 | // safe range starts at `PLOOPY_SAFE_RANGE` instead. | 21 | // safe range starts at `PLOOPY_SAFE_RANGE` instead. |
22 | uint8_t scroll_enabled = 0; | 22 | uint8_t scroll_enabled = 0; |
23 | uint8_t lock_state = 0; | 23 | uint8_t lock_state = 0; |
24 | int16_t delta_x = 0; | 24 | int8_t delta_x = 0; |
25 | int16_t delta_y = 0; | 25 | int8_t delta_y = 0; |
26 | 26 | ||
27 | void process_mouse_user(report_mouse_t *mouse_report, int16_t x, int16_t y) { | 27 | void process_mouse_user(report_mouse_t *mouse_report, int8_t x, int8_t y) { |
28 | if (scroll_enabled) { | 28 | if (scroll_enabled) { |
29 | delta_x += x; | 29 | delta_x += x; |
30 | delta_y += y; | 30 | delta_y += y; |
31 | 31 | ||
32 | if (delta_x > 60) { | 32 | if (delta_x > 60) { |
33 | mouse_report->h = 1; | 33 | mouse_report->h = 1; |
34 | delta_x = 0; | 34 | delta_x = 0; |
@@ -44,10 +44,10 @@ void process_mouse_user(report_mouse_t *mouse_report, int16_t x, int16_t y) { | |||
44 | mouse_report->v = 1; | 44 | mouse_report->v = 1; |
45 | delta_y = 0; | 45 | delta_y = 0; |
46 | } | 46 | } |
47 | } else { | 47 | } else { |
48 | mouse_report->x = x; | 48 | mouse_report->x = x; |
49 | mouse_report->y = y; | 49 | mouse_report->y = y; |
50 | } | 50 | } |
51 | } | 51 | } |
52 | 52 | ||
53 | void keyboard_post_init_user(void) { | 53 | void keyboard_post_init_user(void) { |
@@ -62,7 +62,7 @@ bool led_update_user(led_t led_state) { | |||
62 | scroll_timer = timer_read(); | 62 | scroll_timer = timer_read(); |
63 | lock_count = 0; | 63 | lock_count = 0; |
64 | } | 64 | } |
65 | 65 | ||
66 | if (led_state.num_lock != lock_state) { | 66 | if (led_state.num_lock != lock_state) { |
67 | lock_count++; | 67 | lock_count++; |
68 | 68 | ||
@@ -73,7 +73,7 @@ bool led_update_user(led_t led_state) { | |||
73 | delta_y = 0; | 73 | delta_y = 0; |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | lock_state = led_state.num_lock; | 77 | lock_state = led_state.num_lock; |
78 | return true; | 78 | return true; |
79 | } | 79 | } |
diff --git a/keyboards/ploopyco/trackball_nano/rules.mk b/keyboards/ploopyco/trackball_nano/rules.mk index a26ad93c8..1a29a561e 100644 --- a/keyboards/ploopyco/trackball_nano/rules.mk +++ b/keyboards/ploopyco/trackball_nano/rules.mk | |||
@@ -1,9 +1,6 @@ | |||
1 | # MCU name | 1 | # MCU name |
2 | MCU = atmega32u4 | 2 | MCU = atmega32u4 |
3 | 3 | ||
4 | # Processor frequency | ||
5 | F_CPU = 16000000 | ||
6 | |||
7 | # Bootloader selection | 4 | # Bootloader selection |
8 | BOOTLOADER = atmel-dfu | 5 | BOOTLOADER = atmel-dfu |
9 | 6 | ||
@@ -22,9 +19,7 @@ BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality | |||
22 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow | 19 | RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow |
23 | AUDIO_ENABLE = no # Audio output | 20 | AUDIO_ENABLE = no # Audio output |
24 | POINTING_DEVICE_ENABLE = yes | 21 | POINTING_DEVICE_ENABLE = yes |
22 | POINTING_DEVICE_DRIVER = adns5050 | ||
25 | MOUSEKEY_ENABLE = no # Mouse keys | 23 | MOUSEKEY_ENABLE = no # Mouse keys |
26 | 24 | ||
27 | QUANTUM_LIB_SRC += analog.c | ||
28 | SRC += drivers/sensors/adns5050.c opt_encoder.c | ||
29 | |||
30 | DEFAULT_FOLDER = ploopyco/trackball_nano/rev1_001 | 25 | DEFAULT_FOLDER = ploopyco/trackball_nano/rev1_001 |
diff --git a/keyboards/ploopyco/trackball_nano/trackball_nano.c b/keyboards/ploopyco/trackball_nano/trackball_nano.c index 9bcfa59ef..2702f6055 100644 --- a/keyboards/ploopyco/trackball_nano/trackball_nano.c +++ b/keyboards/ploopyco/trackball_nano/trackball_nano.c | |||
@@ -37,7 +37,8 @@ | |||
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | #ifndef PLOOPY_DPI_OPTIONS | 39 | #ifndef PLOOPY_DPI_OPTIONS |
40 | # define PLOOPY_DPI_OPTIONS { CPI375, CPI750, CPI1375 } | 40 | # define PLOOPY_DPI_OPTIONS \ |
41 | { 375, 750, 1375 } | ||
41 | # ifndef PLOOPY_DPI_DEFAULT | 42 | # ifndef PLOOPY_DPI_DEFAULT |
42 | # define PLOOPY_DPI_DEFAULT 2 | 43 | # define PLOOPY_DPI_DEFAULT 2 |
43 | # endif | 44 | # endif |
@@ -49,12 +50,8 @@ | |||
49 | 50 | ||
50 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; | 51 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { }; |
51 | 52 | ||
52 | // Transformation constants for delta-X and delta-Y | ||
53 | const static float ADNS_X_TRANSFORM = -1.0; | ||
54 | const static float ADNS_Y_TRANSFORM = 1.0; | ||
55 | |||
56 | keyboard_config_t keyboard_config; | 53 | keyboard_config_t keyboard_config; |
57 | uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; | 54 | uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; |
58 | #define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) | 55 | #define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) |
59 | 56 | ||
60 | // TODO: Implement libinput profiles | 57 | // TODO: Implement libinput profiles |
@@ -63,77 +60,13 @@ uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; | |||
63 | // Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC | 60 | // Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC |
64 | 61 | ||
65 | // Trackball State | 62 | // Trackball State |
66 | bool is_scroll_clicked = false; | 63 | bool is_scroll_clicked = false; |
67 | bool BurstState = false; // init burst state for Trackball module | 64 | bool BurstState = false; // init burst state for Trackball module |
68 | uint16_t MotionStart = 0; // Timer for accel, 0 is resting state | 65 | uint16_t MotionStart = 0; // Timer for accel, 0 is resting state |
69 | uint16_t lastScroll = 0; // Previous confirmed wheel event | ||
70 | uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed | ||
71 | uint8_t OptLowPin = OPT_ENC1; | ||
72 | bool debug_encoder = false; | ||
73 | |||
74 | __attribute__((weak)) void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y) { | ||
75 | mouse_report->x = x; | ||
76 | mouse_report->y = y; | ||
77 | } | ||
78 | |||
79 | __attribute__((weak)) void process_mouse(report_mouse_t* mouse_report) { | ||
80 | report_adns_t data = adns_read_burst(); | ||
81 | |||
82 | if (data.dx != 0 || data.dy != 0) { | ||
83 | if (debug_mouse) | ||
84 | dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy); | ||
85 | |||
86 | // Apply delta-X and delta-Y transformations. | ||
87 | // x and y are swapped | ||
88 | // the sensor is rotated | ||
89 | // by 90 degrees | ||
90 | float xt = (float) data.dy * ADNS_X_TRANSFORM; | ||
91 | float yt = (float) data.dx * ADNS_Y_TRANSFORM; | ||
92 | |||
93 | int16_t xti = (int16_t)xt; | ||
94 | int16_t yti = (int16_t)yt; | ||
95 | |||
96 | process_mouse_user(mouse_report, xti, yti); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | bool process_record_kb(uint16_t keycode, keyrecord_t* record) { | ||
101 | xprintf("KL: kc: %u, col: %u, row: %u, pressed: %u\n", keycode, record->event.key.col, record->event.key.row, record->event.pressed); | ||
102 | |||
103 | // Update Timer to prevent accidental scrolls | ||
104 | if ((record->event.key.col == 1) && (record->event.key.row == 0)) { | ||
105 | lastMidClick = timer_read(); | ||
106 | is_scroll_clicked = record->event.pressed; | ||
107 | } | ||
108 | |||
109 | if (!process_record_user(keycode, record)) | ||
110 | return false; | ||
111 | |||
112 | if (keycode == DPI_CONFIG && record->event.pressed) { | ||
113 | keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; | ||
114 | eeconfig_update_kb(keyboard_config.raw); | ||
115 | adns_set_cpi(dpi_array[keyboard_config.dpi_config]); | ||
116 | } | ||
117 | 66 | ||
118 | /* If Mousekeys is disabled, then use handle the mouse button | 67 | void pointing_device_init_kb(void) { |
119 | * keycodes. This makes things simpler, and allows usage of | 68 | // set the DPI. |
120 | * the keycodes in a consistent manner. But only do this if | 69 | pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]); |
121 | * Mousekeys is not enable, so it's not handled twice. | ||
122 | */ | ||
123 | #ifndef MOUSEKEY_ENABLE | ||
124 | if (IS_MOUSEKEY_BUTTON(keycode)) { | ||
125 | report_mouse_t currentReport = pointing_device_get_report(); | ||
126 | if (record->event.pressed) { | ||
127 | currentReport.buttons |= 1 << (keycode - KC_MS_BTN1); | ||
128 | } else { | ||
129 | currentReport.buttons &= ~(1 << (keycode - KC_MS_BTN1)); | ||
130 | } | ||
131 | pointing_device_set_report(currentReport); | ||
132 | pointing_device_send(); | ||
133 | } | ||
134 | #endif | ||
135 | |||
136 | return true; | ||
137 | } | 70 | } |
138 | 71 | ||
139 | // Hardware Setup | 72 | // Hardware Setup |
@@ -143,9 +76,6 @@ void keyboard_pre_init_kb(void) { | |||
143 | // debug_mouse = true; | 76 | // debug_mouse = true; |
144 | // debug_encoder = true; | 77 | // debug_encoder = true; |
145 | 78 | ||
146 | setPinInput(OPT_ENC1); | ||
147 | setPinInput(OPT_ENC2); | ||
148 | |||
149 | /* Ground all output pins connected to ground. This provides additional | 79 | /* Ground all output pins connected to ground. This provides additional |
150 | * pathways to ground. If you're messing with this, know this: driving ANY | 80 | * pathways to ground. If you're messing with this, know this: driving ANY |
151 | * of these pins high will cause a short. On the MCU. Ka-blooey. | 81 | * of these pins high will cause a short. On the MCU. Ka-blooey. |
@@ -162,34 +92,6 @@ void keyboard_pre_init_kb(void) { | |||
162 | keyboard_pre_init_user(); | 92 | keyboard_pre_init_user(); |
163 | } | 93 | } |
164 | 94 | ||
165 | void pointing_device_init(void) { | ||
166 | adns_init(); | ||
167 | opt_encoder_init(); | ||
168 | |||
169 | // reboot the adns. | ||
170 | // if the adns hasn't initialized yet, this is harmless. | ||
171 | adns_write_reg(REG_CHIP_RESET, 0x5a); | ||
172 | |||
173 | // wait maximum time before adns is ready. | ||
174 | // this ensures that the adns is actuall ready after reset. | ||
175 | wait_ms(55); | ||
176 | |||
177 | // read a burst from the adns and then discard it. | ||
178 | // gets the adns ready for write commands | ||
179 | // (for example, setting the dpi). | ||
180 | adns_read_burst(); | ||
181 | |||
182 | // set the DPI. | ||
183 | adns_set_cpi(dpi_array[keyboard_config.dpi_config]); | ||
184 | } | ||
185 | |||
186 | void pointing_device_task(void) { | ||
187 | report_mouse_t mouse_report = pointing_device_get_report(); | ||
188 | process_mouse(&mouse_report); | ||
189 | pointing_device_set_report(mouse_report); | ||
190 | pointing_device_send(); | ||
191 | } | ||
192 | |||
193 | void eeconfig_init_kb(void) { | 95 | void eeconfig_init_kb(void) { |
194 | keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; | 96 | keyboard_config.dpi_config = PLOOPY_DPI_DEFAULT; |
195 | eeconfig_update_kb(keyboard_config.raw); | 97 | eeconfig_update_kb(keyboard_config.raw); |
diff --git a/keyboards/ploopyco/trackball_nano/trackball_nano.h b/keyboards/ploopyco/trackball_nano/trackball_nano.h index 6c8ecace7..88725eab6 100644 --- a/keyboards/ploopyco/trackball_nano/trackball_nano.h +++ b/keyboards/ploopyco/trackball_nano/trackball_nano.h | |||
@@ -20,19 +20,6 @@ | |||
20 | #pragma once | 20 | #pragma once |
21 | 21 | ||
22 | #include "quantum.h" | 22 | #include "quantum.h" |
23 | #include "drivers/sensors/adns5050.h" | ||
24 | #include "analog.h" | ||
25 | #include "opt_encoder.h" | ||
26 | #include "pointing_device.h" | ||
27 | |||
28 | // Sensor defs | ||
29 | #define OPT_ENC1 F0 | ||
30 | #define OPT_ENC2 F4 | ||
31 | #define OPT_ENC1_MUX 0 | ||
32 | #define OPT_ENC2_MUX 4 | ||
33 | |||
34 | void process_mouse(report_mouse_t* mouse_report); | ||
35 | void process_mouse_user(report_mouse_t* mouse_report, int16_t x, int16_t y); | ||
36 | 23 | ||
37 | #define LAYOUT(k00) {{ KC_NO }} | 24 | #define LAYOUT(k00) {{ KC_NO }} |
38 | 25 | ||