matrix.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* Copyright 2020 sekigon-gonnoc
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "grs_70ec.h"
  17. #include "ec_switch_matrix.h"
  18. #include "matrix.h"
  19. #include "debug.h"
  20. #include "split_util.h"
  21. #include "transport.h"
  22. #include "debounce.h"
  23. #ifndef LOW_THRESHOLD
  24. # define LOW_THRESHOLD 200
  25. #endif
  26. #ifndef HIGH_THRESHOLD
  27. # define HIGH_THRESHOLD 300
  28. #endif
  29. #define ERROR_DISCONNECT_COUNT 20
  30. #define ROWS_PER_HAND (MATRIX_ROWS / 2)
  31. // row offsets for each hand
  32. static uint8_t thisHand, thatHand;
  33. // user-defined overridable functions
  34. __attribute__((weak)) void matrix_slave_scan_user(void) {}
  35. void matrix_init_custom(void) {
  36. split_pre_init();
  37. ecsm_config_t ecsm_config = {.low_threshold = LOW_THRESHOLD, .high_threshold = HIGH_THRESHOLD};
  38. ecsm_init(&ecsm_config);
  39. thisHand = is_keyboard_left() ? 0 : (ROWS_PER_HAND);
  40. thatHand = ROWS_PER_HAND - thisHand;
  41. split_post_init();
  42. }
  43. bool matrix_scan_custom(matrix_row_t current_matrix[]) {
  44. bool updated = ecsm_matrix_scan(current_matrix);
  45. static int cnt = 0;
  46. if (cnt++ == 300) {
  47. cnt = 0;
  48. ecsm_print_matrix();
  49. print("\n");
  50. }
  51. return updated;
  52. }