]> git.gir.st - tmk_keyboard.git/blob - common/print.h
Add print_dec() and debug_dec().
[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 <avr/pgmspace.h>
31
32
33 // avoid collision with arduino/Print.h
34 #ifndef __cplusplus
35 // this macro allows you to write print("some text") and
36 // the string is automatically placed into flash memory :)
37 #define print(s) print_P(PSTR(s))
38 #endif
39
40 #define println(s) print_P(PSTR(s "\n"))
41
42 /* for old name */
43 #define pdec(data) print_dec(data)
44 #define pdec16(data) print_dec(data)
45 #define phex(data) print_hex8(data)
46 #define phex16(data) print_hex16(data)
47 #define pbin(data) print_bin8(data)
48 #define pbin16(data) print_bin16(data)
49 #define pbin_reverse(data) print_bin_reverse8(data)
50 #define pbin_reverse16(data) print_bin_reverse16(data)
51
52
53 /* print value utility */
54 #define print_val_dec(v) do { print_P(PSTR(#v ": ")); print_dec(v); print_P(PSTR("\n")); } while (0)
55 #define print_val_decs(v) do { print_P(PSTR(#v ": ")); print_decs(v); print_P(PSTR("\n")); } while (0)
56
57 #define print_val_hex8(v) do { print_P(PSTR(#v ": ")); print_hex8(v); print_P(PSTR("\n")); } while (0)
58 #define print_val_hex16(v) do { print_P(PSTR(#v ": ")); print_hex16(v); print_P(PSTR("\n")); } while (0)
59 #define print_val_hex32(v) do { print_P(PSTR(#v ": ")); print_hex32(v); print_P(PSTR("\n")); } while (0)
60
61 #define print_val_bin8(v) do { print_P(PSTR(#v ": ")); print_bin8(v); print_P(PSTR("\n")); } while (0)
62 #define print_val_bin16(v) do { print_P(PSTR(#v ": ")); print_bin16(v); print_P(PSTR("\n")); } while (0)
63 #define print_val_bin32(v) do { print_P(PSTR(#v ": ")); print_bin32(v); print_P(PSTR("\n")); } while (0)
64 #define print_val_bin_reverse8(v) do { print_P(PSTR(#v ": ")); print_bin_reverse8(v); print_P(PSTR("\n")); } while (0)
65 #define print_val_bin_reverse16(v) do { print_P(PSTR(#v ": ")); print_bin_reverse16(v); print_P(PSTR("\n")); } while (0)
66 #define print_val_bin_reverse32(v) do { print_P(PSTR(#v ": ")); print_bin_reverse32(v); print_P(PSTR("\n")); } while (0)
67
68
69
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73
74 /* function pointer of sendchar to be used by print utility */
75 extern int8_t (*print_sendchar_func)(uint8_t);
76 extern bool print_enable;
77
78 /* print string stored in data memory(SRAM) */
79 void print_S(const char *s);
80 /* print string stored in program memory(FLASH) */
81 void print_P(const char *s);
82
83 void print_CRLF(void);
84
85 /* decimal */
86 void print_dec(uint16_t data);
87 void print_decs(int16_t data);
88
89 /* hex */
90 void print_hex8(uint8_t data);
91 void print_hex16(uint16_t data);
92 void print_hex32(uint32_t data);
93
94 /* binary */
95 void print_bin8(uint8_t data);
96 void print_bin16(uint16_t data);
97 void print_bin32(uint32_t data);
98 void print_bin_reverse8(uint8_t data);
99 void print_bin_reverse16(uint16_t data);
100 void print_bin_reverse32(uint32_t data);
101
102 #ifdef __cplusplus
103 }
104 #endif
105
106 #endif
Imprint / Impressum