summaryrefslogtreecommitdiff
path: root/keyboards/ploopyco/trackball
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2024-02-18 21:17:15 +1100
committerGitHub <noreply@github.com>2024-02-18 21:17:15 +1100
commit9d9cdaaa2d035787b0b50c26f2975695fdbc16f4 (patch)
tree1a9f5d16ffc0e3bd27bc14791c25405a79ccd069 /keyboards/ploopyco/trackball
parent2eb9ff8efd1df2c98724481c71c8ab8a5b62e31e (diff)
Add encoder abstraction. (#21548)
Diffstat (limited to 'keyboards/ploopyco/trackball')
-rw-r--r--keyboards/ploopyco/trackball/config.h3
-rw-r--r--keyboards/ploopyco/trackball/info.json6
-rw-r--r--keyboards/ploopyco/trackball/rules.mk3
-rw-r--r--keyboards/ploopyco/trackball/trackball.c20
4 files changed, 19 insertions, 13 deletions
diff --git a/keyboards/ploopyco/trackball/config.h b/keyboards/ploopyco/trackball/config.h
index de0ed1ebec..a1f3695d81 100644
--- a/keyboards/ploopyco/trackball/config.h
+++ b/keyboards/ploopyco/trackball/config.h
@@ -31,3 +31,6 @@
/* PMW33XX Settings */
#define PMW33XX_CS_PIN B0
#define POINTING_DEVICE_INVERT_Y
+
+/* Custom encoder needs to specify just how many encoders we have */
+#define NUM_ENCODERS 1
diff --git a/keyboards/ploopyco/trackball/info.json b/keyboards/ploopyco/trackball/info.json
index 2c30755aa1..110264ef1c 100644
--- a/keyboards/ploopyco/trackball/info.json
+++ b/keyboards/ploopyco/trackball/info.json
@@ -12,6 +12,12 @@
"bootmagic": {
"matrix": [0, 3]
},
+ "features": {
+ "encoder": true
+ },
+ "encoder": {
+ "driver": "custom"
+ },
"layouts": {
"LAYOUT": {
"layout": [
diff --git a/keyboards/ploopyco/trackball/rules.mk b/keyboards/ploopyco/trackball/rules.mk
index ce7c4f29c8..ca1a8fd17a 100644
--- a/keyboards/ploopyco/trackball/rules.mk
+++ b/keyboards/ploopyco/trackball/rules.mk
@@ -16,9 +16,6 @@ POINTING_DEVICE_ENABLE = yes
POINTING_DEVICE_DRIVER = pmw3360
MOUSEKEY_ENABLE = yes # Mouse keys
-ENCODER_ENABLE := no
-OPTS_DEF += -DENCODER_ENABLE
-
ANALOG_DRIVER_REQUIRED = yes
SRC += opt_encoder.c
diff --git a/keyboards/ploopyco/trackball/trackball.c b/keyboards/ploopyco/trackball/trackball.c
index 8fd5b8650d..0c606bab07 100644
--- a/keyboards/ploopyco/trackball/trackball.c
+++ b/keyboards/ploopyco/trackball/trackball.c
@@ -66,8 +66,6 @@ uint8_t OptLowPin = OPT_ENC1;
bool debug_encoder = false;
bool is_drag_scroll = false;
-__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
-
bool encoder_update_kb(uint8_t index, bool clockwise) {
if (!encoder_update_user(index, clockwise)) {
return false;
@@ -83,7 +81,15 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
return true;
}
-void process_wheel(void) {
+
+void encoder_driver_init(void) {
+ setPinInput(OPT_ENC1);
+ setPinInput(OPT_ENC2);
+
+ opt_encoder_init();
+}
+
+void encoder_driver_task(void) {
// TODO: Replace this with interrupt driven code, polling is S L O W
// Lovingly ripped from the Ploopy Source
@@ -112,11 +118,10 @@ void process_wheel(void) {
int dir = opt_encoder_handler(p1, p2);
if (dir == 0) return;
- encoder_update_kb(0, dir > 0);
+ encoder_queue_event(0, dir == 1);
}
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
- process_wheel();
if (is_drag_scroll) {
#ifdef PLOOPY_DRAGSCROLL_H_INVERT
@@ -189,9 +194,6 @@ void keyboard_pre_init_kb(void) {
// debug_mouse = true;
// debug_encoder = true;
- setPinInput(OPT_ENC1);
- setPinInput(OPT_ENC2);
-
/* Ground all output pins connected to ground. This provides additional
* pathways to ground. If you're messing with this, know this: driving ANY
* of these pins high will cause a short. On the MCU. Ka-blooey.
@@ -216,8 +218,6 @@ void keyboard_pre_init_kb(void) {
void pointing_device_init_kb(void) {
pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
- // initialize the scroll wheel's optical encoder
- opt_encoder_init();
}
void eeconfig_init_kb(void) {