diff options
| author | Sergey Vlasov <sigprof@gmail.com> | 2021-05-31 00:47:44 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-30 14:47:44 -0700 |
| commit | 3aca3d35729bd7445846918cb5a171c5e0093997 (patch) | |
| tree | 48b8ca3726724cc8ede6eb84cf2ac5b975c84288 | |
| parent | 305cca9a5e4c304b0883f07ab4e5de9a493fdbd9 (diff) | |
| download | qmk_firmware-3aca3d35729bd7445846918cb5a171c5e0093997.tar.gz qmk_firmware-3aca3d35729bd7445846918cb5a171c5e0093997.zip | |
merge/um70:via: Avoid sprintf() to make the code fit into flash (#12919)
The code using sprintf() did not fit into flash when `merge/um70:via`
was compiled with avr-gcc 5.4.0:
* The firmware is too large! 29756/28672 (1084 bytes over)
Replacing `sprintf(wpm_str, " %03d", current_wpm);` with custom
formatting code reduces the firmware size by 1504 bytes, which is enough
to make the `merge/um70:via` firmware fit:
* The firmware size is approaching the maximum - 28252/28672 (98%, 420 bytes free)
| -rw-r--r-- | keyboards/merge/um70/keymaps/via/keymap.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/keyboards/merge/um70/keymaps/via/keymap.c b/keyboards/merge/um70/keymaps/via/keymap.c index 59483e64a..17cb2895c 100644 --- a/keyboards/merge/um70/keymaps/via/keymap.c +++ b/keyboards/merge/um70/keymaps/via/keymap.c | |||
| @@ -15,7 +15,6 @@ | |||
| 15 | */ | 15 | */ |
| 16 | 16 | ||
| 17 | #include QMK_KEYBOARD_H | 17 | #include QMK_KEYBOARD_H |
| 18 | #include <stdio.h> | ||
| 19 | 18 | ||
| 20 | enum layer_names { | 19 | enum layer_names { |
| 21 | _BASE, | 20 | _BASE, |
| @@ -123,7 +122,7 @@ static const char PROGMEM merge_logo[] = { | |||
| 123 | 0x01, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 | 122 | 0x01, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 |
| 124 | }; | 123 | }; |
| 125 | 124 | ||
| 126 | int current_wpm = 0; | 125 | uint8_t current_wpm = 0; |
| 127 | 126 | ||
| 128 | static void print_status_narrow(void) { | 127 | static void print_status_narrow(void) { |
| 129 | oled_set_cursor(0,1); | 128 | oled_set_cursor(0,1); |
| @@ -159,10 +158,15 @@ static void print_status_narrow(void) { | |||
| 159 | //oled_write_ln_P(PSTR(" "), false); | 158 | //oled_write_ln_P(PSTR(" "), false); |
| 160 | oled_write_P(PSTR("-----"), false); | 159 | oled_write_P(PSTR("-----"), false); |
| 161 | 160 | ||
| 162 | // WPM counter Start (Need #include <stdio.h> to work) | 161 | // WPM counter Start |
| 163 | char wpm_str[8]; | 162 | char wpm_str[5]; |
| 164 | oled_set_cursor(0,13); | 163 | oled_set_cursor(0,13); |
| 165 | sprintf(wpm_str, " %03d", current_wpm); | 164 | wpm_str[4] = '\0'; |
| 165 | uint8_t n = current_wpm; | ||
| 166 | wpm_str[3] = '0' + n % 10; | ||
| 167 | wpm_str[2] = '0' + (n /= 10) % 10; | ||
| 168 | wpm_str[1] = '0' + n / 10; | ||
| 169 | wpm_str[0] = ' '; | ||
| 166 | oled_write(wpm_str, false); | 170 | oled_write(wpm_str, false); |
| 167 | oled_set_cursor(0,14); | 171 | oled_set_cursor(0,14); |
| 168 | oled_write(" WPM ", false); | 172 | oled_write(" WPM ", false); |
