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.

52 lines
1.6 KiB

  1. /*
  2. Copyright 2017 Alex Ong<the.onga@gmail.com>
  3. Copyright 2021 Simon Arlott
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. /*
  16. Basic global debounce algorithm. Used in 99% of keyboards at time of implementation
  17. When no state changes have occured for DEBOUNCE milliseconds, we push the state.
  18. */
  19. #include "matrix.h"
  20. #include "timer.h"
  21. #include "quantum.h"
  22. #ifndef DEBOUNCE
  23. # define DEBOUNCE 5
  24. #endif
  25. #if DEBOUNCE > 0
  26. static bool debouncing = false;
  27. static fast_timer_t debouncing_time;
  28. void debounce_init(uint8_t num_rows) {}
  29. void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
  30. if (changed) {
  31. debouncing = true;
  32. debouncing_time = timer_read_fast();
  33. }
  34. if (debouncing && timer_elapsed_fast(debouncing_time) >= DEBOUNCE) {
  35. for (int i = 0; i < num_rows; i++) {
  36. cooked[i] = raw[i];
  37. }
  38. debouncing = false;
  39. }
  40. }
  41. bool debounce_active(void) { return debouncing; }
  42. void debounce_free(void) {}
  43. #else // no debouncing.
  44. # include "none.c"
  45. #endif