From f6c7e114260890292dcd12645db7fecd64167973 Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Tue, 16 Jul 2019 01:40:54 -0700 Subject: Remove the need to specify NUM_OF_ENCODERS for the Encoder feature (#6328) * Remove the need to set NUM_OF_ENCODERS Instead, calculate the size of the array, and use that instead * Add hack for split common support * Remove NUM_OF_ENCODERS from keyboard config Can be reverted, if needed --- docs/feature_encoders.md | 1 - keyboards/abstract/ellipse/rev1/config.h | 1 - keyboards/boston_meetup/2019/config.h | 4 +--- keyboards/cannonkeys/ortho75/config.h | 1 - keyboards/cannonkeys/satisfaction75/config.h | 1 - keyboards/hadron/ver3/config.h | 1 - keyboards/handwired/daishi/config.h | 3 +-- keyboards/keebio/bdn9/config.h | 1 - keyboards/keebio/iris/rev3/config.h | 1 - keyboards/maxr1998/pulse4k/config.h | 1 - keyboards/planck/ez/config.h | 1 - keyboards/planck/rev6/config.h | 1 - keyboards/preonic/rev3/config.h | 1 - keyboards/rgbkb/sol/config.h | 1 - keyboards/rgbkb/zen/rev2/config.h | 2 -- keyboards/rgbkb/zygomorph/rev1/config.h | 1 - keyboards/ropro/config.h | 7 +++---- keyboards/tetris/config.h | 1 - quantum/encoder.c | 10 ++++------ quantum/split_common/transport.c | 2 ++ 20 files changed, 11 insertions(+), 31 deletions(-) diff --git a/docs/feature_encoders.md b/docs/feature_encoders.md index 9ac97a9a1..bb2d538e7 100644 --- a/docs/feature_encoders.md +++ b/docs/feature_encoders.md @@ -6,7 +6,6 @@ Basic encoders are supported by adding this to your `rules.mk`: and this to your `config.h`: - #define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { B12 } #define ENCODERS_PAD_B { B13 } diff --git a/keyboards/abstract/ellipse/rev1/config.h b/keyboards/abstract/ellipse/rev1/config.h index a56bfba2f..1fb9b76d9 100644 --- a/keyboards/abstract/ellipse/rev1/config.h +++ b/keyboards/abstract/ellipse/rev1/config.h @@ -239,7 +239,6 @@ along with this program. If not, see . // #define BOOTMAGIC_LITE_ROW 0 // #define BOOTMAGIC_LITE_COLUMN 0 -#define NUMBER_OF_ENCODERS 3 #define ENCODERS_PAD_A { B2, B3, D5 } #define ENCODERS_PAD_B { B1, B7, B4 } #define ENCODER_RESOLUTION 2 diff --git a/keyboards/boston_meetup/2019/config.h b/keyboards/boston_meetup/2019/config.h index 565281644..fa3dda730 100644 --- a/keyboards/boston_meetup/2019/config.h +++ b/keyboards/boston_meetup/2019/config.h @@ -26,7 +26,6 @@ #define MATRIX_ROW_PINS { A3, B8, B9, B1 } #define MATRIX_COL_PINS { A7, A8, B2, B10 } -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { B13 } #define ENCODERS_PAD_B { B14 } @@ -142,7 +141,7 @@ #define FB_LOOPGAIN 1 /* For Low:0, Medium:1, High:2, Very High:3 */ /* default 3V ERM vibration motor voltage and library*/ -#if FB_ERM_LRA == 0 +#if FB_ERM_LRA == 0 #define RATED_VOLTAGE 3 #define V_RMS 2.3 #define V_PEAK 3.30 @@ -193,4 +192,3 @@ #define RGB_MATRIX_KEYPRESSES #define SOLENOID_PIN A14 - diff --git a/keyboards/cannonkeys/ortho75/config.h b/keyboards/cannonkeys/ortho75/config.h index 6c240e2d6..588e2b921 100644 --- a/keyboards/cannonkeys/ortho75/config.h +++ b/keyboards/cannonkeys/ortho75/config.h @@ -39,7 +39,6 @@ along with this program. If not, see . #define BACKLIGHT_BREATHING #define BREATHING_PERIOD 6 -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { B9 } #define ENCODERS_PAD_B { B8 } diff --git a/keyboards/cannonkeys/satisfaction75/config.h b/keyboards/cannonkeys/satisfaction75/config.h index 092b37257..1cbe43fad 100644 --- a/keyboards/cannonkeys/satisfaction75/config.h +++ b/keyboards/cannonkeys/satisfaction75/config.h @@ -35,7 +35,6 @@ along with this program. If not, see . #define MATRIX_ROW_PINS { B3, B4, A0, A2, A4, A3 } #define DIODE_DIRECTION COL2ROW -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { B9 } #define ENCODERS_PAD_B { B8 } diff --git a/keyboards/hadron/ver3/config.h b/keyboards/hadron/ver3/config.h index 5e44b27ae..2912486f4 100644 --- a/keyboards/hadron/ver3/config.h +++ b/keyboards/hadron/ver3/config.h @@ -44,7 +44,6 @@ #define MATRIX_COL_PINS { B8, B2, B10, A0, A1, A2, B0, A3, B1, A6, A7, B12, C13, B11, B9 } #define UNUSED_PINS -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { B13 } #define ENCODERS_PAD_B { B14 } diff --git a/keyboards/handwired/daishi/config.h b/keyboards/handwired/daishi/config.h index 15ff6a6a6..b4665bece 100644 --- a/keyboards/handwired/daishi/config.h +++ b/keyboards/handwired/daishi/config.h @@ -52,10 +52,9 @@ along with this program. If not, see . #define DEBOUNCE 5 /* Set up rotary encoder */ -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { F1 } #define ENCODERS_PAD_B { F0 } #define ENCODER_RESOLUTION 2 /* Set delay for tap_code on rotary encoder */ -#define TAP_CODE_DELAY 10 \ No newline at end of file +#define TAP_CODE_DELAY 10 diff --git a/keyboards/keebio/bdn9/config.h b/keyboards/keebio/bdn9/config.h index 19e625348..641dc5736 100644 --- a/keyboards/keebio/bdn9/config.h +++ b/keyboards/keebio/bdn9/config.h @@ -38,7 +38,6 @@ along with this program. If not, see . { E6, B4, B2 } \ } -#define NUMBER_OF_ENCODERS 2 #define ENCODERS_PAD_A { D1, F5 } #define ENCODERS_PAD_B { D0, F6 } diff --git a/keyboards/keebio/iris/rev3/config.h b/keyboards/keebio/iris/rev3/config.h index 720695b60..965362543 100644 --- a/keyboards/keebio/iris/rev3/config.h +++ b/keyboards/keebio/iris/rev3/config.h @@ -41,7 +41,6 @@ along with this program. If not, see . #define QMK_LED B0 #define QMK_SPEAKER C6 -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { B5 } #define ENCODERS_PAD_B { B7 } diff --git a/keyboards/maxr1998/pulse4k/config.h b/keyboards/maxr1998/pulse4k/config.h index cb4eab699..d1bfaf300 100644 --- a/keyboards/maxr1998/pulse4k/config.h +++ b/keyboards/maxr1998/pulse4k/config.h @@ -43,7 +43,6 @@ along with this program. If not, see . #define DEBOUNCE 5 /* Rotary encoders */ -#define NUMBER_OF_ENCODERS 2 #define ENCODERS_PAD_A { D2, F6 } #define ENCODERS_PAD_B { D3, F5 } #define ENCODER_RESOLUTION 4 diff --git a/keyboards/planck/ez/config.h b/keyboards/planck/ez/config.h index 142382dab..a252b2528 100644 --- a/keyboards/planck/ez/config.h +++ b/keyboards/planck/ez/config.h @@ -43,7 +43,6 @@ #define MATRIX_ROW_PINS { A10, A9, A8, B15, C13, C14, C15, A2 } #define MATRIX_COL_PINS { B11, B10, B2, B1, A7, B0 } -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { B12 } #define ENCODERS_PAD_B { B13 } diff --git a/keyboards/planck/rev6/config.h b/keyboards/planck/rev6/config.h index 841a62190..3354c3f80 100644 --- a/keyboards/planck/rev6/config.h +++ b/keyboards/planck/rev6/config.h @@ -43,7 +43,6 @@ * #define UNUSED_PINS */ -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { B12 } #define ENCODERS_PAD_B { B13 } diff --git a/keyboards/preonic/rev3/config.h b/keyboards/preonic/rev3/config.h index b2a53ee65..2d2993455 100644 --- a/keyboards/preonic/rev3/config.h +++ b/keyboards/preonic/rev3/config.h @@ -43,7 +43,6 @@ * #define UNUSED_PINS */ -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { B12 } #define ENCODERS_PAD_B { B13 } diff --git a/keyboards/rgbkb/sol/config.h b/keyboards/rgbkb/sol/config.h index 1afd973e9..23f4503bf 100644 --- a/keyboards/rgbkb/sol/config.h +++ b/keyboards/rgbkb/sol/config.h @@ -36,7 +36,6 @@ along with this program. If not, see . #define MATRIX_COL_PINS { F0, F1, F4, F5, F6, F7, C7 } // Encoder support -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { D2 } #define ENCODERS_PAD_B { D6 } diff --git a/keyboards/rgbkb/zen/rev2/config.h b/keyboards/rgbkb/zen/rev2/config.h index b9f3d2228..c2bb360bd 100644 --- a/keyboards/rgbkb/zen/rev2/config.h +++ b/keyboards/rgbkb/zen/rev2/config.h @@ -41,8 +41,6 @@ along with this program. If not, see . #define MATRIX_ROW_PINS { C6, E6, B5, D7, B4 } #define MATRIX_COL_PINS { F4, F5, F6, F7, B3, B1, B2 } -#define NUMBER_OF_ENCODERS 1 - #define ENCODERS_PAD_A { D4 } #define ENCODERS_PAD_B { D2 } diff --git a/keyboards/rgbkb/zygomorph/rev1/config.h b/keyboards/rgbkb/zygomorph/rev1/config.h index ad58761cc..6e55a6a5f 100644 --- a/keyboards/rgbkb/zygomorph/rev1/config.h +++ b/keyboards/rgbkb/zygomorph/rev1/config.h @@ -40,7 +40,6 @@ along with this program. If not, see . #define SOFT_SERIAL_PIN D3 -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { D2 } #define ENCODERS_PAD_B { D7 } diff --git a/keyboards/ropro/config.h b/keyboards/ropro/config.h index 0966faf54..5079217f9 100644 --- a/keyboards/ropro/config.h +++ b/keyboards/ropro/config.h @@ -1,4 +1,4 @@ -#pragma once +#pragma once /* Copyright 2019 Garret G. (TheRoyalSweatshirt) * @@ -13,10 +13,10 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see .#pragma once + * along with this program. If not, see .#pragma once */ -#include "config_common.h" +#include "config_common.h" /* USB Device descriptor parameter */ #define VENDOR_ID 0xFEED @@ -30,7 +30,6 @@ #define MATRIX_ROWS 7 #define MATRIX_COLS 14 -#define NUMBER_OF_ENCODERS 1 #define ENCODERS_PAD_A { B7 } #define ENCODERS_PAD_B { D5 } diff --git a/keyboards/tetris/config.h b/keyboards/tetris/config.h index 7fe0c2d64..024d3be0e 100755 --- a/keyboards/tetris/config.h +++ b/keyboards/tetris/config.h @@ -40,7 +40,6 @@ #define NO_MUSIC_MODE #endif -#define NUMBER_OF_ENCODERS 2 #define ENCODERS_PAD_A { D1,F1 } #define ENCODERS_PAD_B { D0,F0 } diff --git a/quantum/encoder.c b/quantum/encoder.c index ddf6234ab..31f00c346 100644 --- a/quantum/encoder.c +++ b/quantum/encoder.c @@ -25,16 +25,14 @@ #define ENCODER_RESOLUTION 4 #endif -#ifndef NUMBER_OF_ENCODERS - #error "Number of encoders not defined by NUMBER_OF_ENCODERS" -#endif - #if !defined(ENCODERS_PAD_A) || !defined(ENCODERS_PAD_B) #error "No encoder pads defined by ENCODERS_PAD_A and ENCODERS_PAD_B" #endif -static pin_t encoders_pad_a[NUMBER_OF_ENCODERS] = ENCODERS_PAD_A; -static pin_t encoders_pad_b[NUMBER_OF_ENCODERS] = ENCODERS_PAD_B; + +#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; static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; diff --git a/quantum/split_common/transport.c b/quantum/split_common/transport.c index b32d48eb8..ba21d0c7b 100644 --- a/quantum/split_common/transport.c +++ b/quantum/split_common/transport.c @@ -17,6 +17,8 @@ #ifdef ENCODER_ENABLE # include "encoder.h" +static pin_t encoders_pad[] = ENCODERS_PAD_A; +# define NUMBER_OF_ENCODERS (sizeof(encoders_pad)/sizeof(pin_t)) #endif #if defined(USE_I2C) || defined(EH) -- cgit v1.2.3