debug.h 5.5 KB

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