]> git.donarmstrong.com Git - tmk_firmware.git/blobdiff - common/avr/xprintf.h
Merge remote-tracking branch 'tmk/master' into cub_layout
[tmk_firmware.git] / common / avr / xprintf.h
diff --git a/common/avr/xprintf.h b/common/avr/xprintf.h
new file mode 100644 (file)
index 0000000..59c6f25
--- /dev/null
@@ -0,0 +1,111 @@
+/*---------------------------------------------------------------------------\r
+   Extended itoa, puts and printf                    (C)ChaN, 2011\r
+-----------------------------------------------------------------------------*/\r
+\r
+#ifndef XPRINTF_H\r
+#define XPRINTF_H\r
+\r
+#include <inttypes.h>\r
+#include <avr/pgmspace.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+extern void (*xfunc_out)(uint8_t);\r
+#define xdev_out(func) xfunc_out = (void(*)(uint8_t))(func)\r
+\r
+/* This is a pointer to user defined output function. It must be initialized\r
+   before using this modle.\r
+*/\r
+\r
+void xputc(char chr);\r
+\r
+/* This is a stub function to forward outputs to user defined output function.\r
+   All outputs from this module are output via this function.\r
+*/\r
+\r
+\r
+/*-----------------------------------------------------------------------------*/\r
+void xputs(const char *string_p);\r
+\r
+/*  The string placed in the ROM is forwarded to xputc() directly.\r
+*/\r
+\r
+\r
+/*-----------------------------------------------------------------------------*/\r
+void xitoa(long value, char radix, char width);\r
+\r
+/* Extended itoa().\r
+\r
+      value  radix  width   output\r
+        100     10      6   "   100"\r
+        100     10     -6   "000100"\r
+        100     10      0   "100"\r
+ 4294967295     10      0   "4294967295"\r
+ 4294967295    -10      0   "-1"\r
+     655360     16     -8   "000A0000"\r
+       1024     16      0   "400"\r
+       0x55      2     -8   "01010101"\r
+*/\r
+\r
+\r
+/*-----------------------------------------------------------------------------*/\r
+#define xprintf(format, ...)            __xprintf(PSTR(format), ##__VA_ARGS__)\r
+#define xsprintf(str, format, ...)      __xsprintf(str, PSTR(format), ##__VA_ARGS__)\r
+#define xfprintf(func, format, ...)     __xfprintf(func, PSTR(format), ##__VA_ARGS__)\r
+\r
+void __xprintf(const char *format_p, ...);     /* Send formatted string to the registered device */\r
+void __xsprintf(char*, const char *format_p, ...);     /* Put formatted string to the memory */\r
+void __xfprintf(void(*func)(uint8_t), const char *format_p, ...); /* Send formatted string to the specified device */\r
+\r
+/* Format string is placed in the ROM. The format flags is similar to printf().\r
+\r
+   %[flag][width][size]type\r
+\r
+   flag\r
+     A '0' means filled with '0' when output is shorter than width.\r
+     ' ' is used in default. This is effective only numeral type.\r
+   width\r
+     Minimum width in decimal number. This is effective only numeral type.\r
+     Default width is zero.\r
+   size\r
+     A 'l' means the argument is long(32bit). Default is short(16bit).\r
+     This is effective only numeral type.\r
+   type\r
+     'c' : Character, argument is the value\r
+     's' : String placed on the RAM, argument is the pointer\r
+     'S' : String placed on the ROM, argument is the pointer\r
+     'd' : Signed decimal, argument is the value\r
+     'u' : Unsigned decimal, argument is the value\r
+     'X' : Hexdecimal, argument is the value\r
+     'b' : Binary, argument is the value\r
+     '%' : '%'\r
+\r
+*/\r
+\r
+\r
+/*-----------------------------------------------------------------------------*/\r
+char xatoi(char **str, long *ret);\r
+\r
+/* Get value of the numeral string. \r
+\r
+  str\r
+    Pointer to pointer to source string\r
+\r
+    "0b11001010" binary\r
+    "0377" octal\r
+    "0xff800" hexdecimal\r
+    "1250000" decimal\r
+    "-25000" decimal\r
+\r
+  ret\r
+    Pointer to return value\r
+*/\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif\r
+\r