rev1.c (3186B)
1 // Copyright 2022 QMK 2 // SPDX-License-Identifier: GPL-2.0-or-later 3 4 #include "quantum.h" 5 6 #ifdef OLED_ENABLE 7 #include <stdio.h> 8 9 oled_rotation_t oled_init_kb(oled_rotation_t rotation) { 10 if (!is_keyboard_master()) { 11 return OLED_ROTATION_180; // flips the display 180 degrees if offhand 12 } 13 return rotation; 14 } 15 16 17 void oled_render_layer_state(void) { 18 oled_write_P(PSTR("Layer: "), false); 19 switch (get_highest_layer(layer_state)) { 20 case 0: 21 oled_write_ln_P(PSTR("Default"), false); 22 break; 23 case 1: 24 oled_write_ln_P(PSTR("Lower"), false); 25 break; 26 case 2: 27 oled_write_ln_P(PSTR("Raise"), false); 28 break; 29 case 3: 30 oled_write_ln_P(PSTR("Adjust"), false); 31 break; 32 default: 33 oled_write_ln_P(PSTR("Undef"), false); 34 35 } 36 } 37 38 char keylog_str[24] = {}; 39 40 const char code_to_name[60] = { 41 ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 42 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 43 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 44 '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 45 'R', 'E', 'B', 'T', '_', '-', '=', '[', ']', '\\', 46 '#', ';', '\'', '`', ',', '.', '/', ' ', ' ', ' '}; 47 48 void set_keylog(uint16_t keycode, keyrecord_t *record) { 49 char name = ' '; 50 if ((keycode >= QK_MOD_TAP && keycode <= QK_MOD_TAP_MAX) || (keycode >= QK_LAYER_TAP && keycode <= QK_LAYER_TAP_MAX)) { 51 keycode = keycode & 0xFF; 52 } 53 if (keycode < 60) { 54 name = code_to_name[keycode]; 55 } 56 57 // update keylog 58 snprintf(keylog_str, sizeof(keylog_str), "%dx%d, k%2d : %c", record->event.key.row, record->event.key.col, keycode, name); 59 } 60 61 void oled_render_keylog(void) { 62 oled_write(keylog_str, false); 63 } 64 65 void render_bootmagic_status(bool status) { 66 /* Show Ctrl-Gui Swap options */ 67 static const char PROGMEM logo[][2][3] = { 68 {{0x97, 0x98, 0}, {0xb7, 0xb8, 0}}, 69 {{0x95, 0x96, 0}, {0xb5, 0xb6, 0}}, 70 }; 71 if (status) { 72 oled_write_ln_P(logo[0][0], false); 73 oled_write_ln_P(logo[0][1], false); 74 } else { 75 oled_write_ln_P(logo[1][0], false); 76 oled_write_ln_P(logo[1][1], false); 77 } 78 } 79 80 void oled_render_logo(void) { 81 static const char PROGMEM crkbd_logo[] = {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, 0x90, 0x91, 0x92, 0x93, 0x94, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0}; 82 oled_write_P(crkbd_logo, false); 83 } 84 85 bool oled_task_kb(void) { 86 if (!oled_task_user()) { 87 return true; 88 } 89 if (is_keyboard_master()) { 90 oled_render_layer_state(); 91 oled_render_keylog(); 92 } else { 93 oled_render_logo(); 94 } 95 return false; 96 } 97 98 bool process_record_kb(uint16_t keycode, keyrecord_t *record) { 99 if (record->event.pressed) { 100 set_keylog(keycode, record); 101 } 102 return process_record_user(keycode, record); 103 } 104 105 #endif // OLED_ENABLE