]> git.donarmstrong.com Git - qmk_firmware.git/blob - docs/feature_debounce_algo.md
Merge branch 'master' into debounce_refactor
[qmk_firmware.git] / docs / feature_debounce_algo.md
1 # Debounce algorithm
2
3 QMK supports multiple debounce algorithms through its debounce API.
4
5 The underlying debounce algorithm is determined by which matrix.c file you are using.
6
7 The logic for which debounce method called is below. It checks various defines that you have set in rules.mk
8
9 ```
10 ifeq ($(strip $(SPLIT_KEYBOARD)), yes)
11     # Do nothing, debouncing is inside matrix.c inside split_common
12 else ifeq ($(strip $(DEBOUNCE_ALGO)), manual)
13     # Do nothing. do your debouncing in matrix.c
14 else ifeq ($(strip $(DEBOUNCE_ALGO)), sym_g)
15     TMK_COMMON_SRC += $(DEBOUNCE)/debounce_sym_g.c
16 else ifeq ($(strip $(DEBOUNCE_ALGO)), eager_pk)
17     TMK_COMMON_SRC += $(DEBOUNCE)/debounce_eager_pk.c
18 else ifeq ($(strip $(CUSTOM_MATRIX)), yes)
19     # Do nothing. Custom matrix code.
20 else # default algorithm
21     TMK_COMMON_SRC += $(DEBOUNCE)/debounce_sym_g.c
22 endif
23 ```
24
25 # Debounce selection
26 The following is for keyboards where ```SPLIT_KEYBOARD``` is **not** defined as ```YES```
27
28 | DEBOUNCE_ALGO    | CUSTOM_MATRIX | Description                                                 | What to do                    |
29 | -------------    |  -------------| ---------------------------------------------------         | ----------------------------- |
30 | Not defined      | Not defined   | You are using the included matrix.c and debounce.c          | Nothing. Debounce_sym_g used. |
31 | manual           | Not defined   | You are using the included matrix.c but your own debounce.c | ```SRC += debounce.c``` add your own debounce.c and implement necessary functions |
32 | sym_g / eager_pk | Not defined   | You are using the included matrix.c and debounce.c          | Nothing. Chosen debounce method used. |
33 | Not defined      | YES           | You have your own matrix.c, and your own debounce           | Write the fully debounced matrix into matrix.c's matrix |
34 | manual           | YES           | Same as above                                               | same as above                                           |
35 | sym_g/ eager_pk  | YES           | You are using your own matrix.c, but included debounce      | Write the raw matrix values into matrix.c's matrix      |
36
37 **Note**: 
38 If ```SPLIT_KEYBOARD = YES``` is defined, the algorithm inside split_common will be used.
39 A future pull request will fix this to use the debounce.c code.
40
41 # Use your own debouncing code
42 * Set ```DEBOUNCE_ALGO = manual```.
43 * Add ```SRC += debounce.c```
44 * Add your own ```debounce.c```. Look at included debounce.c's for sample implementations.
45 * Debouncing occurs after every raw matrix scan.
46
47 # Changing between included debouncing methods
48 You can either use your own code, by including your own debounce.c, or switch to another included one.
49 Included debounce methods are:
50 * debounce_eager_pk - debouncing per key. On any state change, response is immediate, followed by ```DEBOUNCE_DELAY``` millseconds of no further input for that key
51 * debounce_sym_g - debouncing per keyboard. On any state change, a global timer is set. When ```DEBOUNCE_DELAY``` milliseconds of no changes has occured, all input changes are pushed.
52
53