From e30b1b58d6d4d60c6db0313bcf75466c3ebeeabe Mon Sep 17 00:00:00 2001 From: paradoxskin <1312269430@qq.com> Date: Sat, 13 Jul 2024 01:15:39 +0800 Subject: [PATCH] explore tap dance very intersting keychron: tap #5#1 -> ctrl-e hold -> ctrl --- .gitignore | 1 + keyboards/keychron/v4/ansi/config.h | 2 +- .../v4/ansi/keymaps/paradoxskin/keymap.c | 100 ++++++++++++++---- readme.md | 4 +- 4 files changed, 83 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index 13ed2960352a..a93f1ae8158b 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,4 @@ compile_commands.json # VIA(L) json files that don't belong in QMK repo via*.json +.ccls-cache diff --git a/keyboards/keychron/v4/ansi/config.h b/keyboards/keychron/v4/ansi/config.h index 3cbec7238732..396e81b070c0 100644 --- a/keyboards/keychron/v4/ansi/config.h +++ b/keyboards/keychron/v4/ansi/config.h @@ -21,4 +21,4 @@ #define RGB_MATRIX_LED_COUNT DRIVER_1_LED_TOTAL /* Enable CapsLcok LED*/ -#define CAPS_LOCK_LED_INDEX 28 +#define CAPS_LOCK_LED_INDEX 0 diff --git a/keyboards/keychron/v4/ansi/keymaps/paradoxskin/keymap.c b/keyboards/keychron/v4/ansi/keymaps/paradoxskin/keymap.c index e9b13df4609c..ab07e637406a 100644 --- a/keyboards/keychron/v4/ansi/keymaps/paradoxskin/keymap.c +++ b/keyboards/keychron/v4/ansi/keymaps/paradoxskin/keymap.c @@ -23,23 +23,74 @@ enum layers { WIN_BASE, _FN1, _FN2, - _FN3, + _FNX, + _FNY, _TN1, _TN2, - _TNG, + _TN3, }; +typedef struct { + uint16_t tap; + uint16_t hold; + uint16_t held; +} tap_dance_tap_hold_t; + #define KC_TASK LGUI(KC_TAB) #define KC_FLXP LGUI(KC_E) +#define QK_TAP_DANCE_GET_INDEX(kc) ((kc)&0xFF) enum { - TD_C_CE, - TD_R_BK, + TD_TH_CE_C, }; +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + tap_dance_action_t *action; + + switch (keycode) { + case TD(TD_TH_CE_C): // list all tap dance keycodes with tap-hold configurations + action = &tap_dance_actions[QK_TAP_DANCE_GET_INDEX(keycode)]; + if (!record->event.pressed && action->state.count && !action->state.finished) { + tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)action->user_data; + tap_code16(tap_hold->tap); + } + } + return true; +} + +//#include "print.h" + +void tap_dance_tap_hold_finished(tap_dance_state_t *state, void *user_data) { + tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)user_data; + + if (state->pressed) { + //uprintf("F%d %d %d %d\n", state->count, state->interrupted, state->pressed, state->finished); + if (state->count > 0) { + register_code16(tap_hold->hold); + tap_hold->held = tap_hold->hold; + } + //else { + // register_code16(tap_hold->tap); + // tap_hold->held = tap_hold->tap; + //} + } +} + +void tap_dance_tap_hold_reset(tap_dance_state_t *state, void *user_data) { + tap_dance_tap_hold_t *tap_hold = (tap_dance_tap_hold_t *)user_data; + //uprintf("R%d %d %d %d\n", state->count, state->interrupted, state->pressed, state->finished); + + if (tap_hold->held) { + unregister_code16(tap_hold->held); + tap_hold->held = 0; + } +} + +#define ACTION_TAP_DANCE_TAP_HOLD(tap, hold) \ + { .fn = {NULL, tap_dance_tap_hold_finished, tap_dance_tap_hold_reset}, .user_data = (void *)&((tap_dance_tap_hold_t){tap, hold, 0}), } + tap_dance_action_t tap_dance_actions[] = { - [TD_C_CE] = ACTION_TAP_DANCE_DOUBLE(KC_LCTL, C(KC_E)), - [TD_R_BK] = ACTION_TAP_DANCE_LAYER_MOVE(KC_RIGHT, WIN_BASE) + [TD_TH_CE_C] = ACTION_TAP_DANCE_TAP_HOLD(C(KC_E), KC_LCTL) }; const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { @@ -48,16 +99,15 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, - KC_LCTL, KC_LOPT, KC_LCMD, KC_SPC, KC_RCMD, MO(_FN1), MO(_FN3), KC_RCTL + KC_LCTL, KC_LOPT, KC_LCMD, KC_SPC, KC_RCMD, XXXXXXX, XXXXXXX, KC_RCTL ), - // TODO design some interesting layer (lock) from _FN3 [WIN_BASE] = LAYOUT_ansi_61( KC_GRAVE, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, LT(_FN1,KC_ESC), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, RSFT_T(KC_UP), - TD(TD_C_CE), MO(_FN2), KC_LGUI, MT(MOD_LALT,KC_SPC), KC_RALT, LT(_FN1,KC_LEFT), LT(_FN2,KC_DOWN), LT(_FN3,KC_RIGHT) + TD(TD_TH_CE_C), MO(_FN2), KC_LGUI, MT(MOD_LALT,KC_SPC), KC_RALT, LT(_FN1,KC_LEFT), LT(_FN2,KC_DOWN), LT(_FNX,KC_RIGHT) ), [_FN1] = LAYOUT_ansi_61( @@ -65,7 +115,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { XXXXXXX, KC_BTN1, KC_MS_U, KC_BTN2, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_HUI, RGB_SAI, RGB_VAI, XXXXXXX, KC_MS_L, KC_MS_D, KC_MS_R, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_SPI, RGB_MOD, KC_LSFT, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_TOG, - XXXXXXX, XXXXXXX, KC_PSCR, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, TO(WIN_BASE) + XXXXXXX, XXXXXXX, KC_PSCR, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX ), [_FN2] = LAYOUT_ansi_61( @@ -76,12 +126,20 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_MUTE, XXXXXXX, KC_MPLY, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX ), - [_FN3] = LAYOUT_ansi_61( - TO(_TN2), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - TO(_TNG), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - TO(_TN1), _______, _______, _______, _______, _______, _______, _______ + [_FNX] = LAYOUT_ansi_61( + KC_CAPS, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, TO(_TN1), + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, TO(_TN2), + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, TO(_TN3), + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______ + ), + + [_FNY] = LAYOUT_ansi_61( + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + KC_ESC, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, TO(WIN_BASE), _______ ), // TO layer @@ -90,7 +148,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_7, KC_8, KC_9, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_4, KC_5, KC_6, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_1, KC_2, KC_3, _______, _______, _______, _______, _______, _______, _______, _______, _______, - KC_0, KC_0, KC_0, _______, _______, _______, _______, TD(TD_R_BK) + KC_0, KC_0, KC_0, _______, _______, _______, _______, LT(_FNY, KC_RIGHT) ), [_TN2] = LAYOUT_ansi_61( @@ -98,14 +156,14 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - _______, _______, _______, _______, _______, _______, _______, TD(TD_R_BK) + _______, _______, _______, _______, _______, _______, _______, LT(_FNY, KC_RIGHT) ), - [_TNG] = LAYOUT_ansi_61( + [_TN3] = LAYOUT_ansi_61( _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_ESC, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_P, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - KC_LCTL, _______, _______, KC_SPACE, _______, _______, _______, TD(TD_R_BK) + KC_LCTL, _______, _______, KC_SPACE, _______, _______, _______, LT(_FNY, KC_RIGHT) ), }; /* TEMPLATE: diff --git a/readme.md b/readme.md index 3884469736e3..5c469ad1fbfb 100644 --- a/readme.md +++ b/readme.md @@ -40,8 +40,8 @@ QMK is developed and maintained by Jack Humbert of OLKB with contributions from ### Keychron: * Build: `qmk compile -kb keychron/v4/ansi -km paradoxskin` => `keychron_v4_ansi_paradoxskin.bin` -* DFU: Hold reset button under L5#4 while replugin USB -* Flash: Just use qmk-toolbox +* DFU: Hold reset button under L5#4 while replugin USB / Hold L1#1 while replugin USB +* Flash: `qmk flash xxx.bin` ### AP2: