Skip to content

Commit

Permalink
Added Move constructor and bug fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
greiman committed May 11, 2024
1 parent 57900b2 commit aadedbf
Show file tree
Hide file tree
Showing 38 changed files with 500 additions and 175 deletions.
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
### Warning: Major Reformat of Source in 2.2.2
File copy constructors and file assignment operators have been made private by
default in 2.2.3 to prevent call by value and multiple copies of file instances.

There are a huge number of changes in 2.2.2 since I decided to use clang-format
to force Google style formatting.

I did this to avoid warnings from the static analysis programs Cppcheck and
cpplint.

clang-format is aggressive so it may actually cause code to fail. For example
clang-format rearranges the order of includes according to the selected style.
SdFatConfig.h has options to make file constructors and assignment operators
public.

UTF-8 encoded filenames are supported in v2.1.0 or later.

Expand Down
Binary file modified doc/html.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion doc/mainpage.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2011-2021 Bill Greiman
* Copyright (c) 2011-2024 Bill Greiman
* This file is part of the SdFat library for SD memory cards.
*
* MIT License
Expand Down
2 changes: 1 addition & 1 deletion examples/BufferedPrint/BufferedPrint.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 0
#define SD_FAT_TYPE 3
/*
Change the value of SD_CS_PIN if you are using SPI and
your hardware does not use the default value, SS.
Expand Down
2 changes: 1 addition & 1 deletion examples/DirectoryFunctions/DirectoryFunctions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 0
#define SD_FAT_TYPE 3
/*
Change the value of SD_CS_PIN if you are using SPI and
your hardware does not use the default value, SS.
Expand Down
2 changes: 1 addition & 1 deletion examples/OpenNext/OpenNext.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 0
#define SD_FAT_TYPE 3
/*
Change the value of SD_CS_PIN if you are using SPI and
your hardware does not use the default value, SS.
Expand Down
8 changes: 6 additions & 2 deletions examples/QuickStart/QuickStart.ino
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void loop() {
}
cout << F("\nCard successfully initialized.\n");
if (sd.vol()->fatType() == 0) {
cout << F("Can't find a valid FAT16/FAT32 partition.\n");
cout << F("Can't find a valid FAT16/FAT32/exFAT partition.\n");
reformatMsg();
return;
}
Expand All @@ -163,7 +163,11 @@ void loop() {
cout << F("Card size: ") << sizeMB;
cout << F(" MB (MB = 1,000,000 bytes)\n");
cout << endl;
cout << F("Volume is FAT") << int(sd.vol()->fatType());
if (sd.fatType() <= 32) {
cout << F("\nVolume is FAT") << int(sd.fatType());
} else {
cout << F("\nVolume is exFAT");
}
cout << F(", Cluster size (bytes): ") << sd.vol()->bytesPerCluster();
cout << endl << endl;

Expand Down
2 changes: 1 addition & 1 deletion examples/ReadCsvFile/ReadCsvFile.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 0
#define SD_FAT_TYPE 3
/*
Change the value of SD_CS_PIN if you are using SPI and
your hardware does not use the default value, SS.
Expand Down
2 changes: 1 addition & 1 deletion examples/RtcTimestampTest/RtcTimestampTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 0
#define SD_FAT_TYPE 3
/*
Change the value of SD_CS_PIN if you are using SPI and
your hardware does not use the default value, SS.
Expand Down
27 changes: 22 additions & 5 deletions examples/SdInfo/SdInfo.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/*
* This program attempts to initialize an SD card and analyze its structure.
* The CID and CSD registers are also printed in HEX for use in online
* decoders like these.
*
* https://gurumeditation.org/1342/sd-memory-card-register-decoder/
* https://archive.goughlui.com/static/multicid.htm
*/
#include "SdFat.h"
#include "sdios.h"
Expand Down Expand Up @@ -55,7 +60,8 @@ void cidDmp() {
cout << F("Serial number: ") << hex << cid.psn() << dec << endl;
cout << F("Manufacturing date: ");
cout << cid.mdtMonth() << '/' << cid.mdtYear() << endl;
cout << endl;
cout << F("CID HEX: ");
hexDmp(&cid, sizeof(cid));
}
//------------------------------------------------------------------------------
void clearSerialInput() {
Expand All @@ -69,7 +75,7 @@ void clearSerialInput() {
//------------------------------------------------------------------------------
void csdDmp() {
eraseSize = csd.eraseSize();
cout << F("cardSize: ") << 0.000512 * csd.capacity();
cout << F("\ncardSize: ") << 0.000512 * csd.capacity();
cout << F(" MB (MB = 1,000,000 bytes)\n");

cout << F("flashEraseSize: ") << int(eraseSize) << F(" blocks\n");
Expand All @@ -85,6 +91,8 @@ void csdDmp() {
} else {
cout << F("zeros\n");
}
cout << F("CSD HEX: ");
hexDmp(&csd, sizeof(csd));
}
//------------------------------------------------------------------------------
void errorPrint() {
Expand All @@ -96,18 +104,27 @@ void errorPrint() {
}
}
//------------------------------------------------------------------------------
void hexDmp(void* reg, uint8_t size) {
uint8_t* u8 = reinterpret_cast<uint8_t*>(reg);
cout << hex << noshowbase;
for (size_t i = 0; i < size; i++) {
cout << setw(2) << setfill('0') << int(u8[i]);
}
cout << dec << endl;
}
//------------------------------------------------------------------------------
bool mbrDmp() {
MbrSector_t mbr;
bool valid = true;
if (!sd.card()->readSector(0, (uint8_t *)&mbr)) {
if (!sd.card()->readSector(0, (uint8_t*)&mbr)) {
cout << F("\nread MBR failed.\n");
errorPrint();
return false;
}
cout << F("\nSD Partition Table\n");
cout << F("part,boot,bgnCHS[3],type,endCHS[3],start,length\n");
for (uint8_t ip = 1; ip < 5; ip++) {
MbrPart_t *pt = &mbr.part[ip - 1];
MbrPart_t* pt = &mbr.part[ip - 1];
if ((pt->boot != 0 && pt->boot != 0X80) ||
getLe32(pt->relativeSectors) > csd.capacity()) {
valid = false;
Expand Down Expand Up @@ -242,7 +259,7 @@ void loop() {
printCardType();
cout << F("sdSpecVer: ") << 0.01 * scr.sdSpecVer() << endl;
cout << F("HighSpeedMode: ");
if (scr.sdSpecVer() && sd.card()->cardCMD6(0X00FFFFFF, cmd6Data) &&
if (scr.sdSpecVer() > 101 && sd.card()->cardCMD6(0X00FFFFFF, cmd6Data) &&
(2 & cmd6Data[13])) {
cout << F("true\n");
} else {
Expand Down
2 changes: 1 addition & 1 deletion examples/SoftwareSpi/SoftwareSpi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 0
#define SD_FAT_TYPE 3
//
// Chip select may be constant or RAM variable.
const uint8_t SD_CS_PIN = 10;
Expand Down
66 changes: 66 additions & 0 deletions examples/SpiLoopBackTest/SpiLoopBackTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// This is a simple SPI loop-back test.
//
// Connect SD_MISO to SD_MOSI
//
// Modify these defines for your configuration.
#define SD_SPI SPI
#define SD_MISO MISO
#define SD_MOSI MOSI

#include "SPI.h"
void setup() {
uint8_t rx, tx;
Serial.begin(9600);
while (!Serial) {
yield();
}
Serial.println(F("\nType any character to start"));
while (!Serial.available()) {
yield();
}
Serial.print("Begin, SD_MISO: ");
Serial.print(SD_MISO), Serial.print(", SD_MOSI: ");
Serial.println(SD_MOSI);
pinMode(SD_MISO, INPUT_PULLUP);
pinMode(SD_MOSI, OUTPUT);
digitalWrite(SD_MOSI, HIGH);
if (!digitalRead(SD_MISO)) {
Serial.println("Error: SD_MISO not HIGH");
goto fail;
}
digitalWrite(SD_MOSI, LOW);
if (digitalRead(SD_MISO)) {
Serial.println("Error: SD_MISO not LOW");
goto fail;
}
pinMode(SD_MISO, INPUT);
pinMode(SD_MOSI, INPUT);

// Modify if SD_SPI.begin has arguments and use this style SdFat begin call:
// sd.begin(SdSpiConfig(CS_PIN, USER_SPI_BEGIN | <other options>, &SD_SPI));
SD_SPI.begin();

// Start with a 400 kHz clock. Try full speed if success for 400 kHz.
SD_SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
tx = 0;
do {
rx = SD_SPI.transfer(tx);
if (tx != rx) {
Serial.print("Error rx: 0x");
Serial.print(rx, HEX);
Serial.print(" != tx: 0x");
Serial.println(tx, HEX);
SD_SPI.endTransaction();
goto fail;
}
} while (tx++ < 255);
SD_SPI.endTransaction();
Serial.println("Success!");
return;

fail:
SD_SPI.endTransaction();
Serial.println("Is SD_MISO connected to SD_MOSI?");
Serial.println("Are SD_MISO and SD_MOSI correct?");
}
void loop() {}
4 changes: 2 additions & 2 deletions examples/bench/bench.ino
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/*
* This program is a simple binary write/read benchmark.
*/
#include "FreeStack.h"
#include "SdFat.h"
#include "FreeStack.h"
#include "sdios.h"

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 0
#define SD_FAT_TYPE 3
/*
Change the value of SD_CS_PIN if you are using SPI and
your hardware does not use the default value, SS.
Expand Down
2 changes: 1 addition & 1 deletion examples/rename/rename.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h,
// 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
#define SD_FAT_TYPE 0
#define SD_FAT_TYPE 3

/*
Change the value of SD_CS_PIN if you are using SPI and
Expand Down
11 changes: 11 additions & 0 deletions extras/fmt_src.bat
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SdFat
version=2.2.2
version=2.2.3
license=MIT
author=Bill Greiman <fat16lib@sbcglobal.net>
maintainer=Bill Greiman <fat16lib@sbcglobal.net>
Expand Down
8 changes: 5 additions & 3 deletions src/ExFatLib/ExFatFile.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2011-2022 Bill Greiman
* Copyright (c) 2011-2024 Bill Greiman
* This file is part of the SdFat library for SD memory cards.
*
* MIT License
Expand Down Expand Up @@ -223,7 +223,8 @@ bool ExFatFile::open(ExFatFile* dirFile, const char* path, oflag_t oflag) {
DBG_WARN_MACRO;
goto fail;
}
tmpDir = *this;
// tmpDir = *this;
tmpDir.copy(this);
dirFile = &tmpDir;
close();
}
Expand Down Expand Up @@ -254,7 +255,8 @@ bool ExFatFile::openCwd() {
DBG_FAIL_MACRO;
goto fail;
}
*this = *ExFatVolume::cwv()->vwd();
// *this = *ExFatVolume::cwv()->vwd();
this->copy(ExFatVolume::cwv()->vwd());
rewind();
return true;

Expand Down
Loading

0 comments on commit aadedbf

Please sign in to comment.