debug.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 dprintf(fmt, ...) \
  47. do { \
  48. if (debug_config.enable) xprintf(fmt, ##__VA_ARGS__); \
  49. } while (0)
  50. #else /* NO_DEBUG */
  51. # define dprintf(fmt, ...)
  52. #endif /* NO_DEBUG */
  53. #define dprint(s) dprintf(s)
  54. #define dprintln(s) dprintf(s "\r\n")
  55. #define dmsg(s) dprintf("%s at %d: %s\n", __FILE__, __LINE__, s)