mirror of https://github.com/ARMmbed/mbed-os.git
add vprintf to Rawserial.
parent
bb61ea1433
commit
8b605069f7
|
@ -63,9 +63,16 @@ int RawSerial::puts(const char *str)
|
||||||
// length is above a certain threshold, otherwise we use just the stack.
|
// length is above a certain threshold, otherwise we use just the stack.
|
||||||
int RawSerial::printf(const char *format, ...)
|
int RawSerial::printf(const char *format, ...)
|
||||||
{
|
{
|
||||||
lock();
|
|
||||||
std::va_list arg;
|
std::va_list arg;
|
||||||
va_start(arg, format);
|
va_start(arg, format);
|
||||||
|
int len = this->vprintf(format, arg);
|
||||||
|
va_end(arg);
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int RawSerial::vprintf(const char *format, std::va_list arg)
|
||||||
|
{
|
||||||
|
lock();
|
||||||
// ARMCC microlib does not properly handle a size of 0.
|
// ARMCC microlib does not properly handle a size of 0.
|
||||||
// As a workaround supply a dummy buffer with a size of 1.
|
// As a workaround supply a dummy buffer with a size of 1.
|
||||||
char dummy_buf[1];
|
char dummy_buf[1];
|
||||||
|
@ -80,7 +87,6 @@ int RawSerial::printf(const char *format, ...)
|
||||||
puts(temp);
|
puts(temp);
|
||||||
delete[] temp;
|
delete[] temp;
|
||||||
}
|
}
|
||||||
va_end(arg);
|
|
||||||
unlock();
|
unlock();
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "drivers/SerialBase.h"
|
#include "drivers/SerialBase.h"
|
||||||
#include "hal/serial_api.h"
|
#include "hal/serial_api.h"
|
||||||
#include "platform/NonCopyable.h"
|
#include "platform/NonCopyable.h"
|
||||||
|
#include <cstdarg>
|
||||||
|
|
||||||
namespace mbed {
|
namespace mbed {
|
||||||
/** \addtogroup drivers */
|
/** \addtogroup drivers */
|
||||||
|
@ -89,6 +90,7 @@ public:
|
||||||
int puts(const char *str);
|
int puts(const char *str);
|
||||||
|
|
||||||
int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2);
|
int printf(const char *format, ...) MBED_PRINTF_METHOD(1, 2);
|
||||||
|
int vprintf(const char *format, std::va_list arg);
|
||||||
|
|
||||||
#if !(DOXYGEN_ONLY)
|
#if !(DOXYGEN_ONLY)
|
||||||
protected:
|
protected:
|
||||||
|
|
Loading…
Reference in New Issue