Bläddra i källkod

Add printf for Teensy3

main
PaulStoffregen 11 år sedan
förälder
incheckning
8bd53da150
3 ändrade filer med 29 tillägg och 1 borttagningar
  1. +23
    -0
      teensy3/Print.cpp
  2. +4
    -1
      teensy3/Print.h
  3. +2
    -0
      teensy3/mk20dx128.c

+ 23
- 0
teensy3/Print.cpp Visa fil

@@ -75,6 +75,29 @@ size_t Print::println(void)
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)
{

+ 4
- 1
teensy3/Print.h Visa fil

@@ -33,6 +33,7 @@

#include <inttypes.h>
#include <stdio.h> // for size_t - gives sprintf and other stuff to all sketches & libs
#include <stdarg.h>
#include "core_id.h"
#include "WString.h"
#include "Printable.h"
@@ -93,12 +94,14 @@ class Print
size_t println(const Printable &obj) { return obj.printTo(*this) + println(); }
int getWriteError() { return write_error; }
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:
void setWriteError(int err = 1) { write_error = err; }
private:
char write_error;
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 Visa fil

@@ -347,11 +347,13 @@ int _read(int file, char *ptr, int len)
return 0;
}

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

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

Laddar…
Avbryt
Spara