aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXScorpion2 <rcalt2vt@gmail.com>2019-11-15 17:01:50 -0600
committerDrashna Jaelre <drashna@live.com>2019-11-15 15:01:50 -0800
commit0f0c73f14a8ffb83a79b51582c0e7465c2411749 (patch)
tree67767bc5ed4e1e2a610b690c36a1cd075909b0b5
parentf6b5f6db7665512cece0223ce4d19c5b17455ef4 (diff)
downloadqmk_firmware-0f0c73f14a8ffb83a79b51582c0e7465c2411749.tar.gz
qmk_firmware-0f0c73f14a8ffb83a79b51582c0e7465c2411749.zip
Updated slave encoder sync to reduce dropped pulses (#7325)
* 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
-rw-r--r--quantum/encoder.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/quantum/encoder.c b/quantum/encoder.c
index 36a6403b3..e86a0045c 100644
--- a/quantum/encoder.c
+++ b/quantum/encoder.c
@@ -38,14 +38,15 @@ static pin_t encoders_pad_b[] = ENCODERS_PAD_B;
38static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0}; 38static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
39 39
40static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0}; 40static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0};
41static 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
44static int8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0}; 45static uint8_t encoder_value[NUMBER_OF_ENCODERS * 2] = {0};
45// row offsets for each hand 46// row offsets for each hand
46static uint8_t thisHand, thatHand; 47static uint8_t thisHand, thatHand;
47#else 48#else
48static int8_t encoder_value[NUMBER_OF_ENCODERS] = {0}; 49static 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,14 +79,16 @@ void encoder_init(void) {
78} 79}
79 80
80static void encoder_update(int8_t index, uint8_t state) { 81static void encoder_update(int8_t index, uint8_t state) {
81 encoder_value[index] += encoder_LUT[state & 0xF]; 82 encoder_pulses[index] += encoder_LUT[state & 0xF];
82 if (encoder_value[index] >= ENCODER_RESOLUTION) { 83 if (encoder_pulses[index] >= ENCODER_RESOLUTION) {
83 encoder_update_kb(index, false); 84 encoder_value[index]++;
84 }
85 if (encoder_value[index] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
86 encoder_update_kb(index, true); 85 encoder_update_kb(index, true);
87 } 86 }
88 encoder_value[index] %= ENCODER_RESOLUTION; 87 if (encoder_pulses[index] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
88 encoder_value[index]--;
89 encoder_update_kb(index, false);
90 }
91 encoder_pulses[index] %= ENCODER_RESOLUTION;
89} 92}
90 93
91void encoder_read(void) { 94void encoder_read(void) {
@@ -101,11 +104,22 @@ void encoder_read(void) {
101} 104}
102 105
103#ifdef SPLIT_KEYBOARD 106#ifdef SPLIT_KEYBOARD
104void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, encoder_state, sizeof(encoder_state)); } 107void encoder_state_raw(uint8_t* slave_state) { memcpy(slave_state, &encoder_value[thisHand], sizeof(uint8_t) * NUMBER_OF_ENCODERS); }
105 108
106void encoder_update_raw(uint8_t* slave_state) { 109void encoder_update_raw(uint8_t* slave_state) {
107 for (int i = 0; i < NUMBER_OF_ENCODERS; i++) { 110 for (int 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