#include QMK_KEYBOARD_H
#define CAPS_SFT MT(MOD_LSFT, KC_CAPS)
#define QUOT_SFT MT(MOD_RSFT, KC_QUOT)
#define PSCR_SFT MT(MOD_LSFT, KC_PSCR)
#define PAUSE_SFT MT(MOD_RSFT, KC_PAUSE)
#define F_SFT MT(MOD_LSFT, KC_F)
#define J_SFT MT(MOD_RSFT, KC_J)
#define PGUP_GUI MT(MOD_LGUI, KC_PGUP)
#define END_GUI MT(MOD_LGUI, KC_END)
#define UP_GUI MT(MOD_RGUI, KC_UP)
#define LEFT_GUI MT(MOD_RGUI, KC_LEFT)
#define EQL_CTL MT(MOD_RCTL, KC_EQL)
#define MINS_CTL MT(MOD_LCTL, KC_MINS)
#define BSPC_ALT LALT_T(KC_BSPC)
#define ENT_ALT LALT_T(KC_ENT)
#define SPC_ALT RALT_T(KC_SPC)
#define DEL_ALT RALT_T(KC_DEL)
enum tapdance_keycodes {
TD_LEFT,
TD_RGHT,
TD_C_X
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_ESC,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSLS,
CAPS_SFT, KC_A, KC_S, KC_D, F_SFT, KC_G, KC_H, J_SFT, KC_K, KC_L, KC_SCLN, QUOT_SFT,
PSCR_SFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, PAUSE_SFT,
TD(TD_LEFT), KC_INS, KC_LBRC, MINS_CTL, BSPC_ALT, DEL_ALT, TD(TD_C_X), TD(TD_C_X), ENT_ALT, SPC_ALT, EQL_CTL, KC_RBRC, KC_DEL, TD(TD_RGHT),
KC_HOME, PGUP_GUI, END_GUI, LEFT_GUI, UP_GUI, KC_RGHT,
KC_PGDN, KC_DOWN
),
[1] = LAYOUT(
KC_TRNS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_F11,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_F12,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, RESET, RESET, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS
),
};
#define STEPS(DANCE) [DANCE] = ACTION_TAP_DANCE_FN_ADVANCED( \
NULL, \
dance_ ## DANCE ## _finished, \
dance_ ## DANCE ## _reset)
#define CHOREOGRAPH(DANCE, PRESS, RELEASE, TAP, DOUBLETAP) \
static bool dance_ ## DANCE ## _pressed; \
\
void dance_ ## DANCE ## _finished(qk_tap_dance_state_t *state, void *user_data) { \
if (state->count == 1) { \
if (state->pressed) { \
dance_ ## DANCE ## _pressed = true; \
PRESS; \
} else { \
TAP; \
} \
} else if (state->count == 2) { \
if (!state->pressed) { \
DOUBLETAP; \
} \
} \
} \
\
void dance_ ## DANCE ## _reset(qk_tap_dance_state_t *state, void *user_data) { \
if (state->count == 1) { \
if (dance_ ## DANCE ## _pressed) { \
RELEASE; \
dance_ ## DANCE ## _pressed = false; \
} \
} \
}
CHOREOGRAPH(TD_LEFT,
layer_invert(1),
layer_invert(1),
SEND_STRING(SS_DOWN(X_LSFT) SS_DOWN(X_RSFT)
SS_UP(X_LSFT) SS_UP(X_RSFT)),
layer_invert(1));
CHOREOGRAPH(TD_RGHT,
layer_invert(1),
layer_invert(1),
SEND_STRING(SS_DOWN(X_LCTRL) SS_TAP(X_X) SS_TAP(X_S) SS_UP(X_LCTRL)
SS_DOWN(X_LGUI) SS_TAP(X_T) SS_UP(X_LGUI) SS_TAP(X_UP)),
layer_invert(1));
CHOREOGRAPH(TD_C_X,
SEND_STRING(SS_DOWN(X_LCTRL) SS_TAP(X_X)),
SEND_STRING(SS_UP(X_LCTRL)),
SEND_STRING(SS_DOWN(X_LCTRL) SS_TAP(X_X) SS_UP(X_LCTRL)),);
qk_tap_dance_action_t tap_dance_actions[] = {
STEPS(TD_LEFT), STEPS(TD_RGHT), STEPS(TD_C_X)
};
uint16_t get_tapping_term(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case TD(TD_LEFT):
case TD(TD_RGHT):
return 250;
case BSPC_ALT:
case UP_GUI:
case LEFT_GUI:
return 5000;
default:
return TAPPING_TERM;
}
}
bool get_permissive_hold(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case TD(TD_LEFT):
case TD(TD_RGHT):
case BSPC_ALT:
case UP_GUI:
case LEFT_GUI:
return true;
default:
return false;
}
}
layer_state_t layer_state_set_user(layer_state_t state) {
writePin(D0, (get_highest_layer(state) > 0));
return state;
}
void keyboard_post_init_user(void) {
const pin_t pins[] = {D0, D1, D2};
uint8_t i, j;
for (i = 0 ; i < sizeof(pins) / sizeof(pins[0]) + 2 ; i += 1) {
for (j = 0 ; j < sizeof(pins) / sizeof(pins[0]) ; j += 1) {
setPinOutput(pins[j]);
writePin(pins[j], (j == i || j == i - 1));
}
wait_ms(100);
}
}