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

#endif #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_HACKER_DELIGHT_OPTIMIZATION
#define USE_STIMMER_OPTIMIZATION #define USE_STIMMER_OPTIMIZATION
//#define USE_BENCHMARK_CODE //#define USE_BENCHMARK_CODE

+ 3
- 0
teensy/Print.h View File



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

Loading…
Cancel
Save