debug.h (1788B)
1 /* 2 Copyright 2011 Jun Wako <wakojun@gmail.com> 3 4 This program is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 2 of the License, or 7 (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #pragma once 19 20 #include <stdio.h> 21 #include <stdbool.h> 22 #include "print.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 /* 29 * Debug output control 30 */ 31 typedef union debug_config_t { 32 struct { 33 bool enable : 1; 34 bool matrix : 1; 35 bool keyboard : 1; 36 bool mouse : 1; 37 uint8_t reserved : 4; 38 }; 39 uint8_t raw; 40 } debug_config_t; 41 42 extern debug_config_t debug_config; 43 44 #ifdef __cplusplus 45 } 46 #endif 47 48 /* for backward compatibility */ 49 #define debug_enable (debug_config.enable) 50 #define debug_matrix (debug_config.matrix) 51 #define debug_keyboard (debug_config.keyboard) 52 #define debug_mouse (debug_config.mouse) 53 54 /* 55 * Debug print utils 56 */ 57 #ifndef NO_DEBUG 58 # define dprintf(fmt, ...) \ 59 do { \ 60 if (debug_config.enable) xprintf(fmt, ##__VA_ARGS__); \ 61 } while (0) 62 #else /* NO_DEBUG */ 63 # define dprintf(fmt, ...) 64 #endif /* NO_DEBUG */ 65 66 #define dprint(s) dprintf(s) 67 #define dprintln(s) dprintf(s "\r\n") 68 #define dmsg(s) dprintf("%s at %d: %s\n", __FILE__, __LINE__, s)