|
| 1 | +/* |
| 2 | +Copyright 2016 Jun Wako <[email protected]> |
| 3 | +
|
| 4 | +This program is free software: you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU General Public License as published by |
| 6 | +the Free Software Foundation, either version 2 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +
|
| 9 | +This program is distributed in the hope that it will be useful, |
| 10 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | +GNU General Public License for more details. |
| 13 | +
|
| 14 | +You should have received a copy of the GNU General Public License |
| 15 | +along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +*/ |
| 17 | +#include "print.h" |
| 18 | +#include "matrix.h" |
| 19 | + |
| 20 | + |
| 21 | +__attribute__ ((weak)) |
| 22 | +uint8_t matrix_rows(void) |
| 23 | +{ |
| 24 | + return MATRIX_ROWS; |
| 25 | +} |
| 26 | + |
| 27 | +__attribute__ ((weak)) |
| 28 | +uint8_t matrix_cols(void) |
| 29 | +{ |
| 30 | + return MATRIX_COLS; |
| 31 | +} |
| 32 | + |
| 33 | +__attribute__ ((weak)) |
| 34 | +void matrix_clear(void) |
| 35 | +{ |
| 36 | + matrix_init(); |
| 37 | +} |
| 38 | + |
| 39 | +__attribute__ ((weak)) |
| 40 | +void matrix_setup(void) {} |
| 41 | + |
| 42 | +__attribute__ ((weak)) |
| 43 | +bool matrix_is_on(uint8_t row, uint8_t col) |
| 44 | +{ |
| 45 | + return (matrix_get_row(row) & (1<<col)); |
| 46 | +} |
| 47 | + |
| 48 | +__attribute__ ((weak)) |
| 49 | +void matrix_print(void) |
| 50 | +{ |
| 51 | +#if (MATRIX_COLS <= 8) |
| 52 | + print("r/c 01234567\n"); |
| 53 | +#elif (MATRIX_COLS <= 16) |
| 54 | + print("r/c 0123456789ABCDEF\n"); |
| 55 | +#elif (MATRIX_COLS <= 32) |
| 56 | + print("r/c 0123456789ABCDEF0123456789ABCDEF\n"); |
| 57 | +#endif |
| 58 | + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { |
| 59 | + xprintf("%02X:", row); |
| 60 | + |
| 61 | +#if (MATRIX_COLS <= 8) |
| 62 | + print_bin_reverse8(matrix_get_row(row)); |
| 63 | +#elif (MATRIX_COLS <= 16) |
| 64 | + print_bin_reverse16(matrix_get_row(row)); |
| 65 | +#elif (MATRIX_COLS <= 32) |
| 66 | + print_bin_reverse32(matrix_get_row(row)); |
| 67 | +#endif |
| 68 | + |
| 69 | +#ifdef MATRIX_HAS_GHOST |
| 70 | + if (matrix_has_ghost_in_row(row)) { |
| 71 | + print(" <ghost"); |
| 72 | + } |
| 73 | +#endif |
| 74 | + print("\n"); |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +#ifdef MATRIX_HAS_GHOST |
| 79 | +__attribute__ ((weak)) |
| 80 | +bool matrix_has_ghost_in_row(uint8_t row) |
| 81 | +{ |
| 82 | + matrix_row_t matrix_row = matrix_get_row(row); |
| 83 | + // No ghost exists when less than 2 keys are down on the row |
| 84 | + if (((matrix_row - 1) & matrix_row) == 0) |
| 85 | + return false; |
| 86 | + |
| 87 | + // Ghost occurs when the row shares column line with other row |
| 88 | + for (uint8_t i=0; i < MATRIX_ROWS; i++) { |
| 89 | + if (i != row && (matrix_get_row(i) & matrix_row)) |
| 90 | + return true; |
| 91 | + } |
| 92 | + return false; |
| 93 | +} |
| 94 | +#endif |
| 95 | + |
| 96 | +__attribute__ ((weak)) void matrix_power_up(void) {} |
| 97 | +__attribute__ ((weak)) void matrix_power_down(void) {} |
0 commit comments