diff options
Diffstat (limited to 'quantum/encoder.c')
| -rw-r--r-- | quantum/encoder.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/quantum/encoder.c b/quantum/encoder.c index 81ec1bb376..7ca31afedc 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c | |||
| @@ -23,7 +23,7 @@ | |||
| 23 | // for memcpy | 23 | // for memcpy |
| 24 | #include <string.h> | 24 | #include <string.h> |
| 25 | 25 | ||
| 26 | #ifndef ENCODER_RESOLUTION | 26 | #if !defined(ENCODER_RESOLUTIONS) && !defined(ENCODER_RESOLUTION) |
| 27 | # define ENCODER_RESOLUTION 4 | 27 | # define ENCODER_RESOLUTION 4 |
| 28 | #endif | 28 | #endif |
| 29 | 29 | ||
| @@ -34,6 +34,9 @@ | |||
| 34 | #define NUMBER_OF_ENCODERS (sizeof(encoders_pad_a) / sizeof(pin_t)) | 34 | #define NUMBER_OF_ENCODERS (sizeof(encoders_pad_a) / sizeof(pin_t)) |
| 35 | static pin_t encoders_pad_a[] = ENCODERS_PAD_A; | 35 | static pin_t encoders_pad_a[] = ENCODERS_PAD_A; |
| 36 | static pin_t encoders_pad_b[] = ENCODERS_PAD_B; | 36 | static pin_t encoders_pad_b[] = ENCODERS_PAD_B; |
| 37 | #ifdef ENCODER_RESOLUTIONS | ||
| 38 | static uint8_t encoder_resolutions[] = ENCODER_RESOLUTIONS; | ||
| 39 | #endif | ||
| 37 | 40 | ||
| 38 | #ifndef ENCODER_DIRECTION_FLIP | 41 | #ifndef ENCODER_DIRECTION_FLIP |
| 39 | # define ENCODER_CLOCKWISE true | 42 | # define ENCODER_CLOCKWISE true |
| @@ -65,9 +68,15 @@ void encoder_init(void) { | |||
| 65 | if (!isLeftHand) { | 68 | if (!isLeftHand) { |
| 66 | const pin_t encoders_pad_a_right[] = ENCODERS_PAD_A_RIGHT; | 69 | const pin_t encoders_pad_a_right[] = ENCODERS_PAD_A_RIGHT; |
| 67 | const pin_t encoders_pad_b_right[] = ENCODERS_PAD_B_RIGHT; | 70 | const pin_t encoders_pad_b_right[] = ENCODERS_PAD_B_RIGHT; |
| 71 | # if defined(ENCODER_RESOLUTIONS_RIGHT) | ||
| 72 | const uint8_t encoder_resolutions_right[] = ENCODER_RESOLUTIONS_RIGHT; | ||
| 73 | # endif | ||
| 68 | for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { | 74 | for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { |
| 69 | encoders_pad_a[i] = encoders_pad_a_right[i]; | 75 | encoders_pad_a[i] = encoders_pad_a_right[i]; |
| 70 | encoders_pad_b[i] = encoders_pad_b_right[i]; | 76 | encoders_pad_b[i] = encoders_pad_b_right[i]; |
| 77 | # if defined(ENCODER_RESOLUTIONS_RIGHT) | ||
| 78 | encoder_resolutions[i] = encoder_resolutions_right[i]; | ||
| 79 | # endif | ||
| 71 | } | 80 | } |
| 72 | } | 81 | } |
| 73 | #endif | 82 | #endif |
| @@ -87,19 +96,26 @@ void encoder_init(void) { | |||
| 87 | 96 | ||
| 88 | static void encoder_update(int8_t index, uint8_t state) { | 97 | static void encoder_update(int8_t index, uint8_t state) { |
| 89 | uint8_t i = index; | 98 | uint8_t i = index; |
| 99 | |||
| 100 | #ifdef ENCODER_RESOLUTIONS | ||
| 101 | int8_t resolution = encoder_resolutions[i]; | ||
| 102 | #else | ||
| 103 | int8_t resolution = ENCODER_RESOLUTION; | ||
| 104 | #endif | ||
| 105 | |||
| 90 | #ifdef SPLIT_KEYBOARD | 106 | #ifdef SPLIT_KEYBOARD |
| 91 | index += thisHand; | 107 | index += thisHand; |
| 92 | #endif | 108 | #endif |
| 93 | encoder_pulses[i] += encoder_LUT[state & 0xF]; | 109 | encoder_pulses[i] += encoder_LUT[state & 0xF]; |
| 94 | if (encoder_pulses[i] >= ENCODER_RESOLUTION) { | 110 | if (encoder_pulses[i] >= resolution) { |
| 95 | encoder_value[index]++; | 111 | encoder_value[index]++; |
| 96 | encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); | 112 | encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); |
| 97 | } | 113 | } |
| 98 | if (encoder_pulses[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise | 114 | if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise |
| 99 | encoder_value[index]--; | 115 | encoder_value[index]--; |
| 100 | encoder_update_kb(index, ENCODER_CLOCKWISE); | 116 | encoder_update_kb(index, ENCODER_CLOCKWISE); |
| 101 | } | 117 | } |
| 102 | encoder_pulses[i] %= ENCODER_RESOLUTION; | 118 | encoder_pulses[i] %= resolution; |
| 103 | } | 119 | } |
| 104 | 120 | ||
| 105 | void encoder_read(void) { | 121 | void encoder_read(void) { |
