Skip to content

Commit

Permalink
Restructure for RTOS use, getName mods, bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
greiman committed Nov 2, 2021
1 parent 596245a commit bd2c9c5
Show file tree
Hide file tree
Showing 124 changed files with 1,151 additions and 611 deletions.
Binary file modified doc/html.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion examples/AvrAdcLogger/AvrAdcLogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ const uint32_t MAX_FILE_SIZE = MAX_FILE_SIZE_MiB << 20;

// Max SPI rate for AVR is 10 MHz for F_CPU 20 MHz, 8 MHz for F_CPU 16 MHz.
#define SPI_CLOCK SD_SCK_MHZ(10)

// Select fastest interface.
#if ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
Expand Down Expand Up @@ -865,7 +866,7 @@ void loop(void) {
Serial.println(F("r - record ADC data"));

while(!Serial.available()) {
SysCall::yield();
yield();
}
char c = tolower(Serial.read());
Serial.println();
Expand Down
4 changes: 2 additions & 2 deletions examples/DirectoryFunctions/DirectoryFunctions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ void setup() {

// Wait for USB Serial
while (!Serial) {
SysCall::yield();
yield();
}
delay(1000);
cout << F("Type any character to start\n");
while (!Serial.available()) {
SysCall::yield();
yield();
}

// Initialize the SD card.
Expand Down
4 changes: 2 additions & 2 deletions examples/ExFatLogger/ExFatLogger.ino
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ void setup() {

// Wait for USB Serial
while (!Serial) {
SysCall::yield();
yield();
}
delay(1000);
Serial.println(F("Type any character to begin"));
Expand Down Expand Up @@ -568,7 +568,7 @@ void loop() {
Serial.println(F("r - record data"));
Serial.println(F("t - test without logging"));
while(!Serial.available()) {
SysCall::yield();
yield();
}
char c = tolower(Serial.read());
Serial.println();
Expand Down
4 changes: 2 additions & 2 deletions examples/OpenNext/OpenNext.ino
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ void setup() {

// Wait for USB Serial
while (!Serial) {
SysCall::yield();
yield();
}

Serial.println("Type any character to start");
while (!Serial.available()) {
SysCall::yield();
yield();
}

// Initialize the SD.
Expand Down
6 changes: 3 additions & 3 deletions examples/QuickStart/QuickStart.ino
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void setup() {

// Wait for USB Serial
while (!Serial) {
SysCall::yield();
yield();
}
cout << F("\nSPI pins:\n");
cout << F("MISO: ") << int(MISO) << endl;
Expand Down Expand Up @@ -106,7 +106,7 @@ void loop() {

cout << F("\nEnter the chip select pin number: ");
while (!Serial.available()) {
SysCall::yield();
yield();
}
cin.readline();
if (cin >> chipSelect) {
Expand Down Expand Up @@ -182,6 +182,6 @@ void loop() {

cout << F("\nSuccess! Type any character to restart.\n");
while (!Serial.available()) {
SysCall::yield();
yield();
}
}
10 changes: 5 additions & 5 deletions examples/SdFormatter/SdFormatter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void sdErrorHalt() {
cout << F(" = ") << int(m_card->errorCode()) << endl;
cout << F("SD errorData = ") << int(m_card->errorData()) << endl;
}
SysCall::halt();
while (true) {}
}
//------------------------------------------------------------------------------
void clearSerialInput() {
Expand Down Expand Up @@ -158,12 +158,12 @@ void setup() {
Serial.begin(9600);
// Wait for USB Serial
while (!Serial) {
SysCall::yield();
yield();
}
printConfig(SD_CONFIG);
cout << F("\nType any character to start\n");
while (!Serial.available()) {
SysCall::yield();
yield();
}
// Discard any extra characters.
clearSerialInput();
Expand All @@ -183,7 +183,7 @@ void setup() {
"Warning, all data on the card will be erased.\n"
"Enter 'Y' to continue: ");
while (!Serial.available()) {
SysCall::yield();
yield();
}
c = Serial.read();
cout << c << endl;
Expand Down Expand Up @@ -230,7 +230,7 @@ void setup() {
"Enter option: ");

while (!Serial.available()) {
SysCall::yield();
yield();
}
c = Serial.read();
cout << c << endl;
Expand Down
6 changes: 3 additions & 3 deletions examples/SdInfo/SdInfo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bool cidDmp() {
cout << F("Serial number: ") << hex << m_cid.psn << dec << endl;
cout << F("Manufacturing date: ");
cout << int(m_cid.mdt_month) << '/';
cout << (2000 + m_cid.mdt_year_low + 10 * m_cid.mdt_year_high) << endl;
cout << (2000 + 16*m_cid.mdt_year_high + m_cid.mdt_year_low) << endl;
cout << endl;
return true;
}
Expand Down Expand Up @@ -206,7 +206,7 @@ void setup() {
Serial.begin(9600);
// Wait for USB Serial
while (!Serial) {
SysCall::yield();
yield();
}
cout << F("SdFat version: ") << SD_FAT_VERSION_STR << endl;
printConfig(SD_CONFIG);
Expand All @@ -220,7 +220,7 @@ void loop() {
// F stores strings in flash to save RAM
cout << F("\ntype any character to start\n");
while (!Serial.available()) {
SysCall::yield();
yield();
}
uint32_t t = millis();
if (!sd.cardBegin(SD_CONFIG)) {
Expand Down
4 changes: 2 additions & 2 deletions examples/SoftwareSpi/SoftwareSpi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ void setup() {
Serial.begin(9600);
// Wait for USB Serial
while (!Serial) {
SysCall::yield();
yield();
}
Serial.println("Type any character to start");
while (!Serial.available()) {
SysCall::yield();
yield();
}

if (!sd.begin(SD_CONFIG)) {
Expand Down
6 changes: 3 additions & 3 deletions examples/UserChipSelectFunction/UserChipSelectFunction.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// SD_CHIP_SELECT_MODE must be set to one or two in SdFat/SdFatConfig.h.
// A value of one allows optional replacement and two requires replacement.
#if SD_CHIP_SELECT_MODE == 1 || SD_CHIP_SELECT_MODE == 2
#if SD_CHIP_SELECT_MODE == 1 || SD_CHIP_SELECT_MODE == 2

// SD chip select pin.
#define SD_CS_PIN SS
Expand Down Expand Up @@ -34,11 +34,11 @@ void setup() {
sd.initErrorHalt(&Serial);
}
sd.ls(&Serial, LS_SIZE);

Serial.print(F("sdCsInit calls: "));
Serial.println(initCalls);
Serial.print(F("sdCsWrite calls: "));
Serial.println(writeCalls);
Serial.println(writeCalls);
}
//------------------------------------------------------------------------------
void loop() {}
Expand Down
9 changes: 5 additions & 4 deletions examples/bench/bench.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const uint8_t SD_CS_PIN = SDCARD_SS_PIN;
// Try to select the best SD card configuration.
#if HAS_SDIO_CLASS
#define SD_CONFIG SdioConfig(FIFO_SDIO)
#elif ENABLE_DEDICATED_SPI
#elif ENABLE_DEDICATED_SPI
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SPI_CLOCK)
#else // HAS_SDIO_CLASS
#define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SPI_CLOCK)
Expand Down Expand Up @@ -104,7 +104,7 @@ void cidDmp() {
cout << F("Serial number: ") << hex << cid.psn << dec << endl;
cout << F("Manufacturing date: ");
cout << int(cid.mdt_month) << '/';
cout << (2000 + cid.mdt_year_low + 10 * cid.mdt_year_high) << endl;
cout << (2000 + 16*cid.mdt_year_high + cid.mdt_year_low) << endl;
cout << endl;
}
//------------------------------------------------------------------------------
Expand All @@ -122,7 +122,7 @@ void setup() {

// Wait for USB Serial
while (!Serial) {
SysCall::yield();
yield();
}
delay(1000);
cout << F("\nUse a freshly formatted SD for best performance.\n");
Expand All @@ -149,7 +149,7 @@ void loop() {
// F() stores strings in flash to save RAM
cout << F("Type any character to start\n");
while (!Serial.available()) {
SysCall::yield();
yield();
}
#if HAS_UNUSED_STACK
cout << F("FreeStack: ") << FreeStack() << endl;
Expand Down Expand Up @@ -273,4 +273,5 @@ void loop() {
}
cout << endl << F("Done") << endl;
file.close();
sd.end();
}
4 changes: 2 additions & 2 deletions examples/debug/CardBusyTest/CardBusyTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void setup() {

// Wait for USB Serial
while (!Serial) {
SysCall::yield();
yield();
}
delay(1000);
//------------------------------------------------------------------------------
Expand All @@ -47,7 +47,7 @@ void loop() {
clearSerialInput();
Serial.println(F("\nType any character to start\n"));
while (!Serial.available()) {
SysCall::yield();
yield();
}
// Initialize the SD card.
if (!sd.begin(SD_CONFIG)) {
Expand Down
20 changes: 12 additions & 8 deletions examples/debug/ExFatDbgDmp/ExFatDbgDmp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ SdExFat sd;
#define error(s) sd.errorHalt(&Serial, F(s))
void setup() {
Serial.begin(9600);
while (!Serial) {yield();}
while (!Serial) {
yield();
}
Serial.println(F("Type any character to begin"));
while (!Serial.available()) {yield();}
while (!Serial.available()) {
yield();
}
if (!sd.begin(SD_CONFIG)){
error("begin failed");
}
#if DUMP_RAW
sd.dmpSector(&Serial, 0);
sd.dmpSector(&Serial, 0);
for (uint8_t i = 0; i < 24; i++) {
sd.dmpSector(&Serial, 0X8000 + i);
Serial.println();
}
return;
sd.dmpSector(&Serial, 0X8000 + i);
Serial.println();
}
return;
#endif // DUMP_RAW
ExFatFile root;
if (!root.openRoot(&sd)) {
Expand All @@ -37,7 +41,7 @@ void setup() {
#if DUMP_UPCASE
sd.printUpcase(&Serial);
#endif // DUMP_UPCASE
// sd.dmpCluster(&Serial, 8, 0, 4);
// sd.dmpCluster(&Serial, 8, 0, 4);
Serial.println("Done");
}

Expand Down
43 changes: 43 additions & 0 deletions examples/debug/TestGetName/TestGetName.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "SdFat.h"
SdFs sd;
FsFile file;
const char* name[] = {
"SFN.TXT",
"LongFilename.txt",
#if USE_UTF8_LONG_NAMES
u8"très élégant.txt",
#endif // USE_UTF8_LONG_NAMES
nullptr};
char buf[32];
void setup() {
Serial.begin(9600);
while (!Serial) {}
Serial.println("Type any character to begin");
while (!Serial.available()) {}
if (!sd.begin(SS)) {
sd.initErrorHalt();
}
for (uint8_t i = 0; name[i]; i++) {
if (!file.open(name[i], O_CREAT |O_RDWR)) {
sd.errorHalt("open");
}
size_t len = strlen(name[i]);
size_t rtn = file.getName(buf, len);
if (rtn != 0) {
Serial.println("fail len");
}
rtn = file.getName(buf, len + 1);
if (rtn != len) {
Serial.println("fail len + 1");
}
Serial.print(rtn);
Serial.print(' ');
Serial.println(buf);
if (!file.remove()) {
sd.errorHalt("remove");
}
}
Serial.println("Done");
}

void loop() {}
Loading

0 comments on commit bd2c9c5

Please sign in to comment.