qmk

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

keymap.c (6486B)


      1 #include QMK_KEYBOARD_H
      2 #ifdef AUDIO_ENABLE
      3   #include "audio.h"
      4 #endif
      5 
      6 extern keymap_config_t keymap_config;
      7 
      8 //Tap Dance Declarations
      9 enum {
     10   TD_Z_LCTL = 0,
     11   TD_X_LGUI = 1,
     12   TD_C_LALT = 2,
     13   TD_A_TAB = 3,
     14   TD_Q_ESC = 4,
     15 };
     16 
     17 //Friendly Layer Names
     18 enum gherkin_layers {
     19   _QWERTY,
     20   _SONGS,
     21   _NUMBERS,
     22   _SYMBOLS,
     23   _PLOVER,
     24   _ADJUST
     25 };
     26 
     27 // custom keycodes
     28 enum gherkin_keycodes {
     29   QWERTY = SAFE_RANGE,
     30   NUMBERS,
     31   SYMBOLS,
     32   SONGS,
     33   PLOVER,
     34   BACKLIT,
     35   MACSLEEP,
     36   EXT_PLV
     37 };
     38 
     39 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     40   [_QWERTY] = LAYOUT_ortho_3x10(
     41     TD(TD_Q_ESC),   KC_W,               KC_E,           KC_R,  KC_T,               KC_Y,   KC_U,  KC_I,     KC_O,    KC_P,
     42     TD(TD_A_TAB),   LT(_SYMBOLS,KC_S),  KC_D,           KC_F,  KC_G,               KC_H,   KC_J,  KC_K,     KC_L,    LT(_ADJUST,KC_SPC),
     43     TD(TD_Z_LCTL),  TD(TD_X_LGUI),      TD(TD_C_LALT),  KC_V,  KC_B,  LT(_NUMBERS, KC_N),  KC_M,  KC_COMM,  KC_DOT,  SFT_T(KC_ENT)
     44   ),
     45   [_NUMBERS] = LAYOUT_ortho_3x10(
     46     KC_1,   KC_2,   KC_3,   KC_4,    KC_5,                KC_6,     KC_7,     KC_8,     KC_9,     KC_0,
     47     KC_F1,  KC_F2,  KC_F3,  KC_F4,   KC_F5,               KC_F6,    KC_HOME,  KC_PGDN,  KC_PGUP,  KC_END ,
     48     KC_F7,  KC_F8,  KC_F9,  KC_F10,  LT(_ADJUST,KC_F11),  _______,  KC_LEFT,  KC_DOWN,  KC_UP,    KC_RIGHT
     49   ),
     50   [_SYMBOLS] = LAYOUT_ortho_3x10(
     51     KC_EXLM,  KC_AT,        KC_HASH,  KC_DLR,   KC_PERC,  KC_CIRC,  KC_AMPR,  KC_ASTR,  KC_LPRN,     KC_RPRN,
     52     KC_GRV,   _______,      XXXXXXX,  KC_LBRC,  KC_RBRC,  KC_BSLS,  KC_MINS,  KC_EQL ,  KC_SCLN,     KC_QUOT,
     53     KC_TILD,  MO(_ADJUST),  XXXXXXX,  KC_LCBR,  KC_RCBR,  KC_PIPE,  KC_UNDS,  KC_PLUS,  S(KC_SCLN),  S(KC_QUOT)
     54   ),
     55   [_PLOVER] = LAYOUT_ortho_3x10(
     56     KC_Q,     KC_W,     KC_E,  KC_R,  KC_1,     KC_U,  KC_I,  KC_O,     KC_P,     KC_LBRC,
     57     KC_A,     KC_S,     KC_D,  KC_F,  KC_G,     KC_J,  KC_K,  KC_L,     KC_SCLN,  KC_QUOT,
     58     EXT_PLV,  XXXXXXX,  KC_C,  KC_V,  XXXXXXX,  KC_N,  KC_M,  XXXXXXX,  XXXXXXX,  XXXXXXX
     59   ),
     60   [_ADJUST] = LAYOUT_ortho_3x10(
     61     RESET,    _______,  _______,  _______,  _______,  QWERTY,   NUMBERS,  SYMBOLS,  PLOVER,    SONGS,
     62     MUV_DE,   MUV_IN,   MU_ON,    MU_OFF,   _______,  _______,  _______,  _______,  MACSLEEP,  _______,
     63     BACKLIT,  _______,  _______,  _______,  _______,  _______,  _______,  _______,  _______,   _______
     64   )
     65 };
     66 
     67 #ifdef AUDIO_ENABLE
     68 
     69 float tone_startup[][2]    = SONG(STARTUP_SOUND);
     70 float tone_qwerty[][2]     = SONG(QWERTY_SOUND);
     71 float tone_dvorak[][2]     = SONG(DVORAK_SOUND);
     72 float tone_colemak[][2]    = SONG(COLEMAK_SOUND);
     73 float tone_plover[][2]     = SONG(PLOVER_SOUND);
     74 float tone_plover_gb[][2]  = SONG(PLOVER_GOODBYE_SOUND);
     75 float music_scale[][2]     = SONG(MUSIC_SCALE_SOUND);
     76 
     77 float tone_goodbye[][2] = SONG(GOODBYE_SOUND);
     78 #endif
     79 
     80 void persistant_default_layer_set(uint16_t default_layer) {
     81   eeconfig_update_default_layer(default_layer);
     82   default_layer_set(default_layer);
     83 }
     84 
     85 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
     86   switch (keycode) {
     87     case QWERTY:
     88       if (record->event.pressed) {
     89         #ifdef AUDIO_ENABLE
     90           PLAY_SONG(tone_qwerty);
     91         #endif
     92         persistant_default_layer_set(1UL<<_QWERTY);
     93       }
     94       return false;
     95       break;
     96     case NUMBERS:
     97       if (record->event.pressed) {
     98         #ifdef AUDIO_ENABLE
     99           PLAY_SONG(tone_dvorak);
    100         #endif
    101         persistant_default_layer_set(1UL<<_NUMBERS);
    102       }
    103       return false;
    104       break;
    105     case SYMBOLS:
    106       if (record->event.pressed) {
    107         #ifdef AUDIO_ENABLE
    108           PLAY_SONG(tone_colemak);
    109         #endif
    110         persistant_default_layer_set(1UL<<_SYMBOLS);
    111       }
    112       return false;
    113       break;
    114     case PLOVER:
    115       if (record->event.pressed) {
    116         #ifdef AUDIO_ENABLE
    117           stop_all_notes();
    118           PLAY_SONG(tone_plover);
    119         #endif
    120         layer_off(_NUMBERS);
    121         layer_off(_SYMBOLS);
    122         layer_off(_ADJUST);
    123         layer_on(_PLOVER);
    124         if (!eeconfig_is_enabled()) {
    125             eeconfig_init();
    126         }
    127         keymap_config.raw = eeconfig_read_keymap();
    128         keymap_config.nkro = 1;
    129         eeconfig_update_keymap(keymap_config.raw);
    130       }
    131       return false;
    132       break;
    133     case EXT_PLV:
    134       if (record->event.pressed) {
    135         #ifdef AUDIO_ENABLE
    136           PLAY_SONG(tone_plover_gb);
    137         #endif
    138         layer_off(_PLOVER);
    139       }
    140       return false;
    141       break;
    142     case MACSLEEP:
    143       if (record->event.pressed) {
    144           // ACTION_MODS_KEY(MOD_LCTL | MOD_LSFT, KC_POWER);
    145           register_code(KC_RSFT);
    146           register_code(KC_RCTL);
    147           register_code(KC_POWER);
    148           unregister_code(KC_POWER);
    149           unregister_code(KC_RCTL);
    150           unregister_code(KC_RSFT);
    151       }
    152       return false;
    153       break;
    154     case BACKLIT:
    155       if (record->event.pressed) {
    156         register_code(KC_RSFT);
    157         #ifdef BACKLIGHT_ENABLE
    158           backlight_step();
    159         #endif
    160       } else {
    161         unregister_code(KC_RSFT);
    162       }
    163       return false;
    164       break;
    165     }
    166     return true;
    167 }
    168 
    169 void matrix_init_user(void) {
    170     #ifdef AUDIO_ENABLE
    171         startup_user();
    172     #endif
    173 }
    174 
    175 #ifdef AUDIO_ENABLE
    176 
    177 void startup_user()
    178 {
    179     _delay_ms(20); // gets rid of tick
    180     PLAY_SONG(tone_startup);
    181 }
    182 
    183 void shutdown_user()
    184 {
    185     PLAY_SONG(tone_goodbye);
    186     _delay_ms(150);
    187     stop_all_notes();
    188 }
    189 
    190 void music_on_user(void)
    191 {
    192     music_scale_user();
    193 }
    194 
    195 void music_scale_user(void)
    196 {
    197     PLAY_SONG(music_scale);
    198 }
    199 
    200 #endif
    201 
    202 void matrix_scan_user(void) {
    203 }
    204 
    205 //Tap Dance Definitions
    206 qk_tap_dance_action_t tap_dance_actions[] = {
    207   //Tap once for Esc, twice for Caps Lock
    208   [TD_Z_LCTL]  = ACTION_TAP_DANCE_DOUBLE(KC_Z, KC_LCTL),
    209   [TD_X_LGUI]  = ACTION_TAP_DANCE_DOUBLE(KC_X, KC_LGUI),
    210   [TD_C_LALT]  = ACTION_TAP_DANCE_DOUBLE(KC_C, KC_LALT),
    211   [TD_A_TAB]  = ACTION_TAP_DANCE_DOUBLE(KC_A, KC_TAB),
    212   [TD_Q_ESC]  = ACTION_TAP_DANCE_DOUBLE(KC_Q, KC_ESC)
    213 };
    214 
    215 // don't know what this is doing...
    216 /*
    217 void led_set_user(uint8_t usb_led) {
    218 
    219   if (usb_led & (1 << USB_LED_NUM_LOCK)) {
    220     DDRD |= (1 << 5); PORTD &= ~(1 << 5);
    221   } else {
    222     DDRD &= ~(1 << 5); PORTD &= ~(1 << 5);
    223   }
    224 
    225   if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
    226     DDRB |= (1 << 0); PORTB &= ~(1 << 0);
    227   } else {
    228     DDRB &= ~(1 << 0); PORTB &= ~(1 << 0);
    229   }
    230 
    231   if (usb_led & (1 << USB_LED_SCROLL_LOCK)) {
    232 
    233   } else {
    234 
    235   }
    236 
    237   if (usb_led & (1 << USB_LED_COMPOSE)) {
    238 
    239   } else {
    240 
    241   }
    242 
    243   if (usb_led & (1 << USB_LED_KANA)) {
    244 
    245   } else {
    246 
    247   }
    248 
    249 }
    250 */