From 85a0c494ffde3dfa555bbe32bb083eec85b9ca72 Mon Sep 17 00:00:00 2001 From: Takeshi ISHII <2170248+mtei@users.noreply.github.com> Date: Thu, 16 Sep 2021 18:47:47 +0900 Subject: [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 --- keyboards/helix/rev2/keymaps/five_rows/config.h | 6 +- .../five_rows/matrix_output_unselect_delay.c | 31 ++++++++ .../helix/rev2/keymaps/five_rows/oled_display.c | 92 +++++++++++++++++++--- keyboards/helix/rev2/keymaps/five_rows/rules.mk | 13 ++- .../helix/rev3_5rows/keymaps/five_rows/config.h | 6 +- .../five_rows/matrix_output_unselect_delay.c | 31 ++++++++ .../rev3_5rows/keymaps/five_rows/oled_display.c | 92 +++++++++++++++++++--- .../helix/rev3_5rows/keymaps/five_rows/rules.mk | 13 ++- 8 files changed, 256 insertions(+), 28 deletions(-) create mode 100644 keyboards/helix/rev2/keymaps/five_rows/matrix_output_unselect_delay.c create mode 100644 keyboards/helix/rev3_5rows/keymaps/five_rows/matrix_output_unselect_delay.c (limited to 'keyboards/helix') diff --git a/keyboards/helix/rev2/keymaps/five_rows/config.h b/keyboards/helix/rev2/keymaps/five_rows/config.h index b9961f5c48..e1c124f419 100644 --- a/keyboards/helix/rev2/keymaps/five_rows/config.h +++ b/keyboards/helix/rev2/keymaps/five_rows/config.h @@ -29,7 +29,11 @@ along with this program. If not, see . see tmk_core/common/action_tapping.c */ #undef OLED_UPDATE_INTERVAL -#define OLED_UPDATE_INTERVAL 50 +#ifdef DEBUG_MATRIX_SCAN_RATE +# define OLED_UPDATE_INTERVAL 500 +#else +# define OLED_UPDATE_INTERVAL 50 +#endif // place overrides here diff --git a/keyboards/helix/rev2/keymaps/five_rows/matrix_output_unselect_delay.c b/keyboards/helix/rev2/keymaps/five_rows/matrix_output_unselect_delay.c new file mode 100644 index 0000000000..a093afe0a4 --- /dev/null +++ b/keyboards/helix/rev2/keymaps/five_rows/matrix_output_unselect_delay.c @@ -0,0 +1,31 @@ +/* Copyright 2021 mtei + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include QMK_KEYBOARD_H + +void matrix_output_unselect_delay(uint8_t line, bool key_pressed) { + /* If none of the keys are pressed, + * there is no need to wait for time for the next line. */ + if (key_pressed) { +# ifdef MATRIX_IO_DELAY +# if MATRIX_IO_DELAY > 0 + wait_us(MATRIX_IO_DELAY); +# endif +# else + wait_us(30); +# endif + } +} diff --git a/keyboards/helix/rev2/keymaps/five_rows/oled_display.c b/keyboards/helix/rev2/keymaps/five_rows/oled_display.c index 090e8aaec3..fcbd81c9b6 100644 --- a/keyboards/helix/rev2/keymaps/five_rows/oled_display.c +++ b/keyboards/helix/rev2/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<. see tmk_core/common/action_tapping.c */ #undef OLED_UPDATE_INTERVAL -#define OLED_UPDATE_INTERVAL 50 +#ifdef DEBUG_MATRIX_SCAN_RATE +# define OLED_UPDATE_INTERVAL 500 +#else +# define OLED_UPDATE_INTERVAL 50 +#endif // place overrides here diff --git a/keyboards/helix/rev3_5rows/keymaps/five_rows/matrix_output_unselect_delay.c b/keyboards/helix/rev3_5rows/keymaps/five_rows/matrix_output_unselect_delay.c new file mode 100644 index 0000000000..a093afe0a4 --- /dev/null +++ b/keyboards/helix/rev3_5rows/keymaps/five_rows/matrix_output_unselect_delay.c @@ -0,0 +1,31 @@ +/* Copyright 2021 mtei + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include QMK_KEYBOARD_H + +void matrix_output_unselect_delay(uint8_t line, bool key_pressed) { + /* If none of the keys are pressed, + * there is no need to wait for time for the next line. */ + if (key_pressed) { +# ifdef MATRIX_IO_DELAY +# if MATRIX_IO_DELAY > 0 + wait_us(MATRIX_IO_DELAY); +# endif +# else + wait_us(30); +# endif + } +} 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<