add serial.printf() function.

This commit is contained in:
Bigbits
2019-05-04 17:43:19 +08:00
parent e3609f4be6
commit ff02b8ea83
3 changed files with 26 additions and 2 deletions

View File

@@ -28,6 +28,30 @@
#include "Print.h"
// Public Methods //////////////////////////////////////////////////////////////
size_t Print::printf(const char *format, ...)
{
char loc_buf[64];
char * temp = loc_buf;
va_list arg;
va_list copy;
va_start(arg, format);
va_copy(copy, arg);
size_t len = vsnprintf(NULL, 0, format, arg);
va_end(copy);
if(len >= sizeof(loc_buf)){
temp = new char[len+1];
if(temp == NULL) {
return 0;
}
}
len = vsnprintf(temp, len+1, format, arg);
write((uint8_t*)temp, len);
va_end(arg);
if(len >= sizeof(loc_buf)){
delete[] temp;
}
return len;
}
/* default implementation: may be overridden */
size_t Print::write(const uint8_t *buffer, size_t size)

View File

@@ -61,6 +61,7 @@ class Print
return write((const uint8_t *)buffer, size);
}
size_t printf(const char * format, ...) __attribute__ ((format (printf, 2, 3)));
size_t print(const __FlashStringHelper *);
size_t print(const String &);
size_t print(const char[]);

View File

@@ -15,11 +15,10 @@ compiler.objcopy.cmd=riscv64-unknown-elf-objcopy
compiler.elf2hex.cmd=riscv64-unknown-elf-objcopy
compiler.size.cmd=riscv64-unknown-elf-size
compiler.clib.path={runtime.tools.riscv64-unknown-elf-gcc.path}/include
compiler.sdk.path={runtime.platform.path}/cores/arduino/kendryte-standalone-sdk/lib
compiler.lib_hal_inc.path={runtime.platform.path}/cores/arduino/hal/include
compiler.cores.path={runtime.platform.path}/cores/arduino/
compiler.preproc.flags=-I{build.system.path}/include -I{compiler.cores.path} -I{compiler.lib_hal_inc.path} -I{compiler.sdk.path}/bsp/include -I{compiler.sdk.path}/drivers/include -I{compiler.sdk.path}/utils/include -I{compiler.sdk.path}/freertos/conf -I{compiler.sdk.path}/freertos/include -I{compiler.sdk.path}/freertos/portable -I{compiler.clib.path}
compiler.preproc.flags=-I{build.system.path}/include -I{compiler.cores.path} -I{compiler.cores.path}/avr -I{compiler.lib_hal_inc.path} -I{compiler.sdk.path}/bsp/include -I{compiler.sdk.path}/drivers/include -I{compiler.sdk.path}/utils/include -I{compiler.sdk.path}/freertos/conf -I{compiler.sdk.path}/freertos/include -I{compiler.sdk.path}/freertos/portable
compiler.both.flags=-mcmodel=medany -mabi=lp64f -march=rv64imafc -fno-common -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -fno-zero-initialized-in-bss -Os -ggdb -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Werror=frame-larger-than=65536 -Wno-unused-parameter -Wno-sign-compare -Wno-error=missing-braces -Wno-error=return-type -Wno-error=pointer-sign -Wno-missing-braces -Wno-strict-aliasing -Wno-implicit-fallthrough -Wno-missing-field-initializers -Wno-int-to-pointer-cast -Wno-error=comment -Wno-error=logical-not-parentheses -Wno-error=duplicate-decl-specifier -Wno-error=parentheses -Wno-error=narrowing -Wno-error=unused-value