diff options
author | XScorpion2 <rcalt2vt@gmail.com> | 2019-12-08 01:51:42 -0600 |
---|---|---|
committer | Florian Didron <fdidron@users.noreply.github.com> | 2020-01-09 08:57:11 +0900 |
commit | 319e86e1c6e4f7a40f6d377de3e5145cba2e4ebf (patch) | |
tree | 5d208f3958b439ba9089e1fc04d6ec62912004d5 /quantum | |
parent | 37b55e3693d07d4688fa2b5a89d681b1a0e70d9c (diff) |
Updated slave encoder sync to reduce dropped pulses - v2 (#7505)
* Updated slave encoder sync to reduce dropped pulses
* Fixing encoder direction
* Encoder behavior fixes, tested
* Update keyboards/rgbkb/sol/keymaps/xulkal/rules.mk
To make fauxpark happy
Co-Authored-By: fauxpark <fauxpark@gmail.com>
* Update custom_encoder.c
* Update rules.mk
* Iris r4 fix
* More fixes for Iris & Kira
* Fix for right master encoders
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/encoder.c | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/quantum/encoder.c b/quantum/encoder.c index 36a6403b36..c41b89f495 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -38,14 +38,15 @@ static pin_t encoders_pad_b[] = ENCODERS_PAD_B; static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0}; static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0}; +static int8_t encoder_pulses[NUMBER_OF_ENCODERS] = {0}; #ifdef SPLIT_KEYBOARD // right half encoders come over as second set of encoders -static int8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0}; +static uint8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0}; // row offsets for each hand static uint8_t thisHand, thatHand; #else -static int8_t encoder_value[NUMBER_OF_ENCODERS] = {0}; +static uint8_t encoder_value[NUMBER_OF_ENCODERS] = {0}; #endif __attribute__((weak)) void encoder_update_user(int8_t index, bool clockwise) {} @@ -78,34 +79,47 @@ void encoder_init(void) { } static void encoder_update(int8_t index, uint8_t state) { - encoder_value[index] += encoder_LUT[state & 0xF]; - if (encoder_value[index] >= ENCODER_RESOLUTION) { - encoder_update_kb(index, false); - } - if (encoder_value[index] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise + uint8_t i = index; +#ifdef SPLIT_KEYBOARD + index += thisHand; +#endif + encoder_pulses[i] += encoder_LUT[state & 0xF]; + if (encoder_pulses[i] >= ENCODER_RESOLUTION) { + encoder_value[index]++; encoder_update_kb(index, true); } - encoder_value[index] %= ENCODER_RESOLUTION; + if (encoder_pulses[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise + encoder_value[index]--; + encoder_update_kb(index, false); + } + encoder_pulses[i] %= ENCODER_RESOLUTION; } void encoder_read(void) { - for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { + for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { encoder_state[i] <<= 2; encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); -#if SPLIT_KEYBOARD - encoder_update(i + thisHand, encoder_state[i]); -#else encoder_update(i, encoder_state[i]); -#endif } } #ifdef SPLIT_KEYBOARD -void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, encoder_state, sizeof(encoder_state)); } +void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, &encoder_value[thisHand], sizeof(uint8_t) * NUMBER_OF_ENCODERS); } void encoder_update_raw(uint8_t* slave_state) { - for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { - encoder_update(i + thatHand, slave_state[i]); + for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { + uint8_t index = i + thatHand; + int8_t delta = slave_state[i] - encoder_value[index]; + while (delta > 0) { + delta--; + encoder_value[index]++; + encoder_update_kb(index, true); + } + while (delta < 0) { + delta++; + encoder_value[index]--; + encoder_update_kb(index, false); + } } } #endif |