|
1 | | -// Copyright 2024 splitkb.com (support@splitkb.com) |
| 1 | +// Copyright 2026 splitkb.com (support@splitkb.com) |
2 | 2 | // SPDX-License-Identifier: GPL-2.0-or-later |
3 | 3 |
|
4 | | -#include "split_util.h" |
5 | | -#include "atomic_util.h" |
| 4 | +#include QMK_KEYBOARD_H |
| 5 | +#include "matrix.h" |
6 | 6 |
|
7 | 7 | #ifdef SPLIT_KEYBOARD |
8 | 8 | # define ROWS_PER_HAND (MATRIX_ROWS / 2) |
9 | 9 | #else |
10 | 10 | # define ROWS_PER_HAND (MATRIX_ROWS) |
11 | 11 | #endif |
12 | 12 |
|
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]; |
23 | 14 |
|
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 | +}; |
38 | 19 |
|
39 | 20 | 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]); |
57 | 23 | } |
58 | 24 | } |
59 | 25 |
|
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; |
66 | 28 |
|
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 | + } |
85 | 35 | } |
86 | 36 | } |
87 | 37 |
|
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(); |
93 | 40 | } |
94 | 41 |
|
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(); |
136 | 44 | } |
0 commit comments