472dd478c407c4390600fc30dd89a2c747cb878c
[tmk_keyboard.git] / common / debug.h
1 /*
2 Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef DEBUG_H
19 #define DEBUG_H 1
20
21 #include "print.h"
22
23
24 /*
25 * Debug output control
26 */
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 typedef union {
32 struct {
33 bool enable:1;
34 bool matrix:1;
35 bool keyboard:1;
36 bool mouse:1;
37 uint8_t reserved:4;
38 };
39 uint8_t raw;
40 } debug_config_t;
41
42 extern debug_config_t debug_config;
43 debug_config_t debug_config __attribute__ ((weak)) = {};
44
45 #ifdef __cplusplus
46 }
47 #endif
48
49 #define debug_enable (debug_config.enable)
50 #define debug_matrix (debug_config.matrix)
51 #define debug_keyboard (debug_config.keyboard)
52 #define debug_mouse (debug_config.mouse)
53
54
55
56 /*
57 * Debug print utils
58 */
59 #ifndef NO_DEBUG
60
61 #define dprint(s) do { if (debug_enable) print(s); } while (0)
62 #define dprintln(s) do { if (debug_enable) println(s); } while (0)
63 #define dprintf(fmt, ...) do { if (debug_enable) xprintf(fmt, ##__VA_ARGS__); } while (0)
64 #define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s))
65
66 /* Deprecated. DO NOT USE these anymore, use dprintf instead. */
67 #define debug(s) do { if (debug_enable) print(s); } while (0)
68 #define debugln(s) do { if (debug_enable) println(s); } while (0)
69 #define debug_msg(s) do { \
70 if (debug_enable) { \
71 print(__FILE__); print(" at "); print_dec(__LINE__); print(" in "); print(": "); print(s); \
72 } \
73 } while (0)
74 #define debug_dec(data) do { if (debug_enable) print_dec(data); } while (0)
75 #define debug_decs(data) do { if (debug_enable) print_decs(data); } while (0)
76 #define debug_hex4(data) do { if (debug_enable) print_hex4(data); } while (0)
77 #define debug_hex8(data) do { if (debug_enable) print_hex8(data); } while (0)
78 #define debug_hex16(data) do { if (debug_enable) print_hex16(data); } while (0)
79 #define debug_hex32(data) do { if (debug_enable) print_hex32(data); } while (0)
80 #define debug_bin8(data) do { if (debug_enable) print_bin8(data); } while (0)
81 #define debug_bin16(data) do { if (debug_enable) print_bin16(data); } while (0)
82 #define debug_bin32(data) do { if (debug_enable) print_bin32(data); } while (0)
83 #define debug_bin_reverse8(data) do { if (debug_enable) print_bin_reverse8(data); } while (0)
84 #define debug_bin_reverse16(data) do { if (debug_enable) print_bin_reverse16(data); } while (0)
85 #define debug_bin_reverse32(data) do { if (debug_enable) print_bin_reverse32(data); } while (0)
86 #define debug_hex(data) debug_hex8(data)
87 #define debug_bin(data) debug_bin8(data)
88 #define debug_bin_reverse(data) debug_bin8(data)
89
90 #else
91
92 /* NO_DEBUG */
93 #define dprint(s)
94 #define dprintln(s)
95 #define dprintf(fmt, ...)
96 #define dmsg(s)
97 #define debug(s)
98 #define debugln(s)
99 #define debug_msg(s)
100 #define debug_dec(data)
101 #define debug_decs(data)
102 #define debug_hex4(data)
103 #define debug_hex8(data)
104 #define debug_hex16(data)
105 #define debug_hex32(data)
106 #define debug_bin8(data)
107 #define debug_bin16(data)
108 #define debug_bin32(data)
109 #define debug_bin_reverse8(data)
110 #define debug_bin_reverse16(data)
111 #define debug_bin_reverse32(data)
112 #define debug_hex(data)
113 #define debug_bin(data)
114 #define debug_bin_reverse(data)
115
116 #endif
117
118 #endif
Imprint / Impressum