diff --git a/keyboards/planck/keymaps/default/config.h b/keyboards/planck/keymaps/default/config.h index a1635f2ba..8b0abf976 100644 --- a/keyboards/planck/keymaps/default/config.h +++ b/keyboards/planck/keymaps/default/config.h @@ -25,7 +25,7 @@ /* enable basic MIDI features: - MIDI notes can be sent when in Music mode is on */ - + #define MIDI_BASIC /* enable advanced MIDI features: @@ -39,4 +39,8 @@ /* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */ //#define MIDI_TONE_KEYCODE_OCTAVES 2 -#endif \ No newline at end of file + +// Most tactile encoders have detents every 4 stages +#define ENCODER_RESOLUTION 4 + +#endif diff --git a/keyboards/planck/keymaps/default/keymap.c b/keyboards/planck/keymaps/default/keymap.c index 0bb70ca7b..40ae7777e 100644 --- a/keyboards/planck/keymaps/default/keymap.c +++ b/keyboards/planck/keymaps/default/keymap.c @@ -75,7 +75,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TAB, KC_Q, KC_W, KC_F, KC_P, KC_G, KC_J, KC_L, KC_U, KC_Y, KC_SCLN, KC_BSPC, KC_ESC, KC_A, KC_R, KC_S, KC_T, KC_D, KC_H, KC_N, KC_E, KC_I, KC_O, KC_QUOT, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_K, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT , - KC_SPC, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT + BACKLIT, KC_LCTL, KC_LALT, KC_LGUI, LOWER, KC_SPC, KC_SPC, RAISE, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT ), /* Dvorak @@ -266,3 +266,31 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { } return true; } + +void encoder_update(bool direction) { + if (direction) { + register_code(KC_PGUP); + unregister_code(KC_PGUP); + } else { + register_code(KC_PGDN); + unregister_code(KC_PGDN); + } +} + +void dip_update(uint8_t index, bool value) { + switch (index) { + case 0: + if (value) { + #ifdef AUDIO_ENABLE + PLAY_SONG(plover_song); + #endif + layer_on(_ADJUST); + } else { + #ifdef AUDIO_ENABLE + PLAY_SONG(plover_gb_song); + #endif + layer_off(_ADJUST); + } + break; + } +} diff --git a/keyboards/planck/planck.h b/keyboards/planck/planck.h index 626798912..f0a12d933 100644 --- a/keyboards/planck/planck.h +++ b/keyboards/planck/planck.h @@ -60,11 +60,11 @@ { k00, k01, k02, k03, k04, k05 }, \ { k10, k11, k12, k13, k14, k15 }, \ { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k33, k34, k35 }, \ + { k30, k31, k32, k39, k3a, k3b }, \ { k06, k07, k08, k09, k0a, k0b }, \ { k16, k17, k18, k19, k1a, k1b }, \ { k26, k27, k28, k29, k2a, k2b }, \ - { k36, k37, k38, k39, k3a, k3b } \ + { k36, k37, k38, k33, k34, k35 } \ } #define LAYOUT_planck_1x2uR( \ @@ -77,11 +77,11 @@ { k00, k01, k02, k03, k04, k05 }, \ { k10, k11, k12, k13, k14, k15 }, \ { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k33, k34, k35 }, \ + { k30, k31, k32, k39, k3a, k3b }, \ { k06, k07, k08, k09, k0a, k0b }, \ { k16, k17, k18, k19, k1a, k1b }, \ { k26, k27, k28, k29, k2a, k2b }, \ - { k36, k37, k38, k39, k3a, k3b } \ + { k36, k37, k38, k33, k34, k35 } \ } #define LAYOUT_planck_1x2uL( \ @@ -94,11 +94,11 @@ { k00, k01, k02, k03, k04, k05 }, \ { k10, k11, k12, k13, k14, k15 }, \ { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k33, k34, k35 }, \ + { k30, k31, k32, k39, k3a, k3b }, \ { k06, k07, k08, k09, k0a, k0b }, \ { k16, k17, k18, k19, k1a, k1b }, \ { k26, k27, k28, k29, k2a, k2b }, \ - { k36, k37, k38, k39, k3a, k3b } \ + { k36, k37, k38, k33, k34, k35 } \ } #define LAYOUT_planck_2x2u( \ @@ -111,11 +111,11 @@ { k00, k01, k02, k03, k04, k05 }, \ { k10, k11, k12, k13, k14, k15 }, \ { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k33, k34, k35 }, \ + { k30, k31, k32, k39, k3a, k3b }, \ { k06, k07, k08, k09, k0a, k0b }, \ { k16, k17, k18, k19, k1a, k1b }, \ { k26, k27, k28, k29, k2a, k2b }, \ - { k36, k37, k38, k39, k3a, k3b } \ + { k36, k37, k38, k33, k34, k35 } \ } #define LAYOUT_planck_grid( \ @@ -128,11 +128,11 @@ { k00, k01, k02, k03, k04, k05 }, \ { k10, k11, k12, k13, k14, k15 }, \ { k20, k21, k22, k23, k24, k25 }, \ - { k30, k31, k32, k33, k34, k35 }, \ + { k30, k31, k32, k39, k3a, k3b }, \ { k06, k07, k08, k09, k0a, k0b }, \ { k16, k17, k18, k19, k1a, k1b }, \ { k26, k27, k28, k29, k2a, k2b }, \ - { k36, k37, k38, k39, k3a, k3b } \ + { k36, k37, k38, k33, k34, k35 } \ } #define KEYMAP LAYOUT_planck_grid diff --git a/keyboards/planck/rev6/matrix.c b/keyboards/planck/rev6/matrix.c index 007c42f0a..cd025ea49 100644 --- a/keyboards/planck/rev6/matrix.c +++ b/keyboards/planck/rev6/matrix.c @@ -9,6 +9,7 @@ #include "matrix.h" #include "action.h" #include "keycode.h" +#include /* * col: { B11, B10, B2, B1, A7, B0 } @@ -22,7 +23,7 @@ static uint16_t debouncing_time = 0; static uint8_t encoder_state = 0; static int8_t encoder_value = 0; -static int8_t encoder_LUT[] = { 0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 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}; @@ -83,26 +84,37 @@ void matrix_init(void) { matrix_init_quantum(); } +__attribute__ ((weak)) +void dip_update(uint8_t index, bool value) { } + +__attribute__ ((weak)) +void encoder_update(bool direction) { } + +bool last_dip_switch[4] = {0}; + uint8_t matrix_scan(void) { // dip switch dip_switch[0] = palReadPad(GPIOB, 14); dip_switch[1] = palReadPad(GPIOA, 15); dip_switch[2] = palReadPad(GPIOA, 10); dip_switch[3] = palReadPad(GPIOB, 9); + for (uint8_t i = 0; i < 4; i++) { + if (last_dip_switch[i] ^ dip_switch[i]) + dip_update(i, dip_switch[i]); + } + memcpy(last_dip_switch, dip_switch, sizeof(&dip_switch)); // encoder on B12 and B13 encoder_state <<= 2; encoder_state |= (palReadPad(GPIOB, 12) << 0) | (palReadPad(GPIOB, 13) << 1); encoder_value += encoder_LUT[encoder_state & 0xF]; - if (encoder_value >= 4) { - register_code(KC_MS_WH_UP); - unregister_code(KC_MS_WH_UP); + if (encoder_value >= ENCODER_RESOLUTION) { + encoder_update(1); } - if (encoder_value <= -4) { - register_code(KC_MS_WH_DOWN); - unregister_code(KC_MS_WH_DOWN); + if (encoder_value <= -ENCODER_RESOLUTION) { + encoder_update(0); } - encoder_value %= 4; + encoder_value %= ENCODER_RESOLUTION; // actual matrix for (int col = 0; col < MATRIX_COLS; col++) { @@ -186,4 +198,4 @@ void matrix_print(void) { } printf("\n"); } -} \ No newline at end of file +}