1 /*---------------------------------------------------------------------------
2 Extended itoa, puts and printf (C)ChaN, 2011
3 -----------------------------------------------------------------------------*/
9 #include <avr/pgmspace.h>
15 extern void (*xfunc_out)(uint8_t);
16 #define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func)
18 /* This is a pointer to user defined output function. It must be initialized
19 before using this modle.
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.
29 /*-----------------------------------------------------------------------------*/
30 void xputs(const char *string_p);
32 /* The string placed in the ROM is forwarded to xputc() directly.
36 /*-----------------------------------------------------------------------------*/
37 void xitoa(long value, char radix, char width);
41 value radix width output
45 4294967295 10 0 "4294967295"
47 655360 16 -8 "000A0000"
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__)
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 */
62 /* Format string is placed in the ROM. The format flags is similar to printf().
64 %[flag][width][size]type
67 A '0' means filled with '0' when output is shorter than width.
68 ' ' is used in default. This is effective only numeral type.
70 Minimum width in decimal number. This is effective only numeral type.
71 Default width is zero.
73 A 'l' means the argument is long(32bit). Default is short(16bit).
74 This is effective only numeral 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
88 /*-----------------------------------------------------------------------------*/
89 char xatoi(char **str, long *ret);
91 /* Get value of the numeral string.
94 Pointer to pointer to source string
103 Pointer to return value