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