You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
5.5 KiB

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