From 9a05ecd2b08ef4d589886789d82cee3c2243cd41 Mon Sep 17 00:00:00 2001 From: fauxpark Date: Mon, 7 Sep 2020 09:30:40 +1000 Subject: [PATCH 1/2] Per-encoder resolutions --- docs/feature_encoders.md | 6 ++++++ quantum/encoder.c | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/docs/feature_encoders.md b/docs/feature_encoders.md index 8f9ba1a80a79..6cf2585c0f2a 100644 --- a/docs/feature_encoders.md +++ b/docs/feature_encoders.md @@ -32,6 +32,12 @@ Additionally, the resolution, which defines how many pulses the encoder register #define ENCODER_RESOLUTION 4 ``` +It can also be defined per-encoder, by instead defining: + +```c +#define ENCODER_RESOLUTIONS { 4, 2 } +``` + ## Split Keyboards If you are using different pinouts for the encoders on each half of a split keyboard, you can define the pinout for the right half like this: diff --git a/quantum/encoder.c b/quantum/encoder.c index 81ec1bb376c8..622d0c1460d2 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -23,7 +23,7 @@ // for memcpy #include -#ifndef ENCODER_RESOLUTION +#if !defined(ENCODER_RESOLUTIONS) && !defined(ENCODER_RESOLUTION) # define ENCODER_RESOLUTION 4 #endif @@ -34,6 +34,9 @@ #define NUMBER_OF_ENCODERS (sizeof(encoders_pad_a) / sizeof(pin_t)) static pin_t encoders_pad_a[] = ENCODERS_PAD_A; static pin_t encoders_pad_b[] = ENCODERS_PAD_B; +#ifdef ENCODER_RESOLUTIONS +static uint8_t encoder_resolutions[] = ENCODER_RESOLUTIONS; +#endif #ifndef ENCODER_DIRECTION_FLIP # define ENCODER_CLOCKWISE true @@ -87,19 +90,26 @@ void encoder_init(void) { static void encoder_update(int8_t index, uint8_t state) { uint8_t i = index; + +#ifdef ENCODER_RESOLUTIONS + int8_t resolution = encoder_resolutions[i]; +#else + int8_t resolution = ENCODER_RESOLUTION; +#endif + #ifdef SPLIT_KEYBOARD index += thisHand; #endif encoder_pulses[i] += encoder_LUT[state & 0xF]; - if (encoder_pulses[i] >= ENCODER_RESOLUTION) { + if (encoder_pulses[i] >= resolution) { encoder_value[index]++; encoder_update_kb(index, ENCODER_COUNTER_CLOCKWISE); } - if (encoder_pulses[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise + if (encoder_pulses[i] <= -resolution) { // direction is arbitrary here, but this clockwise encoder_value[index]--; encoder_update_kb(index, ENCODER_CLOCKWISE); } - encoder_pulses[i] %= ENCODER_RESOLUTION; + encoder_pulses[i] %= resolution; } void encoder_read(void) { From 6ba0c2952feb6ae6979039fbd816683fb51c86ca Mon Sep 17 00:00:00 2001 From: fauxpark Date: Mon, 7 Sep 2020 15:04:06 +1000 Subject: [PATCH 2/2] Resolutions for right hand --- docs/feature_encoders.md | 3 ++- quantum/encoder.c | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/feature_encoders.md b/docs/feature_encoders.md index 6cf2585c0f2a..e2cafdac48e8 100644 --- a/docs/feature_encoders.md +++ b/docs/feature_encoders.md @@ -40,11 +40,12 @@ It can also be defined per-encoder, by instead defining: ## Split Keyboards -If you are using different pinouts for the encoders on each half of a split keyboard, you can define the pinout for the right half like this: +If you are using different pinouts for the encoders on each half of a split keyboard, you can define the pinout (and optionally, resolutions) for the right half like this: ```c #define ENCODERS_PAD_A_RIGHT { encoder1a, encoder2a } #define ENCODERS_PAD_B_RIGHT { encoder1b, encoder2b } +#define ENCODER_RESOLUTIONS_RIGHT { 2, 4 } ``` ## Callbacks diff --git a/quantum/encoder.c b/quantum/encoder.c index 622d0c1460d2..7ca31afedc2f 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -68,9 +68,15 @@ void encoder_init(void) { if (!isLeftHand) { const pin_t encoders_pad_a_right[] = ENCODERS_PAD_A_RIGHT; const pin_t encoders_pad_b_right[] = ENCODERS_PAD_B_RIGHT; +# if defined(ENCODER_RESOLUTIONS_RIGHT) + const uint8_t encoder_resolutions_right[] = ENCODER_RESOLUTIONS_RIGHT; +# endif for (uint8_t i = 0; i < NUMBER_OF_ENCODERS; i++) { encoders_pad_a[i] = encoders_pad_a_right[i]; encoders_pad_b[i] = encoders_pad_b_right[i]; +# if defined(ENCODER_RESOLUTIONS_RIGHT) + encoder_resolutions[i] = encoder_resolutions_right[i]; +# endif } } #endif