qmk

QMK Firmware
git clone git://git.z3bra.org/qmk.git
Log | Files | Refs | Submodules | LICENSE

keymap.c (14865B)


      1 #include QMK_KEYBOARD_H
      2 #include "drashna.h"
      3 
      4 extern keymap_config_t keymap_config;
      5 extern uint8_t         is_master;
      6 
      7 #ifdef RGBLIGHT_ENABLE
      8 // Following line allows macro to read current RGB settings
      9 extern rgblight_config_t rgblight_config;
     10 #endif
     11 
     12 enum crkbd_keycodes { RGBRST = NEW_SAFE_RANGE };
     13 
     14 // clang-format off
     15 #define LAYOUT_crkbd_base( \
     16     K01, K02, K03, K04, K05, K06, K07, K08, K09, K0A, \
     17     K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, \
     18     K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A  \
     19   ) \
     20   LAYOUT_wrapper( \
     21     KC_ESC,  K01,    K02,     K03,      K04,     K05,                        K06,     K07,     K08,     K09,     K0A,     KC_MINS, \
     22     KC_TAB, ALT_T(K11),  K12, K13,      K14,     K15,                        K16,     K17,     K18,     K19,     K1A,     KC_QUOT, \
     23     OS_LSFT, CTL_T(K21), K22, K23,      K24,     K25,                        K26,     K27,     K28,     K29, RCTL_T(K2A), OS_RSFT, \
     24                                         KC_GRV,  KC_SPC,  BK_LWER, DL_RAIS,  KC_ENT,  OS_RGUI                                      \
     25   )
     26 #define LAYOUT_crkbd_base_wrapper(...)       LAYOUT_crkbd_base(__VA_ARGS__)
     27 
     28 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     29   [_QWERTY] = LAYOUT_crkbd_base_wrapper(
     30     _________________QWERTY_L1_________________, _________________QWERTY_R1_________________,
     31     _________________QWERTY_L2_________________, _________________QWERTY_R2_________________,
     32     _________________QWERTY_L3_________________, _________________QWERTY_R3_________________
     33   ),
     34 
     35   [_COLEMAK] = LAYOUT_crkbd_base_wrapper(
     36     _________________COLEMAK_L1________________, _________________COLEMAK_R1________________,
     37     _________________COLEMAK_L2________________, _________________COLEMAK_R2________________,
     38     _________________COLEMAK_L3________________, _________________COLEMAK_R3________________
     39   ),
     40 
     41   [_DVORAK] = LAYOUT_crkbd_base_wrapper(
     42     _________________DVORAK_L1_________________, _________________DVORAK_R1_________________,
     43     _________________DVORAK_L2_________________, _________________DVORAK_R2_________________,
     44     _________________DVORAK_L3_________________, _________________DVORAK_R3_________________
     45   ),
     46 
     47   [_WORKMAN] = LAYOUT_crkbd_base_wrapper(
     48     _________________WORKMAN_L1________________, _________________WORKMAN_R1________________,
     49     _________________WORKMAN_L2________________, _________________WORKMAN_R2________________,
     50     _________________WORKMAN_L3________________, _________________WORKMAN_R3________________
     51   ),
     52 
     53   [_NORMAN] = LAYOUT_crkbd_base_wrapper(
     54     _________________NORMAN_L1_________________, _________________NORMAN_L1_________________,
     55     _________________NORMAN_L2_________________, _________________NORMAN_R2_________________,
     56     _________________NORMAN_L3_________________, _________________NORMAN_R3_________________
     57   ),
     58 
     59   [_MALTRON] = LAYOUT_crkbd_base_wrapper(
     60     _________________MALTRON_L1________________, _________________MALTRON_R1________________,
     61     _________________MALTRON_L2________________, _________________MALTRON_R2________________,
     62     _________________MALTRON_L3________________, _________________MALTRON_R3________________
     63   ),
     64 
     65   [_EUCALYN] = LAYOUT_crkbd_base_wrapper(
     66     _________________EUCALYN_L1________________, _________________EUCALYN_R1________________,
     67     _________________EUCALYN_L2________________, _________________EUCALYN_R2________________,
     68     _________________EUCALYN_L3________________, _________________EUCALYN_R3________________
     69   ),
     70 
     71   [_CARPLAX] = LAYOUT_crkbd_base_wrapper(
     72     _____________CARPLAX_QFMLWY_L1_____________, _____________CARPLAX_QFMLWY_R1_____________,
     73     _____________CARPLAX_QFMLWY_L2_____________, _____________CARPLAX_QFMLWY_R2_____________,
     74     _____________CARPLAX_QFMLWY_L3_____________, _____________CARPLAX_QFMLWY_R3_____________
     75   ),
     76 
     77   [_MODS] = LAYOUT_wrapper(
     78       _______, ___________________BLANK___________________,                  ___________________BLANK___________________, _______,
     79       _______, ___________________BLANK___________________,                  ___________________BLANK___________________, _______,
     80       KC_LSFT, ___________________BLANK___________________,                  ___________________BLANK___________________, KC_RSFT,
     81                                      _______, _______, _______,        _______, _______, _______
     82   ),
     83 
     84   [_LOWER] = LAYOUT_wrapper(
     85     KC_F11,  _________________LOWER_L1__________________,                    _________________LOWER_R1__________________, KC_F11,
     86     KC_F12,  _________________LOWER_L2__________________,                    _________________LOWER_R2__________________, KC_PIPE,
     87     _______, _________________LOWER_L3__________________,                    _________________LOWER_R3__________________, _______,
     88                                      _______, _______, _______,        _______, _______, _______
     89   ),
     90 
     91   [_RAISE] = LAYOUT_wrapper( \
     92     _______, _________________RAISE_L1__________________,                    _________________RAISE_R1__________________, _______,
     93     _______, _________________RAISE_L2__________________,                    _________________RAISE_R2__________________, KC_BSLS,
     94     _______, _________________RAISE_L3__________________,                    _________________RAISE_R3__________________, _______,
     95                                      _______, _______, _______,        _______, _______, _______
     96   ),
     97 
     98   [_ADJUST] = LAYOUT_wrapper( \
     99     KC_MAKE, _________________ADJUST_L1_________________,                    _________________ADJUST_R1_________________, KC_RESET,
    100     VRSN,    _________________ADJUST_L2_________________,                    _________________ADJUST_R2_________________, EEP_RST,
    101     _______, _________________ADJUST_L3_________________,                    _________________ADJUST_R3_________________, KC_MPLY,
    102                                      _______, KC_NUKE, _______,        _______, TG_MODS, _______
    103   )
    104 };
    105 // clang-format on
    106 
    107 #ifdef OLED_DRIVER_ENABLE
    108 oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_270; }
    109 uint16_t        oled_timer;
    110 
    111 char     keylog_str[5]   = {};
    112 uint8_t  keylogs_str_idx = 0;
    113 uint16_t log_timer       = 0;
    114 
    115 const char code_to_name[60] = {' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\', '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '};
    116 
    117 void add_keylog(uint16_t keycode) {
    118     if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) {
    119         keycode = keycode & 0xFF;
    120     }
    121 
    122     for (uint8_t i = 4; i > 0; i--) {
    123         keylog_str[i] = keylog_str[i - 1];
    124     }
    125     if (keycode < 60) {
    126         keylog_str[0] = code_to_name[keycode];
    127     }
    128     keylog_str[5] = 0;
    129 
    130     log_timer = timer_read();
    131 }
    132 
    133 void update_log(void) {
    134     if (timer_elapsed(log_timer) > 750) {
    135         add_keylog(0);
    136     }
    137 }
    138 
    139 bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
    140     if (record->event.pressed) {
    141         add_keylog(keycode);
    142         oled_timer = timer_read();
    143     }
    144     return true;
    145 }
    146 
    147 void render_rgb_status(void) {
    148     oled_write_ln("RGB:", false);
    149     static char temp[20] = {0};
    150     snprintf(temp, sizeof(temp) + 1, "M:%3dH:%3dS:%3dV:%3d", rgb_matrix_config.mode, rgb_matrix_config.hsv.h, rgb_matrix_config.hsv.s, rgb_matrix_config.hsv.v);
    151     oled_write(temp, false);
    152 }
    153 
    154 void render_status_main(void) {
    155     /* Show Keyboard Layout  */
    156     oled_write("Lyout", false);
    157     switch (biton32(default_layer_state)) {
    158         case _QWERTY:
    159             oled_write(" QRTY", false);
    160             break;
    161         case _COLEMAK:
    162             oled_write(" COLE", false);
    163             break;
    164         case _DVORAK:
    165             oled_write(" DVRK", false);
    166             break;
    167         case _WORKMAN:
    168             oled_write(" WKMN", false);
    169             break;
    170         case _NORMAN:
    171             oled_write(" NORM", false);
    172             break;
    173         case _MALTRON:
    174             oled_write(" MLTN", false);
    175             break;
    176         case _EUCALYN:
    177             oled_write(" ECLN", false);
    178             break;
    179         case _CARPLAX:
    180             oled_write(" CRPX", false);
    181             break;
    182     }
    183 
    184     /* Show Lock Status (only work on master side) */
    185     uint8_t led_usb_state = host_keyboard_leds();
    186     oled_write("Lock:", false);
    187     oled_write(" ", false);
    188     oled_write_ln("NUM", led_usb_state & (1 << USB_LED_NUM_LOCK));
    189     oled_write(" ", false);
    190     oled_write("CAPS", led_usb_state & (1 << USB_LED_CAPS_LOCK));
    191     oled_write(" ", false);
    192     oled_write("SCRL", led_usb_state & (1 << USB_LED_SCROLL_LOCK));
    193 
    194     /* Show Alt-Gui Swap options */
    195     oled_write("BTMGK", false);
    196     oled_write(" ", false);
    197     oled_write_ln("Win", !keymap_config.swap_lalt_lgui);
    198     oled_write(" ", false);
    199     oled_write_ln("Mac", keymap_config.swap_lalt_lgui);
    200 
    201 #    if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
    202     /* Show RGB Options */
    203     render_rgb_status();
    204 #    endif
    205 
    206     oled_write(keylog_str, false);
    207 }
    208 
    209 void render_status_secondary(void) {
    210     /* Show Keyboard Layout  */
    211     oled_write("Lyout", false);
    212     switch (biton32(default_layer_state)) {
    213         case _QWERTY:
    214             oled_write(" QRTY", false);
    215             break;
    216         case _COLEMAK:
    217             oled_write(" COLE", false);
    218             break;
    219         case _DVORAK:
    220             oled_write(" DVRK", false);
    221             break;
    222         case _WORKMAN:
    223             oled_write(" WKMN", false);
    224             break;
    225         case _NORMAN:
    226             oled_write(" NORM", false);
    227             break;
    228         case _MALTRON:
    229             oled_write(" MLTN", false);
    230             break;
    231         case _EUCALYN:
    232             oled_write(" ECLN", false);
    233             break;
    234         case _CARPLAX:
    235             oled_write(" CRPX", false);
    236             break;
    237     }
    238 
    239     /* Show Activate layer */
    240     oled_write("Layer", false);
    241     switch (biton32(layer_state)) {
    242         case _RAISE:
    243             oled_write("Raise", false);
    244             break;
    245         case _LOWER:
    246             oled_write("Lower", false);
    247             break;
    248         case _ADJUST:
    249             oled_write("Adjst", false);
    250             break;
    251         default:
    252             oled_write("Dflt ", false);
    253             break;
    254     }
    255 
    256     /* Show Mod  */
    257     uint8_t modifiers = get_mods() | get_oneshot_mods();
    258 
    259     oled_write("Mods:", false);
    260     oled_write(" ", false);
    261     oled_write_ln("SFT", (modifiers & MOD_MASK_SHIFT));
    262     oled_write(" ", false);
    263     oled_write_ln("CTL", (modifiers & MOD_MASK_CTRL));
    264     oled_write(" ", false);
    265     oled_write_ln("ALT", (modifiers & MOD_MASK_ALT));
    266     oled_write(" ", false);
    267     oled_write_ln("GUI", (modifiers & MOD_MASK_GUI));
    268 
    269 #    if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
    270     render_rgb_status();
    271 #    endif
    272 
    273     /* Show logged Keys */
    274     oled_write(keylog_str, false);
    275 }
    276 
    277 void oled_task_user(void) {
    278     if (timer_elapsed(oled_timer) > 60000) {
    279         oled_off();
    280         return;
    281     }
    282     if (is_master) {
    283         render_status_main();  // Renders the current keyboard state (layer, lock, caps, scroll, etc)
    284     } else {
    285         render_status_secondary();
    286     }
    287 }
    288 
    289 void matrix_scan_keymap(void) { update_log(); }
    290 #endif
    291 
    292 uint16_t get_tapping_term(uint16_t keycode) {
    293     switch (keycode) {
    294         case ALT_T(KC_A):
    295             return TAPPING_TERM + 100;
    296         default:
    297             return TAPPING_TERM;
    298     }
    299 }
    300 
    301 #ifdef RGB_MATRIX_ENABLE
    302 
    303 static bool is_suspended;
    304 static bool rgb_matrix_enabled;
    305 
    306 void suspend_power_down_keymap(void) {
    307     rgb_matrix_set_suspend_state(true);
    308     if (!is_suspended) {
    309         is_suspended = true;
    310         rgb_matrix_enabled = (bool)rgb_matrix_config.enable;
    311         rgb_matrix_disable_noeeprom();
    312     }
    313 }
    314 
    315 void suspend_wakeup_init_keymap(void) {
    316     rgb_matrix_set_suspend_state(false);
    317     is_suspended = false;
    318     if (rgb_matrix_enabled) {
    319         rgb_matrix_enable_noeeprom();
    320     }
    321 }
    322 void rgb_matrix_indicators_user(void) {
    323     if (userspace_config.rgb_layer_change &&
    324 #    ifdef RGB_DISABLE_WHEN_USB_SUSPENDED
    325         !g_suspend_state &&
    326 #    endif
    327 #    if defined(RGBLIGHT_ENABLE)
    328         (!rgblight_config.enable && rgb_matrix_config.enable)
    329 #    else
    330         rgb_matrix_config.enable
    331 #    endif
    332     ) {
    333         switch (biton32(layer_state)) {
    334             case _GAMEPAD:
    335                 rgb_matrix_layer_helper(HSV_ORANGE, 1, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    336                 break;
    337             case _DIABLO:
    338                 rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    339                 break;
    340             case _RAISE:
    341                 rgb_matrix_layer_helper(HSV_YELLOW, 1, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    342                 break;
    343             case _LOWER:
    344                 rgb_matrix_layer_helper(HSV_GREEN, 1, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    345                 break;
    346             case _ADJUST:
    347                 rgb_matrix_layer_helper(HSV_RED, 1, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    348                 break;
    349             default: {
    350                 bool mods_enabled = IS_LAYER_ON(_MODS);
    351                 switch (biton32(default_layer_state)) {
    352                     case _QWERTY:
    353                         rgb_matrix_layer_helper(HSV_CYAN, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    354                         break;
    355                     case _COLEMAK:
    356                         rgb_matrix_layer_helper(HSV_MAGENTA, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    357                         break;
    358                     case _DVORAK:
    359                         rgb_matrix_layer_helper(HSV_SPRINGGREEN, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    360                         break;
    361                     case _WORKMAN:
    362                         rgb_matrix_layer_helper(HSV_GOLDENROD, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    363                         break;
    364                     case _NORMAN:
    365                         rgb_matrix_layer_helper(HSV_CORAL, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    366                         break;
    367                     case _MALTRON:
    368                         rgb_matrix_layer_helper(HSV_YELLOW, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    369                         break;
    370                     case _EUCALYN:
    371                         rgb_matrix_layer_helper(HSV_PINK, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    372                         break;
    373                     case _CARPLAX:
    374                         rgb_matrix_layer_helper(HSV_BLUE, mods_enabled, rgb_matrix_config.speed, LED_FLAG_UNDERGLOW);
    375                         break;
    376                 }
    377                 break;
    378             }
    379         }
    380     }
    381 }
    382 #endif