Browse Source

Add printf for Teensy2

teensy4-core
PaulStoffregen 11 years ago
parent
commit
b4b56ae747
2 changed files with 34 additions and 0 deletions
  1. +31
    -0
      teensy/Print.cpp
  2. +3
    -0
      teensy/Print.h

+ 31
- 0
teensy/Print.cpp View File

@@ -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 View File

@@ -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…
Cancel
Save