summaryrefslogtreecommitdiff
path: root/keyboards
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
parent2eb9ff8efd1df2c98724481c71c8ab8a5b62e31e (diff)
Add encoder abstraction. (#21548)
Diffstat (limited to 'keyboards')
-rw-r--r--keyboards/mechwild/sugarglider/matrix.c6
-rw-r--r--keyboards/pica40/rev2/post_rules.mk8
-rw-r--r--keyboards/pica40/rev2/rev2.c98
-rw-r--r--keyboards/planck/rev7/info.json9
-rw-r--r--keyboards/planck/rev7/matrix.c86
-rw-r--r--keyboards/ploopyco/mouse/config.h3
-rw-r--r--keyboards/ploopyco/mouse/info.json6
-rw-r--r--keyboards/ploopyco/mouse/mouse.c20
-rw-r--r--keyboards/ploopyco/mouse/rules.mk3
-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
-rw-r--r--keyboards/ploopyco/trackball_mini/config.h3
-rw-r--r--keyboards/ploopyco/trackball_mini/info.json6
-rw-r--r--keyboards/ploopyco/trackball_mini/rules.mk3
-rw-r--r--keyboards/ploopyco/trackball_mini/trackball_mini.c20
-rw-r--r--keyboards/ploopyco/trackball_thumb/config.h3
-rw-r--r--keyboards/ploopyco/trackball_thumb/info.json5
-rw-r--r--keyboards/ploopyco/trackball_thumb/post_rules.mk4
-rw-r--r--keyboards/ploopyco/trackball_thumb/trackball_thumb.c20
-rw-r--r--keyboards/ploopyco/trackball_thumb/trackball_thumb.h3
22 files changed, 110 insertions, 228 deletions
diff --git a/keyboards/mechwild/sugarglider/matrix.c b/keyboards/mechwild/sugarglider/matrix.c
index 96a16df542..c76a8345d3 100644
--- a/keyboards/mechwild/sugarglider/matrix.c
+++ b/keyboards/mechwild/sugarglider/matrix.c
@@ -50,7 +50,7 @@ static void select_row(uint8_t row) {
//wait_us(100);
return;
}
-
+
if (row > 1) {
mcp23018_errors += !mcp23018_set_config(I2C_ADDR, mcp23018_PORTB, ALL_INPUT);
mcp23018_errors += !mcp23018_set_config(I2C_ADDR, mcp23018_PORTA, ~(row_pos[row]));
@@ -87,8 +87,10 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
bool changed = false;
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
changed |= read_cols_on_row(current_matrix, current_row);
+
#ifdef ENCODER_ENABLE
- encoder_read();
+ // Need to frequently read the encoder pins while scanning because the I/O expander takes a long time in comparison.
+ encoder_driver_task();
#endif
}
return changed;
diff --git a/keyboards/pica40/rev2/post_rules.mk b/keyboards/pica40/rev2/post_rules.mk
deleted file mode 100644
index e4dda1925b..0000000000
--- a/keyboards/pica40/rev2/post_rules.mk
+++ /dev/null
@@ -1,8 +0,0 @@
-# if ENCODER_ENABLE is set, add defines but avoid adding encoder.c as it's replaced by custom code in rev2.c
-ifeq ($(strip $(ENCODER_ENABLE)), yes)
- ENCODER_ENABLE := no
- OPT_DEFS += -DENCODER_ENABLE
- ifeq ($(strip $(ENCODER_MAP_ENABLE)), yes)
- OPT_DEFS += -DENCODER_MAP_ENABLE
- endif
-endif
diff --git a/keyboards/pica40/rev2/rev2.c b/keyboards/pica40/rev2/rev2.c
index c585ec56d6..2ee73dcc6b 100644
--- a/keyboards/pica40/rev2/rev2.c
+++ b/keyboards/pica40/rev2/rev2.c
@@ -2,99 +2,29 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "rev2.h"
+#include "gpio.h"
#ifdef ENCODER_ENABLE // code based on encoder.c
-static const pin_t encoders_pad_a[] = ENCODERS_PAD_A;
-static const pin_t encoders_pad_b[] = ENCODERS_PAD_B;
-
-static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
-static uint8_t encoder_state = 3;
-static int8_t encoder_pulses = 0;
-static uint8_t encoder_value = 0;
-
-typedef struct encoder_sync_data {
- int value;
-} encoder_sync_data;
+#define ENCODER_PIN_A (((pin_t[])ENCODERS_PAD_A)[0])
+#define ENCODER_PIN_B (((pin_t[])ENCODERS_PAD_B)[0])
// custom handler that returns encoder B pin status from slave side
void encoder_sync_slave_handler(uint8_t in_buflen, const void *in_data, uint8_t out_buflen, void *out_data) {
- encoder_sync_data *data = (encoder_sync_data *)out_data;
- data->value = readPin(encoders_pad_b[0]);
-}
-
-__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) {
- return true;
+ *(uint8_t *)out_data = readPin(ENCODER_PIN_B) ? 1 : 0;
}
-bool encoder_update_kb(uint8_t index, bool clockwise) {
- if (!encoder_update_user(index, clockwise)) return false;
-
- tap_code(clockwise ? KC_VOLU : KC_VOLD);
+void encoder_quadrature_init_pin(uint8_t index, bool pad_b) {}
- return false;
-}
-
-#ifdef ENCODER_MAP_ENABLE
-static void encoder_exec_mapping(uint8_t index, bool clockwise) {
- action_exec(clockwise ? ENCODER_CW_EVENT(index, true) : ENCODER_CCW_EVENT(index, true));
- wait_ms(ENCODER_MAP_KEY_DELAY);
- action_exec(clockwise ? ENCODER_CW_EVENT(index, false) : ENCODER_CCW_EVENT(index, false));
- wait_ms(ENCODER_MAP_KEY_DELAY);
-}
-#endif // ENCODER_MAP_ENABLE
-
-void encoder_init(void) {
- setPinInputHigh(encoders_pad_a[0]);
- setPinInputHigh(encoders_pad_b[0]);
- wait_us(100);
- transaction_register_rpc(ENCODER_SYNC, encoder_sync_slave_handler);
-}
-
-bool encoder_read(void) {
- // ignore if running on slave side
- if (!is_keyboard_master()) return false;
-
- bool changed = false;
- encoder_sync_data data = {0};
- // request pin B status from slave side
- if (transaction_rpc_recv(ENCODER_SYNC, sizeof(data), &data)) {
- uint8_t new_status = (readPin(encoders_pad_a[0]) << 0) | (data.value << 1);
- if ((encoder_state & 0x3) != new_status) {
- encoder_state <<= 2;
- encoder_state |= new_status;
- encoder_pulses += encoder_LUT[encoder_state & 0xF];
-
- if (encoder_pulses >= ENCODER_RESOLUTION) {
- encoder_value++;
- changed = true;
-#ifdef ENCODER_MAP_ENABLE
- encoder_exec_mapping(0, false);
-#else // ENCODER_MAP_ENABLE
- encoder_update_kb(0, false);
-#endif // ENCODER_MAP_ENABLE
- }
-
- if (encoder_pulses <= -ENCODER_RESOLUTION) {
- encoder_value--;
- changed = true;
-#ifdef ENCODER_MAP_ENABLE
- encoder_exec_mapping(0, true);
-#else // ENCODER_MAP_ENABLE
- encoder_update_kb(0, true);
-#endif // ENCODER_MAP_ENABLE
- }
-
- encoder_pulses %= ENCODER_RESOLUTION;
- }
+uint8_t encoder_quadrature_read_pin(uint8_t index, bool pad_b) {
+ if(pad_b) {
+ uint8_t data = 0;
+ transaction_rpc_recv(ENCODER_SYNC, sizeof(data), &data);
+ return data;
}
- return changed;
+ return readPin(ENCODER_PIN_A) ? 1 : 0;
}
-// do not use standard split encoder transactions
-void encoder_state_raw(uint8_t *slave_state) {}
-void encoder_update_raw(uint8_t *slave_state) {}
-
#endif // ENCODER_ENABLE
#ifdef PICA40_RGBLIGHT_TIMEOUT
@@ -125,6 +55,12 @@ bool should_set_rgblight = false;
void keyboard_post_init_kb(void) {
setPinOutput(PICA40_RGB_POWER_PIN);
+#ifdef ENCODER_ENABLE
+ setPinInputHigh(ENCODER_PIN_A);
+ setPinInputHigh(ENCODER_PIN_B);
+ transaction_register_rpc(ENCODER_SYNC, encoder_sync_slave_handler);
+#endif // ENCODER_ENABLE
+
#ifdef PICA40_RGBLIGHT_TIMEOUT
idle_timer = timer_read();
check_rgblight_timer = timer_read();
diff --git a/keyboards/planck/rev7/info.json b/keyboards/planck/rev7/info.json
index 2275965ebd..d674af98d1 100644
--- a/keyboards/planck/rev7/info.json
+++ b/keyboards/planck/rev7/info.json
@@ -26,7 +26,14 @@
},
"encoder": {
"rotary": [
- {"pin_a": "B12", "pin_b": "B13"}
+ {"pin_a": "B12", "pin_b": "B13"},
+ {"pin_a": "B12", "pin_b": "B13"},
+ {"pin_a": "B12", "pin_b": "B13"},
+ {"pin_a": "B12", "pin_b": "B13"},
+ {"pin_a": "B12", "pin_b": "B13"},
+ {"pin_a": "B12", "pin_b": "B13"},
+ {"pin_a": "B12", "pin_b": "B13"},
+ {"pin_a": "B12", "pin_b": "B13"}
]
},
"features": {
diff --git a/keyboards/planck/rev7/matrix.c b/keyboards/planck/rev7/matrix.c
index c89c399a40..350ce93ce0 100644
--- a/keyboards/planck/rev7/matrix.c
+++ b/keyboards/planck/rev7/matrix.c
@@ -32,31 +32,16 @@
#define STM32_IWDG_RL_MS(s) STM32_IWDG_RL_US(s * 1000.0)
#define STM32_IWDG_RL_S(s) STM32_IWDG_RL_US(s * 1000000.0)
-#if !defined(PLANCK_ENCODER_RESOLUTION)
-# define PLANCK_ENCODER_RESOLUTION 4
-#endif
-
#if !defined(PLANCK_WATCHDOG_TIMEOUT)
# define PLANCK_WATCHDOG_TIMEOUT 1.0
#endif
-#ifdef ENCODER_MAP_ENABLE
-#error "The encoder map feature is not currently supported by the Planck's encoder matrix"
-#endif
-
/* matrix state(1:on, 0:off) */
static pin_t matrix_row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
static pin_t matrix_col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
static matrix_row_t matrix_inverted[MATRIX_COLS];
-#ifdef ENCODER_ENABLE
-int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
-uint8_t encoder_state[8] = {0};
-int8_t encoder_pulses[8] = {0};
-uint8_t encoder_value[8] = {0};
-#endif
-
void matrix_init_custom(void) {
// actual matrix setup - cols
for (int i = 0; i < MATRIX_COLS; i++) {
@@ -84,31 +69,6 @@ void matrix_init_custom(void) {
#endif
}
-#ifdef ENCODER_ENABLE
-bool encoder_update(uint8_t index, uint8_t state) {
- bool changed = false;
- uint8_t i = index;
-
- encoder_pulses[i] += encoder_LUT[state & 0xF];
-
- if (encoder_pulses[i] >= PLANCK_ENCODER_RESOLUTION) {
- encoder_value[index]++;
- changed = true;
- encoder_update_kb(index, false);
- }
- if (encoder_pulses[i] <= -PLANCK_ENCODER_RESOLUTION) {
- encoder_value[index]--;
- changed = true;
- encoder_update_kb(index, true);
- }
- encoder_pulses[i] %= PLANCK_ENCODER_RESOLUTION;
-#ifdef ENCODER_DEFAULT_POS
- encoder_pulses[i] = 0;
-#endif
- return changed;
-}
-#endif
-
bool matrix_scan_custom(matrix_row_t current_matrix[]) {
#ifndef PLANCK_WATCHDOG_DISABLE
// reset watchdog
@@ -149,40 +109,16 @@ bool matrix_scan_custom(matrix_row_t current_matrix[]) {
changed |= old != current_matrix[row];
}
-#ifdef ENCODER_ENABLE
- // encoder-matrix functionality
-
- // set up C/rows for encoder read
- for (int i = 0; i < MATRIX_ROWS; i++) {
- setPinOutput(matrix_row_pins[i]);
- writePinHigh(matrix_row_pins[i]);
- }
-
- // set up A & B for reading
- setPinInputHigh(B12);
- setPinInputHigh(B13);
-
- for (int i = 0; i < MATRIX_ROWS; i++) {
- writePinLow(matrix_row_pins[i]);
- wait_us(10);
- uint8_t new_status = (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1);
- if ((encoder_state[i] & 0x3) != new_status) {
- encoder_state[i] <<= 2;
- encoder_state[i] |= new_status;
- encoder_update(i, encoder_state[i]);
- }
- writePinHigh(matrix_row_pins[i]);
- }
-
- // revert A & B to matrix state
- setPinInputLow(B12);
- setPinInputLow(B13);
-
- // revert C/rows to matrix state
- for (int i = 0; i < MATRIX_ROWS; i++) {
- setPinInputLow(matrix_row_pins[i]);
- }
-#endif
-
return changed;
}
+
+uint8_t encoder_quadrature_read_pin(uint8_t index, bool pad_b) {
+ pin_t pin = pad_b ? B13: B12;
+ setPinInputHigh(pin);
+ writePinLow(matrix_row_pins[index]);
+ wait_us(10);
+ uint8_t ret = readPin(pin) ? 1 : 0;
+ setPinInputLow(matrix_row_pins[index]);
+ setPinInputLow(pin);
+ return ret;
+}
diff --git a/keyboards/ploopyco/mouse/config.h b/keyboards/ploopyco/mouse/config.h
index 94bd6ef6af..86af11fc94 100644
--- a/keyboards/ploopyco/mouse/config.h
+++ b/keyboards/ploopyco/mouse/config.h
@@ -32,3 +32,6 @@
/* PMW33XX Settings */
#define PMW33XX_CS_PIN B0
+
+/* Custom encoder needs to specify just how many encoders we have */
+#define NUM_ENCODERS 1
diff --git a/keyboards/ploopyco/mouse/info.json b/keyboards/ploopyco/mouse/info.json
index 5dc53392ff..1f110aad71 100644
--- a/keyboards/ploopyco/mouse/info.json
+++ b/keyboards/ploopyco/mouse/info.json
@@ -31,6 +31,12 @@
["D4", "D2", "E6", "B6", "D7", "C6", "C7", "B7"]
]
},
+ "features": {
+ "encoder": true
+ },
+ "encoder": {
+ "driver": "custom"
+ },
"layouts": {
"LAYOUT": {
"layout": [
diff --git a/keyboards/ploopyco/mouse/mouse.c b/keyboards/ploopyco/mouse/mouse.c
index e2dada4a15..5f4a82e474 100644
--- a/keyboards/ploopyco/mouse/mouse.c
+++ b/keyboards/ploopyco/mouse/mouse.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,14 @@ 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) {
// Lovingly ripped from the Ploopy Source
// If the mouse wheel was just released, do not scroll.
@@ -111,12 +116,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) {
mouse_report.h = mouse_report.x;
#ifdef PLOOPY_DRAGSCROLL_INVERT
@@ -177,9 +180,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.
@@ -204,8 +204,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) {
diff --git a/keyboards/ploopyco/mouse/rules.mk b/keyboards/ploopyco/mouse/rules.mk
index 17df9cc3c9..6356950780 100644
--- a/keyboards/ploopyco/mouse/rules.mk
+++ b/keyboards/ploopyco/mouse/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/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) {
diff --git a/keyboards/ploopyco/trackball_mini/config.h b/keyboards/ploopyco/trackball_mini/config.h
index 789deb5a5f..6b92563fa9 100644
--- a/keyboards/ploopyco/trackball_mini/config.h
+++ b/keyboards/ploopyco/trackball_mini/config.h
@@ -32,3 +32,6 @@
#define ADNS5050_CS_PIN B4
#define POINTING_DEVICE_ROTATION_270
+
+/* Custom encoder needs to specify just how many encoders we have */
+#define NUM_ENCODERS 1
diff --git a/keyboards/ploopyco/trackball_mini/info.json b/keyboards/ploopyco/trackball_mini/info.json
index 301c8d18ec..0e7b12d20d 100644
--- a/keyboards/ploopyco/trackball_mini/info.json
+++ b/keyboards/ploopyco/trackball_mini/info.json
@@ -14,6 +14,12 @@
},
"processor": "atmega32u4",
"bootloader": "atmel-dfu",
+ "features": {
+ "encoder": true
+ },
+ "encoder": {
+ "driver": "custom"
+ },
"layouts": {
"LAYOUT": {
"layout": [
diff --git a/keyboards/ploopyco/trackball_mini/rules.mk b/keyboards/ploopyco/trackball_mini/rules.mk
index bcede0676c..d2bacc3974 100644
--- a/keyboards/ploopyco/trackball_mini/rules.mk
+++ b/keyboards/ploopyco/trackball_mini/rules.mk
@@ -13,9 +13,6 @@ POINTING_DEVICE_ENABLE = yes
POINTING_DEVICE_DRIVER = adns5050
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_mini/trackball_mini.c b/keyboards/ploopyco/trackball_mini/trackball_mini.c
index 8bc0ab99c2..8517a54e70 100644
--- a/keyboards/ploopyco/trackball_mini/trackball_mini.c
+++ b/keyboards/ploopyco/trackball_mini/trackball_mini.c
@@ -74,8 +74,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;
@@ -91,7 +89,14 @@ 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) {
uint16_t p1 = adc_read(OPT_ENC1_MUX);
uint16_t p2 = adc_read(OPT_ENC2_MUX);
@@ -113,21 +118,17 @@ void process_wheel(void) {
}
if (dir == 0) return;
- encoder_update_kb(0, dir > 0);
+ encoder_queue_event(0, dir == 1);
lastScroll = timer_read();
}
void pointing_device_init_kb(void) {
- opt_encoder_init();
-
// set the DPI.
pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
}
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
- process_wheel();
-
if (is_drag_scroll) {
mouse_report.h = mouse_report.x;
#ifdef PLOOPY_DRAGSCROLL_INVERT
@@ -180,9 +181,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.
diff --git a/keyboards/ploopyco/trackball_thumb/config.h b/keyboards/ploopyco/trackball_thumb/config.h
index 8fc084c38c..316755f686 100644
--- a/keyboards/ploopyco/trackball_thumb/config.h
+++ b/keyboards/ploopyco/trackball_thumb/config.h
@@ -31,3 +31,6 @@
/* PMW3360 Settings */
#define POINTING_DEVICE_CS_PIN B0
+
+/* Custom encoder needs to specify just how many encoders we have */
+#define NUM_ENCODERS 1
diff --git a/keyboards/ploopyco/trackball_thumb/info.json b/keyboards/ploopyco/trackball_thumb/info.json
index 72e236a5bb..e27bf47252 100644
--- a/keyboards/ploopyco/trackball_thumb/info.json
+++ b/keyboards/ploopyco/trackball_thumb/info.json
@@ -18,7 +18,10 @@
"mousekey": true,
"nkro": true,
"pointing_device": true,
- "encoder": false
+ "encoder": true
+ },
+ "encoder": {
+ "driver": "custom"
},
"layouts": {
"LAYOUT": {
diff --git a/keyboards/ploopyco/trackball_thumb/post_rules.mk b/keyboards/ploopyco/trackball_thumb/post_rules.mk
deleted file mode 100644
index d922afd9cd..0000000000
--- a/keyboards/ploopyco/trackball_thumb/post_rules.mk
+++ /dev/null
@@ -1,4 +0,0 @@
-# Force encoder to be disabled
-# But enable the defines for it
-ENCODER_ENABLE := no
-OPT_DEFS += -DENCODER_ENABLE
diff --git a/keyboards/ploopyco/trackball_thumb/trackball_thumb.c b/keyboards/ploopyco/trackball_thumb/trackball_thumb.c
index bbc782da45..326410cf13 100644
--- a/keyboards/ploopyco/trackball_thumb/trackball_thumb.c
+++ b/keyboards/ploopyco/trackball_thumb/trackball_thumb.c
@@ -17,6 +17,7 @@
*/
#include "trackball_thumb.h"
+#include "encoder.h"
#ifndef OPT_DEBOUNCE
# define OPT_DEBOUNCE 5 // (ms) Time between scroll events
@@ -57,9 +58,6 @@ uint16_t last_mid_click = 0; // Stops scrollwheel from being read if it was
bool debug_encoder = false;
bool is_drag_scroll = false;
-// require, since core encoder.c (where is is normally defined isn't present
-__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;
@@ -75,25 +73,25 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
return true;
}
-void encoder_init(void) { opt_encoder_init(); }
+void encoder_driver_init(void) { opt_encoder_init(); }
-bool encoder_read(void) {
+void encoder_driver_task(void) {
// Lovingly ripped from the Ploopy Source
// If the mouse wheel was just released, do not scroll.
if (timer_elapsed(last_mid_click) < SCROLL_BUTT_DEBOUNCE) {
- return false;
+ return;
}
// Limit the number of scrolls per unit time.
if (timer_elapsed(last_scroll) < OPT_DEBOUNCE) {
- return false;
+ return;
}
// Don't scroll if the middle button is depressed.
if (is_scroll_clicked) {
#ifndef IGNORE_SCROLL_CLICK
- return false;
+ return;
#endif
}
@@ -104,10 +102,8 @@ bool encoder_read(void) {
int dir = opt_encoder_handler(p1, p2);
- if (dir == 0) return false;
- ;
- encoder_update_kb(0, dir == 1);
- return true;
+ if (dir == 0) return;
+ encoder_queue_event(0, dir == 1);
}
report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
diff --git a/keyboards/ploopyco/trackball_thumb/trackball_thumb.h b/keyboards/ploopyco/trackball_thumb/trackball_thumb.h
index 8ee17634f1..50a71601cf 100644
--- a/keyboards/ploopyco/trackball_thumb/trackball_thumb.h
+++ b/keyboards/ploopyco/trackball_thumb/trackball_thumb.h
@@ -28,9 +28,6 @@
#define OPT_ENC1_MUX 4
#define OPT_ENC2_MUX 0
-bool encoder_update_kb(uint8_t index, bool clockwise);
-bool encoder_update_user(uint8_t index, bool clockwise);
-
typedef union {
uint32_t raw;
struct {