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 | |
parent | 13b93c212da202d210ba28657f1b1c3e06d56655 (diff) | |
download | qmk_firmware-85a0c494ffde3dfa555bbe32bb083eec85b9ca72.tar.gz qmk_firmware-85a0c494ffde3dfa555bbe32bb083eec85b9ca72.zip |
[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')
4 files changed, 128 insertions, 14 deletions
diff --git a/keyboards/helix/rev3_5rows/keymaps/five_rows/config.h b/keyboards/helix/rev3_5rows/keymaps/five_rows/config.h index b9961f5c48..e1c124f419 100644 --- a/keyboards/helix/rev3_5rows/keymaps/five_rows/config.h +++ b/keyboards/helix/rev3_5rows/keymaps/five_rows/config.h @@ -29,7 +29,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. 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 <http://www.gnu.org/licenses/>. + */ + +#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<<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 diff --git a/keyboards/helix/rev3_5rows/keymaps/five_rows/rules.mk b/keyboards/helix/rev3_5rows/keymaps/five_rows/rules.mk index d10972bbdf..b0cca79129 100644 --- a/keyboards/helix/rev3_5rows/keymaps/five_rows/rules.mk +++ b/keyboards/helix/rev3_5rows/keymaps/five_rows/rules.mk @@ -14,9 +14,11 @@ ENCODER_ENABLE = no LTO_ENABLE = no # if firmware size over limit, try this option LED_ANIMATIONS = yes +CUSTOM_DELAY = yes + ifneq ($(strip $(HELIX)),) define KEYMAP_OPTION_PARSE - # parse 'dispoff', 'consle', 'back', 'oled', 'no-ani', 'mini-ani', 'lto', 'no-lto', 'no-enc', 'scan' + # parse 'dispoff', 'consle', 'back', 'oled', 'no-ani', 'mini-ani', 'lto', 'no-lto', 'no-enc', 'scan', 'scan-api' $(if $(SHOW_PARCE),$(info parse .$1.)) #debug ifeq ($(strip $1),dispoff) OLED_ENABLE = no @@ -63,6 +65,11 @@ ifneq ($(strip $(HELIX)),) # see docs/newbs_testing_debugging.md DEBUG_MATRIX_SCAN_RATE_ENABLE = yes endif + ifeq ($(strip $1),scan-api) + # use DEBUG_MATRIX_SCAN_RATE + # see docs/newbs_testing_debugging.md + DEBUG_MATRIX_SCAN_RATE_ENABLE = api + endif endef # end of KEYMAP_OPTION_PARSE COMMA=, @@ -80,6 +87,10 @@ ifeq ($(strip $(LED_ANIMATIONS)), mini) OPT_DEFS += -DLED_ANIMATIONS_LEVEL=1 endif +ifeq ($(strip $(CUSTOM_DELAY)),yes) + SRC += matrix_output_unselect_delay.c +endif + ifeq ($(strip $(DEBUG_CONFIG)), yes) OPT_DEFS += -DDEBUG_CONFIG endif |