qmk

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

keymap.c (11437B)


      1 #include QMK_KEYBOARD_H
      2 
      3 #ifdef PROTOCOL_LUFA
      4   #include "lufa.h"
      5   #include "split_util.h"
      6 #endif
      7 #ifdef SSD1306OLED
      8   #include "ssd1306.h"
      9 #endif
     10 
     11 
     12 extern keymap_config_t keymap_config;
     13 
     14 #ifdef RGBLIGHT_ENABLE
     15 //Following line allows macro to read current RGB settings
     16 extern rgblight_config_t rgblight_config;
     17 #endif
     18 
     19 extern uint8_t is_master;
     20 
     21 #define _QWERTY 0
     22 #define _LOWER 1
     23 #define _RAISE 2
     24 #define _ADJUST 16
     25 
     26 enum custom_keycodes {
     27   QWERTY = SAFE_RANGE,
     28   LOWER,
     29   RAISE,
     30   ADJUST,
     31 };
     32 
     33 
     34 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     35 
     36 /* QWERTY
     37  * ,-----------------------------------------.                    ,-----------------------------------------.
     38  * | ESC  |   1  |   2  |   3  |   4  |   5  |                    |   6  |   7  |   8  |   9  |   0  |  ~   |
     39  * |------+------+------+------+------+------|                    |------+------+------+------+------+------|
     40  * | Tab  |   Q  |   W  |   E  |   R  |   T  |                    |   Y  |   U  |   I  |   O  |   P  |  -   |
     41  * |------+------+------+------+------+------|                    |------+------+------+------+------+------|
     42  * |LCTRL |   A  |   S  |   D  |   F  |   G  |-------.    ,-------|   H  |   J  |   K  |   L  |   ;  |  '   |
     43  * |------+------+------+------+------+------|   [   |    |    ]  |------+------+------+------+------+------|
     44  * |LShift|   Z  |   X  |   C  |   V  |   B  |-------|    |-------|   N  |   M  |   ,  |   .  |   /  |RShift|
     45  * `-----------------------------------------/       /     \      \-----------------------------------------'
     46  *                   |LOWER | LGUI | Alt  | /Space  /       \Enter \  |BackSP| RGUI |RAISE |
     47  *                   |      |      |      |/       /         \      \ |      |      |      |
     48  *                   `-------------------''-------'           '------''--------------------'
     49  */
     50 
     51  [_QWERTY] = LAYOUT( \
     52   KC_ESC,   KC_1,   KC_2,    KC_3,    KC_4,    KC_5,                     KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    KC_GRV, \
     53   KC_TAB,   KC_Q,   KC_W,    KC_E,    KC_R,    KC_T,                     KC_Y,    KC_U,    KC_I,    KC_O,    KC_P,    KC_MINS, \
     54   KC_LCTRL, KC_A,   KC_S,    KC_D,    KC_F,    KC_G,                     KC_H,    KC_J,    KC_K,    KC_L,    KC_SCLN, KC_QUOT, \
     55   KC_LSFT,  KC_Z,   KC_X,    KC_C,    KC_V,    KC_B, KC_LBRC,  KC_RBRC,  KC_N,    KC_M,    KC_COMM, KC_DOT,  KC_SLSH,  KC_RSFT, \
     56                              LOWER,KC_LGUI, KC_LALT, KC_SPC,   KC_ENT,  KC_BSPC, KC_RGUI, RAISE \
     57 ),
     58 /* LOWER
     59  * ,-----------------------------------------.                    ,-----------------------------------------.
     60  * |      |      |      |      |      |      |                    |      |      |      |      |      |      |
     61  * |------+------+------+------+------+------|                    |------+------+------+------+------+------|
     62  * |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |                    |  F7  |  F8  |  F9  | F10  | F11  | F12  |
     63  * |------+------+------+------+------+------|                    |------+------+------+------+------+------|
     64  * |   ~  |   !  |   @  |   #  |   $  |   %  |-------.    ,-------|   ^  |   &  |   *  |   (  |   )  |   -  |
     65  * |------+------+------+------+------+------|   [   |    |    ]  |------+------+------+------+------+------|
     66  * |      |      |      |      |      |      |-------|    |-------|      |   _  |   +  |   {  |   }  |   |  |
     67  * `-----------------------------------------/       /     \      \-----------------------------------------'
     68  *                   |LOWER | LGUI | Alt  | /Space  /       \Enter \  |BackSP| RGUI |RAISE |
     69  *                   |      |      |      |/       /         \      \ |      |      |      |
     70  *                   `-------------------''-------'           '------''--------------------'
     71  */
     72 [_LOWER] = LAYOUT( \
     73   _______, _______, _______, _______, _______, _______,                   _______, _______, _______,_______, _______, _______,\
     74   KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,                     KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12, \
     75   _______, KC_EXLM, KC_AT,   KC_HASH, KC_DLR,  KC_PERC,                   KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_TILD, \
     76   _______, _______, _______, _______, _______, _______, _______, _______, XXXXXXX, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, KC_PIPE, \
     77                              _______, _______, _______, _______, _______,  _______, _______, _______\
     78 ),
     79 /* RAISE
     80  * ,-----------------------------------------.                    ,-----------------------------------------.
     81  * |      |      |      |      |      |      |                    |      |      |      |      |      |      |
     82  * |------+------+------+------+------+------|                    |------+------+------+------+------+------|
     83  * |   `  |   1  |   2  |   3  |   4  |   5  |                    |   6  |   7  |   8  |   9  |   0  |      |
     84  * |------+------+------+------+------+------|                    |------+------+------+------+------+------|
     85  * |  F1  |  F2  |  F3  |  F4  |  F5  |  F6  |-------.    ,-------|      | Left | Down |  Up  |Right |      |
     86  * |------+------+------+------+------+------|   [   |    |    ]  |------+------+------+------+------+------|
     87  * |  F7  |  F8  |  F9  | F10  | F11  | F12  |-------|    |-------|   +  |   -  |   =  |   [  |   ]  |   \  |
     88  * `-----------------------------------------/       /     \      \-----------------------------------------'
     89  *                   |LOWER | LGUI | Alt  | /Space  /       \Enter \  |BackSP| RGUI |RAISE |
     90  *                   |      |      |      |/       /         \      \ |      |      |      |
     91  *                   `-------------------''-------'           '------''--------------------'
     92  */
     93 
     94 [_RAISE] = LAYOUT( \
     95   _______, _______, _______, _______, _______, _______,                     _______, _______, _______, _______, _______, _______, \
     96   KC_GRV,  KC_1,    KC_2,    KC_3,    KC_4,    KC_5,                        KC_6,    KC_7,    KC_8,    KC_9,    KC_0,    _______, \
     97   KC_F1,  KC_F2,    KC_F3,   KC_F4,   KC_F5,   KC_F6,                       XXXXXXX, KC_LEFT, KC_DOWN, KC_UP,   KC_RGHT, XXXXXXX, \
     98   KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,   _______, _______,  KC_PLUS, KC_MINS, KC_EQL,  KC_LBRC, KC_RBRC, KC_BSLS, \
     99                              _______, _______, _______,  _______, _______,  _______, _______, _______ \
    100 ),
    101 
    102 /* ADJUST
    103  * ,-----------------------------------------.                    ,-----------------------------------------.
    104  * |      |      |      |      |      |      |                    |      |      |      |      |      |      |
    105  * |------+------+------+------+------+------|                    |------+------+------+------+------+------|
    106  * |      |      |      |      |      |      |                    |      |      |      |      |      |      |
    107  * |------+------+------+------+------+------|                    |------+------+------+------+------+------|
    108  * |      |      |      |      |      |      |-------.    ,-------|      |      |RGB ON| HUE+ | SAT+ | VAL+ |
    109  * |------+------+------+------+------+------|       |    |       |------+------+------+------+------+------|
    110  * |      |      |      |      |      |      |-------|    |-------|      |      | MODE | HUE- | SAT- | VAL- |
    111  * `-----------------------------------------/       /     \      \-----------------------------------------'
    112  *                   |LOWER | LGUI | Alt  | /Space  /       \Enter \  |BackSP| RGUI |RAISE |
    113  *                   |      |      |      |/       /         \      \ |      |      |      |
    114  *                   `----------------------------'           '------''--------------------'
    115  */ 
    116   [_ADJUST] = LAYOUT( \
    117   XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,                   XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
    118   XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,                   XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, \
    119   XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX,                   XXXXXXX, XXXXXXX, RGB_TOG, RGB_HUI, RGB_SAI, RGB_VAI, \
    120   XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, XXXXXXX, RGB_MOD, RGB_HUD, RGB_SAD, RGB_VAD,\
    121                              _______, _______, _______, _______, _______,  _______, _______, _______ \
    122   )
    123 };
    124 
    125 int RGB_current_mode;
    126 
    127 // Setting ADJUST layer RGB back to default
    128 void update_tri_layer_RGB(uint8_t layer1, uint8_t layer2, uint8_t layer3) {
    129   if (IS_LAYER_ON(layer1) && IS_LAYER_ON(layer2)) {
    130     layer_on(layer3);
    131   } else {
    132     layer_off(layer3);
    133   }
    134 }
    135 
    136 void matrix_init_user(void) {
    137     #ifdef RGBLIGHT_ENABLE
    138       RGB_current_mode = rgblight_config.mode;
    139     #endif
    140     //SSD1306 OLED init, make sure to add #define SSD1306OLED in config.h
    141     #ifdef SSD1306OLED
    142         iota_gfx_init(!has_usb());   // turns on the display
    143     #endif
    144 }
    145 
    146 //SSD1306 OLED update loop, make sure to add #define SSD1306OLED in config.h
    147 #ifdef SSD1306OLED
    148 
    149 // When add source files to SRC in rules.mk, you can use functions.
    150 const char *read_layer_state(void);
    151 const char *read_logo(void);
    152 void set_keylog(uint16_t keycode, keyrecord_t *record);
    153 const char *read_keylog(void);
    154 const char *read_keylogs(void);
    155 
    156 // const char *read_mode_icon(bool swap);
    157 // const char *read_host_led_state(void);
    158 // void set_timelog(void);
    159 // const char *read_timelog(void);
    160 
    161 void matrix_scan_user(void) {
    162    iota_gfx_task();
    163 }
    164 
    165 void matrix_render_user(struct CharacterMatrix *matrix) {
    166   if (is_master) {
    167     // If you want to change the display of OLED, you need to change here
    168     matrix_write_ln(matrix, read_layer_state());
    169     matrix_write_ln(matrix, read_keylog());
    170     matrix_write_ln(matrix, read_keylogs());
    171     //matrix_write_ln(matrix, read_mode_icon(keymap_config.swap_lalt_lgui));
    172     //matrix_write_ln(matrix, read_host_led_state());
    173     //matrix_write_ln(matrix, read_timelog());
    174   } else {
    175     matrix_write(matrix, read_logo());
    176   }
    177 }
    178 
    179 void matrix_update(struct CharacterMatrix *dest, const struct CharacterMatrix *source) {
    180   if (memcmp(dest->display, source->display, sizeof(dest->display))) {
    181     memcpy(dest->display, source->display, sizeof(dest->display));
    182     dest->dirty = true;
    183   }
    184 }
    185 
    186 void iota_gfx_task_user(void) {
    187   struct CharacterMatrix matrix;
    188   matrix_clear(&matrix);
    189   matrix_render_user(&matrix);
    190   matrix_update(&display, &matrix);
    191 }
    192 #endif//SSD1306OLED
    193 
    194 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    195   if (record->event.pressed) {
    196 #ifdef SSD1306OLED
    197     set_keylog(keycode, record);
    198 #endif
    199     // set_timelog();
    200   }
    201 
    202   switch (keycode) {
    203     case QWERTY:
    204       if (record->event.pressed) {
    205         set_single_persistent_default_layer(_QWERTY);
    206       }
    207       return false;
    208       break;
    209     case LOWER:
    210       if (record->event.pressed) {
    211         layer_on(_LOWER);
    212         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    213       } else {
    214         layer_off(_LOWER);
    215         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    216       }
    217       return false;
    218       break;
    219     case RAISE:
    220       if (record->event.pressed) {
    221         layer_on(_RAISE);
    222         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    223       } else {
    224         layer_off(_RAISE);
    225         update_tri_layer_RGB(_LOWER, _RAISE, _ADJUST);
    226       }
    227       return false;
    228       break;
    229     case ADJUST:
    230         if (record->event.pressed) {
    231           layer_on(_ADJUST);
    232         } else {
    233           layer_off(_ADJUST);
    234         }
    235         return false;
    236         break;
    237   }
    238   return true;
    239 }