2015-04-09 16:32:04 +00:00
|
|
|
#include <cstdarg>
|
|
|
|
//#include <stdarg.h>
|
|
|
|
#include "mbed.h"
|
|
|
|
#include "mbed/xprintf.h"
|
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
#define STRING_STACK_LIMIT 120
|
2015-04-09 16:32:04 +00:00
|
|
|
|
2019-08-30 18:19:03 +00:00
|
|
|
// TODO
|
2016-09-08 04:50:58 +00:00
|
|
|
int __xprintf(const char* format, ...) { return 0; }
|
2015-04-09 16:32:04 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* 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;
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
#endif
|