Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

matrix.c 2.4KB

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