qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

keymap.c (5032B)


      1 /* MIT License
      2 
      3 Copyright (c) 2019 Mattia Dal Ben
      4 
      5 Permission is hereby granted, free of charge, to any person obtaining a copy
      6 of this software and associated documentation files (the "Software"), to deal
      7 in the Software without restriction, including without limitation the rights
      8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      9 copies of the Software, and to permit persons to whom the Software is
     10 furnished to do so, subject to the following conditions:
     11 
     12 The above copyright notice and this permission notice shall be included in all
     13 copies or substantial portions of the Software.
     14 
     15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     21 SOFTWARE.
     22 */
     23 
     24 #include QMK_KEYBOARD_H
     25 #include <stdio.h>
     26 
     27 // Each layer gets a name for readability, which is then used in the keymap matrix below.
     28 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
     29 // Layer names don't all need to be of the same length, obviously, and you can also skip them
     30 // entirely and just use numbers.
     31 enum layers {
     32     _BL,
     33     _NV,
     34     _FN
     35 };
     36 
     37 enum custom_keycodes {
     38     KC_DBL0 = SAFE_RANGE,
     39 };
     40 
     41 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     42 /* Keymap _BL: (Base Layer) Default Layer
     43  * ,-------------------.
     44  * | NV | /  | *  |-/FN|
     45  * |----|----|----|----|
     46  * | 7  | 8  | 9  |    |
     47  * |----|----|----| +  |
     48  * | 4  | 5  | 6  |    |
     49  * |----|----|----|----|
     50  * | 1  | 2  | 3  |    |
     51  * |----|----|----| En |
     52  * | 0  | 00 | .  |    |
     53  * `-------------------'
     54  */
     55   [_BL] = LAYOUT(
     56     TG(_NV),  KC_PSLS,  KC_PAST,   LT(_FN, KC_PMNS),
     57     KC_P7,    KC_P8,    KC_P9,
     58     KC_P4,    KC_P5,    KC_P6,     KC_PPLS,
     59     KC_P1,    KC_P2,    KC_P3,
     60     KC_P0,    KC_DBL0,  KC_PDOT,   KC_PENT
     61   ),
     62 
     63 /* Keymap _NV: Navigation layer
     64  * ,-------------------.
     65  * |INS |HOME|PGUP|    |
     66  * |----|----|----|----|
     67  * |DEL |END |PGDN|    |
     68  * |----|----|----|    |
     69  * |    |    |    |    |
     70  * |----|----|----|----|
     71  * |    | UP |    |    |
     72  * |----|----|----|    |
     73  * |LEFT|DOWN|RIGH|    |
     74  * `-------------------'
     75  */
     76   [_NV] = LAYOUT(
     77     KC_INS,   KC_HOME,  KC_PGUP,   TG(_NV),
     78     KC_DEL,   KC_END,   KC_PGDN,
     79     XXXXXXX,  XXXXXXX,  XXXXXXX,   XXXXXXX,
     80     XXXXXXX,  KC_UP,    XXXXXXX,
     81     KC_LEFT,  KC_DOWN,  KC_RGHT,   XXXXXXX
     82   ),
     83 
     84 /* Keymap _FN: RGB Function Layer
     85  * ,-------------------.
     86  * |RMOD|RGBP|RTOG| FN |
     87  * |----|----|----|----|
     88  * |HUD |HUI |    |    |
     89  * |----|----|----|    |
     90  * |SAD |SAI |    |    |
     91  * |----|----|----|----|
     92  * |VAD |VAS |    |    |
     93  * |----|----|----|    |
     94  * |RST |    |    |    |
     95  * `-------------------'
     96  */
     97   [_FN] = LAYOUT(
     98     UG_NEXT,  RGB_M_P,  UG_TOGG,   _______,
     99     UG_HUED,  UG_HUEU,  XXXXXXX,
    100     UG_SATD,  UG_SATU,  XXXXXXX,   XXXXXXX,
    101     UG_VALD,  UG_VALU,  XXXXXXX,
    102     QK_BOOT,  XXXXXXX,  XXXXXXX,   XXXXXXX
    103   ),
    104 };
    105 
    106 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
    107   switch (keycode) {
    108     case KC_DBL0:
    109       if (record->event.pressed) {
    110         SEND_STRING("00");
    111       } else {
    112         // when keycode KC_DBL0 is released
    113       }
    114       break;
    115 
    116   }
    117   return true;
    118 };
    119 
    120 #ifdef OLED_ENABLE
    121 
    122 oled_rotation_t oled_init_user(oled_rotation_t rotation) {
    123     return OLED_ROTATION_270;  // flips the display 270 degrees
    124 }
    125 
    126 bool oled_task_user(void) {
    127   // Host Keyboard Layer Status
    128   oled_write_P(PSTR("Layer"), false);
    129   switch (get_highest_layer(layer_state)) {
    130     case _BL:
    131       oled_write_ln_P(PSTR(" BAS"), false);
    132       break;
    133     case _NV:
    134       oled_write_ln_P(PSTR(" NAV"), false);
    135       break;
    136     case _FN:
    137       oled_write_ln_P(PSTR(" RGB"), false);
    138       break;
    139     default:
    140       // Or use the write_ln shortcut over adding '\n' to the end of your string
    141       oled_write_ln_P(PSTR(" UND"), false);
    142   }
    143 
    144   // Host Keyboard LED Status
    145   led_t led_state = host_keyboard_led_state();
    146   oled_write_P(PSTR("-----"), false);
    147   oled_write_P(PSTR("Stats"), false);
    148   oled_write_P(led_state.num_lock ? PSTR("num:*") : PSTR("num:."), false);
    149   oled_write_P(led_state.caps_lock ? PSTR("cap:*") : PSTR("cap:."), false);
    150   oled_write_P(led_state.scroll_lock ? PSTR("scr:*") : PSTR("scr:."), false);
    151 
    152   // Host Keyboard RGB backlight status
    153   oled_write_P(PSTR("-----"), false);
    154   oled_write_P(PSTR("Light"), false);
    155 
    156   static char led_buf[30];
    157   snprintf(led_buf, sizeof(led_buf) - 1, "RGB:%cM: %2d\nh: %2ds: %2dv: %2d\n",
    158       rgblight_is_enabled() ? '*' : '.', (uint8_t)rgblight_get_mode(),
    159       (uint8_t)(rgblight_get_hue() / RGBLIGHT_HUE_STEP),
    160       (uint8_t)(rgblight_get_sat() / RGBLIGHT_SAT_STEP),
    161       (uint8_t)(rgblight_get_val() / RGBLIGHT_VAL_STEP));
    162   oled_write(led_buf, false);
    163 
    164     return false;
    165 }
    166 #endif