qmk_me

QMK Firmware userspace, keyboards, & keymaps
git clone git://git.pngu.org.org/qmk_me
Log | Files | Refs | Submodules | README | LICENSE

commit 4fd3fd93efb39528f1204931767f8fad64725bc9
parent e1be82b7b670141231e96b95049fe351d059c0a1
Author: Jack Sangdahl <jack@pngu.org>
Date:   Thu, 11 Sep 2025 13:25:33 -0600

Tidy up OLED code (n-th time)

Diffstat:
Mjack/jack.c | 36+-----------------------------------
Mjack/jack.h | 13++++---------
Mjack/oled.c | 69+++++++++++++--------------------------------------------------------
Mjack/oled.h | 43+++++++++++--------------------------------
Mjack/tapping.c | 4+---
Mkeymaps/crkbd/keymap.c | 7+++----
Mkeymaps/kyria/keymap.c | 2+-
7 files changed, 34 insertions(+), 140 deletions(-)

diff --git a/jack/jack.c b/jack/jack.c @@ -2,45 +2,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "jack.h" -#if defined(SPLIT_KEYBOARD) && defined(OLED_ENABLE) -#include "transactions.h" -extern char keylog_str[KEYLOG_LEN + 1]; -void keylogger_sync(uint8_t initiator2target_buffer_size, - const void *initiator2target_buffer, - uint8_t target2initiator_buffer_size, - void *target2initiator_buffer) { - if (initiator2target_buffer_size == 5) - memcpy(&keylog_str, initiator2target_buffer, initiator2target_buffer_size); -} -#endif - __attribute__((weak)) void housekeeping_task_keymap(void) {} -void housekeeping_task_user(void) { -#if defined(SPLIT_KEYBOARD) && defined(OLED_ENABLE) - if (is_keyboard_master()) { - static uint32_t last_sync; - bool needs_sync = false; - static char tmp_keylog[5] = {0}; - if (memcmp(&keylog_str, &tmp_keylog, sizeof(tmp_keylog))) { - needs_sync = true; - memcpy(&tmp_keylog, &keylog_str, sizeof(tmp_keylog)); - } - if (timer_elapsed32(last_sync) > 250) - needs_sync = true; - if (needs_sync) - if (transaction_rpc_send(RPC_ID_USER_KEYLOG_STR, sizeof(tmp_keylog), - &keylog_str)) - last_sync = timer_read32(); - } -#endif - housekeeping_task_keymap(); -} +void housekeeping_task_user(void) { housekeeping_task_keymap(); } __attribute__((weak)) void keyboard_post_init_keymap(void) {} void keyboard_post_init_user(void) { -#if defined(SPLIT_KEYBOARD) && defined(OLED_ENABLE) - transaction_register_rpc(RPC_ID_USER_KEYLOG_STR, keylogger_sync); -#endif #ifdef RGBLIGHT_ENABLE rgblight_enable_noeeprom(); rgblight_sethsv_noeeprom(HSV_CYAN); diff --git a/jack/jack.h b/jack/jack.h @@ -38,23 +38,18 @@ void raise_paste(tap_dance_state_t *state, void *user_data); #endif void oled_timer_reset(void); -void anim_frame(uint16_t size, char const action[][size]); -void wpm_graph(void); -void felix_dog(void); -void layer_anim(void); -void layer_status(void); +void render_wpm_graph(void); +void render_felix_dog(void); +void render_layer_anim(void); +void render_layer_status(void); void render_mod_status(void); -void add_keylog(uint16_t keycode, keyrecord_t *record); -void render_keylog(void); void render_wpm(void); -void render_scan_rate(void); void keyboard_pre_init_keymap(void); void keyboard_post_init_keymap(void); void housekeeping_task_keymap(void); bool oled_task_keymap(void); -#define KEYLOG_LEN 5 #define PNP TD(PLY_NXT_PRV) #define PSTRSE TD(PASTE_RAISE) #define ESCLWR LT(_LOWER, KC_ESC) diff --git a/jack/oled.c b/jack/oled.c @@ -4,9 +4,6 @@ #include "oled.h" uint32_t oled_timer = 0; -char keylog_str[KEYLOG_LEN + 1] = {0}; -extern uint8_t oled_buffer[OLED_MATRIX_SIZE]; -extern OLED_BLOCK_TYPE oled_dirty; void oled_timer_reset(void) { oled_timer = timer_read32(); } @@ -29,10 +26,11 @@ void anim_frame(uint16_t size, char const action[][size]) { oled_write_raw(action[current_frame], size); } -#ifdef OLED_DISPLAY_128X64 -void wpm_graph(void) { +void render_wpm_graph(void) { static uint8_t height = OLED_DISPLAY_HEIGHT - 1, vert_count = 0, max_wpm = 160; + extern uint8_t oled_buffer[OLED_MATRIX_SIZE]; + extern OLED_BLOCK_TYPE oled_dirty; static uint16_t graph_timer = 0; if (timer_elapsed(graph_timer) > 100) { height = 63 - ((get_current_wpm() / (float)max_wpm) * 63); @@ -60,28 +58,26 @@ void wpm_graph(void) { graph_timer = timer_read(); } } -#endif -void felix_dog(void) { +void render_felix_dog(void) { static uint16_t felix_anim_timer = 0; - bool shifted = - get_mods() & MOD_MASK_SHIFT || host_keyboard_led_state().caps_lock; if (timer_elapsed(felix_anim_timer) > 200) { felix_anim_timer = timer_read(); - if (shifted || is_caps_word_on()) - anim_frame(96, felix_bark); + if (get_mods() & MOD_MASK_SHIFT || host_keyboard_led_state().caps_lock || + is_caps_word_on()) + anim_frame(FELIX_FRAME_SIZE, felix_bark); else if (get_mods() & MOD_MASK_CAG) - anim_frame(96, felix_sneak); + anim_frame(FELIX_FRAME_SIZE, felix_sneak); else if (get_current_wpm() > 60) - anim_frame(96, felix_run); + anim_frame(FELIX_FRAME_SIZE, felix_run); else if (get_current_wpm() && get_current_wpm() <= 60) - anim_frame(96, felix_walk); + anim_frame(FELIX_FRAME_SIZE, felix_walk); else - anim_frame(96, felix_sit); + anim_frame(FELIX_FRAME_SIZE, felix_sit); } } -void layer_anim(void) { +void render_layer_anim(void) { static uint16_t layer_anim_timer = 0; if (timer_elapsed(layer_anim_timer) > 200) { layer_anim_timer = timer_read(); @@ -99,7 +95,7 @@ void layer_anim(void) { } } -void layer_status(void) { +void render_layer_status(void) { static const char PROGMEM base[] = {0x20, 0x94, 0x95, 0x96, 0x20, 0x20, 0xb4, 0xb5, 0xb6, 0x20, 0x20, 0xd4, 0xd5, 0xd6, 0x20}; @@ -178,46 +174,7 @@ void render_mod_status(void) { oled_write(mods & MOD_MASK_SHIFT ? shift_on_2 : shift_off_2, false); } -void add_keylog(uint16_t keycode, keyrecord_t *record) { - if (IS_QK_MOD_TAP(keycode)) - keycode = - record->tap.count - ? keycode_config(QK_MOD_TAP_GET_TAP_KEYCODE(keycode)) - : keycode_config(0xE0 + biton(QK_MOD_TAP_GET_MODS(keycode) & 0xF) + - biton(QK_MOD_TAP_GET_MODS(keycode) & 0x10)); - else if (IS_QK_LAYER_TAP(keycode) && (record->tap.count)) - keycode = keycode_config(QK_LAYER_TAP_GET_TAP_KEYCODE(keycode)); - else if (IS_QK_MODS(keycode)) - keycode = keycode_config(QK_MODS_GET_BASIC_KEYCODE(keycode)); - else if (IS_QK_BASIC(keycode)) - keycode = keycode_config(keycode); - if ((keycode == KC_BSPC) && mod_config(get_mods()) & MOD_MASK_CTRL) { - memset(keylog_str, ' ', KEYLOG_LEN); - keylog_str[KEYLOG_LEN] = '\0'; - return; - } - char code = 0; - if (keycode < ARRAY_SIZE(code_to_name)) - code = pgm_read_byte(&code_to_name[keycode]); - if (code) { - memmove(keylog_str, keylog_str + 1, KEYLOG_LEN - 1); - keylog_str[KEYLOG_LEN - 1] = code; - } -} - -void render_keylog(void) { - oled_write(PSTR("KLG: "), false); - oled_write_ln(keylog_str, false); -} - void render_wpm(void) { oled_write(PSTR("WPM: "), false); oled_write_ln(get_u8_str(get_current_wpm(), ' '), false); } - -#ifdef DEBUG_MATRIX_SCAN_RATE -void render_scan_rate(void) { - oled_write(PSTR("MSR: "), false); - oled_write_ln(get_u16_str(get_matrix_scan_rate(), ' '), false); -} -#endif diff --git a/jack/oled.h b/jack/oled.h @@ -2,32 +2,11 @@ // SPDX-License-Identifier: GPL-2.0-or-later #pragma once -static const char PROGMEM code_to_name[256] = { - ' ', ' ', ' ', ' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', - 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', - 'u', 'v', 'w', 'x', 'y', 'z', '1', '2', '3', '4', '5', '6', - '7', '8', '9', '0', 20, 19, 27, 26, 22, '-', '=', '[', - ']', '\\', '#', ';', '\'', '`', ',', '.', '/', 128, 0xD5, 0xD6, - 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0XDF, 0xFB, 'P', 'S', - 19, ' ', 17, 30, 16, 16, 31, 26, 27, 25, 24, 'N', - '/', '*', '-', '+', 23, '1', '2', '3', '4', '5', '6', '7', - '8', '9', '0', '.', '\\', 'A', 0, '=', ' ', ' ', ' ', ' ', - ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 0, ' ', ' ', - ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - ' ', 0x9E, 0x9E, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', - 0x80, 0x80, 0x80, 0x80, 0x80, 0x81, 0x82, 0x80, 0x80, 0x80, 0x80, 0x80, - 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 'C', 'S', 'A', 'G', - 'C', 'S', 'A', 'G', ' ', ' ', ' ', ' ', ' ', 24, 26, 24, - 25, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 24, 25, 27, - 26, ' ', ' ', ' ', -}; +#define FELIX_FRAME_SIZE 96 +#define TAP_NUM_SYS_FRAME_SIZE 520 +#define TAP_SYM_FRAME_SIZE 650 -static const char PROGMEM felix_sit[][96] = { +static const char PROGMEM felix_sit[][FELIX_FRAME_SIZE] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xfc, 0xfe, 0xfd, 0xfe, 0xdc, 0xfc, 0xfc, 0xfe, 0x5d, @@ -49,7 +28,7 @@ static const char PROGMEM felix_sit[][96] = { 0x3f, 0x0f, 0x11, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }}; -static const char PROGMEM felix_walk[][96] = { +static const char PROGMEM felix_walk[][FELIX_FRAME_SIZE] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf0, 0x70, 0x30, 0x20, 0x00, 0x80, 0xc0, 0xc0, 0xf0, 0xf8, 0xf4, 0xf8, 0x70, 0xf0, 0xf0, @@ -71,7 +50,7 @@ static const char PROGMEM felix_walk[][96] = { 0x1f, 0x3f, 0x3f, 0x33, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }}; -static const char PROGMEM felix_run[][96] = { +static const char PROGMEM felix_run[][FELIX_FRAME_SIZE] = { { 0x00, 0x00, 0x00, 0x00, 0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xb0, 0xa0, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xc0, 0xc0, 0xfc, 0xf4, 0xe4, 0xf8, 0x70, @@ -93,7 +72,7 @@ static const char PROGMEM felix_run[][96] = { 0x1f, 0x0f, 0x1f, 0x3f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }}; -static const char PROGMEM felix_bark[][96] = { +static const char PROGMEM felix_bark[][FELIX_FRAME_SIZE] = { { 0x00, 0xc0, 0xe0, 0xf0, 0xf0, 0x30, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0xc0, 0xfc, 0xf4, 0xe4, 0xf8, 0x70, 0xf8, 0xe4, 0xf8, @@ -115,7 +94,7 @@ static const char PROGMEM felix_bark[][96] = { 0x3b, 0x33, 0x07, 0x07, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }}; -static const char PROGMEM felix_sneak[][96] = { +static const char PROGMEM felix_sneak[][FELIX_FRAME_SIZE] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xc0, 0xc0, 0xc0, 0xc0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x40, 0x40, 0x80, 0x00, 0x80, @@ -137,7 +116,7 @@ static const char PROGMEM felix_sneak[][96] = { 0x3f, 0x3f, 0x37, 0x07, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, }}; -static const char PROGMEM tap_num[][520] = { +static const char PROGMEM tap_num[][TAP_NUM_SYS_FRAME_SIZE] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x9c, 0x03, 0x00, 0x00, 0x01, 0x02, 0x04, 0x08, @@ -274,7 +253,7 @@ static const char PROGMEM tap_num[][520] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }}; -static const char PROGMEM tap_sym[][650] = { +static const char PROGMEM tap_sym[][TAP_SYM_FRAME_SIZE] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x40, @@ -444,7 +423,7 @@ static const char PROGMEM tap_sym[][650] = { 0x00, 0x00, 0x00, 0x00, }}; -static const char PROGMEM tap_sys[][520] = { +static const char PROGMEM tap_sys[][TAP_NUM_SYS_FRAME_SIZE] = { { 0x01, 0x80, 0x60, 0x10, 0x48, 0x08, 0x24, 0x04, 0x14, 0x84, 0x14, 0x04, 0x28, 0x88, 0x10, 0x60, 0x80, 0x00, 0x00, 0x04, 0x00, 0x80, 0x60, 0x10, diff --git a/jack/tapping.c b/jack/tapping.c @@ -75,10 +75,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return false; #endif #ifdef OLED_ENABLE - if (record->event.pressed) { + if (record->event.pressed) oled_timer_reset(); - add_keylog(keycode, record); - } #endif #ifdef MOUSE_JIGGLE_ENABLE if (record->event.pressed) { diff --git a/keymaps/crkbd/keymap.c b/keymaps/crkbd/keymap.c @@ -46,14 +46,13 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation) { bool oled_task_keymap(void) { if (is_keyboard_master()) - layer_anim(); + render_layer_anim(); else { - layer_status(); + render_layer_status(); oled_set_cursor(0, 3); - felix_dog(); + render_felix_dog(); oled_set_cursor(0, 7); render_wpm(); - render_keylog(); render_mod_status(); } return false; diff --git a/keymaps/kyria/keymap.c b/keymaps/kyria/keymap.c @@ -30,7 +30,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { #ifdef OLED_ENABLE bool oled_task_keymap(void) { if (is_keyboard_left()) { - wpm_graph(); + render_wpm_graph(); render_wpm(); } return false;