aboutsummaryrefslogtreecommitdiff
path: root/quantum/logging/print.h
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/logging/print.h')
-rw-r--r--quantum/logging/print.h135
1 files changed, 135 insertions, 0 deletions
diff --git a/quantum/logging/print.h b/quantum/logging/print.h
new file mode 100644
index 000000000..8c055f549
--- /dev/null
+++ b/quantum/logging/print.h
@@ -0,0 +1,135 @@
1/* Copyright 2012 Jun Wako <wakojun@gmail.com> */
2/* Very basic print functions, intended to be used with usb_debug_only.c
3 * http://www.pjrc.com/teensy/
4 * Copyright (c) 2008 PJRC.COM, LLC
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25#pragma once
26
27#include <stdint.h>
28#include <stdbool.h>
29#include "util.h"
30#include "sendchar.h"
31#include "progmem.h"
32
33void print_set_sendchar(sendchar_func_t func);
34
35#ifndef NO_PRINT
36# if __has_include_next("_print.h")
37# include_next "_print.h" /* Include the platforms print.h */
38# else
39// Fall back to lib/printf
40# include "printf.h" // lib/printf/printf.h
41
42// Create user & normal print defines
43# define print(s) printf(s)
44# define println(s) printf(s "\r\n")
45# define xprintf printf
46# define uprint(s) printf(s)
47# define uprintln(s) printf(s "\r\n")
48# define uprintf printf
49
50# endif /* __has_include_next("_print.h") */
51#else /* NO_PRINT */
52# undef xprintf
53// Remove print defines
54# define print(s)
55# define println(s)
56# define xprintf(fmt, ...)
57# define uprintf(fmt, ...)
58# define uprint(s)
59# define uprintln(s)
60
61#endif /* NO_PRINT */
62
63#ifdef USER_PRINT
64// Remove normal print defines
65# undef print
66# undef println
67# undef xprintf
68# define print(s)
69# define println(s)
70# define xprintf(fmt, ...)
71#endif
72
73#define print_dec(i) xprintf("%u", i)
74#define print_decs(i) xprintf("%d", i)
75/* hex */
76#define print_hex4(i) xprintf("%X", i)
77#define print_hex8(i) xprintf("%02X", i)
78#define print_hex16(i) xprintf("%04X", i)
79#define print_hex32(i) xprintf("%08lX", i)
80/* binary */
81#define print_bin4(i) xprintf("%04b", i)
82#define print_bin8(i) xprintf("%08b", i)
83#define print_bin16(i) xprintf("%016b", i)
84#define print_bin32(i) xprintf("%032lb", i)
85#define print_bin_reverse8(i) xprintf("%08b", bitrev(i))
86#define print_bin_reverse16(i) xprintf("%016b", bitrev16(i))
87#define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i))
88/* print value utility */
89#define print_val_dec(v) xprintf(#v ": %u\n", v)
90#define print_val_decs(v) xprintf(#v ": %d\n", v)
91#define print_val_hex8(v) xprintf(#v ": %X\n", v)
92#define print_val_hex16(v) xprintf(#v ": %02X\n", v)
93#define print_val_hex32(v) xprintf(#v ": %04lX\n", v)
94#define print_val_bin8(v) xprintf(#v ": %08b\n", v)
95#define print_val_bin16(v) xprintf(#v ": %016b\n", v)
96#define print_val_bin32(v) xprintf(#v ": %032lb\n", v)
97#define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v))
98#define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v))
99#define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v))
100
101// User print disables the normal print messages in the body of QMK/TMK code and
102// is meant as a lightweight alternative to NOPRINT. Use it when you only want to do
103// a spot of debugging but lack flash resources for allowing all of the codebase to
104// print (and store their wasteful strings).
105//
106// !!! DO NOT USE USER PRINT CALLS IN THE BODY OF QMK/TMK !!!
107
108/* decimal */
109#define uprint_dec(i) uprintf("%u", i)
110#define uprint_decs(i) uprintf("%d", i)
111/* hex */
112#define uprint_hex4(i) uprintf("%X", i)
113#define uprint_hex8(i) uprintf("%02X", i)
114#define uprint_hex16(i) uprintf("%04X", i)
115#define uprint_hex32(i) uprintf("%08lX", i)
116/* binary */
117#define uprint_bin4(i) uprintf("%04b", i)
118#define uprint_bin8(i) uprintf("%08b", i)
119#define uprint_bin16(i) uprintf("%016b", i)
120#define uprint_bin32(i) uprintf("%032lb", i)
121#define uprint_bin_reverse8(i) uprintf("%08b", bitrev(i))
122#define uprint_bin_reverse16(i) uprintf("%016b", bitrev16(i))
123#define uprint_bin_reverse32(i) uprintf("%032lb", bitrev32(i))
124/* print value utility */
125#define uprint_val_dec(v) uprintf(#v ": %u\n", v)
126#define uprint_val_decs(v) uprintf(#v ": %d\n", v)
127#define uprint_val_hex8(v) uprintf(#v ": %X\n", v)
128#define uprint_val_hex16(v) uprintf(#v ": %02X\n", v)
129#define uprint_val_hex32(v) uprintf(#v ": %04lX\n", v)
130#define uprint_val_bin8(v) uprintf(#v ": %08b\n", v)
131#define uprint_val_bin16(v) uprintf(#v ": %016b\n", v)
132#define uprint_val_bin32(v) uprintf(#v ": %032lb\n", v)
133#define uprint_val_bin_reverse8(v) uprintf(#v ": %08b\n", bitrev(v))
134#define uprint_val_bin_reverse16(v) uprintf(#v ": %016b\n", bitrev16(v))
135#define uprint_val_bin_reverse32(v) uprintf(#v ": %032lb\n", bitrev32(v))