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.

65 lines
1.6 KiB

  1. // Copyright 2023 QMK
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "matrix.h"
  4. static matrix_row_t read_row(uint8_t row) {
  5. matrix_io_delay(); // without this wait read unstable value.
  6. // keypad and program buttons
  7. if (row == 12) {
  8. return ~(readPin(B4) | (readPin(B5) << 1) | 0b11111100);
  9. }
  10. return ~(readPin(B6) | readPin(B2) << 1 | readPin(B3) << 2 | readPin(B1) << 3 | readPin(F7) << 4 | readPin(F6) << 5 | readPin(F5) << 6 | readPin(F4) << 7);
  11. }
  12. static void unselect_rows(void) {
  13. // set A,B,C,G to 0
  14. PORTD &= 0xF0;
  15. }
  16. static void select_rows(uint8_t row) {
  17. // set A,B,C,G to row value
  18. PORTD |= (0x0F & row);
  19. }
  20. void matrix_init_custom(void) {
  21. // output low (multiplexers)
  22. setPinOutput(D0);
  23. setPinOutput(D1);
  24. setPinOutput(D2);
  25. setPinOutput(D3);
  26. // input with pullup (matrix)
  27. setPinInputHigh(B6);
  28. setPinInputHigh(B2);
  29. setPinInputHigh(B3);
  30. setPinInputHigh(B1);
  31. setPinInputHigh(F7);
  32. setPinInputHigh(F6);
  33. setPinInputHigh(F5);
  34. setPinInputHigh(F4);
  35. // input with pullup (program and keypad buttons)
  36. setPinInputHigh(B4);
  37. setPinInputHigh(B5);
  38. // initialize row and col
  39. unselect_rows();
  40. }
  41. bool matrix_scan_custom(matrix_row_t current_matrix[]) {
  42. bool matrix_has_changed = false;
  43. for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
  44. select_rows(i);
  45. matrix_row_t row = read_row(i);
  46. unselect_rows();
  47. bool row_has_changed = current_matrix[i] != row;
  48. matrix_has_changed |= row_has_changed;
  49. current_matrix[i] = row;
  50. }
  51. return matrix_has_changed;
  52. }