Browse Source

Add printf for Teensy3

main
PaulStoffregen 11 years ago
parent
commit
8bd53da150
3 changed files with 29 additions and 1 deletions
  1. +23
    -0
      teensy3/Print.cpp
  2. +4
    -1
      teensy3/Print.h
  3. +2
    -0
      teensy3/mk20dx128.c

+ 23
- 0
teensy3/Print.cpp View File

return write(buf, 2); return write(buf, 2);
} }


extern "C" {
__attribute__((weak))
int _write(int file, char *ptr, int len)
{
((class Print *)file)->write((uint8_t *)ptr, len);
return 0;
}
}

int Print::printf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
return vdprintf((int)this, format, ap);
}

int Print::printf(const __FlashStringHelper *format, ...)
{
va_list ap;
va_start(ap, format);
return vdprintf((int)this, (const char *)format, ap);
}



size_t Print::printNumber(unsigned long n, uint8_t base, uint8_t sign) size_t Print::printNumber(unsigned long n, uint8_t base, uint8_t sign)
{ {

+ 4
- 1
teensy3/Print.h View File



#include <inttypes.h> #include <inttypes.h>
#include <stdio.h> // for size_t - gives sprintf and other stuff to all sketches & libs #include <stdio.h> // for size_t - gives sprintf and other stuff to all sketches & libs
#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); }
size_t printNumber(unsigned long n, uint8_t base, uint8_t sign);
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:
char write_error; char write_error;
size_t printFloat(double n, uint8_t digits); size_t printFloat(double n, uint8_t digits);
size_t printNumber(unsigned long n, uint8_t base, uint8_t sign);
}; };





+ 2
- 0
teensy3/mk20dx128.c View File

return 0; return 0;
} }


/* moved to Print.cpp, to support Print::printf()
__attribute__((weak)) __attribute__((weak))
int _write(int file, char *ptr, int len) int _write(int file, char *ptr, int len)
{ {
return 0; return 0;
} }
*/


__attribute__((weak)) __attribute__((weak))
int _close(int fd) int _close(int fd)

Loading…
Cancel
Save