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.

72 lines
1.9 KiB

  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. /* matrix state(1:on, 0:off) */
  32. extern matrix_row_t raw_matrix[MATRIX_ROWS]; // raw values
  33. extern matrix_row_t matrix[MATRIX_ROWS]; // debounced values
  34. // row offsets for each hand
  35. uint8_t thisHand, thatHand;
  36. // user-defined overridable functions
  37. __attribute__((weak)) void matrix_slave_scan_user(void) {}
  38. void matrix_init_custom(void) {
  39. split_pre_init();
  40. ecsm_config_t ecsm_config = {.low_threshold = LOW_THRESHOLD, .high_threshold = HIGH_THRESHOLD};
  41. ecsm_init(&ecsm_config);
  42. thisHand = isLeftHand ? 0 : (ROWS_PER_HAND);
  43. thatHand = ROWS_PER_HAND - thisHand;
  44. split_post_init();
  45. }
  46. bool matrix_scan_custom(matrix_row_t current_matrix[]) {
  47. bool updated = ecsm_matrix_scan(current_matrix);
  48. static int cnt = 0;
  49. if (cnt++ == 300) {
  50. cnt = 0;
  51. ecsm_print_matrix();
  52. print("\n");
  53. }
  54. return updated;
  55. }