r2g.c (7404B)
1 /* Copyright 2023 Elliot Powell 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 20 #ifdef OLED_ENABLE 21 22 oled_rotation_t oled_init_kb(oled_rotation_t rotation) { 23 if (!is_keyboard_master()) { 24 return OLED_ROTATION_180; // flips the display 180 degrees if offhand 25 } 26 return rotation; 27 } 28 29 30 void oled_render_layer_state_r2g(void) { 31 oled_write_P(PSTR("Layer: "), false); 32 switch (get_highest_layer(layer_state)) { 33 case 0: 34 oled_write_ln_P(PSTR("Default"), false); 35 break; 36 case 1: 37 oled_write_ln_P(PSTR("Lower"), false); 38 break; 39 case 2: 40 oled_write_ln_P(PSTR("Raise"), false); 41 break; 42 case 3: 43 oled_write_ln_P(PSTR("Adjust"), false); 44 break; 45 default: 46 oled_write_ln_P(PSTR("Unknown"), false); 47 break; 48 } 49 } 50 51 //char keylog_str_r2g[24] = {}; 52 53 const char code_to_name_r2g[60] = { 54 ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 55 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 56 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 57 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 58 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\', 59 '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '}; 60 61 char key_name_r2g = ' '; 62 uint16_t last_keycode_r2g; 63 uint8_t last_row_r2g; 64 uint8_t last_col_r2g; 65 66 void set_keylog_r2g(uint16_t keycode, keyrecord_t *record) { 67 key_name_r2g = ' '; 68 last_keycode_r2g = keycode; 69 if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || 70 (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { last_keycode_r2g = keycode & 0xFF; } 71 if (keycode < 60) { 72 key_name_r2g = code_to_name_r2g[keycode]; 73 } 74 last_row_r2g = record->event.key.row; 75 last_col_r2g = record->event.key.col; 76 } 77 78 const char *depad_str(const char *depad_str, char depad_char) { 79 while (*depad_str == depad_char) ++depad_str; 80 return depad_str; 81 } 82 83 void oled_render_keylog_r2g(void) { 84 //oled_write(keylog_str_r2g, false); 85 const char *last_row_r2g_str = get_u8_str(last_row_r2g, ' '); 86 oled_write(depad_str(last_row_r2g_str, ' '), false); 87 oled_write_P(PSTR("x"), false); 88 const char *last_col_r2g_str = get_u8_str(last_col_r2g, ' '); 89 oled_write(depad_str(last_col_r2g_str, ' '), false); 90 oled_write_P(PSTR(", k"), false); 91 const char *last_keycode_r2g_str = get_u16_str(last_keycode_r2g, ' '); 92 oled_write(depad_str(last_keycode_r2g_str, ' '), false); 93 oled_write_P(PSTR(":"), false); 94 oled_write_char(key_name_r2g, false); 95 } 96 97 void render_bootmagic_status_r2g(bool status) { 98 /* Show Ctrl-Gui Swap options */ 99 static const char PROGMEM logo[][2][3] = { 100 {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}}, 101 {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}}, 102 }; 103 if (status) { 104 oled_write_ln_P(logo[0][0], false); 105 oled_write_ln_P(logo[0][1], false); 106 } else { 107 oled_write_ln_P(logo[1][0], false); 108 oled_write_ln_P(logo[1][1], false); 109 } 110 } 111 112 void oled_render_logo_r2g(void) { 113 static const char PROGMEM mb_logo[] = { 114 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 115 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 116 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x0f, 0x0f, 0x0f, 0x0f, 117 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 118 0xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 121 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 122 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x83, 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, 123 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, 0x83, 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, 0x83, 0x83, 0x83, 124 0x83, 0xff, 0xff, 0x83, 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, 0xff, 0xff, 0x82, 0x82, 0x82, 0x82, 125 0x82, 0xff, 0xff, 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, 0x83, 0x83, 0x83, 0x83, 0x83, 0xff, 0xff, 126 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0xfc, 0xfc, 0xfc, 127 0x9c, 0x9c, 0xfc, 0xfc, 0xf8, 0xf8, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x78, 0x7c, 0x3c, 128 0x9c, 0xfc, 0xfc, 0xf8, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0xf8, 0xf8, 0x3c, 0x3c, 129 0x9c, 0xbc, 0xfc, 0xb8, 0xb8, 0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 130 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41, 0x41, 0xff, 0xff, 131 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41, 0x41, 0xff, 0xff, 0xff, 0xff, 0xff, 132 0xff, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41, 0x41, 0xff, 0xff, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41, 133 0x41, 0xff, 0xff, 0x7f, 0x7f, 0x7f, 0x7f, 0xff, 0xff, 0x41, 0x41, 0x41, 0x41, 0x41, 0xff, 0xff, 134 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f, 0x3f, 0x3f, 135 0x03, 0x07, 0x0f, 0x3f, 0x3f, 0x3e, 0x38, 0x20, 0x00, 0x00, 0x00, 0x00, 0x38, 0x3c, 0x3e, 0x3f, 136 0x3f, 0x3f, 0x3b, 0x39, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0f, 0x1f, 0x3f, 0x3c, 0x38, 137 0x3b, 0x3b, 0x3f, 0x1f, 0x1f, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 138 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 139 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 140 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 141 0xf0, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xff, 0xff, 142 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 143 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 144 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 146 }; 147 oled_write_raw_P(mb_logo, sizeof(mb_logo)); 148 //oled_set_cursor(oled_max_chars()/2,oled_max_lines()/2); 149 //oled_write_P(PSTR("R2G"), false); 150 } 151 152 bool oled_task_kb(void) { 153 if (!oled_task_user()) { return false; } 154 if (is_keyboard_master()) { 155 oled_render_layer_state_r2g(); 156 oled_render_keylog_r2g(); 157 } else { 158 oled_render_logo_r2g(); 159 } 160 return false; 161 } 162 163 bool process_record_kb(uint16_t keycode, keyrecord_t *record) { 164 if (record->event.pressed) { 165 set_keylog_r2g(keycode, record); 166 } 167 return process_record_user(keycode, record); 168 } 169 #endif // OLED_ENABLE