diff options
| author | IBNobody <IBNobody@users.noreply.github.com> | 2016-09-07 23:50:58 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2016-09-07 23:50:58 -0500 |
| commit | fe2aed0d1c8d1535c160755b76186972071aed02 (patch) | |
| tree | da8f2cb3cad4a7dc7e5e95b3594c98740b0da398 | |
| parent | 558f3ec1eb325caf706efc15e2fab26121aba442 (diff) | |
| download | qmk_firmware-fe2aed0d1c8d1535c160755b76186972071aed02.tar.gz qmk_firmware-fe2aed0d1c8d1535c160755b76186972071aed02.zip | |
Added User Print - A "light" console out option (#8)
User print disables the normal print messages in the body of QMK/TMK
code and is meant as a lightweight alternative to NOPRINT. Use it when
you only want to do a spot of debugging but lack flash resources for
allowing all of the codebase to print (and store their wasteful
strings).
| -rw-r--r-- | keyboards/planck/keymaps/pvc/Makefile | 2 | ||||
| -rw-r--r-- | keyboards/planck/keymaps/pvc/config.h | 12 | ||||
| -rw-r--r-- | tmk_core/common/avr/xprintf.h | 6 | ||||
| -rw-r--r-- | tmk_core/common/mbed/xprintf.cpp | 2 | ||||
| -rw-r--r-- | tmk_core/common/mbed/xprintf.h | 2 | ||||
| -rw-r--r-- | tmk_core/common/print.h | 168 |
6 files changed, 166 insertions, 26 deletions
diff --git a/keyboards/planck/keymaps/pvc/Makefile b/keyboards/planck/keymaps/pvc/Makefile index 19c3abc6c..b2ff961fa 100644 --- a/keyboards/planck/keymaps/pvc/Makefile +++ b/keyboards/planck/keymaps/pvc/Makefile | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) | 6 | BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000) |
| 7 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) | 7 | MOUSEKEY_ENABLE = yes # Mouse keys(+4700) |
| 8 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) | 8 | EXTRAKEY_ENABLE = yes # Audio control and System control(+450) |
| 9 | CONSOLE_ENABLE = no # Console for debug(+400) | 9 | CONSOLE_ENABLE = yes # Console for debug(+400) |
| 10 | COMMAND_ENABLE = yes # Commands for debug and configuration | 10 | COMMAND_ENABLE = yes # Commands for debug and configuration |
| 11 | NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work | 11 | NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work |
| 12 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality | 12 | BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality |
diff --git a/keyboards/planck/keymaps/pvc/config.h b/keyboards/planck/keymaps/pvc/config.h index 1113372b0..1004c8b99 100644 --- a/keyboards/planck/keymaps/pvc/config.h +++ b/keyboards/planck/keymaps/pvc/config.h | |||
| @@ -68,10 +68,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 68 | */ | 68 | */ |
| 69 | 69 | ||
| 70 | /* disable debug print */ | 70 | /* disable debug print */ |
| 71 | //#define NO_DEBUG | 71 | #ifndef NO_DEBUG |
| 72 | # define NO_DEBUG | ||
| 73 | #endif | ||
| 72 | 74 | ||
| 73 | /* disable print */ | 75 | /* disable print */ |
| 74 | //#define NO_PRINT | 76 | // #ifndef NO_PRINT |
| 77 | // # define NO_PRINT | ||
| 78 | // #endif | ||
| 79 | |||
| 80 | /* Only print user print statements */ | ||
| 81 | #define USER_PRINT | ||
| 82 | |||
| 75 | 83 | ||
| 76 | /* disable action features */ | 84 | /* disable action features */ |
| 77 | //#define NO_ACTION_LAYER | 85 | //#define NO_ACTION_LAYER |
diff --git a/tmk_core/common/avr/xprintf.h b/tmk_core/common/avr/xprintf.h index e53c0dd8e..08d9f93a0 100644 --- a/tmk_core/common/avr/xprintf.h +++ b/tmk_core/common/avr/xprintf.h | |||
| @@ -56,8 +56,8 @@ void xitoa(long value, char radix, char width); | |||
| 56 | #define xfprintf(func, format, ...) __xfprintf(func, PSTR(format), ##__VA_ARGS__) | 56 | #define xfprintf(func, format, ...) __xfprintf(func, PSTR(format), ##__VA_ARGS__) |
| 57 | 57 | ||
| 58 | void __xprintf(const char *format_p, ...); /* Send formatted string to the registered device */ | 58 | void __xprintf(const char *format_p, ...); /* Send formatted string to the registered device */ |
| 59 | void __xsprintf(char*, const char *format_p, ...); /* Put formatted string to the memory */ | 59 | // void __xsprintf(char*, const char *format_p, ...); /* Put formatted string to the memory */ |
| 60 | void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */ | 60 | // void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */ |
| 61 | 61 | ||
| 62 | /* Format string is placed in the ROM. The format flags is similar to printf(). | 62 | /* Format string is placed in the ROM. The format flags is similar to printf(). |
| 63 | 63 | ||
| @@ -88,7 +88,7 @@ void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send format | |||
| 88 | /*-----------------------------------------------------------------------------*/ | 88 | /*-----------------------------------------------------------------------------*/ |
| 89 | char xatoi(char **str, long *ret); | 89 | char xatoi(char **str, long *ret); |
| 90 | 90 | ||
| 91 | /* Get value of the numeral string. | 91 | /* Get value of the numeral string. |
| 92 | 92 | ||
| 93 | str | 93 | str |
| 94 | Pointer to pointer to source string | 94 | Pointer to pointer to source string |
diff --git a/tmk_core/common/mbed/xprintf.cpp b/tmk_core/common/mbed/xprintf.cpp index 3647ece75..b1aac2c99 100644 --- a/tmk_core/common/mbed/xprintf.cpp +++ b/tmk_core/common/mbed/xprintf.cpp | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #define STRING_STACK_LIMIT 120 | 7 | #define STRING_STACK_LIMIT 120 |
| 8 | 8 | ||
| 9 | //TODO | 9 | //TODO |
| 10 | int xprintf(const char* format, ...) { return 0; } | 10 | int __xprintf(const char* format, ...) { return 0; } |
| 11 | 11 | ||
| 12 | #if 0 | 12 | #if 0 |
| 13 | /* mbed Serial */ | 13 | /* mbed Serial */ |
diff --git a/tmk_core/common/mbed/xprintf.h b/tmk_core/common/mbed/xprintf.h index 26bc529e5..1e7a48c06 100644 --- a/tmk_core/common/mbed/xprintf.h +++ b/tmk_core/common/mbed/xprintf.h | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | extern "C" { | 7 | extern "C" { |
| 8 | #endif | 8 | #endif |
| 9 | 9 | ||
| 10 | int xprintf(const char *format, ...); | 10 | int __xprintf(const char *format, ...); |
| 11 | 11 | ||
| 12 | #ifdef __cplusplus | 12 | #ifdef __cplusplus |
| 13 | } | 13 | } |
diff --git a/tmk_core/common/print.h b/tmk_core/common/print.h index a1352527f..8836c0fc7 100644 --- a/tmk_core/common/print.h +++ b/tmk_core/common/print.h | |||
| @@ -36,40 +36,140 @@ | |||
| 36 | 36 | ||
| 37 | #ifndef NO_PRINT | 37 | #ifndef NO_PRINT |
| 38 | 38 | ||
| 39 | #if defined(__AVR__) /* __AVR__ */ | ||
| 39 | 40 | ||
| 40 | #if defined(__AVR__) | 41 | # include "avr/xprintf.h" |
| 41 | 42 | ||
| 42 | #include "avr/xprintf.h" | 43 | # ifdef USER_PRINT /* USER_PRINT */ |
| 43 | #define print(s) xputs(PSTR(s)) | ||
| 44 | #define println(s) xputs(PSTR(s "\r\n")) | ||
| 45 | 44 | ||
| 46 | #ifdef __cplusplus | 45 | // Remove normal print defines |
| 46 | # define print(s) | ||
| 47 | # define println(s) | ||
| 48 | # undef xprintf | ||
| 49 | # define xprintf(fmt, ...) | ||
| 50 | |||
| 51 | // Create user print defines | ||
| 52 | # define uprint(s) xputs(PSTR(s)) | ||
| 53 | # define uprintln(s) xputs(PSTR(s "\r\n")) | ||
| 54 | # define uprintf(fmt, ...) __xprintf(PSTR(fmt), ##__VA_ARGS__) | ||
| 55 | |||
| 56 | # else /* NORMAL PRINT */ | ||
| 57 | |||
| 58 | // Create user & normal print defines | ||
| 59 | # define print(s) xputs(PSTR(s)) | ||
| 60 | # define println(s) xputs(PSTR(s "\r\n")) | ||
| 61 | # define uprint(s) print(s) | ||
| 62 | # define uprintln(s) println(s) | ||
| 63 | # define uprintf(fmt, ...) xprintf(fmt, ...) | ||
| 64 | |||
| 65 | # endif /* USER_PRINT / NORMAL PRINT */ | ||
| 66 | |||
| 67 | # ifdef __cplusplus | ||
| 47 | extern "C" | 68 | extern "C" |
| 48 | #endif | 69 | # endif |
| 70 | |||
| 49 | /* function pointer of sendchar to be used by print utility */ | 71 | /* function pointer of sendchar to be used by print utility */ |
| 50 | void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); | 72 | void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); |
| 51 | 73 | ||
| 52 | #elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */ | 74 | #elif defined(PROTOCOL_CHIBIOS) /* PROTOCOL_CHIBIOS */ |
| 75 | |||
| 76 | # include "chibios/printf.h" | ||
| 77 | |||
| 78 | # ifdef USER_PRINT /* USER_PRINT */ | ||
| 79 | |||
| 80 | // Remove normal print defines | ||
| 81 | # define print(s) | ||
| 82 | # define println(s) | ||
| 83 | # define xprintf(fmt, ...) | ||
| 84 | |||
| 85 | // Create user print defines | ||
| 86 | # define uprint(s) printf(s) | ||
| 87 | # define uprintln(s) printf(s "\r\n") | ||
| 88 | # define uprintf printf | ||
| 89 | |||
| 90 | # else /* NORMAL PRINT */ | ||
| 91 | |||
| 92 | // Create user & normal print defines | ||
| 93 | # define print(s) printf(s) | ||
| 94 | # define println(s) printf(s "\r\n") | ||
| 95 | # define xprintf printf | ||
| 96 | # define uprint(s) printf(s) | ||
| 97 | # define uprintln(s) printf(s "\r\n") | ||
| 98 | # define uprintf printf | ||
| 53 | 99 | ||
| 54 | #include "chibios/printf.h" | 100 | # endif /* USER_PRINT / NORMAL PRINT */ |
| 55 | 101 | ||
| 56 | #define print(s) printf(s) | 102 | #elif defined(__arm__) /* __arm__ */ |
| 57 | #define println(s) printf(s "\r\n") | ||
| 58 | #define xprintf printf | ||
| 59 | 103 | ||
| 60 | #elif defined(__arm__) /* __AVR__ */ | 104 | # include "mbed/xprintf.h" |
| 61 | 105 | ||
| 62 | #include "mbed/xprintf.h" | 106 | # ifdef USER_PRINT /* USER_PRINT */ |
| 63 | 107 | ||
| 64 | #define print(s) xprintf(s) | 108 | // Remove normal print defines |
| 65 | #define println(s) xprintf(s "\r\n") | 109 | # define print(s) |
| 110 | # define println(s) | ||
| 111 | # define xprintf(fmt, ...) | ||
| 112 | |||
| 113 | // Create user print defines | ||
| 114 | # define uprintf(fmt, ...) __xprintf(fmt, ...) | ||
| 115 | # define uprint(s) xprintf(s) | ||
| 116 | # define uprintln(s) xprintf(s "\r\n") | ||
| 117 | |||
| 118 | # else /* NORMAL PRINT */ | ||
| 119 | |||
| 120 | // Create user & normal print defines | ||
| 121 | # define xprintf(fmt, ...) __xprintf(fmt, ...) | ||
| 122 | # define print(s) xprintf(s) | ||
| 123 | # define println(s) xprintf(s "\r\n") | ||
| 124 | # define uprint(s) print(s) | ||
| 125 | # define uprintln(s) println(s) | ||
| 126 | # define uprintf(fmt, ...) xprintf(fmt, ...) | ||
| 127 | |||
| 128 | # endif /* USER_PRINT / NORMAL PRINT */ | ||
| 66 | 129 | ||
| 67 | /* TODO: to select output destinations: UART/USBSerial */ | 130 | /* TODO: to select output destinations: UART/USBSerial */ |
| 68 | #define print_set_sendchar(func) | 131 | # define print_set_sendchar(func) |
| 132 | |||
| 133 | #endif /* __AVR__ / PROTOCOL_CHIBIOS / __arm__ */ | ||
| 134 | |||
| 135 | // User print disables the normal print messages in the body of QMK/TMK code and | ||
| 136 | // is meant as a lightweight alternative to NOPRINT. Use it when you only want to do | ||
| 137 | // a spot of debugging but lack flash resources for allowing all of the codebase to | ||
| 138 | // print (and store their wasteful strings). | ||
| 139 | // | ||
| 140 | // !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!! | ||
| 141 | // | ||
| 142 | #ifdef USER_PRINT | ||
| 69 | 143 | ||
| 70 | #endif /* __AVR__ */ | 144 | // Disable normal print |
| 145 | #define print_dec(data) | ||
| 146 | #define print_decs(data) | ||
| 147 | #define print_hex4(data) | ||
| 148 | #define print_hex8(data) | ||
| 149 | #define print_hex16(data) | ||
| 150 | #define print_hex32(data) | ||
| 151 | #define print_bin4(data) | ||
| 152 | #define print_bin8(data) | ||
| 153 | #define print_bin16(data) | ||
| 154 | #define print_bin32(data) | ||
| 155 | #define print_bin_reverse8(data) | ||
| 156 | #define print_bin_reverse16(data) | ||
| 157 | #define print_bin_reverse32(data) | ||
| 158 | #define print_val_dec(v) | ||
| 159 | #define print_val_decs(v) | ||
| 160 | #define print_val_hex8(v) | ||
| 161 | #define print_val_hex16(v) | ||
| 162 | #define print_val_hex32(v) | ||
| 163 | #define print_val_bin8(v) | ||
| 164 | #define print_val_bin16(v) | ||
| 165 | #define print_val_bin32(v) | ||
| 166 | #define print_val_bin_reverse8(v) | ||
| 167 | #define print_val_bin_reverse16(v) | ||
| 168 | #define print_val_bin_reverse32(v) | ||
| 71 | 169 | ||
| 170 | #else /* NORMAL_PRINT */ | ||
| 72 | 171 | ||
| 172 | //Enable normal print | ||
| 73 | /* decimal */ | 173 | /* decimal */ |
| 74 | #define print_dec(i) xprintf("%u", i) | 174 | #define print_dec(i) xprintf("%u", i) |
| 75 | #define print_decs(i) xprintf("%d", i) | 175 | #define print_decs(i) xprintf("%d", i) |
| @@ -99,6 +199,39 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); | |||
| 99 | #define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v)) | 199 | #define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v)) |
| 100 | #define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v)) | 200 | #define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v)) |
| 101 | 201 | ||
| 202 | #endif /* USER_PRINT / NORMAL_PRINT */ | ||
| 203 | |||
| 204 | // User Print | ||
| 205 | |||
| 206 | /* decimal */ | ||
| 207 | #define uprint_dec(i) uprintf("%u", i) | ||
| 208 | #define uprint_decs(i) uprintf("%d", i) | ||
| 209 | /* hex */ | ||
| 210 | #define uprint_hex4(i) uprintf("%X", i) | ||
| 211 | #define uprint_hex8(i) uprintf("%02X", i) | ||
| 212 | #define uprint_hex16(i) uprintf("%04X", i) | ||
| 213 | #define uprint_hex32(i) uprintf("%08lX", i) | ||
| 214 | /* binary */ | ||
| 215 | #define uprint_bin4(i) uprintf("%04b", i) | ||
| 216 | #define uprint_bin8(i) uprintf("%08b", i) | ||
| 217 | #define uprint_bin16(i) uprintf("%016b", i) | ||
| 218 | #define uprint_bin32(i) uprintf("%032lb", i) | ||
| 219 | #define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i)) | ||
| 220 | #define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i)) | ||
| 221 | #define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i)) | ||
| 222 | /* print value utility */ | ||
| 223 | #define uprint_val_dec(v) uprintf(#v ": %u\n", v) | ||
| 224 | #define uprint_val_decs(v) uprintf(#v ": %d\n", v) | ||
| 225 | #define uprint_val_hex8(v) uprintf(#v ": %X\n", v) | ||
| 226 | #define uprint_val_hex16(v) uprintf(#v ": %02X\n", v) | ||
| 227 | #define uprint_val_hex32(v) uprintf(#v ": %04lX\n", v) | ||
| 228 | #define uprint_val_bin8(v) uprintf(#v ": %08b\n", v) | ||
| 229 | #define uprint_val_bin16(v) uprintf(#v ": %016b\n", v) | ||
| 230 | #define uprint_val_bin32(v) uprintf(#v ": %032lb\n", v) | ||
| 231 | #define uprint_val_bin_reverse8(v) uprintf(#v ": %08b\n", bitrev(v)) | ||
| 232 | #define uprint_val_bin_reverse16(v) uprintf(#v ": %016b\n", bitrev16(v)) | ||
| 233 | #define uprint_val_bin_reverse32(v) uprintf(#v ": %032lb\n", bitrev32(v)) | ||
| 234 | |||
| 102 | #else /* NO_PRINT */ | 235 | #else /* NO_PRINT */ |
| 103 | 236 | ||
| 104 | #define xprintf(fmt, ...) | 237 | #define xprintf(fmt, ...) |
| @@ -143,5 +276,4 @@ void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t)); | |||
| 143 | #define pbin_reverse(data) print_bin_reverse8(data) | 276 | #define pbin_reverse(data) print_bin_reverse8(data) |
| 144 | #define pbin_reverse16(data) print_bin_reverse16(data) | 277 | #define pbin_reverse16(data) print_bin_reverse16(data) |
| 145 | 278 | ||
| 146 | |||
| 147 | #endif | 279 | #endif |
