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.

67 lines
1.7 KiB

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