summaryrefslogtreecommitdiff
path: root/keyboards/planck/rev7/matrix.c
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/planck/rev7/matrix.c
parent2eb9ff8efd1df2c98724481c71c8ab8a5b62e31e (diff)
Add encoder abstraction. (#21548)
Diffstat (limited to 'keyboards/planck/rev7/matrix.c')
-rw-r--r--keyboards/planck/rev7/matrix.c86
1 files changed, 11 insertions, 75 deletions
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;
+}