First Commit
This commit is contained in:
567
libraries/SdFat/extras/AvrPrintStimmer.cpp
Normal file
567
libraries/SdFat/extras/AvrPrintStimmer.cpp
Normal file
@@ -0,0 +1,567 @@
|
||||
/*
|
||||
Print.cpp - Base class that provides print() and println()
|
||||
Copyright (c) 2008 David A. Mellis. All right reserved.
|
||||
many modifications, by Paul Stoffregen <paul@pjrc.com>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Modified 23 November 2006 by David A. Mellis
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include "Arduino.h" // (was wiring.h)
|
||||
|
||||
#include "Print.h"
|
||||
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#else
|
||||
void Print::write(const char *str)
|
||||
{
|
||||
write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t count = 0;
|
||||
while (size--) count += write(*buffer++);
|
||||
return count;
|
||||
}
|
||||
#else
|
||||
void Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
while (size--) write(*buffer++);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t Print::print(const String &s)
|
||||
{
|
||||
uint8_t buffer[33];
|
||||
size_t count = 0;
|
||||
unsigned int index = 0;
|
||||
unsigned int len = s.length();
|
||||
while (len > 0) {
|
||||
s.getBytes(buffer, sizeof(buffer), index);
|
||||
unsigned int nbytes = len;
|
||||
if (nbytes > sizeof(buffer)-1) nbytes = sizeof(buffer)-1;
|
||||
index += nbytes;
|
||||
len -= nbytes;
|
||||
count += write(buffer, nbytes);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
#else
|
||||
void Print::print(const String &s)
|
||||
{
|
||||
unsigned int len = s.length();
|
||||
for (unsigned int i=0; i < len; i++) {
|
||||
write(s[i]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
uint8_t buffer[32];
|
||||
size_t count = 0;
|
||||
const char PROGMEM *p = (const char PROGMEM *)ifsh;
|
||||
unsigned int len = strlen_P(p);
|
||||
while (len > 0) {
|
||||
unsigned int nbytes = len;
|
||||
if (nbytes > sizeof(buffer)) nbytes = sizeof(buffer);
|
||||
memcpy_P(buffer, p, nbytes);
|
||||
p += nbytes;
|
||||
len -= nbytes;
|
||||
count += write(buffer, nbytes);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
#else
|
||||
void Print::print(const __FlashStringHelper *ifsh)
|
||||
{
|
||||
const char PROGMEM *p = (const char PROGMEM *)ifsh;
|
||||
while (1) {
|
||||
unsigned char c = pgm_read_byte(p++);
|
||||
if (c == 0) return;
|
||||
write(c);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t Print::print(long n)
|
||||
{
|
||||
uint8_t sign=0;
|
||||
|
||||
if (n < 0) {
|
||||
sign = 1;
|
||||
n = -n;
|
||||
}
|
||||
return printNumber(n, sign, 10);
|
||||
}
|
||||
#else
|
||||
void Print::print(long n)
|
||||
{
|
||||
uint8_t sign=0;
|
||||
|
||||
if (n < 0) {
|
||||
sign = 1;
|
||||
n = -n;
|
||||
}
|
||||
printNumber(n, sign, 10);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t Print::println(void)
|
||||
{
|
||||
uint8_t buf[2]={'\r', '\n'};
|
||||
return write(buf, 2);
|
||||
}
|
||||
#else
|
||||
void Print::println(void)
|
||||
{
|
||||
uint8_t buf[2]={'\r', '\n'};
|
||||
write(buf, 2);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
//#define USE_HACKER_DELIGHT_OPTIMIZATION
|
||||
#define USE_STIMMER_OPTIMIZATION
|
||||
#define USE_BENCHMARK_CODE
|
||||
|
||||
|
||||
#ifdef USE_HACKER_DELIGHT_OPTIMIZATION
|
||||
// Adapted from Hacker's Delight (Henry Warren, ISBN 0321842685) www.hackersdelight.org
|
||||
// by Rob Tillaart, Tom Carpenter, "genom2" with input from others...
|
||||
// http://forum.arduino.cc/index.php?topic=167414.0
|
||||
//
|
||||
#define divmod10_asm(in32, tmp32, mod8) \
|
||||
asm volatile ( \
|
||||
"mov %2, %A0 \n\t" /* mod = in */ \
|
||||
"ori %A0, 1 \n\t" /* q = in | 1 */ \
|
||||
"movw %A1, %A0 \n\t" /* x = q */ \
|
||||
"movw %C1, %C0 \n\t" \
|
||||
"lsr %D1 \n\t" /* x = x >> 2 */ \
|
||||
"ror %C1 \n\t" \
|
||||
"ror %B1 \n\t" \
|
||||
"ror %A1 \n\t" \
|
||||
"lsr %D1 \n\t" \
|
||||
"ror %C1 \n\t" \
|
||||
"ror %B1 \n\t" \
|
||||
"ror %A1 \n\t" \
|
||||
"sub %A0, %A1 \n\t" /* q = q - x */ \
|
||||
"sbc %B0, %B1 \n\t" \
|
||||
"sbc %C0, %C1 \n\t" \
|
||||
"sbc %D0, %D1 \n\t" \
|
||||
"movw %A1, %A0 \n\t" /* x = q */ \
|
||||
"movw %C1, %C0 \n\t" \
|
||||
"lsr %D1 \n\t" /* x = x >> 4 */ \
|
||||
"ror %C1 \n\t" \
|
||||
"ror %B1 \n\t" \
|
||||
"ror %A1 \n\t" \
|
||||
"lsr %D1 \n\t" \
|
||||
"ror %C1 \n\t" \
|
||||
"ror %B1 \n\t" \
|
||||
"ror %A1 \n\t" \
|
||||
"lsr %D1 \n\t" \
|
||||
"ror %C1 \n\t" \
|
||||
"ror %B1 \n\t" \
|
||||
"ror %A1 \n\t" \
|
||||
"lsr %D1 \n\t" \
|
||||
"ror %C1 \n\t" \
|
||||
"ror %B1 \n\t" \
|
||||
"ror %A1 \n\t" \
|
||||
"add %A1, %A0 \n\t" /* x = x + q */ \
|
||||
"adc %B1, %B0 \n\t" \
|
||||
"adc %C1, %C0 \n\t" \
|
||||
"adc %D1, %D0 \n\t" \
|
||||
"movw %A0, %A1 \n\t" /* q = x */ \
|
||||
"movw %C0, %C1 \n\t" \
|
||||
"add %A0, %B1 \n\t" /* q = q + (x >> 8) */ \
|
||||
"adc %B0, %C1 \n\t" \
|
||||
"adc %C0, %D1 \n\t" \
|
||||
"adc %D0, r1 \n\t" \
|
||||
"mov %A0, %B0 \n\t" /* q = q >> 8 */ \
|
||||
"mov %B0, %C0 \n\t" \
|
||||
"mov %C0, %D0 \n\t" \
|
||||
"eor %D0, %D0 \n\t" \
|
||||
"add %A0, %A1 \n\t" /* q = q + x */ \
|
||||
"adc %B0, %B1 \n\t" \
|
||||
"adc %C0, %C1 \n\t" \
|
||||
"adc %D0, %D1 \n\t" \
|
||||
"mov %A0, %B0 \n\t" /* q = q >> 8 */ \
|
||||
"mov %B0, %C0 \n\t" \
|
||||
"mov %C0, %D0 \n\t" \
|
||||
"eor %D0, %D0 \n\t" \
|
||||
"add %A0, %A1 \n\t" /* q = q + x */ \
|
||||
"adc %B0, %B1 \n\t" \
|
||||
"adc %C0, %C1 \n\t" \
|
||||
"adc %D0, %D1 \n\t" \
|
||||
"mov %A0, %B0 \n\t" /* q = q >> 8 */ \
|
||||
"mov %B0, %C0 \n\t" \
|
||||
"mov %C0, %D0 \n\t" \
|
||||
"eor %D0, %D0 \n\t" \
|
||||
"add %A0, %A1 \n\t" /* q = q + x */ \
|
||||
"adc %B0, %B1 \n\t" \
|
||||
"adc %C0, %C1 \n\t" \
|
||||
"adc %D0, %D1 \n\t" \
|
||||
"andi %A0, 0xF8 \n\t" /* q = q & ~0x7 */ \
|
||||
"sub %2, %A0 \n\t" /* mod = mod - q */ \
|
||||
"lsr %D0 \n\t" /* q = q >> 2 */ \
|
||||
"ror %C0 \n\t" \
|
||||
"ror %B0 \n\t" \
|
||||
"ror %A0 \n\t" \
|
||||
"lsr %D0 \n\t" \
|
||||
"ror %C0 \n\t" \
|
||||
"ror %B0 \n\t" \
|
||||
"ror %A0 \n\t" \
|
||||
"sub %2, %A0 \n\t" /* mod = mod - q */ \
|
||||
"lsr %D0 \n\t" /* q = q >> 1 */ \
|
||||
"ror %C0 \n\t" \
|
||||
"ror %B0 \n\t" \
|
||||
"ror %A0 \n\t" \
|
||||
: "+d" (in32), "=r" (tmp32), "=r" (mod8) : : "r0" \
|
||||
)
|
||||
#endif // USE_HACKER_DELIGHT_OPTIMIZATION
|
||||
|
||||
#ifdef USE_STIMMER_OPTIMIZATION
|
||||
// http://forum.arduino.cc/index.php?topic=167414.msg1293679#msg1293679
|
||||
#define divmod10_asm32(in32, mod8, tmp8) \
|
||||
asm volatile ( \
|
||||
" ldi %2,51 \n\t" \
|
||||
" mul %A0,%2 \n\t" \
|
||||
" clr %A0 \n\t" \
|
||||
" add r0,%2 \n\t" \
|
||||
" adc %A0,r1 \n\t" \
|
||||
" mov %1,r0 \n\t" \
|
||||
" mul %B0,%2 \n\t" \
|
||||
" clr %B0 \n\t" \
|
||||
" add %A0,r0 \n\t" \
|
||||
" adc %B0,r1 \n\t" \
|
||||
" mul %C0,%2 \n\t" \
|
||||
" clr %C0 \n\t" \
|
||||
" add %B0,r0 \n\t" \
|
||||
" adc %C0,r1 \n\t" \
|
||||
" mul %D0,%2 \n\t" \
|
||||
" clr %D0 \n\t" \
|
||||
" add %C0,r0 \n\t" \
|
||||
" adc %D0,r1 \n\t" \
|
||||
" clr r1 \n\t" \
|
||||
" add %1,%A0 \n\t" \
|
||||
" adc %A0,%B0 \n\t" \
|
||||
" adc %B0,%C0 \n\t" \
|
||||
" adc %C0,%D0 \n\t" \
|
||||
" adc %D0,r1 \n\t" \
|
||||
" add %1,%B0 \n\t" \
|
||||
" adc %A0,%C0 \n\t" \
|
||||
" adc %B0,%D0 \n\t" \
|
||||
" adc %C0,r1 \n\t" \
|
||||
" adc %D0,r1 \n\t" \
|
||||
" add %1,%D0 \n\t" \
|
||||
" adc %A0,r1 \n\t" \
|
||||
" adc %B0,r1 \n\t" \
|
||||
" adc %C0,r1 \n\t" \
|
||||
" adc %D0,r1 \n\t" \
|
||||
" lsr %D0 \n\t" \
|
||||
" ror %C0 \n\t" \
|
||||
" ror %B0 \n\t" \
|
||||
" ror %A0 \n\t" \
|
||||
" ror %1 \n\t" \
|
||||
" ldi %2,10 \n\t" \
|
||||
" mul %1,%2 \n\t" \
|
||||
" mov %1,r1 \n\t" \
|
||||
" clr r1 \n\t" \
|
||||
:"+r"(in32),"=d"(mod8),"=d"(tmp8) : : "r0")
|
||||
|
||||
#define divmod10_asm24(in32, mod8, tmp8) \
|
||||
asm volatile ( \
|
||||
" ldi %2,51 \n\t" \
|
||||
" mul %A0,%2 \n\t" \
|
||||
" clr %A0 \n\t" \
|
||||
" add r0,%2 \n\t" \
|
||||
" adc %A0,r1 \n\t" \
|
||||
" mov %1,r0 \n\t" \
|
||||
" mul %B0,%2 \n\t" \
|
||||
" clr %B0 \n\t" \
|
||||
" add %A0,r0 \n\t" \
|
||||
" adc %B0,r1 \n\t" \
|
||||
" mul %C0,%2 \n\t" \
|
||||
" clr %C0 \n\t" \
|
||||
" add %B0,r0 \n\t" \
|
||||
" adc %C0,r1 \n\t" \
|
||||
" clr r1 \n\t" \
|
||||
" add %1,%A0 \n\t" \
|
||||
" adc %A0,%B0 \n\t" \
|
||||
" adc %B0,%C0 \n\t" \
|
||||
" adc %C0,r1 \n\t" \
|
||||
" add %1,%B0 \n\t" \
|
||||
" adc %A0,%C0 \n\t" \
|
||||
" adc %B0,r1 \n\t" \
|
||||
" adc %C0,r1 \n\t" \
|
||||
" lsr %C0 \n\t" \
|
||||
" ror %B0 \n\t" \
|
||||
" ror %A0 \n\t" \
|
||||
" ror %1 \n\t" \
|
||||
" ldi %2,10 \n\t" \
|
||||
" mul %1,%2 \n\t" \
|
||||
" mov %1,r1 \n\t" \
|
||||
" clr r1 \n\t" \
|
||||
:"+r"(in32),"=d"(mod8),"=d"(tmp8) : : "r0")
|
||||
|
||||
#define divmod10_asm16(in32, mod8, tmp8) \
|
||||
asm volatile ( \
|
||||
" ldi %2,51 \n\t" \
|
||||
" mul %A0,%2 \n\t" \
|
||||
" clr %A0 \n\t" \
|
||||
" add r0,%2 \n\t" \
|
||||
" adc %A0,r1 \n\t" \
|
||||
" mov %1,r0 \n\t" \
|
||||
" mul %B0,%2 \n\t" \
|
||||
" clr %B0 \n\t" \
|
||||
" add %A0,r0 \n\t" \
|
||||
" adc %B0,r1 \n\t" \
|
||||
" clr r1 \n\t" \
|
||||
" add %1,%A0 \n\t" \
|
||||
" adc %A0,%B0 \n\t" \
|
||||
" adc %B0,r1 \n\t" \
|
||||
" add %1,%B0 \n\t" \
|
||||
" adc %A0,r1 \n\t" \
|
||||
" adc %B0,r1 \n\t" \
|
||||
" lsr %B0 \n\t" \
|
||||
" ror %A0 \n\t" \
|
||||
" ror %1 \n\t" \
|
||||
" ldi %2,10 \n\t" \
|
||||
" mul %1,%2 \n\t" \
|
||||
" mov %1,r1 \n\t" \
|
||||
" clr r1 \n\t" \
|
||||
:"+r"(in32),"=d"(mod8),"=d"(tmp8) : : "r0")
|
||||
|
||||
#define divmod10_asm8(in32, mod8, tmp8) \
|
||||
asm volatile ( \
|
||||
" ldi %2,51 \n\t" \
|
||||
" mul %A0,%2 \n\t" \
|
||||
" clr %A0 \n\t" \
|
||||
" add r0,%2 \n\t" \
|
||||
" adc %A0,r1 \n\t" \
|
||||
" mov %1,r0 \n\t" \
|
||||
" clr r1 \n\t" \
|
||||
" add %1,%A0 \n\t" \
|
||||
" adc %A0,r1 \n\t" \
|
||||
" lsr %A0 \n\t" \
|
||||
" ror %1 \n\t" \
|
||||
" ldi %2,10 \n\t" \
|
||||
" mul %1,%2 \n\t" \
|
||||
" mov %1,r1 \n\t" \
|
||||
" clr r1 \n\t" \
|
||||
:"+r"(in32),"=d"(mod8),"=d"(tmp8) : : "r0")
|
||||
#endif // USE_STIMMER_OPTIMIZATION
|
||||
|
||||
|
||||
|
||||
#ifdef USE_BENCHMARK_CODE
|
||||
uint32_t usec_print = 0;
|
||||
#endif
|
||||
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t Print::printNumberDec(unsigned long n, uint8_t sign)
|
||||
#else
|
||||
void Print::printNumberDec(unsigned long n, uint8_t sign)
|
||||
#endif
|
||||
{
|
||||
uint8_t digit, buf[11], *p;
|
||||
uint32_t tmp32;
|
||||
uint8_t tmp8;
|
||||
|
||||
#ifdef USE_BENCHMARK_CODE
|
||||
uint32_t usec = micros();
|
||||
#endif
|
||||
p = buf + (sizeof(buf)-1);
|
||||
|
||||
#if defined(USE_STIMMER_OPTIMIZATION)
|
||||
|
||||
while(n & 0xff000000){divmod10_asm32(n, digit, tmp8);*--p = digit + '0';}
|
||||
while(n & 0xff0000){divmod10_asm24(n, digit, tmp8);*--p = digit + '0';}
|
||||
while(n & 0xff00){divmod10_asm16(n, digit, tmp8);*--p = digit + '0';}
|
||||
while((n & 0xff)>9){divmod10_asm8(n, digit, tmp8);*--p = digit + '0';}
|
||||
*--p = n + '0';
|
||||
|
||||
#else
|
||||
do {
|
||||
#if defined(USE_HACKER_DELIGHT_OPTIMIZATION)
|
||||
divmod10_asm(n, tmp32, digit);
|
||||
#else
|
||||
tmp32 = n;
|
||||
n = n / 10;
|
||||
digit = tmp32 - n * 10;
|
||||
#endif
|
||||
*--p = digit + '0';
|
||||
} while (n);
|
||||
#endif
|
||||
if (sign) *--p = '-';
|
||||
#ifdef USE_BENCHMARK_CODE
|
||||
usec_print += micros() - usec;
|
||||
#endif
|
||||
#if ARDUINO >= 100
|
||||
return write(p, sizeof(buf)-1 - (p - buf));
|
||||
#else
|
||||
write(p, sizeof(buf)-1 - (p - buf));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t Print::printNumberHex(unsigned long n)
|
||||
#else
|
||||
void Print::printNumberHex(unsigned long n)
|
||||
#endif
|
||||
{
|
||||
uint8_t digit, buf[8], *p;
|
||||
|
||||
p = buf + (sizeof(buf)-1);
|
||||
do {
|
||||
digit = n & 15;
|
||||
*--p = (digit < 10) ? '0' + digit : 'A' + digit - 10;
|
||||
n >>= 4;
|
||||
} while (n);
|
||||
#if ARDUINO >= 100
|
||||
return write(p, sizeof(buf)-1 - (p - buf));
|
||||
#else
|
||||
write(p, sizeof(buf)-1 - (p - buf));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t Print::printNumberBin(unsigned long n)
|
||||
#else
|
||||
void Print::printNumberBin(unsigned long n)
|
||||
#endif
|
||||
{
|
||||
uint8_t buf[32], *p;
|
||||
|
||||
p = buf + (sizeof(buf)-1);
|
||||
do {
|
||||
*--p = '0' + ((uint8_t)n & 1);
|
||||
n >>= 1;
|
||||
} while (n);
|
||||
#if ARDUINO >= 100
|
||||
return write(p, sizeof(buf)-1 - (p - buf));
|
||||
#else
|
||||
write(p, sizeof(buf)-1 - (p - buf));
|
||||
#endif
|
||||
}
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t Print::printNumberAny(unsigned long n, uint8_t base)
|
||||
#else
|
||||
void Print::printNumberAny(unsigned long n, uint8_t base)
|
||||
#endif
|
||||
{
|
||||
uint8_t digit, buf[21], *p;
|
||||
uint32_t tmp;
|
||||
//uint32_t usec;
|
||||
|
||||
//usec = micros();
|
||||
p = buf + (sizeof(buf)-1);
|
||||
do {
|
||||
tmp = n;
|
||||
n = n / base;
|
||||
digit = tmp - n * base;
|
||||
*--p = (digit < 10) ? '0' + digit : 'A' + digit - 10;
|
||||
} while (n);
|
||||
//usec_print += micros() - usec;
|
||||
#if ARDUINO >= 100
|
||||
return write(p, sizeof(buf)-1 - (p - buf));
|
||||
#else
|
||||
write(p, sizeof(buf)-1 - (p - buf));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#if ARDUINO >= 100
|
||||
size_t Print::printFloat(double number, uint8_t digits)
|
||||
#else
|
||||
void Print::printFloat(double number, uint8_t digits)
|
||||
#endif
|
||||
{
|
||||
uint8_t sign=0;
|
||||
#if ARDUINO >= 100
|
||||
size_t count=0;
|
||||
#endif
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0) {
|
||||
sign = 1;
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i) {
|
||||
rounding *= 0.1;
|
||||
}
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
#if ARDUINO >= 100
|
||||
count += printNumber(int_part, sign, 10);
|
||||
#else
|
||||
printNumber(int_part, sign, 10);
|
||||
#endif
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
uint8_t n, buf[8], count=1;
|
||||
buf[0] = '.';
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
if (digits > sizeof(buf) - 1) digits = sizeof(buf) - 1;
|
||||
|
||||
while (digits-- > 0) {
|
||||
remainder *= 10.0;
|
||||
n = (uint8_t)(remainder);
|
||||
buf[count++] = '0' + n;
|
||||
remainder -= n;
|
||||
}
|
||||
#if ARDUINO >= 100
|
||||
count += write(buf, count);
|
||||
#else
|
||||
write(buf, count);
|
||||
#endif
|
||||
}
|
||||
#if ARDUINO >= 100
|
||||
return count;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
BIN
libraries/SdFat/extras/USB_Host_Shield/USB_Host_Shield_2.0.zip
Normal file
BIN
libraries/SdFat/extras/USB_Host_Shield/USB_Host_Shield_2.0.zip
Normal file
Binary file not shown.
10
libraries/SdFat/extras/USB_Host_Shield/UsbHostShieldDiff.txt
Normal file
10
libraries/SdFat/extras/USB_Host_Shield/UsbHostShieldDiff.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
master/masstorage.cpp" 2022-10-18 08:48:03.639503200 -0700
|
||||
@@ -796,6 +796,7 @@
|
||||
buf[i] = 0x00;
|
||||
}
|
||||
WriteOk[lun] = true;
|
||||
+ return 0; // WHG - Many USB keys don't respond.
|
||||
uint8_t rc = ModeSense6(lun, 0, 0x3f, 0, 192, buf);
|
||||
if(!rc) {
|
||||
WriteOk[lun] = ((buf[2] & 0x80) == 0);
|
||||
|
||||
6
libraries/SdFat/extras/USB_Host_Shield/readme.txt
Normal file
6
libraries/SdFat/extras/USB_Host_Shield/readme.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
This zip file was downloaded on 10/18/2022 from
|
||||
|
||||
https://github.com/felis/USB_Host_Shield_2.0
|
||||
|
||||
A line was added to fix a problem with sensing read only status,
|
||||
see UsbHostShieldDiff.txt.
|
||||
91
libraries/SdFat/extras/attic/PrintBasic.cpp
Normal file
91
libraries/SdFat/extras/attic/PrintBasic.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2020 Bill Greiman
|
||||
* This file is part of the SdFat library for SD memory cards.
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "PrintBasic.h"
|
||||
#if ENABLE_ARDUINO_FEATURES == 0
|
||||
#include <math.h>
|
||||
|
||||
size_t PrintBasic::print(long n, uint8_t base) {
|
||||
if (n < 0 && base == 10) {
|
||||
return print('-') + printNum(-n, base);
|
||||
}
|
||||
return printNum(n, base);
|
||||
}
|
||||
size_t PrintBasic::printNum(unsigned long n, uint8_t base) {
|
||||
const uint8_t DIM = 8 * sizeof(long);
|
||||
char buf[DIM];
|
||||
char *str = &buf[DIM];
|
||||
|
||||
if (base < 2) return 0;
|
||||
|
||||
do {
|
||||
char c = n % base;
|
||||
n /= base;
|
||||
*--str = c + (c < 10 ? '0' : 'A' - 10);
|
||||
} while (n);
|
||||
return write(str, &buf[DIM] - str);
|
||||
}
|
||||
|
||||
size_t PrintBasic::printDouble(double n, uint8_t prec) {
|
||||
// Max printable 32-bit floating point number. AVR uses 32-bit double.
|
||||
const double maxfp = static_cast<double>(0XFFFFFF00UL);
|
||||
size_t rtn = 0;
|
||||
|
||||
if (isnan(n)) {
|
||||
return write("NaN");
|
||||
}
|
||||
if (n < 0) {
|
||||
n = -n;
|
||||
rtn += print('-');
|
||||
}
|
||||
if (isinf(n)) {
|
||||
return rtn + write("Inf");
|
||||
}
|
||||
if (n > maxfp) {
|
||||
return rtn + write("Ovf");
|
||||
}
|
||||
|
||||
double round = 0.5;
|
||||
for (uint8_t i = 0; i < prec; ++i) {
|
||||
round *= 0.1;
|
||||
}
|
||||
|
||||
n += round;
|
||||
|
||||
uint32_t whole = (uint32_t)n;
|
||||
rtn += print(whole);
|
||||
|
||||
if (prec) {
|
||||
rtn += print('.');
|
||||
double fraction = n - static_cast<double>(whole);
|
||||
for (uint8_t i = 0; i < prec; i++) {
|
||||
fraction *= 10.0;
|
||||
uint8_t digit = fraction;
|
||||
rtn += print(digit);
|
||||
fraction -= digit;
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
#endif // ENABLE_ARDUINO_FEATURES == 0
|
||||
148
libraries/SdFat/extras/attic/PrintBasic.h
Normal file
148
libraries/SdFat/extras/attic/PrintBasic.h
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2020 Bill Greiman
|
||||
* This file is part of the SdFat library for SD memory cards.
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef PrintBasic_h
|
||||
#define PrintBasic_h
|
||||
/**
|
||||
* \file
|
||||
* \brief Stream/Print like replacement for non-Arduino systems.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../SdFatConfig.h"
|
||||
|
||||
#ifndef F
|
||||
#if defined(__AVR__)
|
||||
#include <avr/pgmspace.h>
|
||||
class __FlashStringHelper;
|
||||
#define F(string_literal) \
|
||||
(reinterpret_cast<const __FlashStringHelper *>(PSTR(string_literal)))
|
||||
#else // defined(__AVR__)
|
||||
#define F(str) (str)
|
||||
#endif // defined(__AVR__)
|
||||
#endif // F
|
||||
|
||||
#ifdef BIN
|
||||
#undef BIN
|
||||
#endif // BIN
|
||||
#define BIN 2
|
||||
#define OCT 8
|
||||
#define DEC 10
|
||||
#define HEX 16
|
||||
|
||||
class PrintBasic {
|
||||
public:
|
||||
PrintBasic() : m_error(0) {}
|
||||
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
int getWriteError() { return m_error; }
|
||||
size_t print(char c) { return write(c); }
|
||||
size_t print(const char *str) { return write(str); }
|
||||
size_t print(const __FlashStringHelper *str) {
|
||||
#ifdef __AVR__
|
||||
PGM_P p = reinterpret_cast<PGM_P>(str);
|
||||
size_t n = 0;
|
||||
for (uint8_t c; (c = pgm_read_byte(p + n)) && write(c); n++) {
|
||||
}
|
||||
return n;
|
||||
#else // __AVR__
|
||||
return print(reinterpret_cast<const char *>(str));
|
||||
#endif // __AVR__
|
||||
}
|
||||
size_t println(const __FlashStringHelper *str) {
|
||||
#ifdef __AVR__
|
||||
return print(str) + println();
|
||||
#else // __AVR__
|
||||
return println(reinterpret_cast<const char *>(str));
|
||||
#endif // __AVR__
|
||||
}
|
||||
size_t print(double n, uint8_t prec = 2) { return printDouble(n, prec); }
|
||||
size_t print(signed char n, uint8_t base = 10) {
|
||||
return print((long)n, base);
|
||||
}
|
||||
size_t print(unsigned char n, uint8_t base = 10) {
|
||||
return print((unsigned long)n, base);
|
||||
}
|
||||
size_t print(int n, uint8_t base = 10) { return print((long)n, base); }
|
||||
size_t print(unsigned int n, uint8_t base = 10) {
|
||||
return print((unsigned long)n, base);
|
||||
}
|
||||
size_t print(long n, uint8_t base = 10);
|
||||
size_t print(unsigned long n, uint8_t base = 10) { return printNum(n, base); }
|
||||
size_t println() { return write("\r\n"); }
|
||||
size_t println(char c) { return write(c) + println(); }
|
||||
size_t println(const char *str) { return print(str) + println(); }
|
||||
size_t println(double n, uint8_t prec = 2) {
|
||||
return print(n, prec) + println();
|
||||
}
|
||||
size_t println(signed char n, uint8_t base = 10) {
|
||||
return print(n, base) + println();
|
||||
}
|
||||
size_t println(unsigned char n, uint8_t base = 10) {
|
||||
return print(n, base) + println();
|
||||
}
|
||||
size_t println(int n, uint8_t base = 10) {
|
||||
return print(n, base) + println();
|
||||
}
|
||||
size_t println(unsigned int n, uint8_t base = 10) {
|
||||
return print(n, base) + println();
|
||||
}
|
||||
size_t println(long n, uint8_t base = 10) {
|
||||
return print(n, base) + println();
|
||||
}
|
||||
size_t println(unsigned long n, uint8_t base = 10) {
|
||||
return print(n, base) + println();
|
||||
}
|
||||
size_t write(const char *str) { return write(str, strlen(str)); }
|
||||
virtual size_t write(uint8_t b) = 0;
|
||||
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) {
|
||||
size_t i;
|
||||
for (i = 0; i < size; i++) {
|
||||
if (!write(buffer[i])) break;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
size_t write(const char *buffer, size_t size) {
|
||||
return write(reinterpret_cast<const uint8_t *>(buffer), size);
|
||||
}
|
||||
|
||||
protected:
|
||||
void setWriteError(int err = 1) { m_error = err; }
|
||||
|
||||
private:
|
||||
size_t printDouble(double n, uint8_t prec);
|
||||
size_t printNum(unsigned long n, uint8_t base);
|
||||
int m_error;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
class StreamBasic : public PrintBasic {
|
||||
public:
|
||||
virtual int available() = 0;
|
||||
virtual int peek() = 0;
|
||||
virtual int read() = 0;
|
||||
};
|
||||
#endif // PrintBasic_h
|
||||
500
libraries/SdFat/extras/attic/PrintTemplates.h
Normal file
500
libraries/SdFat/extras/attic/PrintTemplates.h
Normal file
@@ -0,0 +1,500 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2020 Bill Greiman
|
||||
* This file is part of the SdFat library for SD memory cards.
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#ifndef PrintTemplates_h
|
||||
#define PrintTemplates_h
|
||||
/**
|
||||
* \file
|
||||
* \brief templates for printf
|
||||
*/
|
||||
#include <stdarg.h>
|
||||
#include "FmtNumber.h"
|
||||
/** test for digit */
|
||||
#define isDigit(d) ('0' <= (d) && (d) <= '9')
|
||||
/** control for supported floating formats */
|
||||
#define PRINTF_USE_FLOAT 2
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Formatted print.
|
||||
*
|
||||
* \param[in] file destination file or device.
|
||||
* \param[in] fmt format string.
|
||||
* \param[in] ap argument list.
|
||||
*
|
||||
* \return number of character printed for success else a negative value.
|
||||
*/
|
||||
template<typename F>
|
||||
int vfprintf(F* file, const char *fmt, va_list ap) {
|
||||
#if PRINTF_USE_FLOAT
|
||||
char buf[30];
|
||||
double f;
|
||||
#else // PRINTF_USE_FLOAT
|
||||
char buf[15];
|
||||
#endif // PRINTF_USE_FLOAT
|
||||
char prefix[3];
|
||||
unsigned base;
|
||||
int n;
|
||||
int nc = 0;
|
||||
int nf;
|
||||
int nz;
|
||||
int prec;
|
||||
int width;
|
||||
size_t np;
|
||||
size_t ns;
|
||||
size_t nw;
|
||||
long ln;
|
||||
char c;
|
||||
char plusSign;
|
||||
char* ptr; // end of string
|
||||
char* str; // start of string
|
||||
bool altForm;
|
||||
bool leftAdjust;
|
||||
bool isLong;
|
||||
bool zeroPad;
|
||||
|
||||
while (true) {
|
||||
const char* bgn = fmt;
|
||||
while ((c = *fmt++) && c!= '%') {}
|
||||
nw = fmt - bgn - 1;
|
||||
if (nw) {
|
||||
nc += nw;
|
||||
if (nw != file->write(bgn, nw)) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
if (!c) break;
|
||||
altForm = false;
|
||||
leftAdjust = false;
|
||||
np = 0;
|
||||
nz = 0;
|
||||
zeroPad = false;
|
||||
plusSign = 0;
|
||||
c = *fmt++;
|
||||
|
||||
while (true) {
|
||||
if (c == '-') {
|
||||
leftAdjust = true;
|
||||
} else if (c == '+') {
|
||||
plusSign = '+';
|
||||
} else if (c == ' ') {
|
||||
if (plusSign == 0) {
|
||||
plusSign = ' ';
|
||||
}
|
||||
} else if (c == '0') {
|
||||
zeroPad = true;
|
||||
} else if (c == '#') {
|
||||
altForm = true;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
c = *fmt++;
|
||||
}
|
||||
|
||||
width = 0;
|
||||
if (isDigit(c)) {
|
||||
while(isDigit(c)) {
|
||||
width = 10 * width + c - '0';
|
||||
c = *fmt++;
|
||||
}
|
||||
} else if (c == '*') {
|
||||
width = va_arg(ap, int);
|
||||
c = *fmt++;
|
||||
if (width < 0) {
|
||||
leftAdjust = true;
|
||||
width = -width;
|
||||
}
|
||||
}
|
||||
if (leftAdjust) {
|
||||
zeroPad = false;
|
||||
}
|
||||
|
||||
prec = -1;
|
||||
if (c == '.') {
|
||||
zeroPad = false;
|
||||
prec = 0;
|
||||
c = *fmt++;
|
||||
if (isDigit(c)) {
|
||||
while(isDigit(c)) {
|
||||
prec = 10 * prec + c - '0';
|
||||
c = *fmt++;
|
||||
}
|
||||
} else if (c == '*') {
|
||||
prec = va_arg(ap, int);
|
||||
c = *fmt++;
|
||||
}
|
||||
}
|
||||
|
||||
isLong = false;
|
||||
if (c == 'l' || c =='L') {
|
||||
isLong = true;
|
||||
c = *fmt++;
|
||||
}
|
||||
|
||||
if (!c) break;
|
||||
|
||||
str = buf + sizeof(buf);
|
||||
ptr = str;
|
||||
switch(c) {
|
||||
case 'c':
|
||||
*--str = va_arg(ap, int);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
str = va_arg(ap, char *);
|
||||
if (!str) {
|
||||
str = (char*)"(null)";
|
||||
}
|
||||
ns = strlen(str);
|
||||
ptr = str + (prec >= 0 && (size_t)prec < ns ? prec : ns);
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
case 'i':
|
||||
ln = isLong ? va_arg(ap, long) : va_arg(ap, int);
|
||||
if (prec || ln) {
|
||||
if (ln < 0) {
|
||||
prefix[np++] = '-';
|
||||
ln = -ln;
|
||||
} else if (plusSign) {
|
||||
prefix[np++] = plusSign;
|
||||
}
|
||||
str = fmtUnsigned(str, ln, 10, true);
|
||||
nz = prec + str - ptr;
|
||||
}
|
||||
break;
|
||||
|
||||
#if PRINTF_USE_FLOAT > 1
|
||||
case 'e':
|
||||
case 'E':
|
||||
case 'f':
|
||||
case 'F':
|
||||
f = va_arg(ap, double);
|
||||
if (f < 0) {
|
||||
f = -f;
|
||||
prefix[np++] = '-';
|
||||
} else if (plusSign) {
|
||||
prefix[np++] = plusSign;
|
||||
}
|
||||
str = fmtDouble(str, f, prec < 0 ? 6 : prec, altForm, c);
|
||||
break;
|
||||
#elif PRINTF_USE_FLOAT > 0
|
||||
case 'f':
|
||||
case 'F':
|
||||
f = va_arg(ap, double);
|
||||
if (f < 0) {
|
||||
f = -f;
|
||||
prefix[np++] = '-';
|
||||
} else if (plusSign) {
|
||||
prefix[np++] = plusSign;
|
||||
}
|
||||
str = fmtDouble(str, f, prec < 0 ? 6 : prec, altForm);
|
||||
break;
|
||||
#endif // PRINTF_USE_FLOAT
|
||||
|
||||
case 'o':
|
||||
base = 8;
|
||||
goto printUnsigned;
|
||||
|
||||
case 'u':
|
||||
base = 10;
|
||||
altForm = false;
|
||||
goto printUnsigned;
|
||||
|
||||
case 'x':
|
||||
case 'X':
|
||||
base = 16;
|
||||
goto printUnsigned;
|
||||
|
||||
printUnsigned:
|
||||
ln = isLong ? va_arg(ap, long) : va_arg(ap, int);
|
||||
if (prec || ln) {
|
||||
str = fmtUnsigned(str, ln, base, c == 'X');
|
||||
nz = prec + str - ptr;
|
||||
}
|
||||
if (altForm && ln) {
|
||||
if (c == 'o') {
|
||||
*--str = '0';
|
||||
} else {
|
||||
prefix[np++] = '0';
|
||||
prefix[np++] = c;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
*--str = c;
|
||||
break;
|
||||
}
|
||||
ns = (ptr - str);
|
||||
if (nz < 0) nz = 0;
|
||||
n = ns + np + nz;
|
||||
if (width < n) {
|
||||
nc += n;
|
||||
nf = 0;
|
||||
} else {
|
||||
nc += width;
|
||||
if (zeroPad) {
|
||||
nz += width - n;
|
||||
nf = 0;
|
||||
} else {
|
||||
nf = width - n;
|
||||
}
|
||||
}
|
||||
// Do right blank padding.
|
||||
if (!leftAdjust) {
|
||||
for (; nf > 0; nf--) {
|
||||
if (1 != file->write(' ')) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Don't call write if no prefix.
|
||||
if (np && np != file->write(prefix, np)) {
|
||||
goto fail;
|
||||
}
|
||||
// Do zero padding.
|
||||
for (; nz > 0; nz--) {
|
||||
if (1 != file->write('0')) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
// Main item.
|
||||
if (ns != file->write(str, ns)) {
|
||||
goto fail;
|
||||
}
|
||||
// Right blank padding.
|
||||
for (; nf > 0; nf--) {
|
||||
if (1 != file->write(' ')) {
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
return nc;
|
||||
fail:
|
||||
return -1;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Formatted print.
|
||||
*
|
||||
* \param[in] file destination file or device.
|
||||
* \param[in] fmt format string.
|
||||
*
|
||||
* \return number of character printed for success else a negative value.
|
||||
*/
|
||||
template<typename T>
|
||||
int fprintf(T *file, const char* fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int rtn = vfprintf(file, fmt, ap);
|
||||
va_end(ap);
|
||||
return rtn;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Minimal formatted print.
|
||||
*
|
||||
* \param[in] file destination file or device.
|
||||
* \param[in] fmt format string.
|
||||
* \param[in] ap argument list.
|
||||
*
|
||||
* \return number of character printed for success else a negative value.
|
||||
*/
|
||||
template<typename F>
|
||||
int vmprintf(F* file, const char *fmt, va_list ap) {
|
||||
char buf[15];
|
||||
char* ptr;
|
||||
char* str;
|
||||
bool isLong;
|
||||
char c;
|
||||
int nc = 0;
|
||||
size_t ns;
|
||||
long n;
|
||||
|
||||
while (true) {
|
||||
const char* bgn = fmt;
|
||||
while ((c = *fmt++) && c!= '%') {}
|
||||
ns = fmt - bgn - 1;
|
||||
if (ns) {
|
||||
nc += file->write(bgn, ns);
|
||||
}
|
||||
if (!c) {
|
||||
break;
|
||||
}
|
||||
c = *fmt++;
|
||||
if (c == 'l') {
|
||||
isLong = true;
|
||||
c = *fmt++;
|
||||
} else {
|
||||
isLong = false;
|
||||
}
|
||||
if (!c) {
|
||||
break;
|
||||
}
|
||||
ptr = str = buf + sizeof(buf);
|
||||
switch (c) {
|
||||
case 'c':
|
||||
*--str = va_arg(ap, int);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
str = va_arg(ap, char*);
|
||||
ptr = str ? str + strlen(str) : nullptr;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
n = isLong ? va_arg(ap, long) : va_arg(ap, int);
|
||||
str = fmtSigned(str, n, 10, true);
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
n = isLong ? va_arg(ap, long) : va_arg(ap, int);
|
||||
str = fmtUnsigned(str, n, 10, true);
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
case 'X':
|
||||
n = isLong ? va_arg(ap, long) : va_arg(ap, int);
|
||||
str = fmtUnsigned(str, n, 16, c == 'X');
|
||||
break;
|
||||
|
||||
default:
|
||||
*--str = c;
|
||||
break;
|
||||
}
|
||||
ns = ptr - str;
|
||||
nc += file->write(str, ns);
|
||||
}
|
||||
return nc;
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Minimal formatted print.
|
||||
*
|
||||
* \param[in] file destination file or device.
|
||||
* \param[in] fmt format string.
|
||||
*
|
||||
* \return number of character printed for success else a negative value.
|
||||
*/
|
||||
template<typename T>
|
||||
int mprintf(T *file, const char* fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int rtn = vmprintf(file, fmt, ap);
|
||||
va_end(ap);
|
||||
return rtn;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
#ifdef __AVR__
|
||||
/** Minimal formatted print.
|
||||
*
|
||||
* \param[in] file destination file or device.
|
||||
* \param[in] ifsh format string using F() macro.
|
||||
* \param[in] ap argument list.
|
||||
*
|
||||
* \return number of character printed for success else a negative value.
|
||||
*/
|
||||
template<typename F>
|
||||
int vmprintf(F file, const __FlashStringHelper *ifsh, va_list ap) {
|
||||
bool isLong;
|
||||
char buf[15];
|
||||
char c;
|
||||
char* ptr;
|
||||
char* str;
|
||||
size_t ns;
|
||||
int nc = 0;
|
||||
long n;
|
||||
|
||||
PGM_P fmt = reinterpret_cast<PGM_P>(ifsh);
|
||||
while (true) {
|
||||
while ((c = pgm_read_byte(fmt++)) && c != '%') {
|
||||
nc += file->write(c);
|
||||
}
|
||||
if (!c) {
|
||||
break;
|
||||
}
|
||||
c = pgm_read_byte(fmt++);
|
||||
if (c == 'l') {
|
||||
isLong = true;
|
||||
c = pgm_read_byte(fmt++);
|
||||
} else {
|
||||
isLong = false;
|
||||
}
|
||||
if (!c) {
|
||||
break;
|
||||
}
|
||||
ptr = str = buf + sizeof(buf);
|
||||
switch (c) {
|
||||
case 'c':
|
||||
*--str = va_arg(ap, int);
|
||||
break;
|
||||
|
||||
case 's':
|
||||
str = va_arg(ap, char*);
|
||||
ptr = str ? str + strlen(str) : nullptr;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
n = isLong ? va_arg(ap, long) : va_arg(ap, int);
|
||||
str = fmtSigned(str, n, 10, true);
|
||||
break;
|
||||
|
||||
case 'u':
|
||||
n = isLong ? va_arg(ap, long) : va_arg(ap, int);
|
||||
str = fmtUnsigned(str, n, 10, true);
|
||||
break;
|
||||
|
||||
case 'x':
|
||||
case 'X':
|
||||
n = isLong ? va_arg(ap, long) : va_arg(ap, int);
|
||||
str = fmtUnsigned(str, n, 16, c == 'X');
|
||||
break;
|
||||
|
||||
default:
|
||||
*--str = c;
|
||||
break;
|
||||
}
|
||||
ns = ptr - str;
|
||||
nc += file->write(str, ns);
|
||||
}
|
||||
return nc;
|
||||
}
|
||||
#endif // __AVR__
|
||||
//-----------------------------------------------------------------------------
|
||||
/** Minimal formatted print.
|
||||
*
|
||||
* \param[in] file destination file or device.
|
||||
* \param[in] ifsh format string using F() macro.
|
||||
*
|
||||
* \return number of character printed for success else a negative value.
|
||||
*/
|
||||
template<typename F>
|
||||
int mprintf(F* file, const __FlashStringHelper *ifsh, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, ifsh);
|
||||
#ifdef __AVR__
|
||||
int rtn = vmprintf(file, ifsh, ap);
|
||||
#else // __AVR__
|
||||
int rtn = vmprintf(file, (const char*)ifsh, ap);
|
||||
#endif // __AVR__
|
||||
va_end(ap);
|
||||
return rtn;
|
||||
}
|
||||
#endif // PrintTemplates_h
|
||||
55
libraries/SdFat/extras/attic/SysCallBareUno.cpp
Normal file
55
libraries/SdFat/extras/attic/SysCallBareUno.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Copyright (c) 2011-2020 Bill Greiman
|
||||
* This file is part of the SdFat library for SD memory cards.
|
||||
*
|
||||
* MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "SysCall.h"
|
||||
#if 0 // defined(__AVR_ATmega328P__) && !ENABLE_ARDUINO_FEATURES
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
// ISR for timer 2 Compare A interrupt
|
||||
volatile uint16_t timer2 = 0;
|
||||
ISR(TIMER2_COMPA_vect) {
|
||||
timer2++;
|
||||
}
|
||||
SdMillis_t SysCall::curTimeMS() {
|
||||
if (TIMSK2 != (1 << OCIE2A)) {
|
||||
// use system clock (clkI/O).
|
||||
ASSR &= ~(1 << AS2);
|
||||
// Clear Timer on Compare Match (CTC) mode
|
||||
TCCR2A = (1 << WGM21);
|
||||
// Only need 64x prescale bits in TCCR2B
|
||||
TCCR2B = (1 << CS22);
|
||||
// set TOP so timer period is 1 ms.
|
||||
#if F_CPU/64000 > 250
|
||||
#error F_CPU too large.
|
||||
#endif // F_CPU/64000 > 250
|
||||
OCR2A = F_CPU/64000UL - 1;
|
||||
// Enable interrupt.
|
||||
TIMSK2 = (1 << OCIE2A);
|
||||
}
|
||||
cli();
|
||||
uint16_t rtn = timer2;
|
||||
sei();
|
||||
return rtn;
|
||||
}
|
||||
#endif // defined(__AVR_ATmega328P__) && !ENABLE_ARDUINO_FEATURES
|
||||
2
libraries/SdFat/extras/cpplint.bat
Normal file
2
libraries/SdFat/extras/cpplint.bat
Normal file
@@ -0,0 +1,2 @@
|
||||
sh cpplint.sh
|
||||
pause
|
||||
6244
libraries/SdFat/extras/cpplint.py
vendored
Normal file
6244
libraries/SdFat/extras/cpplint.py
vendored
Normal file
File diff suppressed because it is too large
Load Diff
4
libraries/SdFat/extras/cpplint.sh
Normal file
4
libraries/SdFat/extras/cpplint.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
export PATH=/cygdrive/c/Python27:/cygdrive/c/Python27/DLLs:/cygdrive/c/Python27/Scripts:$PATH
|
||||
echo $PATH
|
||||
python cpplint.py --filter=-build/include,-runtime/references,-build/header_guard ../src/*.* ../src/*/*.* 2>cpplint.txt
|
||||
11
libraries/SdFat/extras/fmt_src.bat
Normal file
11
libraries/SdFat/extras/fmt_src.bat
Normal file
@@ -0,0 +1,11 @@
|
||||
clang-format --style=Google -i *.cpp *.h
|
||||
rem clang-format --style=Google -i DigitalIO/*.h
|
||||
rem clang-format --style=Google -i DigitalIO/boards/*.h
|
||||
clang-format --style=Google -i common/*.cpp common/*.h
|
||||
clang-format --style=Google -i ExFatLib/*.cpp ExFatLib/*.h
|
||||
clang-format --style=Google -i FatLib/*.cpp FatLib/*.h
|
||||
clang-format --style=Google -i FsLib/*.cpp FsLib/*.h
|
||||
clang-format --style=Google -i iostream/*.cpp iostream/*.h
|
||||
clang-format --style=Google -i SdCard/*.cpp SdCard/*.h
|
||||
clang-format --style=Google -i SpiDriver/*.cpp SpiDriver/*.h
|
||||
pause
|
||||
Reference in New Issue
Block a user