]>
git.gir.st - tmk_keyboard.git/blob - common/xprintf.h
1 /*---------------------------------------------------------------------------
2 Extended itoa, puts and printf (C)ChaN, 2011
3 -----------------------------------------------------------------------------*/
9 #include <avr/pgmspace.h>
11 extern void (*xfunc_out
)(uint8_t);
12 #define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func)
14 /* This is a pointer to user defined output function. It must be initialized
15 before using this modle.
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.
25 /*-----------------------------------------------------------------------------*/
26 void xputs(const char *string_p
);
28 /* The string placed in the ROM is forwarded to xputc() directly.
32 /*-----------------------------------------------------------------------------*/
33 void xitoa(long value
, char radix
, char width
);
37 value radix width output
41 4294967295 10 0 "4294967295"
43 655360 16 -8 "000A0000"
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__)
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 */
58 /* Format string is placed in the ROM. The format flags is similar to printf().
60 %[flag][width][size]type
63 A '0' means filled with '0' when output is shorter than width.
64 ' ' is used in default. This is effective only numeral type.
66 Minimum width in decimal number. This is effective only numeral type.
67 Default width is zero.
69 A 'l' means the argument is long(32bit). Default is short(16bit).
70 This is effective only numeral 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
84 /*-----------------------------------------------------------------------------*/
85 char xatoi(char **str
, long *ret
);
87 /* Get value of the numeral string.
90 Pointer to pointer to source string
99 Pointer to return value