qmk_firmware

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

sofle.c (4039B)


      1 // Copyright 2023 QMK
      2 // SPDX-License-Identifier: GPL-2.0-or-later
      3 #include "quantum.h"
      4 
      5 #ifdef SWAP_HANDS_ENABLE
      6 
      7 __attribute__ ((weak))
      8 const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS] =
      9     // The LAYOUT macro could work for this, but it was harder to figure out the
     10     // identity using it.
     11 
     12     // This is the identity layout.
     13 /*
     14 {
     15     { {0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0} },
     16     { {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1} },
     17     { {0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2} },
     18     { {0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3} },
     19     { {0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4} },
     20 
     21     { {0, 5}, {1, 5}, {2, 5}, {3, 5}, {4, 5}, {5, 5} },
     22     { {0, 6}, {1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6} },
     23     { {0, 7}, {1, 7}, {2, 7}, {3, 7}, {4, 7}, {5, 7} },
     24     { {0, 8}, {1, 8}, {2, 8}, {3, 8}, {4, 8}, {5, 8} },
     25     { {0, 9}, {1, 9}, {2, 9}, {3, 9}, {4, 9}, {5, 9} },
     26 };
     27 */
     28 
     29     // This is the mirror, q <-> p, w <-> o, etc...
     30 {
     31  { {0, 5}, {1, 5}, {2, 5}, {3, 5}, {4, 5}, {5, 5} },
     32  { {0, 6}, {1, 6}, {2, 6}, {3, 6}, {4, 6}, {5, 6} },
     33  { {0, 7}, {1, 7}, {2, 7}, {3, 7}, {4, 7}, {5, 7} },
     34  { {0, 8}, {1, 8}, {2, 8}, {3, 8}, {4, 8}, {5, 8} },
     35  { {0, 9}, {1, 9}, {2, 9}, {3, 9}, {4, 9}, {5, 9} },
     36 
     37  { {0, 0}, {1, 0}, {2, 0}, {3, 0}, {4, 0}, {5, 0} },
     38  { {0, 1}, {1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1} },
     39  { {0, 2}, {1, 2}, {2, 2}, {3, 2}, {4, 2}, {5, 2} },
     40  { {0, 3}, {1, 3}, {2, 3}, {3, 3}, {4, 3}, {5, 3} },
     41  { {0, 4}, {1, 4}, {2, 4}, {3, 4}, {4, 4}, {5, 4} },
     42 };
     43 
     44 #    ifdef ENCODER_MAP_ENABLE
     45 const uint8_t PROGMEM encoder_hand_swap_config[NUM_ENCODERS] = {1, 0};
     46 #    endif
     47 
     48 #endif
     49 
     50 #ifdef OLED_ENABLE
     51 oled_rotation_t oled_init_kb(oled_rotation_t rotation) {
     52     if (is_keyboard_master()) {
     53         return OLED_ROTATION_270;
     54     }
     55     return rotation;
     56 }
     57 
     58 static void render_logo(void) {
     59     static const char PROGMEM qmk_logo[] = {
     60         0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
     61         0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
     62         0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0
     63     };
     64     oled_write_P(qmk_logo, false);
     65 }
     66 
     67 void print_status_narrow(void) {
     68     oled_write_P(PSTR("\n\n"), false);
     69     switch (get_highest_layer(layer_state)) {
     70         case 0:
     71             oled_write_ln_P(PSTR("Qwrt"), false);
     72             break;
     73         case 1:
     74             oled_write_ln_P(PSTR("Clmk"), false);
     75             break;
     76         default:
     77             oled_write_P(PSTR("Mod\n"), false);
     78             break;
     79     }
     80     oled_write_P(PSTR("\n\n"), false);
     81     oled_write_ln_P(PSTR("LAYER"), false);
     82     switch (get_highest_layer(layer_state)) {
     83         case 0:
     84         case 1:
     85             oled_write_P(PSTR("Base\n"), false);
     86             break;
     87         case 2:
     88             oled_write_P(PSTR("Lower"), false);
     89             break;
     90         case 3:
     91             oled_write_P(PSTR("Raise"), false);
     92             break;
     93         case 4:
     94             oled_write_P(PSTR("Adjust"), false);
     95             break;
     96         default:
     97             oled_write_ln_P(PSTR("Undef"), false);
     98     }
     99     oled_write_P(PSTR("\n\n"), false);
    100     led_t led_usb_state = host_keyboard_led_state();
    101     oled_write_ln_P(PSTR("CPSLK"), led_usb_state.caps_lock);
    102 }
    103 
    104 bool oled_task_kb(void) {
    105     if (!oled_task_user()) {
    106         return false;
    107     }
    108     if (is_keyboard_master()) {
    109         print_status_narrow();
    110     } else {
    111         render_logo();
    112     }
    113     return true;
    114 }
    115 
    116 #endif
    117 
    118 #ifdef ENCODER_ENABLE
    119 bool encoder_update_kb(uint8_t index, bool clockwise) {
    120     if (!encoder_update_user(index, clockwise)) {
    121         return false;
    122     }
    123     if (index == 0) {
    124         if (clockwise) {
    125             tap_code(KC_VOLU);
    126         } else {
    127             tap_code(KC_VOLD);
    128         }
    129     } else if (index == 1) {
    130         if (clockwise) {
    131             tap_code(KC_PGDN);
    132         } else {
    133             tap_code(KC_PGUP);
    134         }
    135     }
    136     return true;
    137 }
    138 #endif