Skip to content

Commit

Permalink
Remove encoder in-matrix workaround code (qmk#20389)
Browse files Browse the repository at this point in the history
    エンコーダーの仮想マッピングを廃止

  - config.h
    エンコーダからマトリクスの仮想定義を削除

  - info.json
    エンコーダからマトリクスの仮想定義を削除

  - keyboard.c
    エンコーダーへ割り当てた処理を削除
    - keymap.cでキーコードの仮想割り当てやめる

    - キーマップ/rules.mk

    ```diff
    + ENCODER_MAP_ENABLE = yes
    ```

    - キーマップ/keymap.c
    仮想定義に割り当ててきたキーコードを削除
    encoder_mapに、エンコーダーで動作させたいキーコードを割り当て(**注意:キーマップレベルでの定義**)

    - VIA定義ファイル(QMK外)
    QMKには直接関係しないが、VIAとRemapがEncoder mapに対応したため、VIA V3向けの定義ファイルも作成した。
    Sandyプロジェクトにファイルを追加。
  • Loading branch information
jpskenn committed Nov 3, 2023
1 parent 3772397 commit 93d131e
Show file tree
Hide file tree
Showing 24 changed files with 158 additions and 221 deletions.
5 changes: 0 additions & 5 deletions keyboards/sandy/dn0020/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
// Number of encoder
#define ENCODERS 2

// Mappings of encoder rotation to key position in key matrix.
// --> {k57, k97}, {k42, k45}
#define ENCODERS_CW_KEY { { 7, 5 }, { 2, 4} }
#define ENCODERS_CCW_KEY { { 7, 9 }, { 5, 4} }

/* RGB LED */
#define RGBLIGHT_HUE_STEP 8
#define RGBLIGHT_SAT_STEP 8
Expand Down
46 changes: 0 additions & 46 deletions keyboards/sandy/dn0020/dn0020.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,52 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

#include QMK_KEYBOARD_H


#ifdef ENCODER_ENABLE
//------------------------------------------------------------------------------
// Rotary Encoder with VIA
//------------------------------------------------------------------------------
static uint8_t encoder_state[ENCODERS] = {0};
static keypos_t encoder_cw[ENCODERS] = ENCODERS_CW_KEY;
static keypos_t encoder_ccw[ENCODERS] = ENCODERS_CCW_KEY;

void encoder_action_unregister(void) {
for (int index = 0; index < ENCODERS; ++index) {
if (encoder_state[index]) {
keyevent_t encoder_event = (keyevent_t) {
.key = encoder_state[index] >> 1 ? encoder_cw[index] : encoder_ccw[index],
.pressed = false,
.time = timer_read(),
.type = KEY_EVENT
};
encoder_state[index] = 0;
action_exec(encoder_event);
}
}
}

void encoder_action_register(uint8_t index, bool clockwise) {
keyevent_t encoder_event = (keyevent_t) {
.key = clockwise ? encoder_cw[index] : encoder_ccw[index],
.pressed = true,
.time = timer_read(),
.type = KEY_EVENT
};
encoder_state[index] = (clockwise ^ 1) | (clockwise << 1);
action_exec(encoder_event);
}

void matrix_scan_kb(void) {
encoder_action_unregister();
matrix_scan_user();
}

bool encoder_update_kb(uint8_t index, bool clockwise) {
encoder_action_register(index, clockwise);
return true;
}
#endif

//------------------------------------------------------------------------------
// Keyboard Initialization
//------------------------------------------------------------------------------
Expand Down
4 changes: 0 additions & 4 deletions keyboards/sandy/dn0020/info.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@
{"label": "", "matrix": [9,6], "x":13, "y":4},
{"label": "", "matrix": [4,7], "x":14, "y":4},

{"label": "", "matrix": [5,7], "x":0, "y":5.25},
{"label": "", "matrix": [9,7], "x":1, "y":5.25},
{"label": "", "matrix": [1,7], "x":7, "y":5.25},
{"label": "", "matrix": [4,2], "x":13, "y":5.25},
{"label": "", "matrix": [4,5], "x":14, "y":5.25},
{"label": "", "matrix": [2,7], "x":6, "y":6.25},
{"label": "", "matrix": [8,7], "x":7, "y":6.25},
{"label": "", "matrix": [7,7], "x":8, "y":6.25},
Expand Down
8 changes: 4 additions & 4 deletions keyboards/sandy/dn0020/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
KC_MUTE, KC_LNG2, KC_LGUI, KC_LALT, SP_LOW, KC_BSPC, _______, KC_ENT, SP_RAI, KC_RALT, KC_RALT, KC_DOWN, KC_RGHT,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
KC_VOLD, KC_VOLU, KC_UP, KC_VOLD, KC_VOLU,
KC_UP,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
KC_LEFT, KC_MUTE, KC_RGHT,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand All @@ -60,7 +60,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
_______, _______, _______, _______, _______, _______, _______, _______, SP_ADJ, _______, _______, _______, _______,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
_______, _______, _______, _______, _______,
_______,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
_______, _______, _______,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand All @@ -79,7 +79,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
_______, _______, _______, _______, SP_ADJ, _______, _______, _______, _______, _______, _______, _______, _______,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
_______, _______, _______, _______, _______,
_______,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
_______, _______, _______,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand All @@ -98,7 +98,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
_______, _______, _______, _______, _______,
_______,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
_______, _______, _______,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand Down
29 changes: 22 additions & 7 deletions keyboards/sandy/dn0020/keymaps/jpskenn/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
XXXXXXX, XXXXXXX, KC_LOPT, GUI_LANG2, SP_SFT, SP_LOW1, KC_BTN1, BS_SFT, SP_RAI1, GUI_LANG1, KC_ROPT, XXXXXXX, XXXXXXX,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
KC_VOLD, KC_VOLU, KC_MS_U, KC_VOLD, KC_VOLU,
KC_MS_U,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
KC_MS_L, KC_BTN1, KC_MS_R,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand All @@ -121,7 +121,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
XXXXXXX, XXXXXXX, KC_LWIN, ALT_LANG2, SP_SFT, SP_LOW1, KC_BTN1, BS_SFT, SP_RAI1, ALT_LANG1, KC_APP, XXXXXXX, XXXXXXX,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
KC_VOLD, KC_VOLU, KC_MS_U, KC_VOLD, KC_VOLU,
KC_MS_U,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
KC_MS_L, KC_BTN1, KC_MS_R,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand All @@ -140,7 +140,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
_______, _______, _______, _______, _______, SP_LOW2, _______, _______, _______, KC_P0, KC_PDOT, _______, _______,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
_______, _______, _______, _______, _______,
_______,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
_______, _______, _______,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand All @@ -159,7 +159,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
_______, _______, KC_WH_U, _______, _______,
KC_WH_U,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
KC_WH_L, KC_BTN2, KC_WH_R,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand All @@ -178,7 +178,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
XXXXXXX, XXXXXXX, KC_LOPT, GUI_LANG2, SP_SFT, _______, KC_BTN1, KC_BTN2, SP_RAI1, GUI_LANG1, KC_ROPT, XXXXXXX, XXXXXXX,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
KC_VOLD, KC_VOLU, KC_MS_U, KC_VOLD, KC_VOLU,
KC_MS_U,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
KC_MS_L, KC_BTN1, KC_MS_R,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand Down Expand Up @@ -216,7 +216,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, KC_VOLD, KC_VOLU, _______, _______,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
_______, _______, KC_WH_U, _______, _______,
KC_WH_U,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
KC_WH_L, KC_BTN2, KC_WH_R,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand Down Expand Up @@ -273,7 +273,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
// |---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------|
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
// |---------+---------+-----------+-----------+---------------+---------+---------+---------+---------------+-----------+-----------+---------+---------|
_______, _______, _______, _______, _______,
_______,
// |---------+---------+-------------------------------------------------+---------+-------------------------------------------------+---------+---------|
_______, _______, _______,
// |-----------------------------------------------------------+---------+---------+---------+-----------------------------------------------------------|
Expand All @@ -282,6 +282,21 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
),
};

//------------------------------------------------------------------------------
// Rotary Encoder with VIA
//------------------------------------------------------------------------------
#ifdef ENCODER_MAP_ENABLE
const uint16_t PROGMEM encoder_map[][ENCODERS][2] = {
[_BASE1] = { ENCODER_CCW_CW(KC_VOLU, KC_VOLD), ENCODER_CCW_CW(KC_VOLU, KC_VOLD) },
[_BASE2] = { ENCODER_CCW_CW(_______, _______), ENCODER_CCW_CW(_______, _______) },
[_BASE3] = { ENCODER_CCW_CW(_______, _______), ENCODER_CCW_CW(_______, _______) },
[_LOWER1] = { ENCODER_CCW_CW(_______, _______), ENCODER_CCW_CW(_______, _______) },
[_LOWER2] = { ENCODER_CCW_CW(_______, _______), ENCODER_CCW_CW(_______, _______) },
[_RAISE1] = { ENCODER_CCW_CW(_______, _______), ENCODER_CCW_CW(_______, _______) },
[_ADJUST] = { ENCODER_CCW_CW(_______, _______), ENCODER_CCW_CW(_______, _______) },
};
#endif

uint16_t key_timer;

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
Expand Down
1 change: 1 addition & 0 deletions keyboards/sandy/dn0020/keymaps/jpskenn/rules.mk
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
VIA_ENABLE = yes
ENCODER_MAP_ENABLE = yes

DYNAMIC_MACRO_ENABLE = yes # Dynamic Macros
Loading

0 comments on commit 93d131e

Please sign in to comment.