summaryrefslogtreecommitdiff
path: root/common/mbed/xprintf.cpp
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2014-06-17 22:41:14 +0900
committertmk <nobody@nowhere>2014-07-30 14:07:43 +0900
commite81c70149ecf73256f8bb7d77cefc07f2b91d2be (patch)
treed918595b92aa099537640cd02285f914b343bd67 /common/mbed/xprintf.cpp
parentee70fe59ee8ebc6dcbf55171b1a2dd72e1744ae6 (diff)
downloadqmk_firmware-e81c70149ecf73256f8bb7d77cefc07f2b91d2be.tar.gz
qmk_firmware-e81c70149ecf73256f8bb7d77cefc07f2b91d2be.zip
Fix common files for mbed
Diffstat (limited to 'common/mbed/xprintf.cpp')
-rw-r--r--common/mbed/xprintf.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/common/mbed/xprintf.cpp b/common/mbed/xprintf.cpp
new file mode 100644
index 0000000000..4342b79f80
--- /dev/null
+++ b/common/mbed/xprintf.cpp
@@ -0,0 +1,46 @@
+#include <cstdarg>
+//#include <stdarg.h>
+#include "mbed.h"
+#include "mbed/xprintf.h"
+
+
+#define STRING_STACK_LIMIT 120
+
+/* mbed Serial */
+Serial ser(UART_TX, UART_RX);
+
+/* TODO: Need small implementation for embedded */
+int xprintf(const char* format, ...)
+{
+ /* copy from mbed/common/RawSerial.cpp */
+ std::va_list arg;
+ va_start(arg, format);
+ int len = vsnprintf(NULL, 0, format, arg);
+ if (len < STRING_STACK_LIMIT) {
+ char temp[STRING_STACK_LIMIT];
+ vsprintf(temp, format, arg);
+ ser.puts(temp);
+ } else {
+ char *temp = new char[len + 1];
+ vsprintf(temp, format, arg);
+ ser.puts(temp);
+ delete[] temp;
+ }
+ va_end(arg);
+ return len;
+
+/* Fail: __builtin_va_arg_pack?
+ * https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Constructing-Calls.html#Constructing-Calls
+ void *arg = __builtin_apply_args();
+ void *ret = __builtin_apply((void*)(&(ser.printf)), arg, 100);
+ __builtin_return(ret)
+*/
+/* Fail: varargs can not be passed to printf
+ //int r = ser.printf("test %i\r\n", 123);
+ va_list arg;
+ va_start(arg, format);
+ int r = ser.printf(format, arg);
+ va_end(arg);
+ return r;
+*/
+}