Fix debug.h
[tmk_keyboard.git] / common / debug.h
CommitLineData
0dde25e8 1/*
2Copyright 2011 Jun Wako <wakojun@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
461e0d3d 18#ifndef DEBUG_H
19#define DEBUG_H 1
20
a9963960 21#include <stdbool.h>
461e0d3d 22#include "print.h"
23
24
ee70fe59 25#ifdef __cplusplus
26extern "C" {
27#endif
28
a9963960 29/*
30 * Debug output control
31 */
ee70fe59 32typedef union {
ee70fe59 33 struct {
34 bool enable:1;
35 bool matrix:1;
36 bool keyboard:1;
37 bool mouse:1;
38 uint8_t reserved:4;
39 };
36395098 40 uint8_t raw;
ee70fe59 41} debug_config_t;
42
43extern debug_config_t debug_config;
ee70fe59 44
45#ifdef __cplusplus
46}
47#endif
48
a9963960 49/* for backward compatibility */
ee70fe59 50#define debug_enable (debug_config.enable)
51#define debug_matrix (debug_config.matrix)
52#define debug_keyboard (debug_config.keyboard)
53#define debug_mouse (debug_config.mouse)
54
55
ee70fe59 56/*
57 * Debug print utils
58 */
9a106537 59#ifndef NO_DEBUG
60
ee70fe59 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 { \
220de27b 70 if (debug_enable) { \
71 print(__FILE__); print(" at "); print_dec(__LINE__); print(" in "); print(": "); print(s); \
72 } \
73} while (0)
ee70fe59 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)
461e0d3d 89
a9963960 90#else /* NO_DEBUG */
ee70fe59 91
ee70fe59 92#define dprint(s)
93#define dprintln(s)
94#define dprintf(fmt, ...)
95#define dmsg(s)
96#define debug(s)
97#define debugln(s)
98#define debug_msg(s)
99#define debug_dec(data)
100#define debug_decs(data)
101#define debug_hex4(data)
102#define debug_hex8(data)
103#define debug_hex16(data)
104#define debug_hex32(data)
105#define debug_bin8(data)
106#define debug_bin16(data)
107#define debug_bin32(data)
108#define debug_bin_reverse8(data)
109#define debug_bin_reverse16(data)
110#define debug_bin_reverse32(data)
111#define debug_hex(data)
112#define debug_bin(data)
113#define debug_bin_reverse(data)
114
a9963960 115#endif /* NO_DEBUG */
461e0d3d 116
117#endif
Imprint / Impressum