diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index cffa5a5df5..b0506735d7 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -259,7 +259,7 @@ uint16_t muse_counter = 0; uint8_t muse_offset = 70; uint16_t muse_tempo = 50; -void encoder_update(bool clockwise) { +void encoder_update(uint8_t index, bool clockwise) { if (muse_mode) { if (IS_LAYER_ON(_RAISE)) { if (clockwise) { @@ -275,12 +275,22 @@ void encoder_update(bool clockwise) { } } } else { - if (clockwise) { - register_code(KC_PGDN); - unregister_code(KC_PGDN); + if (index == 0) { + if (clockwise) { + register_code(KC_PGDN); + unregister_code(KC_PGDN); + } else { + register_code(KC_PGUP); + unregister_code(KC_PGUP); + } } else { - register_code(KC_PGUP); - unregister_code(KC_PGUP); + if (clockwise) { + register_code(KC_MS_WH_DOWN); + unregister_code(KC_MS_WH_DOWN); + } else { + register_code(KC_MS_WH_UP); + unregister_code(KC_MS_WH_UP); + } } } } diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c index e4ebe48acc..c863bf6fc0 100644 --- a/keyboards/planck/rev6/matrix.c +++ b/keyboards/planck/rev6/matrix.c @@ -88,7 +88,7 @@ __attribute__ ((weak)) void dip_update(uint8_t index, bool active) { } __attribute__ ((weak)) -void encoder_update(bool clockwise) { } +void encoder_update(uint8_t index, bool clockwise) { } bool last_dip_switch[4] = {0}; @@ -113,10 +113,10 @@ uint8_t matrix_scan(void) { encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); encoder_value += encoder_LUT[encoder_state & 0xF]; if (encoder_value >= ENCODER_RESOLUTION) { - encoder_update(0); + encoder_update(0, 0); } if (encoder_value <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise - encoder_update(1); + encoder_update(0, 1); } encoder_value %= ENCODER_RESOLUTION; diff --git a/keyboards/planck/thk/matrix.c b/keyboards/planck/thk/matrix.c index efb31030d4..0b3a451da1 100644 --- a/keyboards/planck/thk/matrix.c +++ b/keyboards/planck/thk/matrix.c @@ -17,7 +17,7 @@ along with this program. If not, see . #include #include - +#include #include "matrix.h" #ifndef DEBOUNCE @@ -33,12 +33,54 @@ static uint8_t debouncing = DEBOUNCE; static matrix_row_t matrix[MATRIX_ROWS]; static matrix_row_t matrix_debouncing[MATRIX_ROWS]; +static uint8_t encoder_state[2] = {0}; +static int8_t encoder_value[2] = {0}; +static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0 }; + +static bool dip_switch[4] = {0, 0, 0, 0}; + +__attribute__ ((weak)) +void dip_update(uint8_t index, bool active) { } + +__attribute__ ((weak)) +void encoder_update(uint8_t index, bool clockwise) { } + +bool last_dip_switch[4] = {0}; + +#ifndef ENCODER_RESOLUTION + #define ENCODER_RESOLUTION 4 +#endif + +#define NUMBER_OF_ENCODERS 2 + +uint8_t read_encoder_state(uint8_t index) { + switch (index) { + case 0: + return (((PINB & (1 << 4)) << 0) ? 1 : 0) | ((((PINB & (1 << 3)) << 0) ? 1 : 0) << 1); + break; + case 1: + return (((PINB & (1 << 2)) << 0) ? 1 : 0) | ((((PINB & (1 << 1)) << 0) ? 1 : 0) << 1); + break; + } + return 0; +} + void matrix_init(void) { + // disables JTAG so we can use them as columns MCUCSR = (1<= ENCODER_RESOLUTION) { + encoder_update(i, 0); + } + if (encoder_value[i] <= -ENCODER_RESOLUTION) { // direction is arbitrary here, but this clockwise + encoder_update(i, 1); + } + encoder_value[i] %= ENCODER_RESOLUTION; + } + + // actual matrix scan for (uint8_t c = 0; c < MATRIX_ROWS; c++) { switch (c) { case 0: PORTA &= ~(1 << 7); break; diff --git a/keyboards/planck/thk/rules.mk b/keyboards/planck/thk/rules.mk index 3e292b428e..eb2e414cf0 100644 --- a/keyboards/planck/thk/rules.mk +++ b/keyboards/planck/thk/rules.mk @@ -32,7 +32,7 @@ BOOTLOADER = bootloadHID # build options BOOTMAGIC_ENABLE = no -MOUSEKEY_ENABLE = no +MOUSEKEY_ENABLE = yes EXTRAKEY_ENABLE = yes CONSOLE_ENABLE = no COMMAND_ENABLE = yes