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
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:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
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
30 #include <avr/pgmspace.h>
33 // this macro allows you to write print("some text") and
34 // the string is automatically placed into flash memory :)
35 // TODO: avoid collision with arduino/Print.h
37 #define print(s) print_P(PSTR(s))
39 #define println(s) print_P(PSTR(s "\n"))
42 #define pdec(data) print_dec(data)
43 #define pdec16(data) print_dec(data)
44 #define phex(data) print_hex8(data)
45 #define phex16(data) print_hex16(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)
51 /* print value utility */
52 #define print_val_dec(v) do { print_P(PSTR(#v ": ")); print_dec(v); print_P(PSTR("\n")); } while (0)
53 #define print_val_decs(v) do { print_P(PSTR(#v ": ")); print_decs(v); print_P(PSTR("\n")); } while (0)
54 #define print_val_hex8(v) do { print_P(PSTR(#v ": ")); print_hex8(v); print_P(PSTR("\n")); } while (0)
55 #define print_val_hex16(v) do { print_P(PSTR(#v ": ")); print_hex16(v); print_P(PSTR("\n")); } while (0)
56 #define print_val_hex32(v) do { print_P(PSTR(#v ": ")); print_hex32(v); print_P(PSTR("\n")); } while (0)
57 #define print_val_bin8(v) do { print_P(PSTR(#v ": ")); print_bin8(v); print_P(PSTR("\n")); } while (0)
58 #define print_val_bin16(v) do { print_P(PSTR(#v ": ")); print_bin16(v); print_P(PSTR("\n")); } while (0)
59 #define print_val_bin32(v) do { print_P(PSTR(#v ": ")); print_bin32(v); print_P(PSTR("\n")); } while (0)
60 #define print_val_bin_reverse8(v) do { print_P(PSTR(#v ": ")); print_bin_reverse8(v); print_P(PSTR("\n")); } while (0)
61 #define print_val_bin_reverse16(v) do { print_P(PSTR(#v ": ")); print_bin_reverse16(v); print_P(PSTR("\n")); } while (0)
62 #define print_val_bin_reverse32(v) do { print_P(PSTR(#v ": ")); print_bin_reverse32(v); print_P(PSTR("\n")); } while (0)
71 /* function pointer of sendchar to be used by print utility */
72 void print_set_sendchar(int8_t (*print_sendchar_func)(uint8_t));
74 /* print string stored in data memory(SRAM) */
75 void print_S(const char *s);
76 /* print string stored in program memory(FLASH) */
77 void print_P(const char *s);
79 void print_CRLF(void);
82 void print_dec(uint16_t data);
83 void print_decs(int16_t data);
86 void print_hex4(uint8_t data);
87 void print_hex8(uint8_t data);
88 void print_hex16(uint16_t data);
89 void print_hex32(uint32_t data);
92 void print_bin4(uint8_t data);
93 void print_bin8(uint8_t data);
94 void print_bin16(uint16_t data);
95 void print_bin32(uint32_t data);
96 void print_bin_reverse8(uint8_t data);
97 void print_bin_reverse16(uint16_t data);
98 void print_bin_reverse32(uint32_t data);
105 #define print_set_sendchar(func)
109 #define print_dec(data)
110 #define print_decs(data)
111 #define print_hex4(data)
112 #define print_hex8(data)
113 #define print_hex16(data)
114 #define print_hex32(data)
115 #define print_bin4(data)
116 #define print_bin8(data)
117 #define print_bin16(data)
118 #define print_bin32(data)
119 #define print_bin_reverse8(data)
120 #define print_bin_reverse16(data)
121 #define print_bin_reverse32(data)