]> git.gir.st - tmk_keyboard.git/blob - common/print.h
Squashed 'tmk_core/' changes from d5c5ac6..8da1898
[tmk_keyboard.git] / common / print.h
1 /* Copyright 2012 Jun Wako <wakojun@gmail.com> */
2 /* Very basic print functions, intended to be used with usb_debug_only.c
3 * http://www.pjrc.com/teensy/
4 * Copyright (c) 2008 PJRC.COM, LLC
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 #ifndef PRINT_H__
26 #define PRINT_H__ 1
27
28 #include <stdint.h>
29 #include <stdbool.h>
30 #include "util.h"
31
32
33
34
35 #ifndef NO_PRINT
36
37
38 #if defined(__AVR__)
39
40 #include "avr/xprintf.h"
41 #define print(s) xputs(PSTR(s))
42 #define println(s) xputs(PSTR(s "\r\n"))
43
44 #ifdef __cplusplus
45 extern "C"
46 #endif
47 /* function pointer of sendchar to be used by print utility */
48 void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
49
50 #elif defined(PROTOCOL_CHIBIOS) /* __AVR__ */
51
52 #include "chibios/printf.h"
53
54 #define print(s) printf(s)
55 #define println(s) printf(s "\r\n")
56 #define xprintf printf
57
58 #elif defined(__arm__) /* __AVR__ */
59
60 #include "mbed/xprintf.h"
61
62 #define print(s) xprintf(s)
63 #define println(s) xprintf(s "\r\n")
64
65 /* TODO: to select output destinations: UART/USBSerial */
66 #define print_set_sendchar(func)
67
68 #endif /* __AVR__ */
69
70
71 /* decimal */
72 #define print_dec(i) xprintf("%u", i)
73 #define print_decs(i) xprintf("%d", i)
74 /* hex */
75 #define print_hex4(i) xprintf("%X", i)
76 #define print_hex8(i) xprintf("%02X", i)
77 #define print_hex16(i) xprintf("%04X", i)
78 #define print_hex32(i) xprintf("%08lX", i)
79 /* binary */
80 #define print_bin4(i) xprintf("%04b", i)
81 #define print_bin8(i) xprintf("%08b", i)
82 #define print_bin16(i) xprintf("%016b", i)
83 #define print_bin32(i) xprintf("%032lb", i)
84 #define print_bin_reverse8(i) xprintf("%08b", bitrev(i))
85 #define print_bin_reverse16(i) xprintf("%016b", bitrev16(i))
86 #define print_bin_reverse32(i) xprintf("%032lb", bitrev32(i))
87 /* print value utility */
88 #define print_val_dec(v) xprintf(#v ": %u\n", v)
89 #define print_val_decs(v) xprintf(#v ": %d\n", v)
90 #define print_val_hex8(v) xprintf(#v ": %X\n", v)
91 #define print_val_hex16(v) xprintf(#v ": %02X\n", v)
92 #define print_val_hex32(v) xprintf(#v ": %04lX\n", v)
93 #define print_val_bin8(v) xprintf(#v ": %08b\n", v)
94 #define print_val_bin16(v) xprintf(#v ": %016b\n", v)
95 #define print_val_bin32(v) xprintf(#v ": %032lb\n", v)
96 #define print_val_bin_reverse8(v) xprintf(#v ": %08b\n", bitrev(v))
97 #define print_val_bin_reverse16(v) xprintf(#v ": %016b\n", bitrev16(v))
98 #define print_val_bin_reverse32(v) xprintf(#v ": %032lb\n", bitrev32(v))
99
100 #else /* NO_PRINT */
101
102 #define xprintf(s,...) ((void)0)
103 #define print(s) ((void)0)
104 #define println(s) ((void)0)
105 #define print_set_sendchar(func) ((void)0)
106 #define print_dec(data) ((void)0)
107 #define print_decs(data) ((void)0)
108 #define print_hex4(data) ((void)0)
109 #define print_hex8(data) ((void)0)
110 #define print_hex16(data) ((void)0)
111 #define print_hex32(data) ((void)0)
112 #define print_bin4(data) ((void)0)
113 #define print_bin8(data) ((void)0)
114 #define print_bin16(data) ((void)0)
115 #define print_bin32(data) ((void)0)
116 #define print_bin_reverse8(data) ((void)0)
117 #define print_bin_reverse16(data) ((void)0)
118 #define print_bin_reverse32(data) ((void)0)
119 #define print_val_dec(v) ((void)0)
120 #define print_val_decs(v) ((void)0)
121 #define print_val_hex8(v) ((void)0)
122 #define print_val_hex16(v) ((void)0)
123 #define print_val_hex32(v) ((void)0)
124 #define print_val_bin8(v) ((void)0)
125 #define print_val_bin16(v) ((void)0)
126 #define print_val_bin32(v) ((void)0)
127 #define print_val_bin_reverse8(v) ((void)0)
128 #define print_val_bin_reverse16(v) ((void)0)
129 #define print_val_bin_reverse32(v) ((void)0)
130 #define init_printf(s,ss) ((void)0)
131
132 #endif /* NO_PRINT */
133
134
135 /* Backward compatiblitly for old name */
136 #define pdec(data) print_dec(data)
137 #define pdec16(data) print_dec(data)
138 #define phex(data) print_hex8(data)
139 #define phex16(data) print_hex16(data)
140 #define pbin(data) print_bin8(data)
141 #define pbin16(data) print_bin16(data)
142 #define pbin_reverse(data) print_bin_reverse8(data)
143 #define pbin_reverse16(data) print_bin_reverse16(data)
144
145
146 #endif
Imprint / Impressum