summaryrefslogtreecommitdiff
path: root/quantum/debounce.c
blob: 929023ab2df39b43060b09911172437e0085db87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

#include "matrix.h"
#include "timer.h"
#include "quantum.h"

#ifndef DEBOUNCING_DELAY
#  define DEBOUNCING_DELAY 5
#endif

void debounce_init(uint8_t num_rows) {
}

#if DEBOUNCING_DELAY > 0

static bool debouncing = false;

void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
  static uint16_t debouncing_time;

  if (changed) {
    debouncing = true;
    debouncing_time = timer_read();
  }

  if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
    for (uint8_t i = 0; i < num_rows; i++) {
      cooked[i] = raw[i];
    }
    debouncing = false;
  }
}

bool debounce_active(void) {
  return debouncing;
}

#else

// no debounce
void debounce(matrix_row_t raw[], matrix_row_t cooked[], uint8_t num_rows, bool changed) {
  if (changed)
  {
  for (uint8_t i = 0; i < num_rows; i++) {
      cooked[i] = raw[i];
    }
  }
}

bool debounce_active(void) {
  return false;
}
#endif