mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-12-05 01:15:19 +00:00
add encoder docs
This commit is contained in:
parent
ff4a1ae5d2
commit
21665df8eb
@ -34,6 +34,7 @@
|
||||
* [Bootmagic](feature_bootmagic.md)
|
||||
* [Command](feature_command.md)
|
||||
* [Dynamic Macros](feature_dynamic_macros.md)
|
||||
* [Encoders](feature_encoders.md)
|
||||
* [Grave Escape](feature_grave_esc.md)
|
||||
* [Key Lock](feature_key_lock.md)
|
||||
* [Layouts](feature_layouts.md)
|
||||
|
41
docs/feature_encoders.md
Normal file
41
docs/feature_encoders.md
Normal file
@ -0,0 +1,41 @@
|
||||
# Encoders
|
||||
|
||||
Basic encoders are supported by adding this to your `rules.mk`:
|
||||
|
||||
ENCODER_ENABLE = yes
|
||||
|
||||
and this to your `config.h`:
|
||||
|
||||
#define NUMBER_OF_ENCODERS 1
|
||||
#define ENCODERS_PAD_A { B12 }
|
||||
#define ENCODERS_PAD_B { B13 }
|
||||
|
||||
Each PAD_A/B variable defines an array so multiple encoders can be defined, e.g.:
|
||||
|
||||
#define ENCODERS_PAD_A { encoder1a, encoder2a }
|
||||
#define ENCODERS_PAD_B { encoder1a, encoder2b }
|
||||
|
||||
If your encoder's clockwise directions are incorrect, you can swap the A & B pad definitions.
|
||||
|
||||
Additionally, the resolution can be specified in the same file (the default & suggested is 4):
|
||||
|
||||
#define ENCODER_RESOLUTION 4
|
||||
|
||||
## Callbacks
|
||||
|
||||
The callback functions can be inserted into your `<keyboard>.c`:
|
||||
|
||||
void encoder_update_kb(uint8_t index, bool clockwise) {
|
||||
encoder_update_user(index, clockwise);
|
||||
}
|
||||
|
||||
or `keymap.c`:
|
||||
|
||||
void encoder_update_user(uint8_t index, bool clockwise) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
## Hardware
|
||||
|
||||
The A an B lines of the encoders should be wired directly to the MCU, and the C/common lines should be wired to ground.
|
@ -259,7 +259,7 @@ uint16_t muse_counter = 0;
|
||||
uint8_t muse_offset = 70;
|
||||
uint16_t muse_tempo = 50;
|
||||
|
||||
void encoder_update(bool clockwise) {
|
||||
void encoder_update_user(int8_t index, bool clockwise) {
|
||||
if (muse_mode) {
|
||||
if (IS_LAYER_ON(_RAISE)) {
|
||||
if (clockwise) {
|
||||
|
@ -35,11 +35,11 @@ static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0};
|
||||
static int8_t encoder_value[NUMBER_OF_ENCODERS] = {0};
|
||||
|
||||
__attribute__ ((weak))
|
||||
void encoder_update_user(bool clockwise) { }
|
||||
void encoder_update_user(int8_t index, bool clockwise) { }
|
||||
|
||||
__attribute__ ((weak))
|
||||
void encoder_update_kb(bool clockwise) {
|
||||
encoder_update_user(clockwise);
|
||||
void encoder_update_kb(int8_t index, bool clockwise) {
|
||||
encoder_update_user(index, clockwise);
|
||||
}
|
||||
|
||||
void encoder_init(void) {
|
||||
@ -57,10 +57,10 @@ void encoder_read(void) {
|
||||
encoder_state[i] |= (readPad(encoders_pad_a[i]) << 0) | (readPad(encoders_pad_b[i]) << 1);
|
||||
encoder_value[i] += encoder_LUT[encoder_state[i] & 0xF];
|
||||
if (encoder_value[i] >= ENCODER_RESOLUTION) {
|
||||
encoder_update_kb(COUNTRECLOCKWISE);
|
||||
encoder_update_kb(i, COUNTRECLOCKWISE);
|
||||
}
|
||||
if (encoder_value[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
|
||||
encoder_update_kb(CLOCKWISE);
|
||||
encoder_update_kb(i, CLOCKWISE);
|
||||
}
|
||||
encoder_value[i] %= ENCODER_RESOLUTION;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user