diff options
author | Takeshi ISHII <2170248+mtei@users.noreply.github.com> | 2021-09-16 18:47:47 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-16 18:47:47 +0900 |
commit | 85a0c494ffde3dfa555bbe32bb083eec85b9ca72 (patch) | |
tree | b845ecae039c676d9c88ca87c9493da90bd7b454 /keyboards/helix/rev3_5rows/keymaps/five_rows/oled_display.c | |
parent | 13b93c212da202d210ba28657f1b1c3e06d56655 (diff) |
[Keymap] Update Helix:five_rows OLED code (#14427)
* Stop using snprintf() in keymaps/five_rows/oled_display.c.
The binary size becomes 1350 bytes smaller.
make HELIX=verbose,core-oled helix/rev2/sc:five_rows
(104 bytes over) -> (95%, 1256 bytes free)
make helix/rev3_5rows:five_rows
(528 bytes over) -> (97%, 830 bytes free)
* add matrix scan rate display to OLED for keymaps/five_rows
* add matrix_output_unselect_delay.c to helix keymaps/five_rows
* add GPLv2 header
* apply review comment
Diffstat (limited to 'keyboards/helix/rev3_5rows/keymaps/five_rows/oled_display.c')
-rw-r--r-- | keyboards/helix/rev3_5rows/keymaps/five_rows/oled_display.c | 92 |
1 files changed, 80 insertions, 12 deletions
diff --git a/keyboards/helix/rev3_5rows/keymaps/five_rows/oled_display.c b/keyboards/helix/rev3_5rows/keymaps/five_rows/oled_display.c index 090e8aaec3..fcbd81c9b6 100644 --- a/keyboards/helix/rev3_5rows/keymaps/five_rows/oled_display.c +++ b/keyboards/helix/rev3_5rows/keymaps/five_rows/oled_display.c @@ -64,6 +64,55 @@ void matrix_update(struct CharacterMatrix *dest, } # endif +static char *sprint_decimal(char *buf, int data) { + if (data > 9) { + buf = sprint_decimal(buf, data/10); + } + *buf++ = "0123456789"[data%10]; + *buf = '\0'; + return buf; +} + +static char *sprint_hex(char *buf, uint32_t data) { + if (data > 0xf) { + buf = sprint_hex(buf, data/0x10); + } + *buf++ = "0123456789abcdef"[data & 0xf]; + *buf = '\0'; + return buf; +} + +char *sprints(char *buf, char *src) { + while (*src) { + *buf++ = *src++; + } + *buf = '\0'; + return buf; +} + +char *sprintx(char *buf, char *leadstr, uint32_t data) { + buf = sprints(buf, leadstr); + buf = sprint_hex(buf, data); + return buf; +} + +char *sprintd(char *buf, char *leadstr, int data) { + buf = sprints(buf, leadstr); + buf = sprint_decimal(buf, data); + return buf; +} + +char *sprint2d(char *buf, char *leadstr, int data) { + buf = sprints(buf, leadstr); + if (data > 99) { + return sprint_decimal(buf, data); + } + if (data < 10) { + *buf++ = ' '; + } + return sprint_decimal(buf, data); +} + # ifdef SSD1306OLED static void render_logo(struct CharacterMatrix *matrix) { # else @@ -76,20 +125,35 @@ static void render_logo(void) { 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4, 0}; oled_write_P(helix_logo, false); -# ifdef RGBLIGHT_ENABLE char buf[30]; + char *bufp; +# ifdef RGBLIGHT_ENABLE if (RGBLIGHT_MODES > 1 && rgblight_is_enabled()) { - snprintf(buf, sizeof(buf), " LED %2d: %d,%d,%d ", - rgblight_get_mode(), - rgblight_get_hue()/RGBLIGHT_HUE_STEP, - rgblight_get_sat()/RGBLIGHT_SAT_STEP, - rgblight_get_val()/RGBLIGHT_VAL_STEP); + bufp = sprint2d(buf, " LED ", rgblight_get_mode()); +# ifdef DEBUG_MATRIX_SCAN_RATE + bufp = sprintd(bufp, " scan:", get_matrix_scan_rate()); +# else + bufp = sprintd(bufp, ": ", rgblight_get_hue()/RGBLIGHT_HUE_STEP); + bufp = sprintd(bufp, ",", rgblight_get_sat()/RGBLIGHT_SAT_STEP); + bufp = sprintd(bufp, ",", rgblight_get_val()/RGBLIGHT_VAL_STEP); + bufp = sprints(bufp, " "); +# endif oled_write(buf, false); # ifndef SSD1306OLED } else { +# ifdef DEBUG_MATRIX_SCAN_RATE + bufp = sprintd(buf, " scan:", get_matrix_scan_rate()); + oled_write(buf, false); +# endif oled_write_P( PSTR("\n"), false); # endif } +# else +# ifdef DEBUG_MATRIX_SCAN_RATE + bufp = sprintd(buf, " scan:", get_matrix_scan_rate()); + bufp = sprints(bufp, " "); + oled_write(buf, false); +# endif # endif } @@ -142,6 +206,11 @@ void render_status(void) { int name_num; uint32_t lstate; oled_write_P(layer_names[current_default_layer], false); +# ifdef DEBUG_MATRIX_SCAN_RATE + char buf[16]; + sprintd(buf, " scan:", get_matrix_scan_rate()); + oled_write(buf, false); +# endif oled_write_P(PSTR("\n"), false); for (lstate = layer_state, name_num = 0; lstate && name_num < sizeof(layer_names)/sizeof(char *); @@ -152,14 +221,13 @@ void render_status(void) { } } } + oled_write_P(PSTR("\n"), false); // Host Keyboard LED Status - char led[40]; - snprintf(led, sizeof(led), "\n%s %s %s", - (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ", - (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ", - (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " "); - oled_write(led, false); + led_t led_state = host_keyboard_led_state(); + oled_write_P(led_state.num_lock ? PSTR("NUMLOCK ") : PSTR(" "), false); + oled_write_P(led_state.caps_lock ? PSTR("CAPS ") : PSTR(" "), false); + oled_write_P(led_state.scroll_lock ? PSTR("SCLK ") : PSTR(" "), false); } # ifdef SSD1306OLED |