]> git.donarmstrong.com Git - qmk_firmware.git/blob - docs/feature_debounce_type.md
Debounce refactor / API (#3720)
[qmk_firmware.git] / docs / feature_debounce_type.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 DEBOUNCE_TYPE?= sym_g
11 VALID_DEBOUNCE_TYPES := sym_g eager_pk custom
12 ifeq ($(filter $(DEBOUNCE_TYPE),$(VALID_DEBOUNCE_TYPES)),)
13     $(error DEBOUNCE_TYPE="$(DEBOUNCE_TYPE)" is not a valid debounce algorithm)
14 endif
15 ifeq ($(strip $(DEBOUNCE_TYPE)), sym_g)
16     QUANTUM_SRC += $(DEBOUNCE_DIR)/debounce_sym_g.c
17 else ifeq ($(strip $(DEBOUNCE_TYPE)), eager_pk)
18     QUANTUM_SRC += $(DEBOUNCE_DIR)/debounce_eager_pk.c
19 endif
20 ```
21
22 # Debounce selection
23
24 | DEBOUNCE_ALGO    | Description                                                 | What to do                    |
25 | -------------    | ---------------------------------------------------         | ----------------------------- |
26 | Not defined      | You are using the included matrix.c and debounce.c          | Nothing. Debounce_sym_g will be compiled, and used if necessary |
27 | custom           | Use your own debounce.c                                     | ```SRC += debounce.c``` add your own debounce.c and implement necessary functions |
28 | sym_g / eager_pk | You are using the included matrix.c and debounce.c          | Use an alternative debounce algorithm |
29
30 **Regarding split keyboards**: 
31 The debounce code is compatible with split keyboards.
32
33 # Use your own debouncing code
34 * Set ```DEBOUNCE_TYPE = custom ```.
35 * Add ```SRC += debounce.c```
36 * Add your own ```debounce.c```. Look at included ```debounce_sym_g.c```s for sample implementations.
37 * Debouncing occurs after every raw matrix scan.
38 * Use num_rows rather than MATRIX_ROWS, so that split keyboards are supported correctly.
39
40 # Changing between included debouncing methods
41 You can either use your own code, by including your own debounce.c, or switch to another included one.
42 Included debounce methods are:
43 * 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
44 * 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.
45
46