]>
git.gir.st - tmk_keyboard.git/blob - common/mbed/xprintf.cpp
4 #include "mbed/xprintf.h"
7 #define STRING_STACK_LIMIT 120
10 Serial
ser(UART_TX
, UART_RX
);
12 /* TODO: Need small implementation for embedded */
13 int xprintf(const char* format
, ...)
15 /* copy from mbed/common/RawSerial.cpp */
17 va_start(arg
, format
);
18 int len
= vsnprintf(NULL
, 0, format
, arg
);
19 if (len
< STRING_STACK_LIMIT
) {
20 char temp
[STRING_STACK_LIMIT
];
21 vsprintf(temp
, format
, arg
);
24 char *temp
= new char[len
+ 1];
25 vsprintf(temp
, format
, arg
);
32 /* Fail: __builtin_va_arg_pack?
33 * https://gcc.gnu.org/onlinedocs/gcc-4.3.5/gcc/Constructing-Calls.html#Constructing-Calls
34 void *arg = __builtin_apply_args();
35 void *ret = __builtin_apply((void*)(&(ser.printf)), arg, 100);
38 /* Fail: varargs can not be passed to printf
39 //int r = ser.printf("test %i\r\n", 123);
41 va_start(arg, format);
42 int r = ser.printf(format, arg);