aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ploopyco
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2021-11-29 08:23:29 -0800
committerGitHub <noreply@github.com>2021-11-29 08:23:29 -0800
commit62e01928cd4d978d275eb28992866ddf0d39922f (patch)
treea516ac7d57d9f1845274ebcbbbb90c9ae33b4980 /keyboards/ploopyco
parent285afa3a8a2c3ae6ad4efffecdc96108f1b2fadc (diff)
downloadqmk_firmware-62e01928cd4d978d275eb28992866ddf0d39922f.tar.gz
qmk_firmware-62e01928cd4d978d275eb28992866ddf0d39922f.zip
[Keyboard] Ploopy improvements (#15348)
Diffstat (limited to 'keyboards/ploopyco')
-rw-r--r--keyboards/ploopyco/mouse/mouse.c25
-rw-r--r--keyboards/ploopyco/mouse/mouse.h13
-rw-r--r--keyboards/ploopyco/mouse/rules.mk3
-rw-r--r--keyboards/ploopyco/trackball/rules.mk3
-rw-r--r--keyboards/ploopyco/trackball/trackball.c30
-rw-r--r--keyboards/ploopyco/trackball/trackball.h3
-rw-r--r--keyboards/ploopyco/trackball_mini/rules.mk5
-rw-r--r--keyboards/ploopyco/trackball_mini/trackball_mini.c58
-rw-r--r--keyboards/ploopyco/trackball_mini/trackball_mini.h13
9 files changed, 109 insertions, 44 deletions
diff --git a/keyboards/ploopyco/mouse/mouse.c b/keyboards/ploopyco/mouse/mouse.c
index 1b00ef3b7..25ebd1ee2 100644
--- a/keyboards/ploopyco/mouse/mouse.c
+++ b/keyboards/ploopyco/mouse/mouse.c
@@ -66,7 +66,24 @@ uint8_t OptLowPin = OPT_ENC1;
66bool debug_encoder = false; 66bool debug_encoder = false;
67bool is_drag_scroll = false; 67bool is_drag_scroll = false;
68 68
69void process_wheel(report_mouse_t* mouse_report) { 69__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
70
71bool encoder_update_kb(uint8_t index, bool clockwise) {
72 if (!encoder_update_user(index, clockwise)) {
73 return false;
74 }
75#ifdef MOUSEKEY_ENABLE
76 tap_code(clockwise ? KC_WH_U : KC_WH_D);
77#else
78 mouse_report_t mouse_report = pointing_device_get_report();
79 mouse_report.v = clockwise ? 1 : -1;
80 pointing_device_set_report(mouse_report);
81 pointing_device_send();
82#endif
83 return true;
84}
85
86void process_wheel(void) {
70 // Lovingly ripped from the Ploopy Source 87 // Lovingly ripped from the Ploopy Source
71 88
72 // If the mouse wheel was just released, do not scroll. 89 // If the mouse wheel was just released, do not scroll.
@@ -94,11 +111,11 @@ void process_wheel(report_mouse_t* mouse_report) {
94 int dir = opt_encoder_handler(p1, p2); 111 int dir = opt_encoder_handler(p1, p2);
95 112
96 if (dir == 0) return; 113 if (dir == 0) return;
97 mouse_report->v = (int8_t)(dir * OPT_SCALE); 114 encoder_update_kb(0, dir == 1);
98} 115}
99 116
100__attribute__((weak)) report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { 117report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
101 process_wheel(&mouse_report); 118 process_wheel();
102 119
103 if (is_drag_scroll) { 120 if (is_drag_scroll) {
104 mouse_report.h = mouse_report.x; 121 mouse_report.h = mouse_report.x;
diff --git a/keyboards/ploopyco/mouse/mouse.h b/keyboards/ploopyco/mouse/mouse.h
index ee5982713..8383049aa 100644
--- a/keyboards/ploopyco/mouse/mouse.h
+++ b/keyboards/ploopyco/mouse/mouse.h
@@ -28,16 +28,16 @@
28#define OPT_ENC1_MUX 0 28#define OPT_ENC1_MUX 0
29#define OPT_ENC2_MUX 4 29#define OPT_ENC2_MUX 4
30 30
31void process_wheel(report_mouse_t* mouse_report); 31void process_wheel(void);
32 32
33#define LAYOUT(BLL, BL, BM, BR, BRR, BF, BB, BDPI) \ 33#define LAYOUT(BLL, BL, BM, BR, BRR, BF, BB, BDPI) \
34 { {BL, BM, BR, BF, BB, BRR, BLL, BDPI}, } 34 { {BL, BM, BR, BF, BB, BRR, BLL, BDPI}, }
35 35
36typedef union { 36typedef union {
37 uint32_t raw; 37 uint32_t raw;
38 struct { 38 struct {
39 uint8_t dpi_config; 39 uint8_t dpi_config;
40 }; 40 };
41} keyboard_config_t; 41} keyboard_config_t;
42 42
43extern keyboard_config_t keyboard_config; 43extern keyboard_config_t keyboard_config;
@@ -56,3 +56,6 @@ enum ploopy_keycodes {
56 PLOOPY_SAFE_RANGE, 56 PLOOPY_SAFE_RANGE,
57#endif 57#endif
58}; 58};
59
60bool encoder_update_user(uint8_t index, bool clockwise);
61bool encoder_update_kb(uint8_t index, bool clockwise);
diff --git a/keyboards/ploopyco/mouse/rules.mk b/keyboards/ploopyco/mouse/rules.mk
index 45cb38901..fd2989be0 100644
--- a/keyboards/ploopyco/mouse/rules.mk
+++ b/keyboards/ploopyco/mouse/rules.mk
@@ -25,5 +25,8 @@ POINTING_DEVICE_ENABLE = yes
25POINTING_DEVICE_DRIVER = pmw3360 25POINTING_DEVICE_DRIVER = pmw3360
26MOUSEKEY_ENABLE = yes # Mouse keys 26MOUSEKEY_ENABLE = yes # Mouse keys
27 27
28ENCODER_ENABLE := no
29OPTS_DEF += -DENCODER_ENABLE
30
28QUANTUM_LIB_SRC += analog.c 31QUANTUM_LIB_SRC += analog.c
29SRC += opt_encoder.c 32SRC += opt_encoder.c
diff --git a/keyboards/ploopyco/trackball/rules.mk b/keyboards/ploopyco/trackball/rules.mk
index d11858152..ea34c0f1d 100644
--- a/keyboards/ploopyco/trackball/rules.mk
+++ b/keyboards/ploopyco/trackball/rules.mk
@@ -22,6 +22,9 @@ POINTING_DEVICE_ENABLE = yes
22POINTING_DEVICE_DRIVER = pmw3360 22POINTING_DEVICE_DRIVER = pmw3360
23MOUSEKEY_ENABLE = yes # Mouse keys 23MOUSEKEY_ENABLE = yes # Mouse keys
24 24
25ENCODER_ENABLE := no
26OPTS_DEF += -DENCODER_ENABLE
27
25QUANTUM_LIB_SRC += analog.c 28QUANTUM_LIB_SRC += analog.c
26SRC += opt_encoder.c 29SRC += opt_encoder.c
27 30
diff --git a/keyboards/ploopyco/trackball/trackball.c b/keyboards/ploopyco/trackball/trackball.c
index da4bbf224..25b36574a 100644
--- a/keyboards/ploopyco/trackball/trackball.c
+++ b/keyboards/ploopyco/trackball/trackball.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
49keyboard_config_t keyboard_config; 50keyboard_config_t keyboard_config;
@@ -65,7 +66,24 @@ uint8_t OptLowPin = OPT_ENC1;
65bool debug_encoder = false; 66bool debug_encoder = false;
66bool is_drag_scroll = false; 67bool is_drag_scroll = false;
67 68
68void process_wheel(report_mouse_t* mouse_report) { 69__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
70
71bool encoder_update_kb(uint8_t index, bool clockwise) {
72 if (!encoder_update_user(index, clockwise)) {
73 return false;
74 }
75#ifdef MOUSEKEY_ENABLE
76 tap_code(clockwise ? KC_WH_U : KC_WH_D);
77#else
78 mouse_report_t mouse_report = pointing_device_get_report();
79 mouse_report.v = clockwise ? 1 : -1;
80 pointing_device_set_report(mouse_report);
81 pointing_device_send();
82#endif
83 return true;
84}
85
86void process_wheel(void) {
69 // TODO: Replace this with interrupt driven code, polling is S L O W 87 // TODO: Replace this with interrupt driven code, polling is S L O W
70 // Lovingly ripped from the Ploopy Source 88 // Lovingly ripped from the Ploopy Source
71 89
@@ -94,11 +112,11 @@ void process_wheel(report_mouse_t* mouse_report) {
94 int dir = opt_encoder_handler(p1, p2); 112 int dir = opt_encoder_handler(p1, p2);
95 113
96 if (dir == 0) return; 114 if (dir == 0) return;
97 mouse_report->v = (int8_t)(dir * OPT_SCALE); 115 encoder_update_kb(0, dir == 1);
98} 116}
99 117
100report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { 118report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
101 process_wheel(&mouse_report); 119 process_wheel();
102 120
103 if (is_drag_scroll) { 121 if (is_drag_scroll) {
104 mouse_report.h = mouse_report.x; 122 mouse_report.h = mouse_report.x;
diff --git a/keyboards/ploopyco/trackball/trackball.h b/keyboards/ploopyco/trackball/trackball.h
index 52d955325..add2deb29 100644
--- a/keyboards/ploopyco/trackball/trackball.h
+++ b/keyboards/ploopyco/trackball/trackball.h
@@ -61,3 +61,6 @@ enum ploopy_keycodes {
61 PLOOPY_SAFE_RANGE, 61 PLOOPY_SAFE_RANGE,
62#endif 62#endif
63}; 63};
64
65bool encoder_update_user(uint8_t index, bool clockwise);
66bool encoder_update_kb(uint8_t index, bool clockwise);
diff --git a/keyboards/ploopyco/trackball_mini/rules.mk b/keyboards/ploopyco/trackball_mini/rules.mk
index 8d76c9b3d..428c8e8ef 100644
--- a/keyboards/ploopyco/trackball_mini/rules.mk
+++ b/keyboards/ploopyco/trackball_mini/rules.mk
@@ -20,7 +20,10 @@ RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow
20AUDIO_ENABLE = no # Audio output 20AUDIO_ENABLE = no # Audio output
21POINTING_DEVICE_ENABLE = yes 21POINTING_DEVICE_ENABLE = yes
22POINTING_DEVICE_DRIVER = adns5050 22POINTING_DEVICE_DRIVER = adns5050
23MOUSEKEY_ENABLE = no # Mouse keys 23MOUSEKEY_ENABLE = yes # Mouse keys
24
25ENCODER_ENABLE := no
26OPTS_DEF += -DENCODER_ENABLE
24 27
25QUANTUM_LIB_SRC += analog.c 28QUANTUM_LIB_SRC += analog.c
26SRC += opt_encoder.c 29SRC += opt_encoder.c
diff --git a/keyboards/ploopyco/trackball_mini/trackball_mini.c b/keyboards/ploopyco/trackball_mini/trackball_mini.c
index 2158a8f48..2b511c4ea 100644
--- a/keyboards/ploopyco/trackball_mini/trackball_mini.c
+++ b/keyboards/ploopyco/trackball_mini/trackball_mini.c
@@ -45,11 +45,11 @@
45# define PLOOPY_DRAGSCROLL_DPI 375 // Fixed-DPI Drag Scroll 45# define PLOOPY_DRAGSCROLL_DPI 375 // Fixed-DPI Drag Scroll
46#endif 46#endif
47#ifndef PLOOPY_DRAGSCROLL_MULTIPLIER 47#ifndef PLOOPY_DRAGSCROLL_MULTIPLIER
48# define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll 48# define PLOOPY_DRAGSCROLL_MULTIPLIER 0.75 // Variable-DPI Drag Scroll
49#endif 49#endif
50 50
51keyboard_config_t keyboard_config; 51keyboard_config_t keyboard_config;
52uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS; 52uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
53#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t)) 53#define DPI_OPTION_SIZE (sizeof(dpi_array) / sizeof(uint16_t))
54 54
55// TODO: Implement libinput profiles 55// TODO: Implement libinput profiles
@@ -58,23 +58,38 @@ uint16_t dpi_array[] = PLOOPY_DPI_OPTIONS;
58// Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC 58// Valid options are ACC_NONE, ACC_LINEAR, ACC_CUSTOM, ACC_QUADRATIC
59 59
60// Trackball State 60// Trackball State
61bool is_scroll_clicked = false; 61bool is_scroll_clicked = false;
62bool BurstState = false; // init burst state for Trackball module 62bool BurstState = false; // init burst state for Trackball module
63uint16_t MotionStart = 0; // Timer for accel, 0 is resting state 63uint16_t MotionStart = 0; // Timer for accel, 0 is resting state
64uint16_t lastScroll = 0; // Previous confirmed wheel event 64uint16_t lastScroll = 0; // Previous confirmed wheel event
65uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed 65uint16_t lastMidClick = 0; // Stops scrollwheel from being read if it was pressed
66uint8_t OptLowPin = OPT_ENC1; 66uint8_t OptLowPin = OPT_ENC1;
67bool debug_encoder = false; 67bool debug_encoder = false;
68bool is_drag_scroll = false; 68bool is_drag_scroll = false;
69 69
70void process_wheel(report_mouse_t* mouse_report) { 70__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
71
72bool encoder_update_kb(uint8_t index, bool clockwise) {
73 if (!encoder_update_user(index, clockwise)) {
74 return false;
75 }
76#ifdef MOUSEKEY_ENABLE
77 tap_code(clockwise ? KC_WH_U : KC_WH_D);
78#else
79 mouse_report_t mouse_report = pointing_device_get_report();
80 mouse_report.v = clockwise ? 1 : -1;
81 pointing_device_set_report(mouse_report);
82 pointing_device_send();
83#endif
84 return true;
85}
86
87void process_wheel(void) {
71 // If the mouse wheel was just released, do not scroll. 88 // If the mouse wheel was just released, do not scroll.
72 if (timer_elapsed(lastMidClick) < SCROLL_BUTT_DEBOUNCE) 89 if (timer_elapsed(lastMidClick) < SCROLL_BUTT_DEBOUNCE) return;
73 return;
74 90
75 // Limit the number of scrolls per unit time. 91 // Limit the number of scrolls per unit time.
76 if (timer_elapsed(lastScroll) < OPT_DEBOUNCE) 92 if (timer_elapsed(lastScroll) < OPT_DEBOUNCE) return;
77 return;
78 93
79 // Don't scroll if the middle button is depressed. 94 // Don't scroll if the middle button is depressed.
80 if (is_scroll_clicked) { 95 if (is_scroll_clicked) {
@@ -87,15 +102,12 @@ void process_wheel(report_mouse_t* mouse_report) {
87 uint16_t p1 = adc_read(OPT_ENC1_MUX); 102 uint16_t p1 = adc_read(OPT_ENC1_MUX);
88 uint16_t p2 = adc_read(OPT_ENC2_MUX); 103 uint16_t p2 = adc_read(OPT_ENC2_MUX);
89 104
90 if (debug_encoder) 105 if (debug_encoder) dprintf("OPT1: %d, OPT2: %d\n", p1, p2);
91 dprintf("OPT1: %d, OPT2: %d\n", p1, p2);
92 106
93 uint8_t dir = opt_encoder_handler(p1, p2); 107 uint8_t dir = opt_encoder_handler(p1, p2);
94 108
95 if (dir == 0) 109 if (dir == 0) return;
96 return; 110 encoder_update_kb(0, dir == 1);
97
98 mouse_report->v = (int8_t)(dir * OPT_SCALE);
99} 111}
100 112
101void pointing_device_init_kb(void) { 113void pointing_device_init_kb(void) {
@@ -106,6 +118,7 @@ void pointing_device_init_kb(void) {
106} 118}
107 119
108report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) { 120report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
121 process_wheel();
109 122
110 if (is_drag_scroll) { 123 if (is_drag_scroll) {
111 mouse_report.h = mouse_report.x; 124 mouse_report.h = mouse_report.x;
@@ -127,12 +140,11 @@ bool process_record_kb(uint16_t keycode, keyrecord_t* record) {
127 140
128 // Update Timer to prevent accidental scrolls 141 // Update Timer to prevent accidental scrolls
129 if ((record->event.key.col == 1) && (record->event.key.row == 0)) { 142 if ((record->event.key.col == 1) && (record->event.key.row == 0)) {
130 lastMidClick = timer_read(); 143 lastMidClick = timer_read();
131 is_scroll_clicked = record->event.pressed; 144 is_scroll_clicked = record->event.pressed;
132 } 145 }
133 146
134 if (!process_record_user(keycode, record)) 147 if (!process_record_user(keycode, record)) return false;
135 return false;
136 148
137 if (keycode == DPI_CONFIG && record->event.pressed) { 149 if (keycode == DPI_CONFIG && record->event.pressed) {
138 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE; 150 keyboard_config.dpi_config = (keyboard_config.dpi_config + 1) % DPI_OPTION_SIZE;
diff --git a/keyboards/ploopyco/trackball_mini/trackball_mini.h b/keyboards/ploopyco/trackball_mini/trackball_mini.h
index fc86fe776..3af2a49b5 100644
--- a/keyboards/ploopyco/trackball_mini/trackball_mini.h
+++ b/keyboards/ploopyco/trackball_mini/trackball_mini.h
@@ -29,16 +29,16 @@
29#define OPT_ENC1_MUX 0 29#define OPT_ENC1_MUX 0
30#define OPT_ENC2_MUX 4 30#define OPT_ENC2_MUX 4
31 31
32void process_wheel(report_mouse_t* mouse_report); 32void process_wheel(void);
33 33
34#define LAYOUT(BL, BM, BR, BF, BB) \ 34#define LAYOUT(BL, BM, BR, BF, BB) \
35 { {BL, BM, BR, BF, BB}, } 35 { {BL, BM, BR, BF, BB}, }
36 36
37typedef union { 37typedef union {
38 uint32_t raw; 38 uint32_t raw;
39 struct { 39 struct {
40 uint8_t dpi_config; 40 uint8_t dpi_config;
41 }; 41 };
42} keyboard_config_t; 42} keyboard_config_t;
43 43
44extern keyboard_config_t keyboard_config; 44extern keyboard_config_t keyboard_config;
@@ -56,3 +56,6 @@ enum ploopy_keycodes {
56 PLOOPY_SAFE_RANGE, 56 PLOOPY_SAFE_RANGE,
57#endif 57#endif
58}; 58};
59
60bool encoder_update_user(uint8_t index, bool clockwise);
61bool encoder_update_kb(uint8_t index, bool clockwise);