debug.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. #ifndef PROTOCOL_ARM_ATSAM
  16. # include <stdio.h>
  17. #endif
  18. #include <stdbool.h>
  19. #include "print.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /*
  24. * Debug output control
  25. */
  26. typedef union {
  27. struct {
  28. bool enable : 1;
  29. bool matrix : 1;
  30. bool keyboard : 1;
  31. bool mouse : 1;
  32. uint8_t reserved : 4;
  33. };
  34. uint8_t raw;
  35. } debug_config_t;
  36. extern debug_config_t debug_config;
  37. #ifdef __cplusplus
  38. }
  39. #endif
  40. /* for backward compatibility */
  41. #define debug_enable (debug_config.enable)
  42. #define debug_matrix (debug_config.matrix)
  43. #define debug_keyboard (debug_config.keyboard)
  44. #define debug_mouse (debug_config.mouse)
  45. /*
  46. * Debug print utils
  47. */
  48. #ifndef NO_DEBUG
  49. # define dprintf(fmt, ...) \
  50. do { \
  51. if (debug_config.enable) xprintf(fmt, ##__VA_ARGS__); \
  52. } while (0)
  53. #else /* NO_DEBUG */
  54. # define dprintf(fmt, ...)
  55. #endif /* NO_DEBUG */
  56. #define dprint(s) dprintf(s)
  57. #define dprintln(s) dprintf(s "\r\n")
  58. #define dmsg(s) dprintf("%s at %d: %s\n", __FILE__, __LINE__, s)