a074364c |
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 <stdbool.h> |
22 | #include "print.h" |
23 | |
a074364c |
24 | #ifdef __cplusplus |
25 | extern "C" { |
26 | #endif |
27 | |
28 | /* |
29 | * Debug output control |
30 | */ |
31 | typedef union { |
32 | struct { |
b624f32f |
33 | bool enable : 1; |
34 | bool matrix : 1; |
35 | bool keyboard : 1; |
36 | bool mouse : 1; |
37 | uint8_t reserved : 4; |
a074364c |
38 | }; |
39 | uint8_t raw; |
40 | } debug_config_t; |
41 | |
42 | extern debug_config_t debug_config; |
43 | |
44 | #ifdef __cplusplus |
45 | } |
46 | #endif |
47 | |
48 | /* for backward compatibility */ |
b624f32f |
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) |
a074364c |
53 | |
54 | /* |
55 | * Debug print utils |
56 | */ |
57 | #ifndef NO_DEBUG |
58 | |
b624f32f |
59 | # define dprint(s) \ |
60 | do { \ |
61 | if (debug_enable) print(s); \ |
62 | } while (0) |
63 | # define dprintln(s) \ |
64 | do { \ |
65 | if (debug_enable) println(s); \ |
66 | } while (0) |
67 | # define dprintf(fmt, ...) \ |
68 | do { \ |
69 | if (debug_enable) xprintf(fmt, ##__VA_ARGS__); \ |
70 | } while (0) |
71 | # define dmsg(s) dprintf("%s at %s: %S\n", __FILE__, __LINE__, PSTR(s)) |
a074364c |
72 | |
73 | /* Deprecated. DO NOT USE these anymore, use dprintf instead. */ |
b624f32f |
74 | # define debug(s) \ |
75 | do { \ |
76 | if (debug_enable) print(s); \ |
77 | } while (0) |
78 | # define debugln(s) \ |
79 | do { \ |
80 | if (debug_enable) println(s); \ |
81 | } while (0) |
82 | # define debug_msg(s) \ |
83 | do { \ |
84 | if (debug_enable) { \ |
85 | print(__FILE__); \ |
86 | print(" at "); \ |
87 | print_dec(__LINE__); \ |
88 | print(" in "); \ |
89 | print(": "); \ |
90 | print(s); \ |
91 | } \ |
92 | } while (0) |
93 | # define debug_dec(data) \ |
94 | do { \ |
95 | if (debug_enable) print_dec(data); \ |
96 | } while (0) |
97 | # define debug_decs(data) \ |
98 | do { \ |
99 | if (debug_enable) print_decs(data); \ |
100 | } while (0) |
101 | # define debug_hex4(data) \ |
102 | do { \ |
103 | if (debug_enable) print_hex4(data); \ |
104 | } while (0) |
105 | # define debug_hex8(data) \ |
106 | do { \ |
107 | if (debug_enable) print_hex8(data); \ |
108 | } while (0) |
109 | # define debug_hex16(data) \ |
110 | do { \ |
111 | if (debug_enable) print_hex16(data); \ |
112 | } while (0) |
113 | # define debug_hex32(data) \ |
114 | do { \ |
115 | if (debug_enable) print_hex32(data); \ |
116 | } while (0) |
117 | # define debug_bin8(data) \ |
118 | do { \ |
119 | if (debug_enable) print_bin8(data); \ |
120 | } while (0) |
121 | # define debug_bin16(data) \ |
122 | do { \ |
123 | if (debug_enable) print_bin16(data); \ |
124 | } while (0) |
125 | # define debug_bin32(data) \ |
126 | do { \ |
127 | if (debug_enable) print_bin32(data); \ |
128 | } while (0) |
129 | # define debug_bin_reverse8(data) \ |
130 | do { \ |
131 | if (debug_enable) print_bin_reverse8(data); \ |
132 | } while (0) |
133 | # define debug_bin_reverse16(data) \ |
134 | do { \ |
135 | if (debug_enable) print_bin_reverse16(data); \ |
136 | } while (0) |
137 | # define debug_bin_reverse32(data) \ |
138 | do { \ |
139 | if (debug_enable) print_bin_reverse32(data); \ |
140 | } while (0) |
141 | # define debug_hex(data) debug_hex8(data) |
142 | # define debug_bin(data) debug_bin8(data) |
143 | # define debug_bin_reverse(data) debug_bin8(data) |
a074364c |
144 | |
145 | #else /* NO_DEBUG */ |
146 | |
b624f32f |
147 | # define dprint(s) |
148 | # define dprintln(s) |
149 | # define dprintf(fmt, ...) |
150 | # define dmsg(s) |
151 | # define debug(s) |
152 | # define debugln(s) |
153 | # define debug_msg(s) |
154 | # define debug_dec(data) |
155 | # define debug_decs(data) |
156 | # define debug_hex4(data) |
157 | # define debug_hex8(data) |
158 | # define debug_hex16(data) |
159 | # define debug_hex32(data) |
160 | # define debug_bin8(data) |
161 | # define debug_bin16(data) |
162 | # define debug_bin32(data) |
163 | # define debug_bin_reverse8(data) |
164 | # define debug_bin_reverse16(data) |
165 | # define debug_bin_reverse32(data) |
166 | # define debug_hex(data) |
167 | # define debug_bin(data) |
168 | # define debug_bin_reverse(data) |
a074364c |
169 | |
170 | #endif /* NO_DEBUG */ |
171 | |
172 | #endif |