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