Revising the OLED functionality

- optimized by using the set cursor to position text vs using print statements
- recombined the OLED code into one file
- redid all the rendering methods so they can be reused between a
vertical and horizontal display
- Removed keyboard specific code in my rules.mk
This commit is contained in:
Victor 2024-06-05 22:34:49 -05:00
parent 3fa49a03d1
commit fff0ef034b
Failed to generate hash of commit
5 changed files with 143 additions and 234 deletions

View file

@ -1,51 +1,45 @@
#include "oled32.h" #include "oled.h"
#if defined(WPM_ENABLE) #if defined(WPM_ENABLE)
#include "luna.c" #include "luna.c"
#endif #endif
// Prints the current base layer
// (e.g. Qwerty, Colemak DH, etc)
void render_default_layer_state(void) {
switch (get_highest_layer(default_layer_state)) {
case _QWERTY:
oled_write_P(PSTR(OLED_RENDER_LAYOUT_QWERTY), false);
break;
case _COLEMAK_DH:
oled_write_P(PSTR(OLED_RENDER_LAYOUT_COLEMAK_DH), false);
break;
case _GAME:
oled_write_ln_P(PSTR(OLED_RENDER_LAYOUT_GAME), false);
break;
}
}
// Shows the currently enabled Layer name // Shows the currently enabled Layer name
// Also shows where on the layer stack it is
void render_layer_state(void) { void render_layer_state(void) {
switch (get_highest_layer(layer_state)) { switch (get_highest_layer(layer_state)) {
case _NAVIGATION: case _NAVIGATION:
oled_write_ln_P(PSTR(OLED_RENDER_LAYER_NAVIGATION), false); oled_write_P(PSTR(OLED_RENDER_LAYER_2), false);
break; break;
case _NUMBER: case _NUMBER:
oled_write_ln_P(PSTR(OLED_RENDER_LAYER_NUMBER), false); oled_write_P(PSTR(OLED_RENDER_LAYER_3), false);
break; break;
case _SYMBOL: case _SYMBOL:
oled_write_ln_P(PSTR(OLED_RENDER_LAYER_SYMBOL), false); oled_write_P(PSTR(OLED_RENDER_LAYER_4), false);
break; break;
case _CONFIG: case _CONFIG:
oled_write_ln_P(PSTR(OLED_RENDER_LAYER_CONFIG), false); oled_write_P(PSTR(OLED_RENDER_LAYER_5), false);
break; break;
default: default:
oled_write_ln_P(PSTR(OLED_RENDER_LAYER_BASE), false); switch (get_highest_layer(default_layer_state)) {
case _DEFAULT_LAYER_2:
oled_write_P(PSTR(OLED_RENDER_DEFAULT_LAYER2), false);
break;
case _DEFAULT_LAYER_3:
oled_write_P(PSTR(OLED_RENDER_DEFAULT_LAYER3), false);
break;
default:
oled_write_P(PSTR(OLED_RENDER_DEFAULT_LAYER1), false);
break;
}
break; break;
} }
oled_write_ln_P(PSTR(" "),false); }
// Graphic to show which layer on the stack is enabled
void render_layer_state_graphic(void) {
switch (get_highest_layer(layer_state)) { switch (get_highest_layer(layer_state)) {
case _NAVIGATION: case _NAVIGATION:
@ -68,42 +62,51 @@ void render_layer_state(void) {
} }
// Shows the Host LED State (Num lock, caps lock , scroll lock) // Shows the Host LED State (Num lock, caps lock , scroll lock)
void render_keylock_status(void) { void render_keylock_status(bool vertical) {
if (vertical) {
oled_write_ln_P(PSTR(OLED_RENDER_KEYLOCK_NAME), false); oled_write_ln_P(PSTR(OLED_RENDER_KEYLOCK_NAME), false);
oled_write_P(PSTR(" "), false); oled_write_P(PSTR(" "), false);
}
host_keyboard_led_state().num_lock ? oled_write_P(num_on, false ) : oled_write_P(num_off, false ); host_keyboard_led_state().num_lock ? oled_write_P(num_on, false ) : oled_write_P(num_off, false );
host_keyboard_led_state().caps_lock || is_caps_word_on() ? oled_write_P(caps_on, false ) : oled_write_P(caps_off, false ); host_keyboard_led_state().caps_lock || is_caps_word_on() ? oled_write_P(caps_on, false ) : oled_write_P(caps_off, false );
host_keyboard_led_state().scroll_lock ? oled_write_ln_P(scroll_on, false ) : oled_write_ln_P(scroll_off, false ); host_keyboard_led_state().scroll_lock ? oled_write_P(scroll_on, false ) : oled_write_P(scroll_off, false );
} }
// Indicates which modifies are enabled // Indicates which modifies are enabled
void render_mod_status(void) { void render_mod_status(bool vertical) {
uint8_t current_mod = get_mods(); uint8_t current_mod = get_mods();
uint8_t current_osm = get_oneshot_mods(); uint8_t current_osm = get_oneshot_mods();
if (vertical) {
oled_write_ln_P(PSTR(OLED_RENDER_MODS_NAME), false); oled_write_ln_P(PSTR(OLED_RENDER_MODS_NAME), false);
oled_write_P(PSTR(" "), false); oled_write_P(PSTR(" "), false);
}
(current_mod | current_osm) & MOD_MASK_SHIFT ? oled_write_P(shift_on, false) : oled_write_P(shift_off, false ); (current_mod | current_osm) & MOD_MASK_SHIFT ? oled_write_P(shift_on, false) : oled_write_P(shift_off, false );
(current_mod | current_osm) & MOD_MASK_CTRL ? oled_write_P(ctrl_on, false ) : oled_write_P(ctrl_off, false ); (current_mod | current_osm) & MOD_MASK_CTRL ? oled_write_P(ctrl_on, false ) : oled_write_P(ctrl_off, false );
if (vertical) {
oled_write_P(PSTR(" "), false); oled_write_P(PSTR(" "), false);
}
(current_mod | current_osm) & MOD_MASK_ALT ? oled_write_P(alt_on, false ): oled_write_P(alt_off, false ); (current_mod | current_osm) & MOD_MASK_ALT ? oled_write_P(alt_on, false ): oled_write_P(alt_off, false );
(current_mod | current_osm) & MOD_MASK_GUI ? oled_write_P(gui_on, false ): oled_write_P(gui_off, false ); (current_mod | current_osm) & MOD_MASK_GUI ? oled_write_P(gui_on, false ): oled_write_P(gui_off, false );
} }
// Indicates which features are turned on or off
void render_feature_status(void) {
// Indicates which features are turned on or off
void render_feature_status(bool vertical) {
if (vertical) {
oled_write_ln_P(PSTR(OLED_RENDER_FEATURE_NAME), false); oled_write_ln_P(PSTR(OLED_RENDER_FEATURE_NAME), false);
oled_write_P(PSTR(" "), false); oled_write_P(PSTR(" "), false);
}
#if defined(RGB_MATRIX_ENABLE) #if defined(RGB_MATRIX_ENABLE)
rgb_matrix_is_enabled() ? oled_write_P(rgb_on, false) : oled_write_P(rgb_off, false); rgb_matrix_is_enabled() ? oled_write_P(rgb_on, false) : oled_write_P(rgb_off, false);
@ -114,7 +117,9 @@ oled_write_P(PSTR(" "), false);
// only works on master side // only works on master side
drag_scroll_is_enabled() ? oled_write_P(dragscr_on, false) : oled_write_P(dragscr_off, false); drag_scroll_is_enabled() ? oled_write_P(dragscr_on, false) : oled_write_P(dragscr_off, false);
if (vertical) {
oled_write_P(PSTR(" "), false); oled_write_P(PSTR(" "), false);
}
#if defined(AUDIO_ENABLE) #if defined(AUDIO_ENABLE)
is_audio_on() ? oled_write_P(sound_on, false) : oled_write_P(sound_off, false); is_audio_on() ? oled_write_P(sound_on, false) : oled_write_P(sound_off, false);
@ -134,36 +139,80 @@ oled_write_P(PSTR(" "), false);
// Coordinate the OLED rendering // Coordinate the OLED rendering
bool oled_task_user(void) { bool oled_task_user(void) {
#if defined(OLED_DISPLAY_128X64)
if (is_keyboard_master()) {
oled_set_cursor(0,0);
render_layer_state();
oled_set_cursor(0,1);
oled_write_P(sep_v, false);
oled_set_cursor(0,4);
render_mod_status(false);
oled_set_cursor(0,5);
oled_write_P(sep_v, false);
oled_set_cursor(0,7);
render_keylock_status(false);
oled_set_cursor(13,7);
render_feature_status(false);
oled_set_cursor(15,3);
oled_write_P(klor_small_face_1, false);
oled_set_cursor(15,4);
oled_write_P(klor_small_face_2, false);
} else {
oled_set_cursor(0,0);
oled_write_raw_P(klor_face, sizeof(klor_face));
}
#else
//process_record_user is only processed on master side //process_record_user is only processed on master side
//split side OLED does not respond to key presses custom behaviors //split side OLED does not respond to key presses custom behaviors
if (is_keyboard_master()) { if (is_keyboard_master()) {
render_keylock_status(); oled_set_cursor(0,0);
render_keylock_status(true);
oled_write_ln_P(PSTR(" "), false); oled_set_cursor(0,3);
render_feature_status(); render_feature_status(true);
#if defined(WPM_ENABLE) #if defined(WPM_ENABLE)
oled_write_ln_P(PSTR(" "), false);
oled_write_ln_P(PSTR(OLED_RENDER_WPM_NAME), false); oled_set_cursor(0,7);
oled_write_P(PSTR(" "), false); oled_write_P(PSTR(OLED_RENDER_WPM_NAME), false);
oled_set_cursor(1,8);
oled_write_P(get_u8_str(get_current_wpm(), ' '), false); oled_write_P(get_u8_str(get_current_wpm(), ' '), false);
render_luna(); render_luna();
#endif //WPM_ENABLE #endif //WPM_ENABLE
} else { } else {
render_default_layer_state(); oled_set_cursor(0,0);
render_layer_state(); render_layer_state();
oled_write_ln_P(PSTR(" "), false); oled_set_cursor(0,2);
render_mod_status(); render_layer_state_graphic();
oled_write_ln_P(PSTR(" "), false); oled_set_cursor(0,7);
render_mod_status(true);
oled_set_cursor(0,13);
oled_write_P(qmk_logo_small, false); oled_write_P(qmk_logo_small, false);
} }
#endif
return false; return false;
} }
@ -172,8 +221,12 @@ bool oled_task_user(void) {
oled_rotation_t oled_init_user(oled_rotation_t rotation) { oled_rotation_t oled_init_user(oled_rotation_t rotation) {
//OLED_ROTATION_270 for Rollow/Corne/Swoop //OLED_ROTATION_270 for Rollow/Corne/Swoop
//OLED_ROTATION_0 for KLOR //OLED_ROTATION_180 for KLOR
#if defined(OLED_DISPLAY_128X64)
return OLED_ROTATION_180;
#else
return OLED_ROTATION_270; return OLED_ROTATION_270;
#endif
} }

View file

@ -7,31 +7,42 @@
#define OLED_RENDER_FEATURE_NAME "Feat" #define OLED_RENDER_FEATURE_NAME "Feat"
#define OLED_RENDER_WPM_NAME "Wpm" #define OLED_RENDER_WPM_NAME "Wpm"
#define OLED_RENDER_LAYOUT_QWERTY "QWRTY" #if defined(OLED_DISPLAY_128X64)
#define OLED_RENDER_LAYOUT_COLEMAK_DH "CLMAK" # define OLED_RENDER_DEFAULT_LAYER1 "QWERTY "
#define OLED_RENDER_LAYOUT_GAME "GAME" # define OLED_RENDER_DEFAULT_LAYER2 "COLEMAK DH"
# define OLED_RENDER_DEFAULT_LAYER3 "GAME "
#define OLED_RENDER_LAYER_BASE " Def" # define OLED_RENDER_LAYER_2 "Navigation"
#define OLED_RENDER_LAYER_NAVIGATION " Nav" # define OLED_RENDER_LAYER_3 "Number "
#define OLED_RENDER_LAYER_NUMBER " Num" # define OLED_RENDER_LAYER_4 "Symbol "
#define OLED_RENDER_LAYER_SYMBOL " Sym" # define OLED_RENDER_LAYER_5 "Config "
#define OLED_RENDER_LAYER_CONFIG " Cfg" #else
//128x32 are ? x 5 char wide
# define OLED_RENDER_DEFAULT_LAYER1 "Qwrty"
# define OLED_RENDER_DEFAULT_LAYER2 "Clmak"
# define OLED_RENDER_DEFAULT_LAYER3 "Game "
# define OLED_RENDER_LAYER_2 " Nav "
# define OLED_RENDER_LAYER_3 " Num "
# define OLED_RENDER_LAYER_4 " Sym "
# define OLED_RENDER_LAYER_5 " Cfg "
#endif
// LUNA PET Variables // LUNA PET Variables
#if defined(WPM_ENABLE) #if defined(WPM_ENABLE)
# define OLED_LUNA_X 0 # define OLED_LUNA_X 0
# define OLED_LUNA_Y 5 # define OLED_LUNA_Y 13
# define OLED_LUNA_MIN_WALK_SPEED 10 # define OLED_LUNA_MIN_WALK_SPEED 10
# define OLED_LUNA_MIN_RUN_SPEED 40 # define OLED_LUNA_MIN_RUN_SPEED 40
# define OLED_LUNA_ANIM_FRAME_DURATION 200 // how long each frame lasts in ms # define OLED_LUNA_ANIM_FRAME_DURATION 200 // how long each frame lasts in ms
# define OLED_LUNA_ANIM_SIZE 96 // number of bytes in array. If you change sprites, minimize for adequate firmware size. max is 1024 # define OLED_LUNA_ANIM_SIZE 96 // number of bytes in array. If you change sprites, minimize for adequate firmware size. max is 1024
#endif //WPM_ENABLE #endif //WPM_ENABLE
void render_default_layer_state(void);
void render_layer_state(void); void render_layer_state(void);
void render_keylock_status(void); void render_layer_state_graphic(void);
void render_mod_status(void); void render_keylock_status(bool vertical);
void render_feature_status(void); void render_mod_status(bool vertical);
void render_feature_status(bool vertical);
static const char PROGMEM scroll_off[] = {0x8D, 0}; static const char PROGMEM scroll_off[] = {0x8D, 0};
@ -108,8 +119,12 @@ static const char PROGMEM qmk_logo_small[] = {
0xE1, 0xDD, 0xDE, 0xDF, 0xE1, 0x00 0xE1, 0xDD, 0xDE, 0xDF, 0xE1, 0x00
}; };
#if defined(OLED_DISPLAY_128X64)
#if defined(KEYBOARD_klor) static const char PROGMEM sep_v[] = {0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0xC0, 0};
static const char PROGMEM klor_small_face_1[] = {0x80, 0x81, 0x82, 0x83, 0x84, 0xE1, 0};
static const char PROGMEM klor_small_face_2[] = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xE1, 0};
static const char PROGMEM klor_face[] = { static const char PROGMEM klor_face[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -146,4 +161,4 @@ static const char PROGMEM klor_face[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
}; };
#endif // KEYBOARD_klor #endif // OLED_DISPLAY_128X64

View file

@ -1,111 +0,0 @@
#pragma once
#include "t4corun.h"
#define OLED_RENDER_KEYLOCK_NAME "Lock"
#define OLED_RENDER_MODS_NAME "Mods"
#define OLED_RENDER_FEATURE_NAME "Feat"
#define OLED_RENDER_WPM_NAME "Wpm"
#define OLED_RENDER_LAYOUT_QWERTY "QWRTY"
#define OLED_RENDER_LAYOUT_COLEMAK_DH "CLMAK"
#define OLED_RENDER_LAYOUT_GAME "GAME"
#define OLED_RENDER_LAYER_BASE " Def"
#define OLED_RENDER_LAYER_NAVIGATION " Nav"
#define OLED_RENDER_LAYER_NUMBER " Num"
#define OLED_RENDER_LAYER_SYMBOL " Sym"
#define OLED_RENDER_LAYER_CONFIG " Cfg"
// LUNA PET Variables
#if defined(WPM_ENABLE)
# define OLED_LUNA_X 0
# define OLED_LUNA_Y 13
# define OLED_LUNA_MIN_WALK_SPEED 10
# define OLED_LUNA_MIN_RUN_SPEED 40
# define OLED_LUNA_ANIM_FRAME_DURATION 200 // how long each frame lasts in ms
# define OLED_LUNA_ANIM_SIZE 96 // number of bytes in array. If you change sprites, minimize for adequate firmware size. max is 1024
#endif //WPM_ENABLE
void render_default_layer_state(void);
void render_layer_state(void);
void render_keylock_status(void);
void render_mod_status(void);
void render_feature_status(void);
static const char PROGMEM scroll_off[] = {0x8D, 0};
static const char PROGMEM scroll_on[] = {0x8E, 0};
static const char PROGMEM num_off[] = {0xAD, 0};
static const char PROGMEM num_on[] = {0xAE, 0};
static const char PROGMEM caps_off[] = {0xCD, 0};
static const char PROGMEM caps_on[] = {0xCE, 0};
static const char PROGMEM shift_off[] = {0x85, 0x86, 0};
static const char PROGMEM shift_on[] = {0x87, 0x88, 0};
static const char PROGMEM ctrl_off[] = {0xA9, 0xAA, 0};
static const char PROGMEM ctrl_on[] = {0xAB, 0xAC, 0};
static const char PROGMEM alt_off[] = {0xA5, 0xA6, 0};
static const char PROGMEM alt_on[] = {0xA7, 0xA8, 0};
static const char PROGMEM gui_off[] = {0x89, 0x8A, 0};
static const char PROGMEM gui_on[] = {0x8B, 0x8C, 0};
static const char PROGMEM rgb_off[] = {0xC5, 0xC6, 0};
static const char PROGMEM rgb_on[] = {0xC7, 0xC8, 0};
static const char PROGMEM dragscr_off[] = {0xC9, 0xCA, 0};
static const char PROGMEM dragscr_on[] = {0xCB, 0xCC, 0};
static const char PROGMEM sound_off[] = {0x8F, 0x90, 0};
static const char PROGMEM sound_on[] = {0xAF, 0xB0, 0};
static const char PROGMEM haptic_off[] = {0x91, 0x92, 0};
static const char PROGMEM haptic_on[] = {0xB1, 0xB2, 0};
static const char PROGMEM lyr_cfg[] = {
0xE1, 0xD1, 0xD2, 0xD3, 0xE1,
0xE1, 0xBA, 0xBB, 0xBC, 0xE1,
0xE1, 0xB7, 0xB8, 0xB9, 0xE1,
0xE1, 0xD7, 0xD8, 0xD9, 0xE1, 0x00
};
static const char PROGMEM lyr_sym[] = {
0xE1, 0x97, 0x98, 0x99, 0xE1,
0xE1, 0xDA, 0xDB, 0xDC, 0xE1,
0xE1, 0xB7, 0xB8, 0xB9, 0xE1,
0xE1, 0xD7, 0xD8, 0xD9, 0xE1, 0x00
};
static const char PROGMEM lyr_num[] = {
0xE1, 0x97, 0x98, 0x99, 0xE1,
0xE1, 0x9A, 0x9B, 0x9C, 0xE1,
0xE1, 0xBA, 0xBB, 0xBC, 0xE1,
0xE1, 0xD7, 0xD8, 0xD9, 0xE1, 0x00
};
static const char PROGMEM lyr_nav[] = {
0xE1, 0x97, 0x98, 0x99, 0xE1,
0xE1, 0xB7, 0xB8, 0xB9, 0xE1,
0xE1, 0xDA, 0xDB, 0xDC, 0xE1,
0xE1, 0xD7, 0xD8, 0xD9, 0xE1, 0x00
};
static const char PROGMEM lyr_def[] = {
0xE1, 0x97, 0x98, 0x99, 0xE1,
0xE1, 0xB7, 0xB8, 0xB9, 0xE1,
0xE1, 0x9A, 0x9B, 0x9C, 0xE1,
0xE1, 0xD4, 0xD5, 0xD6, 0xE1, 0x00
};
static const char PROGMEM qmk_logo_small[] = {
0xE1, 0x9D, 0x9E, 0x9F, 0xE1,
0xE1, 0xBD, 0xBE, 0xBF, 0xE1,
0xE1, 0xDD, 0xDE, 0xDF, 0xE1, 0x00
};

View file

@ -1,44 +0,0 @@
#include "oled64.h"
#if defined(WPM_ENABLE)
#include "luna.c"
#endif
// Coordinate the OLED rendering
bool oled_task_user(void) {
if (is_keyboard_master()) {
/*
oled_write_P(PSTR("123456789012345678901"), true);
oled_write_ln_P(PSTR("2"), false);
oled_write_ln_P(PSTR("3"), false);
oled_write_ln_P(PSTR("4"), false);
oled_write_ln_P(PSTR("5"), false);
oled_write_ln_P(PSTR("6"), false);
oled_write_ln_P(PSTR("7"), false);
oled_write_ln_P(PSTR("8"), false);
//oled_write_ln_P(PSTR("9"), false);
*/
#if defined(WPM_ENABLE)
render_luna();
#endif
} else {
oled_write_raw_P(klor_face, sizeof(klor_face));
}
return false;
}
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
//OLED_ROTATION_270 for Rollow/Corne/Swoop
//OLED_ROTATION_180 for KLOR
return OLED_ROTATION_270;
}

View file

@ -53,11 +53,7 @@ INTROSPECTION_KEYMAP_C += features/combo.c
# include optional code for enabled features for each keyboard # include optional code for enabled features for each keyboard
ifeq ($(strip $(OLED_ENABLE)), yes) ifeq ($(strip $(OLED_ENABLE)), yes)
ifeq ($(filter $(KEYBOARD), klor klor/2040),) SRC += features/oled.c
SRC += features/oled32.c
else
SRC += features/oled64.c
endif
endif endif
ifeq ($(strip $(AUDIO_ENABLE)), yes) ifeq ($(strip $(AUDIO_ENABLE)), yes)