瀏覽代碼

Add printf for Teensy2

main
PaulStoffregen 11 年之前
父節點
當前提交
b4b56ae747
共有 2 個文件被更改,包括 34 次插入0 次删除
  1. +31
    -0
      teensy/Print.cpp
  2. +3
    -0
      teensy/Print.h

+ 31
- 0
teensy/Print.cpp 查看文件

@@ -152,6 +152,37 @@ void Print::println(void)
#endif


#if ARDUINO >= 100
static int printf_putchar(char c, FILE *fp)
{
((class Print *)(fdev_get_udata(fp)))->write((uint8_t)c);
return 0;
}

int Print::printf(const char *format, ...)
{
FILE f;
va_list ap;

fdev_setup_stream(&f, printf_putchar, NULL, _FDEV_SETUP_WRITE);
fdev_set_udata(&f, this);
va_start(ap, format);
return vfprintf(&f, format, ap);
}

int Print::printf(const __FlashStringHelper *format, ...)
{
FILE f;
va_list ap;

fdev_setup_stream(&f, printf_putchar, NULL, _FDEV_SETUP_WRITE);
fdev_set_udata(&f, this);
va_start(ap, format);
return vfprintf_P(&f, (const char *)format, ap);
}
#endif


//#define USE_HACKER_DELIGHT_OPTIMIZATION
#define USE_STIMMER_OPTIMIZATION
//#define USE_BENCHMARK_CODE

+ 3
- 0
teensy/Print.h 查看文件

@@ -22,6 +22,7 @@

#include <inttypes.h>
#include <stdio.h> // for size_t
#include <stdarg.h>
#include "core_id.h"
#include "WString.h"
#include "Printable.h"
@@ -83,6 +84,8 @@ class Print
size_t println(const Printable &obj) { return obj.printTo(*this) + println(); }
int getWriteError() { return write_error; }
void clearWriteError() { setWriteError(0); }
int printf(const char *format, ...);
int printf(const __FlashStringHelper *format, ...);
protected:
void setWriteError(int err = 1) { write_error = err; }
private:

Loading…
取消
儲存