]> git.gir.st - tmk_keyboard.git/blob - common/print.h
Add print utility
[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 #define phex(data) print_hex8(data)
43 #define phex16(data) print_hex16(data)
44 #define pdec(data) print_dec8(data)
45 #define pdec16(data) print_dec16(data)
46 #define pbin(data) print_bin8(data)
47 #define pbin16(data) print_bin16(data)
48 #define pbin_reverse(data) print_bin_reverse8(data)
49 #define pbin_reverse16(data) print_bin_reverse16(data)
50
51
52 /* print value utility */
53 #define pv_hex8(v) do { print_P(PSTR(#v ": ")); print_hex8(v); print_P(PSTR("\n")); } while (0)
54 #define pv_hex16(v) do { print_P(PSTR(#v ": ")); print_hex16(v); print_P(PSTR("\n")); } while (0)
55 #define pv_hex32(v) do { print_P(PSTR(#v ": ")); print_hex32(v); print_P(PSTR("\n")); } while (0)
56 #define pv_dec8(v) do { print_P(PSTR(#v ": ")); print_dec8(v); print_P(PSTR("\n")); } while (0)
57 #define pv_dec16(v) do { print_P(PSTR(#v ": ")); print_dec16(v); print_P(PSTR("\n")); } while (0)
58 #define pv_dec32(v) do { print_P(PSTR(#v ": ")); print_dec32(v); print_P(PSTR("\n")); } while (0)
59 #define pv_bin8(v) do { print_P(PSTR(#v ": ")); print_bin8(v); print_P(PSTR("\n")); } while (0)
60 #define pv_bin16(v) do { print_P(PSTR(#v ": ")); print_bin16(v); print_P(PSTR("\n")); } while (0)
61 #define pv_bin32(v) do { print_P(PSTR(#v ": ")); print_bin32(v); print_P(PSTR("\n")); } while (0)
62 #define pv_bin_reverse8(v) do { print_P(PSTR(#v ": ")); print_bin_reverse8(v); print_P(PSTR("\n")); } while (0)
63 #define pv_bin_reverse16(v) do { print_P(PSTR(#v ": ")); print_bin_reverse16(v); print_P(PSTR("\n")); } while (0)
64 #define pv_bin_reverse32(v) do { print_P(PSTR(#v ": ")); print_bin_reverse32(v); print_P(PSTR("\n")); } while (0)
65
66
67
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71
72 /* function pointer of sendchar to be used by print utility */
73 extern int8_t (*print_sendchar_func)(uint8_t);
74 extern bool print_enable;
75
76 /* print string stored in data memory(SRAM) */
77 void print_S(const char *s);
78 /* print string stored in program memory(FLASH) */
79 void print_P(const char *s);
80
81 void print_hex8(uint8_t data);
82 void print_hex16(uint16_t data);
83 void print_hex32(uint32_t data);
84 void print_dec8(uint8_t data);
85 void print_dec16(uint16_t data);
86 void print_bin8(uint8_t data);
87 void print_bin16(uint16_t data);
88 void print_bin_reverse8(uint8_t data);
89 void print_bin_reverse16(uint16_t data);
90
91 #ifdef __cplusplus
92 }
93 #endif
94
95 #endif
Imprint / Impressum