rev2.c (7361B)
1 /* Copyright 2023 @BenRoe (keycapsss.com) 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 "quantum.h" 18 19 enum layers { _QWERTY, _LOWER, _RAISE, _ADJUST }; 20 21 # ifdef OLED_ENABLE 22 23 oled_rotation_t oled_init_kb(oled_rotation_t rotation) { 24 return OLED_ROTATION_270; 25 } 26 27 // NOTE: Most of the OLED code was originally written by Soundmonster for the Corne, 28 // and has been copied directly from `crkbd/soundmonster/keymap.c` 29 30 void render_mod_status_gui_alt(uint8_t modifiers) { 31 static const char PROGMEM gui_off_1[] = {0x85, 0x86, 0}; 32 static const char PROGMEM gui_off_2[] = {0xa5, 0xa6, 0}; 33 static const char PROGMEM gui_on_1[] = {0x8d, 0x8e, 0}; 34 static const char PROGMEM gui_on_2[] = {0xad, 0xae, 0}; 35 36 static const char PROGMEM alt_off_1[] = {0x87, 0x88, 0}; 37 static const char PROGMEM alt_off_2[] = {0xa7, 0xa8, 0}; 38 static const char PROGMEM alt_on_1[] = {0x8f, 0x90, 0}; 39 static const char PROGMEM alt_on_2[] = {0xaf, 0xb0, 0}; 40 41 // fillers between the modifier icons bleed into the icon frames 42 static const char PROGMEM off_off_1[] = {0xc5, 0}; 43 static const char PROGMEM off_off_2[] = {0xc6, 0}; 44 static const char PROGMEM on_off_1[] = {0xc7, 0}; 45 static const char PROGMEM on_off_2[] = {0xc8, 0}; 46 static const char PROGMEM off_on_1[] = {0xc9, 0}; 47 static const char PROGMEM off_on_2[] = {0xca, 0}; 48 static const char PROGMEM on_on_1[] = {0xcb, 0}; 49 static const char PROGMEM on_on_2[] = {0xcc, 0}; 50 51 if (modifiers & MOD_MASK_GUI) { 52 oled_write_P(gui_on_1, false); 53 } else { 54 oled_write_P(gui_off_1, false); 55 } 56 57 if ((modifiers & MOD_MASK_GUI) && (modifiers & MOD_MASK_ALT)) { 58 oled_write_P(on_on_1, false); 59 } else if (modifiers & MOD_MASK_GUI) { 60 oled_write_P(on_off_1, false); 61 } else if (modifiers & MOD_MASK_ALT) { 62 oled_write_P(off_on_1, false); 63 } else { 64 oled_write_P(off_off_1, false); 65 } 66 67 if (modifiers & MOD_MASK_ALT) { 68 oled_write_P(alt_on_1, false); 69 } else { 70 oled_write_P(alt_off_1, false); 71 } 72 73 if (modifiers & MOD_MASK_GUI) { 74 oled_write_P(gui_on_2, false); 75 } else { 76 oled_write_P(gui_off_2, false); 77 } 78 79 if ((modifiers & MOD_MASK_GUI) && (modifiers & MOD_MASK_ALT)) { 80 oled_write_P(on_on_2, false); 81 } else if (modifiers & MOD_MASK_GUI) { 82 oled_write_P(on_off_2, false); 83 } else if (modifiers & MOD_MASK_ALT) { 84 oled_write_P(off_on_2, false); 85 } else { 86 oled_write_P(off_off_2, false); 87 } 88 89 if (modifiers & MOD_MASK_ALT) { 90 oled_write_P(alt_on_2, false); 91 } else { 92 oled_write_P(alt_off_2, false); 93 } 94 } 95 96 void render_mod_status_ctrl_shift(uint8_t modifiers) { 97 static const char PROGMEM ctrl_off_1[] = {0x89, 0x8a, 0}; 98 static const char PROGMEM ctrl_off_2[] = {0xa9, 0xaa, 0}; 99 static const char PROGMEM ctrl_on_1[] = {0x91, 0x92, 0}; 100 static const char PROGMEM ctrl_on_2[] = {0xb1, 0xb2, 0}; 101 102 static const char PROGMEM shift_off_1[] = {0x8b, 0x8c, 0}; 103 static const char PROGMEM shift_off_2[] = {0xab, 0xac, 0}; 104 static const char PROGMEM shift_on_1[] = {0xcd, 0xce, 0}; 105 static const char PROGMEM shift_on_2[] = {0xcf, 0xd0, 0}; 106 107 // fillers between the modifier icons bleed into the icon frames 108 static const char PROGMEM off_off_1[] = {0xc5, 0}; 109 static const char PROGMEM off_off_2[] = {0xc6, 0}; 110 static const char PROGMEM on_off_1[] = {0xc7, 0}; 111 static const char PROGMEM on_off_2[] = {0xc8, 0}; 112 static const char PROGMEM off_on_1[] = {0xc9, 0}; 113 static const char PROGMEM off_on_2[] = {0xca, 0}; 114 static const char PROGMEM on_on_1[] = {0xcb, 0}; 115 static const char PROGMEM on_on_2[] = {0xcc, 0}; 116 117 if (modifiers & MOD_MASK_CTRL) { 118 oled_write_P(ctrl_on_1, false); 119 } else { 120 oled_write_P(ctrl_off_1, false); 121 } 122 123 if ((modifiers & MOD_MASK_CTRL) && (modifiers & MOD_MASK_SHIFT)) { 124 oled_write_P(on_on_1, false); 125 } else if (modifiers & MOD_MASK_CTRL) { 126 oled_write_P(on_off_1, false); 127 } else if (modifiers & MOD_MASK_SHIFT) { 128 oled_write_P(off_on_1, false); 129 } else { 130 oled_write_P(off_off_1, false); 131 } 132 133 if (modifiers & MOD_MASK_SHIFT) { 134 oled_write_P(shift_on_1, false); 135 } else { 136 oled_write_P(shift_off_1, false); 137 } 138 139 if (modifiers & MOD_MASK_CTRL) { 140 oled_write_P(ctrl_on_2, false); 141 } else { 142 oled_write_P(ctrl_off_2, false); 143 } 144 145 if ((modifiers & MOD_MASK_CTRL) && (modifiers & MOD_MASK_SHIFT)) { 146 oled_write_P(on_on_2, false); 147 } else if (modifiers & MOD_MASK_CTRL) { 148 oled_write_P(on_off_2, false); 149 } else if (modifiers & MOD_MASK_SHIFT) { 150 oled_write_P(off_on_2, false); 151 } else { 152 oled_write_P(off_off_2, false); 153 } 154 155 if (modifiers & MOD_MASK_SHIFT) { 156 oled_write_P(shift_on_2, false); 157 } else { 158 oled_write_P(shift_off_2, false); 159 } 160 } 161 162 void render_logo(void) { 163 static const char PROGMEM kimiko_logo[] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0}; 164 oled_advance_page(false); 165 oled_advance_page(false); 166 oled_write_P(kimiko_logo, false); 167 // oled_write_P(PSTR("Kimiko"), false); 168 } 169 170 void render_layer_state(void) { 171 static const char PROGMEM default_layer[] = {0x20, 0x94, 0x95, 0x96, 0x20, 0x20, 0xb4, 0xb5, 0xb6, 0x20, 0x20, 0xd4, 0xd5, 0xd6, 0x20, 0}; 172 static const char PROGMEM raise_layer[] = {0x20, 0x97, 0x98, 0x99, 0x20, 0x20, 0xb7, 0xb8, 0xb9, 0x20, 0x20, 0xd7, 0xd8, 0xd9, 0x20, 0}; 173 static const char PROGMEM lower_layer[] = {0x20, 0x9a, 0x9b, 0x9c, 0x20, 0x20, 0xba, 0xbb, 0xbc, 0x20, 0x20, 0xda, 0xdb, 0xdc, 0x20, 0}; 174 static const char PROGMEM adjust_layer[] = {0x20, 0x9d, 0x9e, 0x9f, 0x20, 0x20, 0xbd, 0xbe, 0xbf, 0x20, 0x20, 0xdd, 0xde, 0xdf, 0x20, 0}; 175 176 if (layer_state_is(_ADJUST)) { 177 oled_write_P(adjust_layer, false); 178 } else if (layer_state_is(_LOWER)) { 179 oled_write_P(lower_layer, false); 180 } else if (layer_state_is(_RAISE)) { 181 oled_write_P(raise_layer, false); 182 } else { 183 oled_write_P(default_layer, false); 184 } 185 } 186 187 void render_status_main(void) { 188 render_logo(); 189 oled_advance_page(false); 190 render_layer_state(); 191 oled_advance_page(false); 192 render_mod_status_gui_alt(get_mods() | get_oneshot_mods()); 193 render_mod_status_ctrl_shift(get_mods() | get_oneshot_mods()); 194 } 195 196 bool oled_task_kb(void) { 197 if (!oled_task_user()) { 198 return false; 199 } 200 201 if (is_keyboard_master()) { 202 render_status_main(); // Renders the current keyboard state (layer, lock, caps, scroll, etc) 203 } else { 204 render_logo(); 205 } 206 207 return true; 208 } 209 # endif // OLED_ENABLE