logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

matrix.c (1796B)


  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 ~(gpio_read_pin(B4) | (gpio_read_pin(B5) << 1) | 0b11111100);
  9. }
  10. 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);
  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. gpio_set_pin_output(D0);
  23. gpio_set_pin_output(D1);
  24. gpio_set_pin_output(D2);
  25. gpio_set_pin_output(D3);
  26. // input with pullup (matrix)
  27. gpio_set_pin_input_high(B6);
  28. gpio_set_pin_input_high(B2);
  29. gpio_set_pin_input_high(B3);
  30. gpio_set_pin_input_high(B1);
  31. gpio_set_pin_input_high(F7);
  32. gpio_set_pin_input_high(F6);
  33. gpio_set_pin_input_high(F5);
  34. gpio_set_pin_input_high(F4);
  35. // input with pullup (program and keypad buttons)
  36. gpio_set_pin_input_high(B4);
  37. gpio_set_pin_input_high(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. }