From cf96dd1a11f0a50d6e22df3f7f6d10a8b0f9f37a Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Sat, 20 Nov 2021 15:36:20 -0800 Subject: [PATCH 1/9] [Docs] Squeezing space out of AVR --- docs/_summary.md | 1 + docs/cleaning_up_avr.md | 142 ++++++++++++++++++++++++++++++++++++++++ docs/syllabus.md | 1 + 3 files changed, 144 insertions(+) create mode 100644 docs/cleaning_up_avr.md diff --git a/docs/_summary.md b/docs/_summary.md index 2f6309e41d1d..b5cf5232aed9 100644 --- a/docs/_summary.md +++ b/docs/_summary.md @@ -13,6 +13,7 @@ * [Troubleshooting QMK](faq_misc.md) * [Debugging QMK](faq_debug.md) * [Keymap FAQ](faq_keymap.md) + * [Squeezing Space from AVR](cleaning_up_avr.md) * [Glossary](reference_glossary.md) * Configurator diff --git a/docs/cleaning_up_avr.md b/docs/cleaning_up_avr.md new file mode 100644 index 000000000000..55ca5873c093 --- /dev/null +++ b/docs/cleaning_up_avr.md @@ -0,0 +1,142 @@ +# Squeezing the most out of AVR + +First, death to AVR. It's old, it's slow, it's past time to retire it. The only issue with migrating away is the shortage. + +If you want to reduce the compiled size of your firmware, there are a number of options to do so. + +## rules.mk +First and foremost is enabling link time optimization. To do so, add this to your rules.mk: +```make +LTO_ENABLE = yes +``` +This will cause the final step to take longer, but should get you a smaller compiled size. This also disables Action Functions, and Action Macros, both of which are deprecated. +This will get you the most savings, in most situations. + +From there, disabling extraneous systems will help. Eg: +```make +CONSOLE_ENABLE = no +COMMAND_ENABlE = no +MOUSEKEY_ENABLE = no +EXTRAKEY_ENABLE = no +``` +This disables some of the functionality that you may not need. But note that extrakeys disables stuff like the media keys and system volume control. + +If that doesn't help, then there are some additional features that you can disable: +```make +SPACE_CADET_ENABLE = no +GRAVE_ESC_ENABLE = no +MAGIC_ENABLE = no +``` +These features are enabled by default, but may not be needed. Double check to make sure, though. +Biggest is "magic", as this is the magic keycodes, that control things like NKRO toggling, GUI and ALT/CTRL swapping, etc. Disabling it will disable those functions. + +## config.h +If you've done all of that, and you don't want to disable featuse like RGB, Audio, OLEDs, etc, there are some additional options that you can add to your config.h that can help. + +Starting with Lock Key support. If you have an Cherry MX Lock switch (lucky you!), you don't want to do this. But chances are, you don't. In that case, add this to your `config.h`: +```c +#undef LOCKING_SUPPORT_ENABLE +#undef LOCKING_RESYNC_ENABLE +``` + + +Oneshots. If you're not using these, you can disable the feature by adding this to your `config.h`: +```c +#define NO_ACTION_ONESHOT +``` +The same with tapping keys (mod tap, layer tap, etc) +```c +#define NO_ACTION_TAPPING +``` +## Audio + + +If you're using the Audio feature, by default that includes the music mode feature. This tranlates matrix positions into notes. It's neat for sure, but most likely, you're not using it. You can disable it by adding this to your `config.h`: +```c +#define NO_MUSIC_MODE +``` +And by adding this to your `rules.mk` +```make +MUSIC_ENABLE = no +``` + +## Layers + +There are also some options for layers. For instance, you can outright remove them, by adding this to your config.h: +```c +#define NO_ACTION_LAYER +``` +Or, probably better, you can limit the number of layers that the firmware uses: +```c +#define LAYER_STATE_8BIT +``` +or +```c +#define LAYER_STATE_16BIT +``` + +## RGB + +If you're using RGB on your board, both RGB Light (Underglow) and RGB Matrix (per key RGB) require defines to enable different animations. For RGB Light: +```c +#undef RGBLIGHT_ANIMATIONS +#undef RGBLIGHT_EFFECT_BREATHING +#undef RGBLIGHT_EFFECT_RAINBOW_MOOD +#undef RGBLIGHT_EFFECT_RAINBOW_SWIRL +#undef RGBLIGHT_EFFECT_SNAKE +#undef RGBLIGHT_EFFECT_KNIGHT +#undef RGBLIGHT_EFFECT_CHRISTMAS +#undef RGBLIGHT_EFFECT_STATIC_GRADIENT +#undef RGBLIGHT_EFFECT_RGB_TEST +#undef RGBLIGHT_EFFECT_ALTERNATING +#undef RGBLIGHT_EFFECT_TWINKLE +``` + +For RGB Matrix, these are explicitly enabled, as well (or will be shortly)... +To disable a specific animation: +```c +#undef ENABLE_RGB_MATRIX_ALPHAS_MODS +#undef ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN +#undef ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT +#undef ENABLE_RGB_MATRIX_BREATHING +#undef ENABLE_RGB_MATRIX_BAND_SAT +#undef ENABLE_RGB_MATRIX_BAND_VAL +#undef ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT +#undef ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL +#undef ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT +#undef ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL +#undef ENABLE_RGB_MATRIX_CYCLE_ALL +#undef ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT +#undef ENABLE_RGB_MATRIX_CYCLE_UP_DOWN +#undef ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON +#undef ENABLE_RGB_MATRIX_CYCLE_OUT_IN +#undef ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL +#undef ENABLE_RGB_MATRIX_CYCLE_PINWHEEL +#undef ENABLE_RGB_MATRIX_CYCLE_SPIRAL +#undef ENABLE_RGB_MATRIX_DUAL_BEACON +#undef ENABLE_RGB_MATRIX_RAINBOW_BEACON +#undef ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS +#undef ENABLE_RGB_MATRIX_RAINDROPS +#undef ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS +#undef ENABLE_RGB_MATRIX_HUE_BREATHING +#undef ENABLE_RGB_MATRIX_HUE_PENDULUM +#undef ENABLE_RGB_MATRIX_HUE_WAVE +#undef ENABLE_RGB_MATRIX_PIXEL_FRACTAL +#undef ENABLE_RGB_MATRIX_PIXEL_RAIN + +#undef ENABLE_RGB_MATRIX_TYPING_HEATMAP +#undef ENABLE_RGB_MATRIX_DIGITAL_RAIN + +#undef ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE +#undef ENABLE_RGB_MATRIX_SOLID_REACTIVE +#undef ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE +#undef ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE +#undef ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS +#undef ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS +#undef ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS +#undef ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS +#undef ENABLE_RGB_MATRIX_SPLASH +#undef ENABLE_RGB_MATRIX_MULTISPLASH +#undef ENABLE_RGB_MATRIX_SOLID_SPLASH +#undef ENABLE_RGB_MATRIX_SOLID_MULTISPLASH +``` diff --git a/docs/syllabus.md b/docs/syllabus.md index ccb382c5d4a9..96717155e0dd 100644 --- a/docs/syllabus.md +++ b/docs/syllabus.md @@ -31,6 +31,7 @@ These topics start to dig into some of the features that QMK supports. You don't * [RGB Lighting](feature_rgblight.md) * [RGB Matrix](feature_rgb_matrix.md) * [Tap-Hold Configuration](tap_hold.md) + * [Squeezing Space from AVR](cleaning_up_avr.md) * **Learn More About Keymaps** * [Keymaps](keymap.md) * [Custom Functions and Keycodes](custom_quantum_functions.md) From df28ad80930e331b6a7ef867d9a4df3fffa1519a Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Sat, 20 Nov 2021 15:52:21 -0800 Subject: [PATCH 2/9] Add more info --- docs/cleaning_up_avr.md | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/docs/cleaning_up_avr.md b/docs/cleaning_up_avr.md index 55ca5873c093..fba33c68a9a3 100644 --- a/docs/cleaning_up_avr.md +++ b/docs/cleaning_up_avr.md @@ -4,7 +4,7 @@ First, death to AVR. It's old, it's slow, it's past time to retire it. The onl If you want to reduce the compiled size of your firmware, there are a number of options to do so. -## rules.mk +## `rules.mk` Settings First and foremost is enabling link time optimization. To do so, add this to your rules.mk: ```make LTO_ENABLE = yes @@ -30,7 +30,8 @@ MAGIC_ENABLE = no These features are enabled by default, but may not be needed. Double check to make sure, though. Biggest is "magic", as this is the magic keycodes, that control things like NKRO toggling, GUI and ALT/CTRL swapping, etc. Disabling it will disable those functions. -## config.h +## `config.h` Settings + If you've done all of that, and you don't want to disable featuse like RGB, Audio, OLEDs, etc, there are some additional options that you can add to your config.h that can help. Starting with Lock Key support. If you have an Cherry MX Lock switch (lucky you!), you don't want to do this. But chances are, you don't. In that case, add this to your `config.h`: @@ -48,8 +49,7 @@ The same with tapping keys (mod tap, layer tap, etc) ```c #define NO_ACTION_TAPPING ``` -## Audio - +## Audio Settings If you're using the Audio feature, by default that includes the music mode feature. This tranlates matrix positions into notes. It's neat for sure, but most likely, you're not using it. You can disable it by adding this to your `config.h`: ```c @@ -75,7 +75,7 @@ or #define LAYER_STATE_16BIT ``` -## RGB +## RGB Settings If you're using RGB on your board, both RGB Light (Underglow) and RGB Matrix (per key RGB) require defines to enable different animations. For RGB Light: ```c @@ -140,3 +140,16 @@ To disable a specific animation: #undef ENABLE_RGB_MATRIX_SOLID_SPLASH #undef ENABLE_RGB_MATRIX_SOLID_MULTISPLASH ``` + +# Final Thoughts + +If you've done all of this, and your firmware is still too large, then it's time. It's time to consider making the switch to ARM. Unfortunately, right now is the worst possible time for that, due to the silicon shortage, and supply chain issues. Getting an ARM chip is difficult, at best, and significantly overpriced, at worst. + -- Drashna + +That said, there are a number of Pro Micro replacements with ARM controllers: +* [Proton C](https://qmk.fm/proton-c/) (out of stock) +* [Bonsai C](https://github.com/customMK/Bonsai-C) (Open Source, DIY/PCBA) +* [Raspberry Pi 2040](https://www.sparkfun.com/products/18288) (not currently supported, no ETA) + +There are other, non-Pro Micro compatible boards out there. The most popular being: +* [WeAct Blackpill F411](https://www.aliexpress.com/item/1005001456186625.html) (~$6 USD) From b388031147c179b9c00452287c0f1a7284195f5b Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Sat, 20 Nov 2021 15:54:17 -0800 Subject: [PATCH 3/9] Apply suggestions from code review Co-authored-by: Nick Brassel --- docs/cleaning_up_avr.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/cleaning_up_avr.md b/docs/cleaning_up_avr.md index fba33c68a9a3..6a6f3340908a 100644 --- a/docs/cleaning_up_avr.md +++ b/docs/cleaning_up_avr.md @@ -2,7 +2,7 @@ First, death to AVR. It's old, it's slow, it's past time to retire it. The only issue with migrating away is the shortage. -If you want to reduce the compiled size of your firmware, there are a number of options to do so. +If you need to reduce the compiled size of your firmware, there are a number of options to do so. ## `rules.mk` Settings First and foremost is enabling link time optimization. To do so, add this to your rules.mk: @@ -15,7 +15,7 @@ This will get you the most savings, in most situations. From there, disabling extraneous systems will help. Eg: ```make CONSOLE_ENABLE = no -COMMAND_ENABlE = no +COMMAND_ENABLE = no MOUSEKEY_ENABLE = no EXTRAKEY_ENABLE = no ``` @@ -66,18 +66,18 @@ There are also some options for layers. For instance, you can outright remove t ```c #define NO_ACTION_LAYER ``` -Or, probably better, you can limit the number of layers that the firmware uses: +Or, probably better, you can limit the number of layers that the firmware uses -- if you're using less than 8 layers in total: ```c #define LAYER_STATE_8BIT ``` -or +or if you require up to 16 layers instead: ```c #define LAYER_STATE_16BIT ``` ## RGB Settings -If you're using RGB on your board, both RGB Light (Underglow) and RGB Matrix (per key RGB) require defines to enable different animations. For RGB Light: +If you're using RGB on your board, both RGB Light (Underglow) and RGB Matrix (per key RGB) now require defines to enable different animations. For RGB Light: ```c #undef RGBLIGHT_ANIMATIONS #undef RGBLIGHT_EFFECT_BREATHING @@ -92,7 +92,7 @@ If you're using RGB on your board, both RGB Light (Underglow) and RGB Matrix (pe #undef RGBLIGHT_EFFECT_TWINKLE ``` -For RGB Matrix, these are explicitly enabled, as well (or will be shortly)... +For RGB Matrix, these need to be explicitly enabled, as well: To disable a specific animation: ```c #undef ENABLE_RGB_MATRIX_ALPHAS_MODS From 657605e2a4acb1cc60bfbcfbb277b02ddd96a94d Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Sat, 20 Nov 2021 16:02:36 -0800 Subject: [PATCH 4/9] Add oled section --- docs/cleaning_up_avr.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/docs/cleaning_up_avr.md b/docs/cleaning_up_avr.md index 6a6f3340908a..3e39f8bd4595 100644 --- a/docs/cleaning_up_avr.md +++ b/docs/cleaning_up_avr.md @@ -75,6 +75,38 @@ or if you require up to 16 layers instead: #define LAYER_STATE_16BIT ``` +## OLED tweaks + +One place you can save a bunch of space here is by not using `sprintf` or `snprintf`. This function call takes up ~1.5kB of firmware space, and can be rewritten. For instance, WPM uses this a lot. + +You can convert this: +```c + sprintf(wpm_str, "WPM: %03d", get_current_wpm()); +``` +into this: +```c + uint8_t n = get_current_wpm(); + char wpm_counter[4]; + wpm_counter[3] = '\0'; + wpm_counter[2] = '0' + n % 10; + wpm_counter[1] = (n /= 10) % 10 ? '0' + (n) % 10 : (n / 10) % 10 ? '0' : ' '; + wpm_counter[0] = n / 10 ? '0' + n / 10 : ' '; + oled_write_P(PSTR("WPM: "), false); + oled_write(wpm_counter, false); +``` +which outputs `WPM: 5`. Or this: +```c + uint8_t n = get_current_wpm(); + char wpm_counter[4]; + wpm_counter[3] = '\0'; + wpm_counter[2] = '0' + n % 10; + wpm_counter[1] = '0' + (n /= 10) % 10; + wpm_counter[0] = '0' + n / 10 ; + oled_write_P(PSTR("WPM: "), false); + oled_write(wpm_counter, false); +``` +which outputs `WPM: 005`. + ## RGB Settings If you're using RGB on your board, both RGB Light (Underglow) and RGB Matrix (per key RGB) now require defines to enable different animations. For RGB Light: From 45f57c40cce7a15c3c3b9156a9c844fa537446be Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 22 Nov 2021 08:17:24 -0800 Subject: [PATCH 5/9] Apply suggestions from code review Co-authored-by: Nick Brassel --- docs/cleaning_up_avr.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/docs/cleaning_up_avr.md b/docs/cleaning_up_avr.md index 3e39f8bd4595..347a426fdc53 100644 --- a/docs/cleaning_up_avr.md +++ b/docs/cleaning_up_avr.md @@ -1,6 +1,6 @@ # Squeezing the most out of AVR -First, death to AVR. It's old, it's slow, it's past time to retire it. The only issue with migrating away is the shortage. +AVR is severely resource-constrained, and QMK is close to the point where support for AVR needs to be moved to legacy status as newer development is unable to fit into those constraints. If you need to reduce the compiled size of your firmware, there are a number of options to do so. @@ -12,7 +12,7 @@ LTO_ENABLE = yes This will cause the final step to take longer, but should get you a smaller compiled size. This also disables Action Functions, and Action Macros, both of which are deprecated. This will get you the most savings, in most situations. -From there, disabling extraneous systems will help. Eg: +From there, disabling extraneous systems will help -- e.g.: ```make CONSOLE_ENABLE = no COMMAND_ENABLE = no @@ -21,26 +21,24 @@ EXTRAKEY_ENABLE = no ``` This disables some of the functionality that you may not need. But note that extrakeys disables stuff like the media keys and system volume control. -If that doesn't help, then there are some additional features that you can disable: +If that isn't enough to get your firmware down to size, then there are some additional features that you can disable: ```make SPACE_CADET_ENABLE = no GRAVE_ESC_ENABLE = no MAGIC_ENABLE = no ``` These features are enabled by default, but may not be needed. Double check to make sure, though. -Biggest is "magic", as this is the magic keycodes, that control things like NKRO toggling, GUI and ALT/CTRL swapping, etc. Disabling it will disable those functions. +Largest in size is "magic" -- the QMK magic keycodes -- which control things like NKRO toggling, GUI and ALT/CTRL swapping, etc. Disabling it will disable those functions. ## `config.h` Settings -If you've done all of that, and you don't want to disable featuse like RGB, Audio, OLEDs, etc, there are some additional options that you can add to your config.h that can help. +If you've done all of that, and you don't want to disable features like RGB, Audio, OLEDs, etc, there are some additional options that you can add to your config.h that can help. Starting with Lock Key support. If you have an Cherry MX Lock switch (lucky you!), you don't want to do this. But chances are, you don't. In that case, add this to your `config.h`: ```c #undef LOCKING_SUPPORT_ENABLE #undef LOCKING_RESYNC_ENABLE ``` - - Oneshots. If you're not using these, you can disable the feature by adding this to your `config.h`: ```c #define NO_ACTION_ONESHOT @@ -109,7 +107,7 @@ which outputs `WPM: 005`. ## RGB Settings -If you're using RGB on your board, both RGB Light (Underglow) and RGB Matrix (per key RGB) now require defines to enable different animations. For RGB Light: +If you're using RGB on your board, both RGB Light (Underglow) and RGB Matrix (per key RGB) now require defines to enable different animations -- some keyboards enable a lot of animations by default, so you can generally gain back some space by disabling specific animations if you don't use them.. For RGB Light you can disable these in your keymap's `config.h`: ```c #undef RGBLIGHT_ANIMATIONS #undef RGBLIGHT_EFFECT_BREATHING @@ -124,8 +122,7 @@ If you're using RGB on your board, both RGB Light (Underglow) and RGB Matrix (pe #undef RGBLIGHT_EFFECT_TWINKLE ``` -For RGB Matrix, these need to be explicitly enabled, as well: -To disable a specific animation: +For RGB Matrix, these need to be explicitly enabled as well. To disable any that were enabled by the keyboard, add one or more of these to your keymap's `config.h`: ```c #undef ENABLE_RGB_MATRIX_ALPHAS_MODS #undef ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN From d949787df8539cd651b7d56aff5cb42ec55c1261 Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Mon, 22 Nov 2021 08:36:23 -0800 Subject: [PATCH 6/9] Update layers and intro wording --- docs/cleaning_up_avr.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/cleaning_up_avr.md b/docs/cleaning_up_avr.md index 347a426fdc53..5a585d4e53f6 100644 --- a/docs/cleaning_up_avr.md +++ b/docs/cleaning_up_avr.md @@ -1,8 +1,8 @@ # Squeezing the most out of AVR -AVR is severely resource-constrained, and QMK is close to the point where support for AVR needs to be moved to legacy status as newer development is unable to fit into those constraints. +AVR is severely resource-constrained, and as QMK continues to grow, it is approaching a point where support for AVR may need to be moved to legacy status as newer development is unable to fit into those constraints. -If you need to reduce the compiled size of your firmware, there are a number of options to do so. +However, if you need to reduce the compiled size of your firmware, there are a number of options to do so. ## `rules.mk` Settings First and foremost is enabling link time optimization. To do so, add this to your rules.mk: @@ -60,11 +60,9 @@ MUSIC_ENABLE = no ## Layers -There are also some options for layers. For instance, you can outright remove them, by adding this to your config.h: -```c -#define NO_ACTION_LAYER -``` -Or, probably better, you can limit the number of layers that the firmware uses -- if you're using less than 8 layers in total: +There are also some options for layers, that can reduce the firmware size. All of these settngs are for your `config.h`. + +You can limit the number of layers that the firmware uses -- if you're using less than 8 layers in total: ```c #define LAYER_STATE_8BIT ``` @@ -72,6 +70,11 @@ or if you require up to 16 layers instead: ```c #define LAYER_STATE_16BIT ``` +Or if you're not using layers at all, you can outright remove the functionality altogether: +```c +#define NO_ACTION_LAYER +``` + ## OLED tweaks From 3f5b8c53c22d91a059890f75b76531e9399c3b09 Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Mon, 22 Nov 2021 08:39:11 -0800 Subject: [PATCH 7/9] Rename doc file --- docs/_summary.md | 2 +- docs/{cleaning_up_avr.md => squeezing_avr.md} | 0 docs/syllabus.md | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename docs/{cleaning_up_avr.md => squeezing_avr.md} (100%) diff --git a/docs/_summary.md b/docs/_summary.md index b5cf5232aed9..09af2250250b 100644 --- a/docs/_summary.md +++ b/docs/_summary.md @@ -13,7 +13,7 @@ * [Troubleshooting QMK](faq_misc.md) * [Debugging QMK](faq_debug.md) * [Keymap FAQ](faq_keymap.md) - * [Squeezing Space from AVR](cleaning_up_avr.md) + * [Squeezing Space from AVR](squeezing_avr.md) * [Glossary](reference_glossary.md) * Configurator diff --git a/docs/cleaning_up_avr.md b/docs/squeezing_avr.md similarity index 100% rename from docs/cleaning_up_avr.md rename to docs/squeezing_avr.md diff --git a/docs/syllabus.md b/docs/syllabus.md index 96717155e0dd..f5cdea21820e 100644 --- a/docs/syllabus.md +++ b/docs/syllabus.md @@ -31,7 +31,7 @@ These topics start to dig into some of the features that QMK supports. You don't * [RGB Lighting](feature_rgblight.md) * [RGB Matrix](feature_rgb_matrix.md) * [Tap-Hold Configuration](tap_hold.md) - * [Squeezing Space from AVR](cleaning_up_avr.md) + * [Squeezing Space from AVR](squeezing_avr.md) * **Learn More About Keymaps** * [Keymaps](keymap.md) * [Custom Functions and Keycodes](custom_quantum_functions.md) From 037ed72c96cf35752fd44094601ab0ba3d0653a7 Mon Sep 17 00:00:00 2001 From: Drashna Jael're Date: Mon, 22 Nov 2021 09:02:51 -0800 Subject: [PATCH 8/9] add get_u8_str support --- docs/squeezing_avr.md | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/docs/squeezing_avr.md b/docs/squeezing_avr.md index 5a585d4e53f6..3dd9f66f0145 100644 --- a/docs/squeezing_avr.md +++ b/docs/squeezing_avr.md @@ -86,25 +86,13 @@ You can convert this: ``` into this: ```c - uint8_t n = get_current_wpm(); - char wpm_counter[4]; - wpm_counter[3] = '\0'; - wpm_counter[2] = '0' + n % 10; - wpm_counter[1] = (n /= 10) % 10 ? '0' + (n) % 10 : (n / 10) % 10 ? '0' : ' '; - wpm_counter[0] = n / 10 ? '0' + n / 10 : ' '; oled_write_P(PSTR("WPM: "), false); - oled_write(wpm_counter, false); + oled_write(get_u8_str(get_current_wpm(), ' '), false); ``` which outputs `WPM: 5`. Or this: ```c - uint8_t n = get_current_wpm(); - char wpm_counter[4]; - wpm_counter[3] = '\0'; - wpm_counter[2] = '0' + n % 10; - wpm_counter[1] = '0' + (n /= 10) % 10; - wpm_counter[0] = '0' + n / 10 ; oled_write_P(PSTR("WPM: "), false); - oled_write(wpm_counter, false); + oled_write(get_u8_str(get_current_wpm(), '0'), false); ``` which outputs `WPM: 005`. From 5abcd99d4afbbcbbd0cda01fde7c7518f6a06f5e Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Mon, 22 Nov 2021 09:09:51 -0800 Subject: [PATCH 9/9] oled clarifications Co-authored-by: Nick Brassel --- docs/squeezing_avr.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/squeezing_avr.md b/docs/squeezing_avr.md index 3dd9f66f0145..f48643d1d9c7 100644 --- a/docs/squeezing_avr.md +++ b/docs/squeezing_avr.md @@ -82,15 +82,20 @@ One place you can save a bunch of space here is by not using `sprintf` or `snpri You can convert this: ```c + // OLD CODE + char wpm_str[4] = {0}; sprintf(wpm_str, "WPM: %03d", get_current_wpm()); + oled_write(wpm_str, ' '), false); ``` into this: ```c + // NEW CODE oled_write_P(PSTR("WPM: "), false); oled_write(get_u8_str(get_current_wpm(), ' '), false); ``` which outputs `WPM: 5`. Or this: ```c + // NEW CODE oled_write_P(PSTR("WPM: "), false); oled_write(get_u8_str(get_current_wpm(), '0'), false); ```