Skip to content

Commit 27756ef

Browse files
committed
Simplify encoder massivly
1 parent c3e2c18 commit 27756ef

1 file changed

Lines changed: 22 additions & 114 deletions

File tree

Lines changed: 22 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,136 +1,44 @@
1-
// Copyright 2024 splitkb.com (support@splitkb.com)
1+
// Copyright 2026 splitkb.com (support@splitkb.com)
22
// SPDX-License-Identifier: GPL-2.0-or-later
33

4-
#include "split_util.h"
5-
#include "atomic_util.h"
4+
#include QMK_KEYBOARD_H
5+
#include "matrix.h"
66

77
#ifdef SPLIT_KEYBOARD
88
# define ROWS_PER_HAND (MATRIX_ROWS / 2)
99
#else
1010
# define ROWS_PER_HAND (MATRIX_ROWS)
1111
#endif
1212

13-
#ifdef MATRIX_ROW_PINS_RIGHT
14-
# define SPLIT_MUTABLE_ROW
15-
#else
16-
# define SPLIT_MUTABLE_ROW const
17-
#endif
18-
#ifdef MATRIX_COL_PINS_RIGHT
19-
# define SPLIT_MUTABLE_COL
20-
#else
21-
# define SPLIT_MUTABLE_COL const
22-
#endif
13+
extern matrix_row_t matrix[MATRIX_ROWS];
2314

24-
#ifndef MATRIX_INPUT_PRESSED_STATE
25-
# define MATRIX_INPUT_PRESSED_STATE 0
26-
#endif
27-
28-
#ifdef DIRECT_PINS
29-
static SPLIT_MUTABLE pin_t direct_pins[ROWS_PER_HAND][MATRIX_COLS] = DIRECT_PINS;
30-
#elif (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW)
31-
# ifdef MATRIX_ROW_PINS
32-
static SPLIT_MUTABLE_ROW pin_t row_pins[ROWS_PER_HAND] = MATRIX_ROW_PINS;
33-
# endif // MATRIX_ROW_PINS
34-
# ifdef MATRIX_COL_PINS
35-
static SPLIT_MUTABLE_COL pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
36-
# endif // MATRIX_COL_PINS
37-
#endif
15+
static const uint8_t button_pins[] = {
16+
HLC_ENCODER_BUTTON,
17+
// Add more pins here as needed
18+
};
3819

3920
void matrix_init_kb(void) {
40-
41-
gpio_set_pin_input_high(HLC_ENCODER_BUTTON);
42-
43-
// Also need to define here otherwise right half is swapped
44-
if (!isLeftHand) {
45-
# ifdef MATRIX_ROW_PINS_RIGHT
46-
const pin_t row_pins_right[ROWS_PER_HAND] = MATRIX_ROW_PINS_RIGHT;
47-
for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
48-
row_pins[i] = row_pins_right[i];
49-
}
50-
# endif
51-
# ifdef MATRIX_COL_PINS_RIGHT
52-
const pin_t col_pins_right[MATRIX_COLS] = MATRIX_COL_PINS_RIGHT;
53-
for (uint8_t i = 0; i < MATRIX_COLS; i++) {
54-
col_pins[i] = col_pins_right[i];
55-
}
56-
# endif
21+
for (uint8_t i = 0; i < sizeof(button_pins)/sizeof(button_pins[0]); i++) {
22+
gpio_set_pin_input_high(button_pins[i]);
5723
}
5824
}
5925

60-
static inline void setPinOutput_writeLow(pin_t pin) {
61-
ATOMIC_BLOCK_FORCEON {
62-
gpio_set_pin_output(pin);
63-
gpio_write_pin_low(pin);
64-
}
65-
}
26+
static void scan_buttons(void) {
27+
uint8_t row = is_keyboard_left() ? ROWS_PER_HAND - 1 : MATRIX_ROWS - 1;
6628

67-
static inline void setPinOutput_writeHigh(pin_t pin) {
68-
ATOMIC_BLOCK_FORCEON {
69-
gpio_set_pin_output(pin);
70-
gpio_write_pin_high(pin);
71-
}
72-
}
73-
74-
static inline void setPinInputHigh_atomic(pin_t pin) {
75-
ATOMIC_BLOCK_FORCEON {
76-
gpio_set_pin_input_high(pin);
77-
}
78-
}
79-
80-
static inline uint8_t readMatrixPin(pin_t pin) {
81-
if (pin != NO_PIN) {
82-
return (gpio_read_pin(pin) == MATRIX_INPUT_PRESSED_STATE) ? 0 : 1;
83-
} else {
84-
return 1;
29+
for (uint8_t i = 0; i < sizeof(button_pins)/sizeof(button_pins[0]); i++) {
30+
if (gpio_read_pin(button_pins[i]) == 0) {
31+
matrix[row] |= (1 << i);
32+
} else {
33+
matrix[row] &= ~(1 << i);
34+
}
8535
}
8636
}
8737

88-
// THIS FUNCTION IS CHANGED, removed NO_PIN check
89-
static bool select_row(uint8_t row) {
90-
pin_t pin = row_pins[row];
91-
setPinOutput_writeLow(pin);
92-
return true;
38+
void matrix_scan_kb(void) {
39+
scan_buttons();
9340
}
9441

95-
static void unselect_row(uint8_t row) {
96-
pin_t pin = row_pins[row];
97-
if (pin != NO_PIN) {
98-
# ifdef MATRIX_UNSELECT_DRIVE_HIGH
99-
setPinOutput_writeHigh(pin);
100-
# else
101-
setPinInputHigh_atomic(pin);
102-
# endif
103-
}
104-
}
105-
106-
void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
107-
// Start with a clear matrix row
108-
matrix_row_t current_row_value = 0;
109-
110-
if (!select_row(current_row)) { // Select row
111-
return; // skip NO_PIN row
112-
}
113-
matrix_output_select_delay();
114-
115-
// ↓↓↓ THIS HAS BEEN ADDED/CHANGED
116-
if (current_row == (ROWS_PER_HAND - 1)) {
117-
current_row_value |= ((!gpio_read_pin(HLC_ENCODER_BUTTON)) & 1) << 0;
118-
} else {
119-
// For each col...
120-
matrix_row_t row_shifter = MATRIX_ROW_SHIFTER;
121-
for (uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++, row_shifter <<= 1) {
122-
uint8_t pin_state = readMatrixPin(col_pins[col_index]);
123-
124-
// Populate the matrix row with the state of the col pin
125-
current_row_value |= pin_state ? 0 : row_shifter;
126-
}
127-
}
128-
// ↑↑↑ THIS HAS BEEN ADDED/CHANGED
129-
130-
// Unselect row
131-
unselect_row(current_row);
132-
matrix_output_unselect_delay(current_row, current_row_value != 0); // wait for all Col signals to go HIGH
133-
134-
// Update the matrix
135-
current_matrix[current_row] = current_row_value;
42+
void matrix_slave_scan_kb(void) {
43+
scan_buttons();
13644
}

0 commit comments

Comments
 (0)