ctrl-kbd-annabunches/keymap.c

403 lines
18 KiB
C
Raw Normal View History

2023-09-16 02:25:25 +00:00
#include QMK_KEYBOARD_H
enum ctrl_keycodes {
U_T_AUTO = SAFE_RANGE, //USB Extra Port Toggle Auto Detect / Always Active
U_T_AGCR, //USB Toggle Automatic GCR control
DBG_MTRX, //DEBUG Toggle Matrix Prints
DBG_KBD, //DEBUG Toggle Keyboard Prints
DBG_MOU, //DEBUG Toggle Mouse Prints
MD_BOOT, //Restart into bootloader after hold timeout
AB_TYPE,
AB_FFXIV,
AB_GENSHIN,
AB_IDLE,
AB_DIM,
AB_KSP,
// TODO: delete if we ever figure out unicode support
AB_ROSE,
AB_MUSHROOM,
AB_CRAB,
2023-09-16 02:25:25 +00:00
};
enum tapdance_codes {
TD_TRIPLE_COMPOSE,
TD_TRIPLE_META,
};
enum layer_codes {
_LAYER_DEFAULT,
_LAYER_QWERTY,
_LAYER_PROTECT,
_LAYER_FUNCTION,
};
// FIXME: These should be used with UM() for unicode input, but it doesn't seem to work...
/* enum unicode_names { */
/* AB_MUSHROOM, */
/* AB_ROSE, */
/* }; */
/* const uint32_t PROGMEM unicode_map[] = { */
/* [AB_MUSHROOM] = 0x1f344, // <20><> */
/* [AB_ROSE] = 0x1f339, // <20><> */
/* }; */
keymap_config_t keymap_config;
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_LAYER_DEFAULT] = LAYOUT(
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_SCRL, KC_PAUS, \
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_LBRC, KC_RBRC, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, \
KC_TAB, KC_QUOT, KC_COMM, KC_DOT, KC_P, KC_Y, KC_F, KC_G, KC_C, KC_R, KC_L, KC_SLSH, KC_EQL, KC_BSLS, KC_DEL, KC_END, KC_PGDN, \
KC_F14, KC_A, KC_O, KC_E, KC_U, KC_I, KC_D, KC_H, KC_T, KC_N, KC_S, KC_MINS, KC_ENT, \
KC_LSFT, KC_SCLN, KC_Q, KC_J, KC_K, KC_X, KC_B, KC_M, KC_W, KC_V, KC_Z, KC_RSFT, KC_UP, \
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_LALT, MO(_LAYER_FUNCTION), KC_APP, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT \
),
[_LAYER_QWERTY] = LAYOUT(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MINS, KC_EQL, _______, _______, _______, _______, \
_______, 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_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, _______, \
_______, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, _______, _______, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
),
// protection mask - triple-tap protection for caps and windows button
[_LAYER_PROTECT] = LAYOUT(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
TD(TD_TRIPLE_COMPOSE), _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
_______, TD(TD_TRIPLE_META), _______, _______, _______, _______, _______, _______, _______, _______, _______ \
),
[_LAYER_FUNCTION] = LAYOUT(
TG(_LAYER_QWERTY), _______, _______, _______, _______, _______, _______, _______, _______, UC_WINC, UC_LINX, _______, DB_TOGG, _______, KC_MUTE, _______, \
_______, AB_TYPE, AB_DIM, AB_FFXIV, AB_KSP, AB_IDLE, _______, _______, _______, _______, _______, _______, _______, _______, KC_MPLY, KC_MSTP, KC_VOLU, \
_______, RGB_SPD, RGB_VAI, RGB_SPI, RGB_HUI, RGB_SAI, _______, U_T_AUTO, U_T_AGCR, AB_ROSE, _______, _______, _______, _______, KC_MPRV, KC_MNXT, KC_VOLD, \
KC_CAPS, AB_MUSHROOM, AB_ROSE, AB_CRAB, RGB_HUD, RGB_SAD, RGB_RMOD, _______, _______, _______, _______, _______, _______, \
_______, RGB_TOG, RGB_VAD, RGB_MOD, _______, MD_BOOT, NK_TOGG, _______, _______, _______, _______, _______, _______, \
2023-09-16 02:25:25 +00:00
_______, TG(_LAYER_PROTECT), _______, _______, _______, _______, _______, _______, _______, _______, _______ \
),
/*
[X] = LAYOUT(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \
_______, _______, _______, _______, _______, _______, NK_TOGG, _______, _______, _______, _______, _______, _______, \
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______ \
),
*/
};
// TAP DANCE FUNCTIONS
void triple_protect_meta(tap_dance_state_t *state, void *user_data) {
if (state->count >= 3) {
register_code(KC_LGUI);
}
}
void triple_protect_meta_reset(tap_dance_state_t *state, void *user_data) {
unregister_code(KC_LGUI);
}
void triple_protect_compose(tap_dance_state_t *state, void *user_data) {
if (state->count >= 3) {
register_code(KC_F14);
}
}
void triple_protect_compose_reset(tap_dance_state_t *state, void *user_data) {
unregister_code(KC_F14);
}
tap_dance_action_t tap_dance_actions[] = {
[TD_TRIPLE_META] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, triple_protect_meta, triple_protect_meta_reset),
[TD_TRIPLE_COMPOSE] = ACTION_TAP_DANCE_FN_ADVANCED(NULL, triple_protect_compose, triple_protect_compose_reset),
};
// END TAP DANCE FUNCTIONS
// Runs constantly in the background, in a loop.
void matrix_scan_user(void) {
};
#define MODS_SHIFT (get_mods() & MOD_MASK_SHIFT)
#define MODS_CTRL (get_mods() & MOD_MASK_CTRL)
#define MODS_ALT (get_mods() & MOD_MASK_ALT)
// CUSTOM RGB LIGHTING CODE
led_t local_led_state;
bool led_update_user(led_t led_state) {
local_led_state = led_state;
return false;
}
#define RGB_DIM 0x55, 0x55, 0x55
#define HSV_DIM 0, 0, 0x55
enum annabunches_mode{
ANNABUNCHES_NONE,
ANNABUNCHES_TYPE,
ANNABUNCHES_FFXIV,
ANNABUNCHES_KSP,
ANNABUNCHES_GENSHIN,
ANNABUNCHES_DIM,
ANNABUNCHES_IDLE
};
enum annabunches_mode custom_mode = 0;
enum color_map_codes {
_COLOR_FFXIV,
_COLOR_KSP,
_COLOR_GENSHIN,
};
const uint8_t PROGMEM color_map[][119][3] = {
[_COLOR_FFXIV] = {
{RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_BLUE}, {RGB_BLUE}, {RGB_BLUE}, {RGB_BLUE}, {RGB_BLUE}, {RGB_BLUE}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_BLUE}, {RGB_PURPLE}, {RGB_BLUE}, {RGB_BLUE}, {RGB_BLUE}, {RGB_DIM}, {RGB_DIM}, {RGB_GREEN}, {RGB_GREEN}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_PURPLE}, {RGB_PURPLE}, {RGB_PURPLE}, {RGB_BLUE}, {RGB_YELLOW}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_BLUE}, {RGB_BLUE}, {RGB_BLUE}, {RGB_BLUE}, {RGB_BLUE}, {RGB_YELLOW}, {RGB_RED}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}
},
[_COLOR_KSP] = {
{RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_PURPLE}, {RGB_PURPLE}, {RGB_PURPLE}, {RGB_RED}, {RGB_RED}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_GREEN}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_PURPLE}, {RGB_PURPLE}, {RGB_PURPLE}, {RGB_DIM}, {RGB_GREEN}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_RED}, {RGB_RED}, {RGB_RED}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_GREEN}, {RGB_YELLOW}, {RGB_YELLOW}, {RGB_YELLOW}, {RGB_DIM}, {RGB_DIM},
{RGB_RED}, {RGB_DIM}, {RGB_DIM}, {RGB_RED}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}
},
[_COLOR_GENSHIN] = {
{RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_GREEN}, {RGB_GREEN}, {RGB_GREEN}, {RGB_GREEN}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_BLUE}, {RGB_PURPLE}, {RGB_BLUE}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_PURPLE}, {RGB_PURPLE}, {RGB_PURPLE}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_YELLOW}, {RGB_DIM}, {RGB_YELLOW}, {RGB_DIM}, {RGB_RED}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM},
{RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}, {RGB_DIM}
}
};
uint8_t PROGMEM rainbow_ring[][3] = {{RGB_RED}, {RGB_ORANGE}, {RGB_YELLOW}, {RGB_GREEN}, {RGB_BLUE}, {RGB_PURPLE}, {RGB_MAGENTA}};
uint8_t rainbow_ring_size = 7;
uint8_t PROGMEM bisexual_ring[][3] = {{RGB_PURPLE}, {RGB_BLUE}, {RGB_MAGENTA}};
uint8_t bisexual_ring_size = 3;
// set the under-keyboard LED ring to use alternating color pattern
void set_led_ring(uint8_t colors[][3], uint8_t num_colors) {
for (int i = 87; i < 119; i++) {
rgb_matrix_set_color(i, colors[i%num_colors][0], colors[i%num_colors][1], colors[i%num_colors][2]);
}
}
bool rgb_matrix_indicators_user() {
switch (custom_mode) {
case ANNABUNCHES_FFXIV:
for (int i = 0; i < 87; i++) {
rgb_matrix_set_color(i, color_map[_COLOR_FFXIV][i][0], color_map[_COLOR_FFXIV][i][1], color_map[_COLOR_FFXIV][i][2]);
}
set_led_ring(rainbow_ring, rainbow_ring_size);
break;
case ANNABUNCHES_KSP:
for (int i = 0; i < 87; i++) {
rgb_matrix_set_color(i, color_map[_COLOR_KSP][i][0], color_map[_COLOR_KSP][i][1], color_map[_COLOR_KSP][i][2]);
}
set_led_ring(bisexual_ring, bisexual_ring_size);
break;
case ANNABUNCHES_GENSHIN:
for (int i = 0; i < 87; i++) {
rgb_matrix_set_color(i, color_map[_COLOR_GENSHIN][i][0], color_map[_COLOR_GENSHIN][i][1], color_map[_COLOR_GENSHIN][i][2]);
}
set_led_ring(bisexual_ring, bisexual_ring_size);
break;
case ANNABUNCHES_TYPE:
case ANNABUNCHES_IDLE:
case ANNABUNCHES_DIM:
case ANNABUNCHES_NONE:
default:
break;
}
if (IS_LAYER_ON(_LAYER_PROTECT)) {
rgb_matrix_set_color(77, RGB_WHITE);
}
if (IS_LAYER_ON(_LAYER_QWERTY)) {
rgb_matrix_set_color(0, RGB_RED);
}
if (local_led_state.caps_lock) {
rgb_matrix_set_color(50, RGB_WHITE);
}
if (local_led_state.scroll_lock) {
rgb_matrix_set_color(14, RGB_WHITE);
}
return true; // TODO: if colors get wonky, change this!
}
void annabunches_mode_init(void) {
#ifndef RGB_MATRIX_MODE
rgb_matrix_enable_noeeprom();
#endif
rgb_matrix_set_color_all(0, 0, 0);
custom_mode = ANNABUNCHES_NONE;
layer_off(_LAYER_PROTECT);
layer_off(_LAYER_QWERTY);
}
void annabunches_mode_type(void) {
annabunches_mode_init();
rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE);
rgb_matrix_set_speed_noeeprom(32);
rgb_matrix_sethsv_noeeprom(HSV_PINK);
custom_mode = ANNABUNCHES_TYPE;
}
void annabunches_mode_dim(void) {
annabunches_mode_init();
rgb_matrix_mode_noeeprom(RGB_MATRIX_SOLID_COLOR);
rgb_matrix_sethsv_noeeprom(HSV_DIM);
custom_mode = ANNABUNCHES_DIM;
}
void annabunches_mode_ffxiv(void) {
annabunches_mode_init();
layer_on(_LAYER_PROTECT);
rgb_matrix_mode_noeeprom(RGB_MATRIX_NONE);
custom_mode = ANNABUNCHES_FFXIV;
}
void annabunches_mode_ksp(void) {
annabunches_mode_init();
rgb_matrix_mode_noeeprom(RGB_MATRIX_NONE);
custom_mode = ANNABUNCHES_KSP;
}
void annabunches_mode_genshin(void) {
annabunches_mode_init();
layer_on(_LAYER_PROTECT);
layer_on(_LAYER_QWERTY);
rgb_matrix_mode_noeeprom(RGB_MATRIX_NONE);
custom_mode = ANNABUNCHES_GENSHIN;
}
void annabunches_mode_idle(void) {
annabunches_mode_init();
rgb_matrix_mode_noeeprom(RGB_MATRIX_JELLYBEAN_RAINDROPS);
custom_mode = ANNABUNCHES_IDLE;
}
// END CUSTOM RGB LIGHTING CODE
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
static uint32_t key_timer;
switch (keycode) {
case U_T_AUTO:
if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
TOGGLE_FLAG_AND_PRINT(usb_extra_manual, "USB extra port manual mode");
}
return false;
case U_T_AGCR:
if (record->event.pressed && MODS_SHIFT && MODS_CTRL) {
TOGGLE_FLAG_AND_PRINT(usb_gcr_auto, "USB GCR auto mode");
}
return false;
case DBG_MTRX:
if (record->event.pressed) {
TOGGLE_FLAG_AND_PRINT(debug_matrix, "Debug matrix");
}
return false;
case DBG_KBD:
if (record->event.pressed) {
TOGGLE_FLAG_AND_PRINT(debug_keyboard, "Debug keyboard");
}
return false;
case DBG_MOU:
if (record->event.pressed) {
TOGGLE_FLAG_AND_PRINT(debug_mouse, "Debug mouse");
}
return false;
case MD_BOOT:
if (record->event.pressed) {
key_timer = timer_read32();
} else {
if (timer_elapsed32(key_timer) >= 500) {
reset_keyboard();
}
}
return false;
case RGB_TOG:
if (record->event.pressed) {
switch (rgb_matrix_get_flags()) {
case LED_FLAG_ALL: {
rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER);
rgb_matrix_set_color_all(0, 0, 0);
}
break;
case LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER: {
rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
rgb_matrix_set_color_all(0, 0, 0);
}
break;
case LED_FLAG_UNDERGLOW: {
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_disable_noeeprom();
}
break;
default: {
rgb_matrix_set_flags(LED_FLAG_ALL);
rgb_matrix_enable_noeeprom();
}
break;
}
}
return false;
case AB_TYPE:
if (record->event.pressed) annabunches_mode_type();
return false;
case AB_FFXIV:
if (record->event.pressed) annabunches_mode_ffxiv();
return false;
case AB_KSP:
if (record->event.pressed) annabunches_mode_ksp();
return false;
case AB_GENSHIN:
if (record->event.pressed) annabunches_mode_genshin();
return false;
case AB_DIM:
if (record->event.pressed) annabunches_mode_dim();
return false;
case AB_IDLE:
if (record->event.pressed) annabunches_mode_idle();
return false;
case AB_MUSHROOM:
layer_off(_LAYER_QWERTY);
2023-09-16 02:25:25 +00:00
if (record->event.pressed) SEND_STRING(SS_TAP(X_F14)"u1f344"SS_TAP(X_ENT));
return false;
case AB_ROSE:
layer_off(_LAYER_QWERTY);
2023-09-16 02:25:25 +00:00
if (record->event.pressed) SEND_STRING(SS_TAP(X_F14)"u1f339"SS_TAP(X_ENT));
return false;
case AB_CRAB:
layer_on(_LAYER_QWERTY);
if (record->event.pressed) SEND_STRING(SS_TAP(X_F14)"u1f980"SS_TAP(X_ENT));
return false;
2023-09-16 02:25:25 +00:00
default:
return true; //Process all other keycodes normally
}
}
// Runs just one time when the keyboard initializes.
void matrix_init_user(void) {
annabunches_mode_idle();
};
void keyboard_post_init_user(void) {
debug_keyboard=true;
}