diff options
author | XScorpion2 <rcalt2vt@gmail.com> | 2019-12-08 01:51:42 -0600 |
---|---|---|
committer | Drashna Jaelre <drashna@live.com> | 2019-12-07 23:51:42 -0800 |
commit | 201c5bfa5cdce723f148b6e9a276219c8f2e8613 (patch) | |
tree | 8b485522ba2a4f0d4679870ab3f6d861e8161054 /quantum/encoder.c | |
parent | 34f302e1a5b301d62001d7f5f35d0039b14bad5d (diff) | |
download | qmk_firmware-201c5bfa5cdce723f148b6e9a276219c8f2e8613.tar.gz qmk_firmware-201c5bfa5cdce723f148b6e9a276219c8f2e8613.zip |
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/encoder.c')
-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 36a6403b3..c41b89f49 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c | |||
@@ -38,14 +38,15 @@ static pin_t encoders_pad_b[] = ENCODERS_PAD_B; | |||
38 | static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0}; | 38 | static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0}; |
39 | 39 | ||
40 | static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0}; | 40 | static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0}; |
41 | static int8_t encoder_pulses[NUMBER_OF_ENCODERS] = {0}; | ||
41 | 42 | ||
42 | #ifdef SPLIT_KEYBOARD | 43 | #ifdef SPLIT_KEYBOARD |
43 | // right half encoders come over as second set of encoders | 44 | // right half encoders come over as second set of encoders |
44 | static int8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0}; | 45 | static uint8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0}; |
45 | // row offsets for each hand | 46 | // row offsets for each hand |
46 | static uint8_t thisHand, thatHand; | 47 | static uint8_t thisHand, thatHand; |
47 | #else | 48 | #else |
48 | static int8_t encoder_value[NUMBER_OF_ENCODERS] = {0}; | 49 | static uint8_t encoder_value[NUMBER_OF_ENCODERS] = {0}; |
49 | #endif | 50 | #endif |
50 | 51 | ||
51 | __attribute__((weak)) void encoder_update_user(int8_t index, bool clockwise) {} | 52 | __attribute__((weak)) void encoder_update_user(int8_t index, bool clockwise) {} |
@@ -78,34 +79,47 @@ void encoder_init(void) { | |||
78 | } | 79 | } |
79 | 80 | ||
80 | static void encoder_update(int8_t index, uint8_t state) { | 81 | static void encoder_update(int8_t index, uint8_t state) { |
81 | encoder_value[index] += encoder_LUT[state & 0xF]; | 82 | uint8_t i = index; |
82 | if (encoder_value[index] >= ENCODER_RESOLUTION) { | 83 | #ifdef SPLIT_KEYBOARD |
83 | encoder_update_kb(index, false); | 84 | index += thisHand; |
84 | } | 85 | #endif |
85 | if (encoder_value[index] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise | 86 | encoder_pulses[i] += encoder_LUT[state & 0xF]; |
87 | if (encoder_pulses[i] >= ENCODER_RESOLUTION) { | ||
88 | encoder_value[index]++; | ||
86 | encoder_update_kb(index, true); | 89 | encoder_update_kb(index, true); |
87 | } | 90 | } |
88 | encoder_value[index] %= ENCODER_RESOLUTION; | 91 | if (encoder_pulses[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise |
92 | encoder_value[index]--; | ||
93 | encoder_update_kb(index, false); | ||
94 | } | ||
95 | encoder_pulses[i] %= ENCODER_RESOLUTION; | ||
89 | } | 96 | } |
90 | 97 | ||
91 | void encoder_read(void) { | 98 | void encoder_read(void) { |
92 | for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { | 99 | for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { |
93 | encoder_state[i] <<= 2; | 100 | encoder_state[i] <<= 2; |
94 | encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); | 101 | encoder_state[i] |= (readPin(encoders_pad_a[i]) << 0) | (readPin(encoders_pad_b[i]) << 1); |
95 | #if SPLIT_KEYBOARD | ||
96 | encoder_update(i + thisHand, encoder_state[i]); | ||
97 | #else | ||
98 | encoder_update(i, encoder_state[i]); | 102 | encoder_update(i, encoder_state[i]); |
99 | #endif | ||
100 | } | 103 | } |
101 | } | 104 | } |
102 | 105 | ||
103 | #ifdef SPLIT_KEYBOARD | 106 | #ifdef SPLIT_KEYBOARD |
104 | void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, encoder_state, sizeof(encoder_state)); } | 107 | void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, &encoder_value[thisHand], sizeof(uint8_t) * NUMBER_OF_ENCODERS); } |
105 | 108 | ||
106 | void encoder_update_raw(uint8_t* slave_state) { | 109 | void encoder_update_raw(uint8_t* slave_state) { |
107 | for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { | 110 | for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { |
108 | encoder_update(i + thatHand, slave_state[i]); | 111 | uint8_t index = i + thatHand; |
112 | int8_t delta = slave_state[i] - encoder_value[index]; | ||
113 | while (delta > 0) { | ||
114 | delta--; | ||
115 | encoder_value[index]++; | ||
116 | encoder_update_kb(index, true); | ||
117 | } | ||
118 | while (delta < 0) { | ||
119 | delta++; | ||
120 | encoder_value[index]--; | ||
121 | encoder_update_kb(index, false); | ||
122 | } | ||
109 | } | 123 | } |
110 | } | 124 | } |
111 | #endif | 125 | #endif |