diff options
Diffstat (limited to 'tmk_core/common/avr/xprintf.h')
-rw-r--r-- | tmk_core/common/avr/xprintf.h | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/tmk_core/common/avr/xprintf.h b/tmk_core/common/avr/xprintf.h new file mode 100644 index 000000000..59c6f2531 --- /dev/null +++ b/tmk_core/common/avr/xprintf.h | |||
@@ -0,0 +1,111 @@ | |||
1 | /*--------------------------------------------------------------------------- | ||
2 | Extended itoa, puts and printf (C)ChaN, 2011 | ||
3 | -----------------------------------------------------------------------------*/ | ||
4 | |||
5 | #ifndef XPRINTF_H | ||
6 | #define XPRINTF_H | ||
7 | |||
8 | #include <inttypes.h> | ||
9 | #include <avr/pgmspace.h> | ||
10 | |||
11 | #ifdef __cplusplus | ||
12 | extern "C" { | ||
13 | #endif | ||
14 | |||
15 | extern void (*xfunc_out)(uint8_t); | ||
16 | #define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func) | ||
17 | |||
18 | /* This is a pointer to user defined output function. It must be initialized | ||
19 | before using this modle. | ||
20 | */ | ||
21 | |||
22 | void xputc(char chr); | ||
23 | |||
24 | /* This is a stub function to forward outputs to user defined output function. | ||
25 | All outputs from this module are output via this function. | ||
26 | */ | ||
27 | |||
28 | |||
29 | /*-----------------------------------------------------------------------------*/ | ||
30 | void xputs(const char *string_p); | ||
31 | |||
32 | /* The string placed in the ROM is forwarded to xputc() directly. | ||
33 | */ | ||
34 | |||
35 | |||
36 | /*-----------------------------------------------------------------------------*/ | ||
37 | void xitoa(long value, char radix, char width); | ||
38 | |||
39 | /* Extended itoa(). | ||
40 | |||
41 | value radix width output | ||
42 | 100 10 6 " 100" | ||
43 | 100 10 -6 "000100" | ||
44 | 100 10 0 "100" | ||
45 | 4294967295 10 0 "4294967295" | ||
46 | 4294967295 -10 0 "-1" | ||
47 | 655360 16 -8 "000A0000" | ||
48 | 1024 16 0 "400" | ||
49 | 0x55 2 -8 "01010101" | ||
50 | */ | ||
51 | |||
52 | |||
53 | /*-----------------------------------------------------------------------------*/ | ||
54 | #define xprintf(format, ...) __xprintf(PSTR(format), ##__VA_ARGS__) | ||
55 | #define xsprintf(str, format, ...) __xsprintf(str, PSTR(format), ##__VA_ARGS__) | ||
56 | #define xfprintf(func, format, ...) __xfprintf(func, PSTR(format), ##__VA_ARGS__) | ||
57 | |||
58 | void __xprintf(const char *format_p, ...); /* Send formatted string to the registered device */ | ||
59 | void __xsprintf(char*, const char *format_p, ...); /* Put formatted string to the memory */ | ||
60 | void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */ | ||
61 | |||
62 | /* Format string is placed in the ROM. The format flags is similar to printf(). | ||
63 | |||
64 | %[flag][width][size]type | ||
65 | |||
66 | flag | ||
67 | A '0' means filled with '0' when output is shorter than width. | ||
68 | ' ' is used in default. This is effective only numeral type. | ||
69 | width | ||
70 | Minimum width in decimal number. This is effective only numeral type. | ||
71 | Default width is zero. | ||
72 | size | ||
73 | A 'l' means the argument is long(32bit). Default is short(16bit). | ||
74 | This is effective only numeral type. | ||
75 | type | ||
76 | 'c' : Character, argument is the value | ||
77 | 's' : String placed on the RAM, argument is the pointer | ||
78 | 'S' : String placed on the ROM, argument is the pointer | ||
79 | 'd' : Signed decimal, argument is the value | ||
80 | 'u' : Unsigned decimal, argument is the value | ||
81 | 'X' : Hexdecimal, argument is the value | ||
82 | 'b' : Binary, argument is the value | ||
83 | '%' : '%' | ||
84 | |||
85 | */ | ||
86 | |||
87 | |||
88 | /*-----------------------------------------------------------------------------*/ | ||
89 | char xatoi(char **str, long *ret); | ||
90 | |||
91 | /* Get value of the numeral string. | ||
92 | |||
93 | str | ||
94 | Pointer to pointer to source string | ||
95 | |||
96 | "0b11001010" binary | ||
97 | "0377" octal | ||
98 | "0xff800" hexdecimal | ||
99 | "1250000" decimal | ||
100 | "-25000" decimal | ||
101 | |||
102 | ret | ||
103 | Pointer to return value | ||
104 | */ | ||
105 | |||
106 | #ifdef __cplusplus | ||
107 | } | ||
108 | #endif | ||
109 | |||
110 | #endif | ||
111 | |||