aboutsummaryrefslogtreecommitdiff
path: root/quantum/encoder.c
diff options
context:
space:
mode:
authorJames Young <xxiinophobia@yahoo.com>2020-02-29 12:00:00 -0800
committerJames Young <xxiinophobia@yahoo.com>2020-02-29 11:59:30 -0800
commit26eef35f07698d23aafae90e1c230b52e100a334 (patch)
treeeb8e43fc58ca55788e6e89430af0db55ea79e324 /quantum/encoder.c
parent85041ff05bf0e5f4ff4535caf6e638491a5614c8 (diff)
downloadqmk_firmware-26eef35f07698d23aafae90e1c230b52e100a334.tar.gz
qmk_firmware-26eef35f07698d23aafae90e1c230b52e100a334.zip
2020 February 29 Breaking Changes Update (#8064)
Diffstat (limited to 'quantum/encoder.c')
-rw-r--r--quantum/encoder.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/quantum/encoder.c b/quantum/encoder.c
index 8e11562eb..81ec1bb37 100644
--- a/quantum/encoder.c
+++ b/quantum/encoder.c
@@ -35,6 +35,13 @@
35static pin_t encoders_pad_a[] = ENCODERS_PAD_A; 35static pin_t encoders_pad_a[] = ENCODERS_PAD_A;
36static pin_t encoders_pad_b[] = ENCODERS_PAD_B; 36static pin_t encoders_pad_b[] = ENCODERS_PAD_B;
37 37
38#ifndef ENCODER_DIRECTION_FLIP
39# define ENCODER_CLOCKWISE true
40# define ENCODER_COUNTER_CLOCKWISE false
41#else
42# define ENCODER_CLOCKWISE false
43# define ENCODER_COUNTER_CLOCKWISE true
44#endif
38static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0}; 45static int8_t encoder_LUT[] = {0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
39 46
40static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0}; 47static uint8_t encoder_state[NUMBER_OF_ENCODERS] = {0};
@@ -86,11 +93,11 @@ static void encoder_update(int8_t index, uint8_t state) {
86 encoder_pulses[i] += encoder_LUT[state & 0xF]; 93 encoder_pulses[i] += encoder_LUT[state & 0xF];
87 if (encoder_pulses[i] >= ENCODER_RESOLUTION) { 94 if (encoder_pulses[i] >= ENCODER_RESOLUTION) {
88 encoder_value[index]++; 95 encoder_value[index]++;
89 encoder_update_kb(index, true); 96 encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE);
90 } 97 }
91 if (encoder_pulses[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise 98 if (encoder_pulses[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise
92 encoder_value[index]--; 99 encoder_value[index]--;
93 encoder_update_kb(index, false); 100 encoder_update_kb(index, ENCODER_CLOCKWISE);
94 } 101 }
95 encoder_pulses[i] %= ENCODER_RESOLUTION; 102 encoder_pulses[i] %= ENCODER_RESOLUTION;
96} 103}
@@ -113,12 +120,12 @@ void encoder_update_raw(uint8_t* slave_state) {
113 while (delta > 0) { 120 while (delta > 0) {
114 delta--; 121 delta--;
115 encoder_value[index]++; 122 encoder_value[index]++;
116 encoder_update_kb(index, true); 123 encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE);
117 } 124 }
118 while (delta < 0) { 125 while (delta < 0) {
119 delta++; 126 delta++;
120 encoder_value[index]--; 127 encoder_value[index]--;
121 encoder_update_kb(index, false); 128 encoder_update_kb(index, ENCODER_CLOCKWISE);
122 } 129 }
123 } 130 }
124} 131}