1
0
Fork 0

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)
This commit is contained in:
Sergey Vlasov 2021-05-31 00:47:44 +03:00 committed by GitHub
parent 305cca9a5e
commit 3aca3d3572
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,7 +15,6 @@
*/ */
#include QMK_KEYBOARD_H #include QMK_KEYBOARD_H
#include <stdio.h>
enum layer_names { enum layer_names {
_BASE, _BASE,
@ -123,7 +122,7 @@ static const char PROGMEM merge_logo[] = {
0x01, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00 0x01, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00
}; };
int current_wpm = 0; uint8_t current_wpm = 0;
static void print_status_narrow(void) { static void print_status_narrow(void) {
oled_set_cursor(0,1); oled_set_cursor(0,1);
@ -159,10 +158,15 @@ static void print_status_narrow(void) {
//oled_write_ln_P(PSTR(" "), false); //oled_write_ln_P(PSTR(" "), false);
oled_write_P(PSTR("-----"), false); oled_write_P(PSTR("-----"), false);
// WPM counter Start (Need #include <stdio.h> to work) // WPM counter Start
char wpm_str[8]; char wpm_str[5];
oled_set_cursor(0,13); oled_set_cursor(0,13);
sprintf(wpm_str, " %03d", current_wpm); wpm_str[4] = '\0';
uint8_t n = current_wpm;
wpm_str[3] = '0' + n % 10;
wpm_str[2] = '0' + (n /= 10) % 10;
wpm_str[1] = '0' + n / 10;
wpm_str[0] = ' ';
oled_write(wpm_str, false); oled_write(wpm_str, false);
oled_set_cursor(0,14); oled_set_cursor(0,14);
oled_write(" WPM ", false); oled_write(" WPM ", false);