···3232#define STM32_IWDG_RL_MS(s) STM32_IWDG_RL_US(s * 1000.0)
3333#define STM32_IWDG_RL_S(s) STM32_IWDG_RL_US(s * 1000000.0)
34343535-#if !defined(PLANCK_ENCODER_RESOLUTION)
3636-# define PLANCK_ENCODER_RESOLUTION 4
3737-#endif
3838-3935#if !defined(PLANCK_WATCHDOG_TIMEOUT)
4036# define PLANCK_WATCHDOG_TIMEOUT 1.0
4137#endif
42384343-#ifdef ENCODER_MAP_ENABLE
4444-#error "The encoder map feature is not currently supported by the Planck's encoder matrix"
4545-#endif
4646-4739/* matrix state(1:on, 0:off) */
4840static pin_t matrix_row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
4941static pin_t matrix_col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
50425143static matrix_row_t matrix_inverted[MATRIX_COLS];
52445353-#ifdef ENCODER_ENABLE
5454-int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
5555-uint8_t encoder_state[8] = {0};
5656-int8_t encoder_pulses[8] = {0};
5757-uint8_t encoder_value[8] = {0};
5858-#endif
5959-6045void matrix_init_custom(void) {
6146 // actual matrix setup - cols
6247 for (int i = 0; i < MATRIX_COLS; i++) {
···8469#endif
8570}
86718787-#ifdef ENCODER_ENABLE
8888-bool encoder_update(uint8_t index, uint8_t state) {
8989- bool changed = false;
9090- uint8_t i = index;
9191-9292- encoder_pulses[i] += encoder_LUT[state & 0xF];
9393-9494- if (encoder_pulses[i] >= PLANCK_ENCODER_RESOLUTION) {
9595- encoder_value[index]++;
9696- changed = true;
9797- encoder_update_kb(index, false);
9898- }
9999- if (encoder_pulses[i] <= -PLANCK_ENCODER_RESOLUTION) {
100100- encoder_value[index]--;
101101- changed = true;
102102- encoder_update_kb(index, true);
103103- }
104104- encoder_pulses[i] %= PLANCK_ENCODER_RESOLUTION;
105105-#ifdef ENCODER_DEFAULT_POS
106106- encoder_pulses[i] = 0;
107107-#endif
108108- return changed;
109109-}
110110-#endif
111111-11272bool matrix_scan_custom(matrix_row_t current_matrix[]) {
11373#ifndef PLANCK_WATCHDOG_DISABLE
11474 // reset watchdog
···149109 changed |= old != current_matrix[row];
150110 }
151111152152-#ifdef ENCODER_ENABLE
153153- // encoder-matrix functionality
154154-155155- // set up C/rows for encoder read
156156- for (int i = 0; i < MATRIX_ROWS; i++) {
157157- setPinOutput(matrix_row_pins[i]);
158158- writePinHigh(matrix_row_pins[i]);
159159- }
160160-161161- // set up A & B for reading
162162- setPinInputHigh(B12);
163163- setPinInputHigh(B13);
112112+ return changed;
113113+}
164114165165- for (int i = 0; i < MATRIX_ROWS; i++) {
166166- writePinLow(matrix_row_pins[i]);
167167- wait_us(10);
168168- uint8_t new_status = (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1);
169169- if ((encoder_state[i] & 0x3) != new_status) {
170170- encoder_state[i] <<= 2;
171171- encoder_state[i] |= new_status;
172172- encoder_update(i, encoder_state[i]);
173173- }
174174- writePinHigh(matrix_row_pins[i]);
175175- }
176176-177177- // revert A & B to matrix state
178178- setPinInputLow(B12);
179179- setPinInputLow(B13);
180180-181181- // revert C/rows to matrix state
182182- for (int i = 0; i < MATRIX_ROWS; i++) {
183183- setPinInputLow(matrix_row_pins[i]);
184184- }
185185-#endif
186186-187187- return changed;
115115+uint8_t encoder_quadrature_read_pin(uint8_t index, bool pad_b) {
116116+ pin_t pin = pad_b ? B13: B12;
117117+ setPinInputHigh(pin);
118118+ writePinLow(matrix_row_pins[index]);
119119+ wait_us(10);
120120+ uint8_t ret = readPin(pin) ? 1 : 0;
121121+ setPinInputLow(matrix_row_pins[index]);
122122+ setPinInputLow(pin);
123123+ return ret;
188124}
+3
keyboards/ploopyco/mouse/config.h
···32323333/* PMW33XX Settings */
3434#define PMW33XX_CS_PIN B0
3535+3636+/* Custom encoder needs to specify just how many encoders we have */
3737+#define NUM_ENCODERS 1
···3131/* PMW33XX Settings */
3232#define PMW33XX_CS_PIN B0
3333#define POINTING_DEVICE_INVERT_Y
3434+3535+/* Custom encoder needs to specify just how many encoders we have */
3636+#define NUM_ENCODERS 1
···6666bool debug_encoder = false;
6767bool is_drag_scroll = false;
68686969-__attribute__((weak)) bool encoder_update_user(uint8_t index, bool clockwise) { return true; }
7070-7169bool encoder_update_kb(uint8_t index, bool clockwise) {
7270 if (!encoder_update_user(index, clockwise)) {
7371 return false;
···8381 return true;
8482}
85838686-void process_wheel(void) {
8484+8585+void encoder_driver_init(void) {
8686+ setPinInput(OPT_ENC1);
8787+ setPinInput(OPT_ENC2);
8888+8989+ opt_encoder_init();
9090+}
9191+9292+void encoder_driver_task(void) {
8793 // TODO: Replace this with interrupt driven code, polling is S L O W
8894 // Lovingly ripped from the Ploopy Source
8995···112118 int dir = opt_encoder_handler(p1, p2);
113119114120 if (dir == 0) return;
115115- encoder_update_kb(0, dir > 0);
121121+ encoder_queue_event(0, dir == 1);
116122}
117123118124report_mouse_t pointing_device_task_kb(report_mouse_t mouse_report) {
119119- process_wheel();
120125121126 if (is_drag_scroll) {
122127#ifdef PLOOPY_DRAGSCROLL_H_INVERT
···189194 // debug_mouse = true;
190195 // debug_encoder = true;
191196192192- setPinInput(OPT_ENC1);
193193- setPinInput(OPT_ENC2);
194194-195197 /* Ground all output pins connected to ground. This provides additional
196198 * pathways to ground. If you're messing with this, know this: driving ANY
197199 * of these pins high will cause a short. On the MCU. Ka-blooey.
···216218217219void pointing_device_init_kb(void) {
218220 pointing_device_set_cpi(dpi_array[keyboard_config.dpi_config]);
219219- // initialize the scroll wheel's optical encoder
220220- opt_encoder_init();
221221}
222222223223void eeconfig_init_kb(void) {
+3
keyboards/ploopyco/trackball_mini/config.h
···3232#define ADNS5050_CS_PIN B4
33333434#define POINTING_DEVICE_ROTATION_270
3535+3636+/* Custom encoder needs to specify just how many encoders we have */
3737+#define NUM_ENCODERS 1
···31313232/* PMW3360 Settings */
3333#define POINTING_DEVICE_CS_PIN B0
3434+3535+/* Custom encoder needs to specify just how many encoders we have */
3636+#define NUM_ENCODERS 1
···11+// Copyright 2023 Nick Brassel (@tzarc)
22+// SPDX-License-Identifier: GPL-2.0-or-later
33+#pragma once
44+55+// Override the one in quantum/util because it doesn't like working on x64 builds.
66+#define ARRAY_SIZE(array) (sizeof((array)) / sizeof((array)[0]))
+2-1
quantum/encoder/tests/config_mock.h
···11-// Copyright 2022 Nick Brassel (@tzarc)
11+// Copyright 2022-2023 Nick Brassel (@tzarc)
22// SPDX-License-Identifier: GPL-2.0-or-later
33#pragma once
44+#include "config_encoder_common.h"
4556#define MATRIX_ROWS 1
67#define MATRIX_COLS 1