]> git.donarmstrong.com Git - kiibohd-controller.git/blob - Debug/print/print.h
Removed a keyscan layer and added more debug information
[kiibohd-controller.git] / Debug / print / print.h
1 /* Copyright (C) 2011-2013 by Jacob Alexander
2  * 
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  * 
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  * 
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19  * THE SOFTWARE.
20  */
21
22 #ifndef print_h__
23 #define print_h__
24
25 // ----- Includes -----
26
27 // Compiler Includes
28 #if defined(_at90usb162_) || defined(_atmega32u4_) || defined(_at90usb646_) || defined(_at90usb1286_)
29
30 #include <avr/pgmspace.h>
31 #include "avr/usb_keyboard_debug.h"
32
33 #elif defined(_mk20dx128_)
34
35 #include "arm/usb_serial.h"
36
37 #endif
38
39
40
41 // ----- Defines -----
42 #define NL "\r\n"
43
44
45
46 // ----- Functions and Corresponding Function Aliases -----
47
48 /* XXX
49  * Note that all the variadic functions below, take comma separated string lists, they are purposely not printf style (simplicity)
50  */
51
52 // Function Aliases
53 #define dPrint(c)         usb_debug_putstr(c)
54 #define dPrintStr(c)      usb_debug_putstr(c)
55 #define dPrintStrs(...)   usb_debug_putstrs(__VA_ARGS__, "\0\0\0")      // Convenience Variadic Macro
56 #define dPrintStrNL(c)    dPrintStrs       (c, NL)                      // Appends New Line Macro
57 #define dPrintStrsNL(...) usb_debug_putstrs(__VA_ARGS__, NL, "\0\0\0")  // Appends New Line Macro
58
59 // Special Msg Constructs (Uses VT100 tags)
60 #define dPrintMsg(colour_code_str,msg,...) \
61                           usb_debug_putstrs("\033[", colour_code_str, "m", msg, "\033[0m - ", __VA_ARGS__, NL, "\0\0\0")
62 #define printMsgNL(colour_code_str,msg,str) \
63                           print("\033[" colour_code_str "m" msg "\033[0m - " str NL)
64 #define printMsg(colour_code_str,msg,str) \
65                           print("\033[" colour_code_str "m" msg "\033[0m - " str)
66
67 // Info Messages
68 #define info_dPrint(...)  dPrintMsg        ("1;32",   "INFO",    __VA_ARGS__) // Info Msg
69 #define info_print(str)   printMsgNL       ("1;32",   "INFO",    str)         // Info Msg
70 #define info_msg(str)     printMsg         ("1;32",   "INFO",    str)         // Info Msg
71
72 // Warning Messages
73 #define warn_dPrint(...)  dPrintMsg        ("1;33",   "WARNING", __VA_ARGS__) // Warning Msg
74 #define warn_print(str)   printMsgNL       ("1;33",   "WARNING", str)         // Warning Msg
75 #define warn_msg(str)     printMsg         ("1;33",   "WARNING", str)         // Warning Msg
76
77 // Error Messages
78 #define erro_dPrint(...)  dPrintMsg        ("1;5;31", "ERROR",   __VA_ARGS__) // Error Msg
79 #define erro_print(str)   printMsgNL       ("1;5;31", "ERROR",   str)         // Error Msg
80 #define erro_msg(str)     printMsg         ("1;5;31", "ERROR",   str)         // Error Msg
81
82 // Debug Messages
83 #define dbug_dPrint(...)  dPrintMsg        ("1;35",   "DEBUG",   __VA_ARGS__) // Debug Msg
84 #define dbug_print(str)   printMsgNL       ("1;35",   "DEBUG",   str)         // Debug Msg
85 #define dbug_msg(str)     printMsg         ("1;35",   "DEBUG",   str)         // Debug Msg
86
87
88 // Static String Printing
89 #define print(s) _print(PSTR(s))
90
91 void _print(const char *s);
92 void usb_debug_putstr( char* s );
93 void usb_debug_putstrs( char* first, ... );
94
95
96 // Printing numbers
97 #define printHex(hex) printHex_op(hex, 1)
98
99 void printInt8  ( uint8_t  in );
100 void printInt16 ( uint16_t in );
101 void printHex_op( uint16_t in, uint8_t op );
102
103
104 // String Functions
105 #define hexToStr(hex, out) hexToStr_op(hex, out, 1)
106
107 void int8ToStr  ( uint8_t  in, char*  out );
108 void int16ToStr ( uint16_t in, char*  out );
109 void hexToStr_op( uint16_t in, char*  out, uint8_t op );
110 void revsStr    ( char*  in );
111 uint16_t lenStr ( char*  in );
112
113 #endif
114