Skip to content

Commit 36ab0c0

Browse files
authored
Add core/fallback encoder behaviour (qmk#20320)
1 parent 7e48a4e commit 36ab0c0

File tree

107 files changed

+30
-1759
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+30
-1759
lines changed

docs/feature_encoders.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ Using encoder mapping pumps events through the normal QMK keycode processing pip
102102
103103
## Callbacks
104104
105-
When not using `ENCODER_MAP_ENABLE = yes`, the callback functions can be inserted into your `<keyboard>.c`:
105+
?> [**Default Behaviour**](https://github.com/qmk/qmk_firmware/blob/master/quantum/encoder.c#L79-#L98): all encoders installed will function as volume up (`KC_VOLU`) on clockwise rotation and volume down (`KC_VOLD`) on counter-clockwise rotation. If you do not wish to override this, no further configuration is necessary.
106106
107-
?> Those who are adding new keyboard support where encoders are enabled at the keyboard level should include basic encoder functionality at the keyboard level (`<keyboard>.c`) using the `encoder_update_kb()` function, that way it works for QMK Configuator users and exists in general.
107+
If you would like the alter the default behaviour, and are not using `ENCODER_MAP_ENABLE = yes`, the callback functions can be inserted into your `<keyboard>.c`:
108108
109109
```c
110110
bool encoder_update_kb(uint8_t index, bool clockwise) {
@@ -113,9 +113,9 @@ bool encoder_update_kb(uint8_t index, bool clockwise) {
113113
}
114114
if (index == 0) { /* First encoder */
115115
if (clockwise) {
116-
tap_code_delay(KC_VOLU, 10);
116+
tap_code(KC_PGDN);
117117
} else {
118-
tap_code_delay(KC_VOLD, 10);
118+
tap_code(KC_PGUP);
119119
}
120120
} else if (index == 1) { /* Second encoder */
121121
if (clockwise) {
@@ -134,9 +134,9 @@ or `keymap.c`:
134134
bool encoder_update_user(uint8_t index, bool clockwise) {
135135
if (index == 0) { /* First encoder */
136136
if (clockwise) {
137-
tap_code_delay(KC_VOLU, 10);
137+
tap_code(KC_PGDN);
138138
} else {
139-
tap_code_delay(KC_VOLD, 10);
139+
tap_code(KC_PGUP);
140140
}
141141
} else if (index == 1) { /* Second encoder */
142142
if (clockwise) {
@@ -149,7 +149,7 @@ bool encoder_update_user(uint8_t index, bool clockwise) {
149149
}
150150
```
151151
152-
!> If you return `true` in the keymap level `_user` function, it will allow the keyboard level encoder code to run on top of your own. Returning `false` will override the keyboard level function, if setup correctly. This is generally the safest option to avoid confusion.
152+
!> If you return `true` in the keymap level `_user` function, it will allow the keyboard/core level encoder code to run on top of your own. Returning `false` will override the keyboard level function, if setup correctly. This is generally the safest option to avoid confusion.
153153
154154
## Hardware
155155

keyboards/acheron/shark/beta/beta.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,3 @@ void board_init(void) {
2020
setPinInput(B6);
2121
setPinInput(B7);
2222
}
23-
24-
#ifdef ENCODER_ENABLE
25-
bool encoder_update_kb(uint8_t index, bool clockwise) {
26-
if(!encoder_update_user(index, clockwise)) return false;
27-
if (index == 0) {
28-
if (clockwise) tap_code_delay(KC_VOLU, 10);
29-
else tap_code_delay(KC_VOLD, 10);
30-
}
31-
return true;
32-
}
33-
#endif

keyboards/adafruit/macropad/macropad.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,3 @@ led_config_t g_led_config = { {
4040
} };
4141

4242
#endif
43-
44-
#ifdef ENCODER_ENABLE
45-
bool encoder_update_kb(uint8_t index, bool clockwise) {
46-
if (!encoder_update_user(index, clockwise)) { return false; }
47-
if (index == 0) {
48-
if (clockwise) {
49-
tap_code_delay(KC_VOLU, 10);
50-
} else {
51-
tap_code_delay(KC_VOLD, 10);
52-
}
53-
}
54-
return true;
55-
}
56-
#endif

keyboards/aidansmithdotdev/fine40/fine40.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,3 @@ bool oled_task_kb(void) {
6868
return(true);
6969
}
7070
#endif
71-
72-
#ifdef ENCODER_ENABLE
73-
bool encoder_update_kb(uint8_t index, bool clockwise) {
74-
if (!encoder_update_user(index, clockwise)) {
75-
return false;
76-
}
77-
// Volume control
78-
if (clockwise) {
79-
tap_code(KC_VOLU);
80-
} else {
81-
tap_code(KC_VOLD);
82-
}
83-
return true;
84-
}
85-
#endif

keyboards/anavi/knob1/knob1.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ void keyboard_post_init_kb(void) {
1414
keyboard_post_init_user();
1515
}
1616

17-
#ifdef ENCODER_ENABLE
18-
bool encoder_update_kb(uint8_t index, bool clockwise) {
19-
if (!encoder_update_user(index, clockwise)) { return false; }
20-
if (clockwise) {
21-
tap_code(KC_VOLU);
22-
} else {
23-
tap_code(KC_VOLD);
24-
}
25-
return true;
26-
}
27-
#endif
28-
2917
#ifdef OLED_ENABLE
3018

3119
bool oled_task_kb(void) {

keyboards/anavi/macropad10/macropad10.c

Lines changed: 0 additions & 16 deletions
This file was deleted.

keyboards/ano/ano.c

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,3 @@
1515
*/
1616

1717
#include "ano.h"
18-
19-
/* The encoder_update_user is a function.
20-
* It'll be called by QMK every time you turn the encoder.
21-
*
22-
* The index parameter tells you which encoder was turned. If you only have
23-
* one encoder, the index will always be zero.
24-
*
25-
* The clockwise parameter tells you the direction of the encoder. It'll be
26-
* true when you turned the encoder clockwise, and false otherwise.
27-
*/
28-
29-
#ifdef ENCODER_ENABLE
30-
bool encoder_update_kb(uint8_t index, bool clockwise) {
31-
if (!encoder_update_user(index, clockwise)) { return false; }
32-
if (index == 0) {
33-
if (clockwise) {
34-
tap_code(KC_AUDIO_VOL_UP);
35-
} else {
36-
tap_code(KC_AUDIO_VOL_DOWN);
37-
}
38-
}
39-
return true;
40-
}
41-
#endif

keyboards/atlantis/ps17/ps17.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,6 @@ void keyboard_pre_init_kb(void) {
1919
keyboard_pre_init_user();
2020
}
2121

22-
#if defined(ENCODER_ENABLE)
23-
bool encoder_update_kb(uint8_t index, bool clockwise) {
24-
if (!encoder_update_user(index, clockwise)) {
25-
/* Don't process further events if user function exists and returns false */
26-
return false;
27-
}
28-
29-
/* Ignore index - only one encoder on this board */
30-
if (clockwise) {
31-
tap_code_delay(KC_VOLU, 10);
32-
} else {
33-
tap_code_delay(KC_VOLD, 10);
34-
}
35-
return false;
36-
}
37-
#endif
38-
3922
#ifdef RGB_MATRIX_ENABLE
4023
void suspend_power_down_kb(void) {
4124
/* Disable indicator LEDs when going to sleep */

keyboards/bolsa/damapad/damapad.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,3 @@ oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
6565
return OLED_ROTATION_180;
6666
}
6767
#endif
68-
69-
#ifdef ENCODER_ENABLE
70-
bool encoder_update_kb(uint8_t index, bool clockwise) {
71-
if (!encoder_update_user(index, clockwise)) { return false; }
72-
if (index == 0) {
73-
if (clockwise) {
74-
tap_code_delay(KC_VOLU, 10);
75-
} else {
76-
tap_code_delay(KC_VOLD, 10);
77-
}
78-
}
79-
return true;
80-
}
81-
#endif

keyboards/cannonkeys/balance/balance.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,3 @@ You should have received a copy of the GNU General Public License
1515
along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717
#include "balance.h"
18-
19-
bool encoder_update_kb(uint8_t index, bool clockwise) {
20-
if (!encoder_update_user(index, clockwise)) { return false; }
21-
if (clockwise) {
22-
tap_code(KC_VOLU);
23-
} else {
24-
tap_code(KC_VOLD);
25-
}
26-
return true;
27-
}

keyboards/cannonkeys/ortho60v2/ortho60v2.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,3 @@ You should have received a copy of the GNU General Public License
1515
along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717
#include "ortho60v2.h"
18-
19-
#ifdef ENCODER_ENABLE
20-
bool encoder_update_kb(uint8_t index, bool clockwise) {
21-
if (!encoder_update_user(index, clockwise)) {
22-
return false;
23-
}
24-
if (clockwise) {
25-
tap_code_delay(KC_VOLU, 10);
26-
} else {
27-
tap_code_delay(KC_VOLD, 10);
28-
}
29-
return true;
30-
}
31-
#endif

keyboards/checkerboards/phoenix45_ortho/phoenix45_ortho.c

Lines changed: 0 additions & 29 deletions
This file was deleted.

keyboards/checkerboards/quark/quark.c

Lines changed: 0 additions & 29 deletions
This file was deleted.

keyboards/checkerboards/quark_squared/quark_squared.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,3 @@
1515
*/
1616

1717
#include "quark_squared.h"
18-
19-
bool encoder_update_kb(uint8_t index, bool clockwise) {
20-
if (!encoder_update_user(index, clockwise)) { return false; }
21-
if (index == 0) {
22-
if (clockwise) {
23-
tap_code_delay(KC_VOLD, 10);
24-
} else {
25-
tap_code_delay(KC_VOLU, 10);
26-
}
27-
}
28-
return true;
29-
}

keyboards/chocofly/chocofly.c

Lines changed: 0 additions & 16 deletions
This file was deleted.

keyboards/ck60i/ck60i.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,3 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*/
1717

1818
#include "ck60i.h"
19-
20-
bool encoder_update_kb(uint8_t index, bool clockwise) {
21-
if (!encoder_update_user(index, clockwise)) return false;
22-
if (index == 0) { /* First encoder */
23-
if (clockwise) {
24-
tap_code(KC_VOLU);
25-
} else {
26-
tap_code(KC_VOLD);
27-
}
28-
}
29-
return true;
30-
}

keyboards/coban/pad3a/pad3a.c

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)