diff options
Diffstat (limited to 'keyboards/rgbkb/mun/matrix.c')
-rw-r--r-- | keyboards/rgbkb/mun/matrix.c | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/keyboards/rgbkb/mun/matrix.c b/keyboards/rgbkb/mun/matrix.c index b859847f1..2472d217c 100644 --- a/keyboards/rgbkb/mun/matrix.c +++ b/keyboards/rgbkb/mun/matrix.c | |||
@@ -11,7 +11,19 @@ | |||
11 | #include "atomic_util.h" | 11 | #include "atomic_util.h" |
12 | #include "gpio.h" | 12 | #include "gpio.h" |
13 | 13 | ||
14 | static pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | 14 | #define ROWS_PER_HAND (MATRIX_ROWS / 2) |
15 | static const pin_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | ||
16 | static const pin_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | ||
17 | |||
18 | void matrix_init_pins(void) { | ||
19 | for (size_t i = 0; i < MATRIX_COLS; i++) { | ||
20 | setPinInputHigh(col_pins[i]); | ||
21 | } | ||
22 | for (size_t i = 0; i < ROWS_PER_HAND; i++) { | ||
23 | setPinOutput(row_pins[i]); | ||
24 | writePinHigh(row_pins[i]); | ||
25 | } | ||
26 | } | ||
15 | 27 | ||
16 | void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { | 28 | void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) { |
17 | /* Drive row pin low. */ | 29 | /* Drive row pin low. */ |
@@ -22,15 +34,17 @@ void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
22 | uint16_t porta = palReadPort(GPIOA); | 34 | uint16_t porta = palReadPort(GPIOA); |
23 | uint16_t portb = palReadPort(GPIOB); | 35 | uint16_t portb = palReadPort(GPIOB); |
24 | 36 | ||
37 | // clang-format off | ||
25 | /* Order of pins on the mun is: A0, B11, B0, B10, B12, B2, A8 | 38 | /* Order of pins on the mun is: A0, B11, B0, B10, B12, B2, A8 |
26 | Pin is active low, therefore we have to invert the result. */ | 39 | Pin is active low, therefore we have to invert the result. */ |
27 | matrix_row_t cols = ~(((porta & (0x1 << 0)) >> 0) // A0 (0) | 40 | matrix_row_t cols = ~(((porta & (0x1 << 0)) >> 0) // A0 (0) |
28 | | ((portb & (0x1 << 11)) >> 10) // B11 (1) | 41 | | ((portb & (0x1 << 11)) >> 10) // B11 (1) |
29 | | ((portb & (0x1 << 0)) << 2) // B0 (2) | 42 | | ((portb & (0x1 << 0)) << 2) // B0 (2) |
30 | | ((portb & (0x1 << 10)) >> 7) // B10 (3) | 43 | | ((portb & (0x1 << 10)) >> 7) // B10 (3) |
31 | | ((portb & (0x1 << 12)) >> 8) // B12 (4) | 44 | | ((portb & (0x1 << 12)) >> 8) // B12 (4) |
32 | | ((portb & (0x1 << 2)) << 3) // B2 (5) | 45 | | ((portb & (0x1 << 2)) << 3) // B2 (5) |
33 | | ((porta & (0x1 << 8)) >> 2)); // A8 (6) | 46 | | ((porta & (0x1 << 8)) >> 2)); // A8 (6) |
47 | // clang-format on | ||
34 | 48 | ||
35 | /* Reverse the order of columns for left hand as the board is flipped. */ | 49 | /* Reverse the order of columns for left hand as the board is flipped. */ |
36 | // if (isLeftHand) { | 50 | // if (isLeftHand) { |
@@ -50,7 +64,7 @@ void matrix_read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) | |||
50 | 64 | ||
51 | /* Drive row pin high again. */ | 65 | /* Drive row pin high again. */ |
52 | ATOMIC_BLOCK_FORCEON { writePinHigh(row_pins[current_row]); } | 66 | ATOMIC_BLOCK_FORCEON { writePinHigh(row_pins[current_row]); } |
53 | matrix_output_unselect_delay(current_row, row_pins[current_row] != 0); | 67 | matrix_output_unselect_delay(current_row, cols != 0); |
54 | } | 68 | } |
55 | 69 | ||
56 | #if defined(BUSY_WAIT) | 70 | #if defined(BUSY_WAIT) |