qmk_firmware

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

keymap.c (4913B)


      1 /* Copyright 2020-2021 doodboard
      2  *
      3  * This program is free software: you can redistribute it and/or modify
      4  * it under the terms of the GNU General Public License as published by
      5  * the Free Software Foundation, either version 2 of the License, or
      6  * (at your option) any later version.
      7  *
      8  * This program is distributed in the hope that it will be useful,
      9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     11  * GNU General Public License for more details.
     12  *
     13  * You should have received a copy of the GNU General Public License
     14  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
     15  */
     16 
     17 #include QMK_KEYBOARD_H
     18 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
     19     [0] = LAYOUT(
     20                  TG(1),   KC_PSLS, KC_PAST, KC_PMNS,
     21                  KC_7,    KC_8,    KC_9,
     22                  KC_4,    KC_5,    KC_6,    KC_PPLS,
     23                  KC_1,    KC_2,    KC_3,
     24         KC_BSPC, KC_0,    KC_0,    KC_DOT,  KC_ENT),
     25 
     26     [1] = LAYOUT(
     27                  TG(1),   KC_TRNS, KC_TRNS, KC_TRNS,
     28                  KC_HOME, KC_UP,   KC_PGUP,
     29                  KC_LEFT, KC_TRNS, KC_RGHT, KC_TRNS,
     30                  KC_END,  KC_DOWN, KC_PGDN,
     31         TG(2),   KC_TRNS, KC_INS,  KC_DEL,  KC_TRNS),
     32 
     33     [2] = LAYOUT(
     34                  KC_TRNS, UG_TOGG, UG_NEXT, KC_TRNS,
     35                  UG_HUEU, UG_SATU, UG_VALU,
     36                  UG_HUED, UG_SATD, UG_VALD, KC_TRNS,
     37                  KC_TRNS, KC_TRNS, KC_TRNS,
     38         TG(2),   QK_BOOT, KC_TRNS, KC_TRNS, KC_TRNS),
     39 };
     40 
     41 bool encoder_update_user(uint8_t index, bool clockwise) {
     42     if (index == 0) { /* First encoder */
     43         if (clockwise) {
     44             tap_code(KC_VOLU);
     45         } else {
     46             tap_code(KC_VOLD);
     47         }
     48     }
     49     return true;
     50 }
     51 
     52 
     53 #ifdef OLED_ENABLE
     54 oled_rotation_t oled_init_user(oled_rotation_t rotation) { return OLED_ROTATION_270; }
     55 
     56 
     57 // WPM-responsive animation stuff here
     58 #define IDLE_FRAMES 2
     59 #define IDLE_SPEED 40 // below this wpm value your animation will idle
     60 
     61 #define ANIM_FRAME_DURATION 200 // how long each frame lasts in ms
     62 // #define SLEEP_TIMER 60000 // should sleep after this period of 0 wpm, needs fixing
     63 #define ANIM_SIZE 636 // number of bytes in array, minimize for adequate firmware size, max is 1024
     64 
     65 uint32_t anim_timer = 0;
     66 uint32_t anim_sleep = 0;
     67 uint8_t current_idle_frame = 0;
     68 
     69 // Credit to u/Pop-X- for the initial code. You can find his commit here https://github.com/qmk/qmk_firmware/pull/9264/files#diff-303f6e3a7a5ee54be0a9a13630842956R196-R333.
     70 static void render_anim(void) {
     71     static const char PROGMEM idle[IDLE_FRAMES][ANIM_SIZE] = {
     72         {
     73         0,  0,192,192,192,192,192,192,192,248,248, 30, 30,254,254,248,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  3,  3,  3,  3,  3,255,255,255,255,255,255,255,128,128,128,128,128,128,128,128,128,128,128,128,128,128,128,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,127,127,255,255,255,255,255,159,159,135,135,129,129,129, 97, 97, 25, 25,  7,  7,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1, 97, 97,127,  1,  1, 97, 97,127,  1,  1,  0,  0,  0,  0,  0,  0,  0,  0,  0
     74         },
     75         {
     76         0,  0,128,128,128,128,128,128,128,240,240, 60, 60,252,252,240,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  1,  1,  7,  7,  7,  7,  7,255,255,254,254,255,255,255,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,255,255,255,255,255,255,255, 63, 63, 15, 15,  3,  3,  3,195,195, 51, 51, 15, 15,  3,  3,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  3,  3, 99, 99,127,  3,  3, 99, 99,127,  3,  3,  0,  0,  0,  0,  0,  0,  0,  0,  0
     77         }
     78     };
     79 
     80     //assumes 1 frame prep stage
     81     void animation_phase(void) {
     82             current_idle_frame = (current_idle_frame + 1) % IDLE_FRAMES;
     83             oled_write_raw_P(idle[abs((IDLE_FRAMES-1)-current_idle_frame)], ANIM_SIZE);
     84     }
     85 
     86         if(timer_elapsed32(anim_timer) > ANIM_FRAME_DURATION) {
     87             anim_timer = timer_read32();
     88             animation_phase();
     89         }
     90     }
     91 
     92 bool oled_task_user(void) {
     93         render_anim();
     94         oled_set_cursor(0,6);
     95         oled_write_P(PSTR("DUCK\nBOARD\n"), false);
     96     oled_write_P(PSTR("-----\n"), false);
     97     // Host Keyboard Layer Status
     98     oled_write_P(PSTR("MODE\n"), false);
     99     oled_write_P(PSTR("\n"), false);
    100 
    101     switch (get_highest_layer(layer_state)) {
    102         case 0:
    103             oled_write_P(PSTR("BASE\n"), false);
    104             break;
    105         case 1:
    106             oled_write_P(PSTR("FUNC\n"), false);
    107             break;
    108         case 2:
    109             oled_write_P(PSTR("RGB\n"), false);
    110             break;
    111     }
    112     return false;
    113 }
    114 #endif
    115 
    116 void keyboard_post_init_user(void) {
    117   //Customise these values to debug
    118   debug_enable=true;
    119   debug_matrix=true;
    120   //debug_keyboard=true;
    121   //debug_mouse=true;
    122 }