2020 February 29 Breaking Changes Update (#8064)
[jackhill/qmk/firmware.git] / docs / feature_encoders.md
CommitLineData
85688e5b
JH
1# Encoders
2
3Basic encoders are supported by adding this to your `rules.mk`:
4
26eef35f
JY
5```make
6ENCODER_ENABLE = yes
7```
85688e5b
JH
8
9and this to your `config.h`:
10
26eef35f
JY
11```c
12#define ENCODERS_PAD_A { B12 }
13#define ENCODERS_PAD_B { B13 }
14```
85688e5b
JH
15
16Each PAD_A/B variable defines an array so multiple encoders can be defined, e.g.:
17
26eef35f
JY
18```c
19#define ENCODERS_PAD_A { encoder1a, encoder2a }
20#define ENCODERS_PAD_B { encoder1b, encoder2b }
21```
22
23If your encoder's clockwise directions are incorrect, you can swap the A & B pad definitions. They can also be flipped with a define:
85688e5b 24
26eef35f
JY
25```c
26#define ENCODER_DIRECTION_FLIP
27```
85688e5b
JH
28
29Additionally, the resolution can be specified in the same file (the default & suggested is 4):
30
26eef35f
JY
31```c
32#define ENCODER_RESOLUTION 4
33```
85688e5b 34
36dd261d
D
35## Split Keyboards
36
37If you are using different pinouts for the encoders on each half of a split keyboard, you can define the pinout for the right half like this:
38
39```c
40#define ENCODERS_PAD_A_RIGHT { encoder1a, encoder2a }
41#define ENCODERS_PAD_B_RIGHT { encoder1b, encoder2b }
42```
43
85688e5b
JH
44## Callbacks
45
46The callback functions can be inserted into your `<keyboard>.c`:
47
26eef35f
JY
48```c
49void encoder_update_kb(uint8_t index, bool clockwise) {
50 encoder_update_user(index, clockwise);
51}
52```
85688e5b
JH
53
54or `keymap.c`:
55
26eef35f
JY
56```c
57void encoder_update_user(uint8_t index, bool clockwise) {
58 if (index == 0) { /* First encoder */
52f12067 59 if (clockwise) {
26eef35f 60 tap_code(KC_PGDN);
52f12067 61 } else {
26eef35f 62 tap_code(KC_PGUP);
24b3556e 63 }
26eef35f 64 } else if (index == 1) { /* Second encoder */
52f12067 65 if (clockwise) {
26eef35f 66 tap_code(KC_DOWN);
52f12067 67 } else {
26eef35f 68 tap_code(KC_UP);
52f12067 69 }
85688e5b 70 }
26eef35f
JY
71}
72```
85688e5b 73
85688e5b
JH
74## Hardware
75
76The A an B lines of the encoders should be wired directly to the MCU, and the C/common lines should be wired to ground.