├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ ├── config.yml │ └── feature_request.md └── workflows │ └── githubci.yml ├── .gitignore ├── LICENSE.md ├── README.md ├── doc ├── Doxyfile ├── SdErrorCodes.txt ├── SdFat.html ├── ZipMsg │ └── index.html ├── clean_html.bat ├── del_html.bat ├── html.zip ├── html │ └── index.html └── mainpage.h ├── examples ├── AvrAdcLogger │ ├── .none.test.only │ ├── AvrAdcLogger.h │ └── AvrAdcLogger.ino ├── BackwardCompatibility │ ├── .skip.txt │ └── BackwardCompatibility.ino ├── BufferedPrint │ └── BufferedPrint.ino ├── DirectoryFunctions │ └── DirectoryFunctions.ino ├── ExFatLogger │ ├── ExFatLogger.h │ └── ExFatLogger.ino ├── MinimumSizeSdReader │ └── MinimumSizeSdReader.ino ├── OpenNext │ └── OpenNext.ino ├── QuickStart │ └── QuickStart.ino ├── ReadCsvFile │ └── ReadCsvFile.ino ├── Rp2040SdioSetup │ ├── .metro_rp2040.test.only │ └── Rp2040SdioSetup.ino ├── RtcTimestampTest │ └── RtcTimestampTest.ino ├── SdErrorCodes │ └── SdErrorCodes.ino ├── SdFormatter │ └── SdFormatter.ino ├── SdInfo │ └── SdInfo.ino ├── SoftwareSpi │ ├── .none.test.only │ └── SoftwareSpi.ino ├── SpiLoopBackTest │ └── SpiLoopBackTest.ino ├── TeensyDmaAdcLogger │ ├── .none.test.only │ └── TeensyDmaAdcLogger.ino ├── TeensyRtcTimestamp │ ├── .none.test.only │ └── TeensyRtcTimestamp.ino ├── TeensySdioDemo │ ├── .none.test.only │ └── TeensySdioDemo.ino ├── TeensySdioLogger │ ├── .none.test.only │ └── TeensySdioLogger.ino ├── UnicodeFilenames │ ├── .skip.txt │ └── UnicodeFilenames.ino ├── UserChipSelectFunction │ ├── .none.test.only │ └── UserChipSelectFunction.ino ├── UserSPIDriver │ ├── .none.test.only │ └── UserSPIDriver.ino ├── bench │ └── bench.ino ├── debug │ ├── CardBusyTest │ │ └── CardBusyTest.ino │ ├── ExFatDbgDmp │ │ └── ExFatDbgDmp.ino │ ├── TestGetName │ │ ├── .skip.txt │ │ └── TestGetName.ino │ ├── TestMkdir │ │ ├── .skip.txt │ │ └── TestMkdir.ino │ ├── TestRmdir │ │ ├── .skip.txt │ │ └── TestRmdir.ino │ └── TimestampTest │ │ └── TimestampTest.ino ├── examplesV1 │ ├── #attic │ │ ├── AnalogLogger │ │ │ └── AnalogLogger.ino │ │ ├── BaseExtCaseTest │ │ │ └── BaseExtCaseTest.ino │ │ ├── HelloWorld │ │ │ └── HelloWorld.ino │ │ ├── MiniSerial │ │ │ ├── .none.test.only │ │ │ └── MiniSerial.ino │ │ ├── PrintBenchmarkSD │ │ │ ├── .skip.txt │ │ │ └── PrintBenchmarkSD.ino │ │ ├── SD_Size │ │ │ ├── .skip.txt │ │ │ └── SD_Size.ino │ │ ├── SdFatSize │ │ │ └── SdFatSize.ino │ │ ├── StreamParseInt │ │ │ ├── .skip.txt │ │ │ └── StreamParseInt.ino │ │ ├── append │ │ │ └── append.ino │ │ ├── average │ │ │ └── average.ino │ │ ├── benchSD │ │ │ ├── .skip.txt │ │ │ └── benchSD.ino │ │ ├── bufstream │ │ │ └── bufstream.ino │ │ ├── cin_cout │ │ │ └── cin_cout.ino │ │ ├── eventlog │ │ │ └── eventlog.ino │ │ ├── fgetsRewrite │ │ │ └── fgetsRewrite.ino │ │ ├── readlog │ │ │ └── readlog.ino │ │ └── readme.txt │ ├── AnalogBinLogger │ │ ├── .none.test.only │ │ ├── AnalogBinLogger.h │ │ └── AnalogBinLogger.ino │ ├── LongFileName │ │ ├── LongFileName.ino │ │ └── testFiles │ │ │ ├── A long name can be 255 characters.txt │ │ │ ├── LFN,NAME.TXT │ │ │ ├── MIXCASE.txt │ │ │ ├── Not_8_3.txt │ │ │ ├── OK%83.TXT │ │ │ ├── STD_8_3.TXT │ │ │ ├── With Blank.txt │ │ │ ├── With.Two dots.txt │ │ │ ├── lower.txt │ │ │ └── mixed.TXT │ ├── LowLatencyLogger │ │ ├── .none.test.only │ │ ├── LowLatencyLogger.ino │ │ ├── UserFunctions.cpp │ │ └── UserTypes.h │ ├── LowLatencyLoggerADXL345 │ │ ├── .none.test.only │ │ ├── LowLatencyLogger.ino │ │ ├── LowLatencyLoggerADXL345.ino │ │ ├── UserFunctions.cpp │ │ ├── UserTypes.h │ │ └── readme.txt │ ├── LowLatencyLoggerMPU6050 │ │ ├── .none.test.only │ │ ├── LowLatencyLogger.ino │ │ ├── LowLatencyLoggerMPU6050.ino │ │ ├── UserFunctions.cpp │ │ └── UserTypes.h │ ├── PrintBenchmark │ │ └── PrintBenchmark.ino │ ├── RawWrite │ │ ├── .none.test.only │ │ └── RawWrite.ino │ ├── ReadCsv │ │ ├── .skip.txt │ │ └── ReadCsv.ino │ ├── ReadCsvArray │ │ ├── .skip.txt │ │ └── ReadCsvArray.ino │ ├── ReadCsvStream │ │ └── ReadCsvStream.ino │ ├── ReadWrite │ │ ├── .skip.txt │ │ └── ReadWrite.ino │ ├── STM32Test │ │ ├── .none.test.only │ │ └── STM32Test.ino │ ├── StdioBench │ │ └── StdioBench.ino │ ├── Timestamp │ │ └── Timestamp.ino │ ├── TwoCards │ │ └── TwoCards.ino │ ├── VolumeFreeSpace │ │ ├── .none.test.only │ │ └── VolumeFreeSpace.ino │ ├── dataLogger │ │ └── dataLogger.ino │ ├── fgets │ │ └── fgets.ino │ ├── formatting │ │ └── formatting.ino │ ├── getline │ │ └── getline.ino │ └── wipe │ │ ├── .none.test.only │ │ └── wipe.ino └── rename │ └── rename.ino ├── extras ├── AvrPrintStimmer.cpp ├── USB_Host_Shield │ ├── USB_Host_Shield_2.0.zip │ ├── UsbHostShieldDiff.txt │ └── readme.txt ├── attic │ ├── PrintBasic.cpp │ ├── PrintBasic.h │ ├── PrintTemplates.h │ └── SysCallBareUno.cpp ├── cpplint.bat ├── cpplint.py ├── cpplint.sh └── fmt_src.bat ├── images ├── SdioSpi.jpg └── picowbell.jpg ├── library.properties └── src ├── .clang-format-ignore ├── BufferedPrint.h ├── CPPLINT.cfg ├── DigitalIO ├── DigitalPin.h ├── SoftSPI.h ├── boards │ ├── AvrDevelopersGpioPinMap.h │ ├── BobuinoGpioPinMap.h │ ├── GpioPinMap.h │ ├── LeonardoGpioPinMap.h │ ├── MegaGpioPinMap.h │ ├── SleepingBeautyGpioPinMap.h │ ├── Standard1284GpioPinMap.h │ ├── Teensy2GpioPinMap.h │ ├── Teensy2ppGpioPinMap.h │ └── UnoGpioPinMap.h └── readme.txt ├── ExFatLib ├── ExFatDbg.cpp ├── ExFatFile.cpp ├── ExFatFile.h ├── ExFatFilePrint.cpp ├── ExFatFileWrite.cpp ├── ExFatFormatter.cpp ├── ExFatFormatter.h ├── ExFatLib.h ├── ExFatName.cpp ├── ExFatPartition.cpp ├── ExFatPartition.h ├── ExFatVolume.cpp └── ExFatVolume.h ├── FatLib ├── FatDbg.cpp ├── FatFile.cpp ├── FatFile.h ├── FatFileLFN.cpp ├── FatFilePrint.cpp ├── FatFileSFN.cpp ├── FatFormatter.cpp ├── FatFormatter.h ├── FatLib.h ├── FatName.cpp ├── FatPartition.cpp ├── FatPartition.h ├── FatVolume.cpp └── FatVolume.h ├── FreeStack.cpp ├── FreeStack.h ├── FsLib ├── FsFile.cpp ├── FsFile.h ├── FsFormatter.h ├── FsLib.h ├── FsNew.cpp ├── FsNew.h ├── FsVolume.cpp └── FsVolume.h ├── MinimumSerial.cpp ├── MinimumSerial.h ├── RingBuf.h ├── SdCard ├── Rp2040Sdio │ ├── CPPLINT.cfg │ ├── DbgLog.h │ ├── PioDbgInfo.h │ ├── PioSdioCard.cpp │ ├── PioSdioCard.pio │ ├── PioSdioCard.pio.h │ └── Rp2040SdioConfig.h ├── SdCard.h ├── SdCardInfo.cpp ├── SdCardInfo.h ├── SdCardInterface.h ├── SdSpiCard.cpp ├── SdSpiCard.h ├── SdioCard.h └── TeensySdio │ ├── CPPLINT.cfg │ ├── TeensySdio.cpp │ ├── TeensySdioConfig.h │ └── TeensySdioDefs.h ├── SdFat.h ├── SdFatConfig.h ├── SdFatDebugConfig.h ├── SdFat_Adafruit_Fork.h ├── SpiDriver ├── SdSpiArduinoDriver.h ├── SdSpiArtemis.cpp ├── SdSpiAvr.h ├── SdSpiBareUnoDriver.h ├── SdSpiBaseClass.h ├── SdSpiChipSelect.cpp ├── SdSpiDriver.h ├── SdSpiDue.cpp ├── SdSpiLibDriver.h ├── SdSpiParticle.cpp ├── SdSpiSTM32.cpp ├── SdSpiSTM32Core.cpp ├── SdSpiSoftDriver.h └── SdSpiTeensy3.cpp ├── common ├── ArduinoFiles.h ├── CPPLINT.cfg ├── CompileDateTime.h ├── DebugMacros.h ├── FmtNumber.cpp ├── FmtNumber.h ├── FsApiConstants.h ├── FsBlockDevice.h ├── FsBlockDeviceInterface.h ├── FsCache.cpp ├── FsCache.h ├── FsDateTime.cpp ├── FsDateTime.h ├── FsName.cpp ├── FsName.h ├── FsStructs.cpp ├── FsStructs.h ├── FsUtf.cpp ├── FsUtf.h ├── PrintBasic.cpp ├── PrintBasic.h ├── SysCall.h ├── upcase.cpp └── upcase.h ├── fmt_src.bat ├── iostream ├── ArduinoStream.h ├── StdioStream.cpp ├── StdioStream.h ├── StreamBaseClass.cpp ├── bufstream.h ├── fstream.h ├── ios.h ├── iostream.h ├── istream.cpp ├── istream.h ├── ostream.cpp └── ostream.h └── sdios.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: Report a problem 3 | labels: 'Bug' 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thanks for taking the time to fill out this bug report! 9 | It's okay to leave some blank if it doesn't apply to your problem. 10 | 11 | - type: dropdown 12 | attributes: 13 | label: Operating System 14 | options: 15 | - Linux 16 | - MacOS 17 | - RaspberryPi OS 18 | - Windows 7 19 | - Windows 10 20 | - Windows 11 21 | - Others 22 | validations: 23 | required: true 24 | 25 | - type: input 26 | attributes: 27 | label: IDE version 28 | placeholder: e.g Arduino 1.8.15 29 | validations: 30 | required: true 31 | 32 | - type: input 33 | attributes: 34 | label: Board 35 | placeholder: e.g Feather nRF52840 Express 36 | validations: 37 | required: true 38 | 39 | - type: input 40 | attributes: 41 | label: BSP version 42 | description: Can be found under "Board Manager" menu 43 | validations: 44 | required: true 45 | 46 | - type: input 47 | attributes: 48 | label: SPIFlash Library version 49 | placeholder: "Release version or github latest" 50 | validations: 51 | required: true 52 | 53 | - type: textarea 54 | attributes: 55 | label: Sketch 56 | placeholder: | 57 | e.g examples/flash_info 58 | If it is custom sketch, please provide links to your minimal sources or as attached files. 59 | validations: 60 | required: true 61 | 62 | - type: textarea 63 | attributes: 64 | label: What happened ? 65 | placeholder: A clear and concise description of what the bug is. 66 | validations: 67 | required: true 68 | 69 | - type: textarea 70 | attributes: 71 | label: How to reproduce ? 72 | placeholder: | 73 | 1. Go to '...' 74 | 2. Click on '....' 75 | 3. See error 76 | validations: 77 | required: true 78 | 79 | - type: textarea 80 | attributes: 81 | label: Debug Log 82 | placeholder: | 83 | Debug log where the issue occurred as attached txt file, best with comments to explain the actual events. 84 | validations: 85 | required: false 86 | 87 | - type: textarea 88 | attributes: 89 | label: Screenshots 90 | description: If applicable, add screenshots to help explain your problem. 91 | validations: 92 | required: false 93 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | contact_links: 2 | - name: Adafruit Support Forum 3 | url: https://forums.adafruit.com 4 | about: If you have other questions or need help, post it here. 5 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: Feature 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/githubci.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [pull_request, push, repository_dispatch] 4 | 5 | jobs: 6 | build: 7 | strategy: 8 | fail-fast: false 9 | matrix: 10 | arduino-platform: 11 | - 'feather_esp32s2' 12 | - 'feather_esp32s3' 13 | - 'feather_rp2040' 14 | - 'metro_rp2040' 15 | - 'metro_m0' 16 | - 'metro_m4' 17 | - 'nrf52840' 18 | 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Setup Python 22 | uses: actions/setup-python@v4 23 | with: 24 | python-version: '3.x' 25 | 26 | - name: Checkout code 27 | uses: actions/checkout@v4 28 | 29 | - name: Checkout adafruit/ci-arduino 30 | uses: actions/checkout@v4 31 | with: 32 | repository: adafruit/ci-arduino 33 | path: ci 34 | 35 | - name: pre-install 36 | run: bash ci/actions_install.sh 37 | 38 | - name: Install Libraries for building examples 39 | run: arduino-cli lib install RTClib SD 40 | 41 | - name: test platforms 42 | run: python3 ci/build_platform.py ${{ matrix.arduino-platform }} 43 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # ========================= 18 | # Operating System Files 19 | # ========================= 20 | 21 | # OSX 22 | # ========================= 23 | 24 | .DS_Store 25 | .AppleDouble 26 | .LSOverride 27 | 28 | # Icon must ends with two \r. 29 | Icon 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2011..2020 Bill Greiman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /doc/SdErrorCodes.txt: -------------------------------------------------------------------------------- 1 | 2025-01-01 2 | 3 | Run the SdErrorCode example to produce an updated list. 4 | 5 | Code,Symbol - failed operation 6 | 0X00,SD_CARD_ERROR_NONE - No error 7 | 0X01,SD_CARD_ERROR_CMD0 - Card reset failed 8 | 0X02,SD_CARD_ERROR_CMD2 - SDIO read CID 9 | 0X03,SD_CARD_ERROR_CMD3 - SDIO publish RCA 10 | 0X04,SD_CARD_ERROR_CMD6 - Switch card function 11 | 0X05,SD_CARD_ERROR_CMD7 - SDIO card select 12 | 0X06,SD_CARD_ERROR_CMD8 - Send and check interface settings 13 | 0X07,SD_CARD_ERROR_CMD9 - Read CSD data 14 | 0X08,SD_CARD_ERROR_CMD10 - Read CID data 15 | 0X09,SD_CARD_ERROR_CMD12 - Stop multiple block transmission 16 | 0X0A,SD_CARD_ERROR_CMD13 - Read card status 17 | 0X0B,SD_CARD_ERROR_CMD17 - Read single block 18 | 0X0C,SD_CARD_ERROR_CMD18 - Read multiple blocks 19 | 0X0D,SD_CARD_ERROR_CMD24 - Write single block 20 | 0X0E,SD_CARD_ERROR_CMD25 - Write multiple blocks 21 | 0X0F,SD_CARD_ERROR_CMD32 - Set first erase block 22 | 0X10,SD_CARD_ERROR_CMD33 - Set last erase block 23 | 0X11,SD_CARD_ERROR_CMD38 - Erase selected blocks 24 | 0X12,SD_CARD_ERROR_CMD58 - Read OCR register 25 | 0X13,SD_CARD_ERROR_CMD59 - Set CRC mode 26 | 0X14,SD_CARD_ERROR_ACMD6 - Set SDIO bus width 27 | 0X15,SD_CARD_ERROR_ACMD13 - Read extended status 28 | 0X16,SD_CARD_ERROR_ACMD23 - Set pre-erased count 29 | 0X17,SD_CARD_ERROR_ACMD41 - Activate card initialization 30 | 0X18,SD_CARD_ERROR_ACMD51 - Read SCR data 31 | 0X19,SD_CARD_ERROR_READ_TOKEN - Bad read data token 32 | 0X1A,SD_CARD_ERROR_READ_CRC - Read CRC error 33 | 0X1B,SD_CARD_ERROR_READ_FIFO - SDIO fifo read timeout 34 | 0X1C,SD_CARD_ERROR_READ_REG - Read CID or CSD failed. 35 | 0X1D,SD_CARD_ERROR_READ_START - Bad readStart argument 36 | 0X1E,SD_CARD_ERROR_READ_TIMEOUT - Read data timeout 37 | 0X1F,SD_CARD_ERROR_STOP_TRAN - Multiple block stop failed 38 | 0X20,SD_CARD_ERROR_TRANSFER_COMPLETE - SDIO transfer complete 39 | 0X21,SD_CARD_ERROR_WRITE_DATA - Write data not accepted 40 | 0X22,SD_CARD_ERROR_WRITE_FIFO - SDIO fifo write timeout 41 | 0X23,SD_CARD_ERROR_WRITE_START - Bad writeStart argument 42 | 0X24,SD_CARD_ERROR_WRITE_PROGRAMMING - Flash programming 43 | 0X25,SD_CARD_ERROR_WRITE_TIMEOUT - Write timeout 44 | 0X26,SD_CARD_ERROR_DMA - DMA transfer failed 45 | 0X27,SD_CARD_ERROR_ERASE - Card did not accept erase commands 46 | 0X28,SD_CARD_ERROR_ERASE_SINGLE_SECTOR - Card does not support erase 47 | 0X29,SD_CARD_ERROR_ERASE_TIMEOUT - Erase command timeout 48 | 0X2A,SD_CARD_ERROR_INIT_NOT_CALLED - Card has not been initialized 49 | 0X2B,SD_CARD_ERROR_INVALID_CARD_CONFIG - Invalid card config 50 | 0X2C,SD_CARD_ERROR_FUNCTION_NOT_SUPPORTED - Unsupported SDIO command 51 | 0X2D,SD_CARD_ERROR_UNKNOWN - Unknown error 52 | -------------------------------------------------------------------------------- /doc/SdFat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | A web page that points a browser to a different page 4 | 5 | 6 | 7 | 8 | Your browser didn't automatically redirect. Open html/index.html manually. 9 | 10 | 11 | -------------------------------------------------------------------------------- /doc/ZipMsg/index.html: -------------------------------------------------------------------------------- 1 |

Replace the content of the html folder by unzipping html.zip.

2 |

I have zipped the documentation since Doxygen changes every file each time it runs.

3 |

This makes viewing changes on GitHub difficult.

4 |

 

-------------------------------------------------------------------------------- /doc/clean_html.bat: -------------------------------------------------------------------------------- 1 | del html\*.md5 2 | del html\*.map 3 | pause -------------------------------------------------------------------------------- /doc/del_html.bat: -------------------------------------------------------------------------------- 1 | rm html/*.* 2 | rm html/search/*.* 3 | pause -------------------------------------------------------------------------------- /doc/html.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/doc/html.zip -------------------------------------------------------------------------------- /doc/html/index.html: -------------------------------------------------------------------------------- 1 |

Replace the content of the html folder by unzipping html.zip.

2 |

I have zipped the documentation since Doxygen changes every file each time it runs.

3 |

This makes viewing changes on GitHub difficult.

4 |

 

-------------------------------------------------------------------------------- /examples/AvrAdcLogger/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/AvrAdcLogger/.none.test.only -------------------------------------------------------------------------------- /examples/AvrAdcLogger/AvrAdcLogger.h: -------------------------------------------------------------------------------- 1 | #ifndef AnalogBinLogger_h 2 | #define AnalogBinLogger_h 3 | const size_t BLOCK_SIZE = 64; 4 | //------------------------------------------------------------------------------ 5 | // First block of file. 6 | const size_t PIN_NUM_DIM = 7 | BLOCK_SIZE - 3 * sizeof(uint32_t) - 2 * sizeof(uint8_t); 8 | struct metadata_t { 9 | uint32_t adcFrequency; // ADC clock frequency 10 | uint32_t cpuFrequency; // CPU clock frequency 11 | uint32_t sampleInterval; // Sample interval in CPU cycles. 12 | uint8_t recordEightBits; // Size of ADC values, nonzero for 8-bits. 13 | uint8_t pinCount; // Number of analog pins in a sample. 14 | uint8_t pinNumber[PIN_NUM_DIM]; // List of pin numbers in a sample. 15 | }; 16 | //------------------------------------------------------------------------------ 17 | // Data block for 8-bit ADC mode. 18 | const size_t DATA_DIM8 = (BLOCK_SIZE - 2 * sizeof(uint16_t)) / sizeof(uint8_t); 19 | struct block8_t { 20 | uint16_t count; // count of data values 21 | uint16_t overrun; // count of overruns since last block 22 | uint8_t data[DATA_DIM8]; 23 | }; 24 | //------------------------------------------------------------------------------ 25 | // Data block for 10-bit ADC mode. 26 | const size_t DATA_DIM16 = 27 | (BLOCK_SIZE - 2 * sizeof(uint16_t)) / sizeof(uint16_t); 28 | struct block16_t { 29 | unsigned short count; // count of data values 30 | unsigned short overrun; // count of overruns since last block 31 | unsigned short data[DATA_DIM16]; 32 | }; 33 | #endif // AnalogBinLogger_h 34 | -------------------------------------------------------------------------------- /examples/BackwardCompatibility/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_rp2040 2 | metro_rp2040 -------------------------------------------------------------------------------- /examples/BackwardCompatibility/BackwardCompatibility.ino: -------------------------------------------------------------------------------- 1 | // A simple read/write example for SD.h. 2 | // Mostly from the SD.h ReadWrite example. 3 | // 4 | // Your SD must be formatted FAT16/FAT32. 5 | // 6 | // SD.h does not support some default SdFat features. 7 | // To compare flash size, set USE_FAT_FILE_FLAG_CONTIGUOUS, 8 | // ENABLE_DEDICATED_SPI, and USE_LONG_FILE_NAMES to zero also 9 | // set SDFAT_FILE_TYPE to one in SdFat/src/SdFatCongfig.h 10 | // 11 | // Set USE_SD_H nonzero to use SD.h. 12 | // Set USE_SD_H zero to use SdFat.h. 13 | // 14 | #define USE_SD_H 0 15 | // 16 | #if USE_SD_H 17 | #include 18 | #else // USE_SD_H 19 | #include "SdFat.h" 20 | SdFat SD; 21 | #endif // USE_SD_H 22 | 23 | // Modify SD_CS_PIN for your board. 24 | // For Teensy 3.6 and SdFat.h use BUILTIN_SDCARD. 25 | #define SD_CS_PIN SS 26 | 27 | File myFile; 28 | 29 | void setup() { 30 | Serial.begin(9600); 31 | while (!Serial) { 32 | } 33 | 34 | #if USE_SD_H 35 | Serial.println(F("Using SD.h. Set USE_SD_H zero to use SdFat.h.")); 36 | #else // USE_SD_H 37 | Serial.println(F("Using SdFat.h. Set USE_SD_H nonzero to use SD.h.")); 38 | #endif // USE_SD_H 39 | Serial.println(F("\nType any character to begin.")); 40 | while (!Serial.available()) { 41 | yield(); 42 | } 43 | Serial.print("Initializing SD card..."); 44 | 45 | if (!SD.begin(SD_CS_PIN)) { 46 | Serial.println("initialization failed!"); 47 | return; 48 | } 49 | Serial.println("initialization done."); 50 | 51 | // open the file. 52 | myFile = SD.open("test.txt", FILE_WRITE); 53 | 54 | // if the file opened okay, write to it: 55 | if (myFile) { 56 | Serial.print("Writing to test.txt..."); 57 | myFile.println("testing 1, 2, 3."); 58 | // close the file: 59 | myFile.close(); 60 | Serial.println("done."); 61 | } else { 62 | // if the file didn't open, print an error: 63 | Serial.println("error opening test.txt"); 64 | } 65 | 66 | // re-open the file for reading: 67 | myFile = SD.open("test.txt"); 68 | if (myFile) { 69 | Serial.println("test.txt:"); 70 | 71 | // read from the file until there's nothing else in it: 72 | while (myFile.available()) { 73 | Serial.write(myFile.read()); 74 | } 75 | // close the file: 76 | myFile.close(); 77 | } else { 78 | // if the file didn't open, print an error: 79 | Serial.println("error opening test.txt"); 80 | } 81 | } 82 | void loop() { 83 | // nothing happens after setup 84 | } -------------------------------------------------------------------------------- /examples/ExFatLogger/ExFatLogger.h: -------------------------------------------------------------------------------- 1 | // Avoid IDE problems by defining struct in septate .h file. 2 | // Pad record so size is a power of two for best write performance. 3 | #ifndef ExFatLogger_h 4 | #define ExFatLogger_h 5 | const size_t ADC_COUNT = 4; 6 | struct data_t { 7 | uint16_t adc[ADC_COUNT]; 8 | }; 9 | #endif // ExFatLogger_h -------------------------------------------------------------------------------- /examples/MinimumSizeSdReader/MinimumSizeSdReader.ino: -------------------------------------------------------------------------------- 1 | // Create a text file on the SD with this path using short 8.3 names. 2 | #define SFN_PATH "/DIR/TEST.TXT" 3 | 4 | // Modify CS_PIN for your chip select pin. 5 | #define CS_PIN SS 6 | 7 | // Set USE_SD_H to one for SD.h or zero for SdFat. 8 | #define USE_SD_H 0 9 | 10 | #if USE_SD_H 11 | #include "SD.h" 12 | File file; 13 | #else 14 | #include "SdFat.h" 15 | // Setting ENABLE_DEDICATED_SPI to zero saves over 200 more bytes. 16 | #if ENABLE_DEDICATED_SPI 17 | #warning \ 18 | "Set ENABLE_DEDICATED_SPI zero in SdFat/src/SdFatConfig.h for minimum size" 19 | #endif // ENABLE_DEDICATED_SPI 20 | // Insure FAT16/FAT32 only. 21 | SdFat32 SD; 22 | // FatFile does not support Stream functions, just simple read/write. 23 | FatFile file; 24 | #endif 25 | 26 | void error(const char* msg) { 27 | Serial.println(msg); 28 | while (true) { 29 | } 30 | } 31 | void setup() { 32 | int n; 33 | char buf[4]; 34 | 35 | Serial.begin(9600); 36 | while (!Serial) { 37 | } 38 | Serial.println("Type any character to begin"); 39 | while (!Serial.available()) { 40 | } 41 | 42 | if (!SD.begin(CS_PIN)) error("SD.begin"); 43 | 44 | #if USE_SD_H 45 | file = SD.open(SFN_PATH); 46 | if (!file) error("open"); 47 | #else 48 | // Open existing file with a path of 8.3 names. 49 | // Directories will be opened O_RDONLY files O_RDWR. 50 | if (!file.openExistingSFN(SFN_PATH)) error("open"); 51 | #endif 52 | while ((n = file.read(buf, sizeof(buf)))) { 53 | Serial.write(buf, n); 54 | } 55 | // close() is only needed if you write to the file. For example, read 56 | // config data, modify the data, rewind the file and write the data. 57 | // file.close(); 58 | } 59 | 60 | void loop() {} 61 | -------------------------------------------------------------------------------- /examples/Rp2040SdioSetup/.metro_rp2040.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/Rp2040SdioSetup/.metro_rp2040.test.only -------------------------------------------------------------------------------- /examples/SdErrorCodes/SdErrorCodes.ino: -------------------------------------------------------------------------------- 1 | // Print a list of error codes, symbols, and comments. 2 | #include "SdFat.h" 3 | void setup() { 4 | Serial.begin(9600); 5 | while (!Serial) { 6 | } 7 | delay(1000); 8 | Serial.println(); 9 | Serial.println(F("Code,Symbol - failed operation")); 10 | for (uint8_t code = 0; code <= SD_CARD_ERROR_UNKNOWN; code++) { 11 | Serial.print(code < 16 ? "0X0" : "0X"); 12 | Serial.print(code, HEX); 13 | Serial.print(","); 14 | printSdErrorSymbol(&Serial, code); 15 | Serial.print(" - "); 16 | printSdErrorText(&Serial, code); 17 | Serial.println(); 18 | } 19 | } 20 | void loop() {} -------------------------------------------------------------------------------- /examples/SoftwareSpi/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/SoftwareSpi/.none.test.only -------------------------------------------------------------------------------- /examples/SoftwareSpi/SoftwareSpi.ino: -------------------------------------------------------------------------------- 1 | // An example of the SoftSpiDriver template class. 2 | // This example is for an old Adafruit Data Logging Shield on a Mega. 3 | // Software SPI is required on Mega since this shield connects to pins 10-13. 4 | // This example will also run on an Uno and other boards using software SPI. 5 | // 6 | #include "SdFat.h" 7 | #if SPI_DRIVER_SELECT == 2 // Must be set in SdFat/SdFatConfig.h 8 | 9 | // SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h, 10 | // 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT. 11 | #define SD_FAT_TYPE 3 12 | // 13 | // Chip select may be constant or RAM variable. 14 | const uint8_t SD_CS_PIN = 10; 15 | // 16 | // Pin numbers in templates must be constants. 17 | const uint8_t SOFT_MISO_PIN = 12; 18 | const uint8_t SOFT_MOSI_PIN = 11; 19 | const uint8_t SOFT_SCK_PIN = 13; 20 | 21 | // SdFat software SPI template 22 | SoftSpiDriver softSpi; 23 | // Speed argument is ignored for software SPI. 24 | #if ENABLE_DEDICATED_SPI 25 | #define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(0), &softSpi) 26 | #else // ENABLE_DEDICATED_SPI 27 | #define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(0), &softSpi) 28 | #endif // ENABLE_DEDICATED_SPI 29 | 30 | #if SD_FAT_TYPE == 0 31 | SdFat sd; 32 | File file; 33 | #elif SD_FAT_TYPE == 1 34 | SdFat32 sd; 35 | File32 file; 36 | #elif SD_FAT_TYPE == 2 37 | SdExFat sd; 38 | ExFile file; 39 | #elif SD_FAT_TYPE == 3 40 | SdFs sd; 41 | FsFile file; 42 | #else // SD_FAT_TYPE 43 | #error Invalid SD_FAT_TYPE 44 | #endif // SD_FAT_TYPE 45 | 46 | void setup() { 47 | Serial.begin(9600); 48 | // Wait for USB Serial 49 | while (!Serial) { 50 | yield(); 51 | } 52 | Serial.println("Type any character to start"); 53 | while (!Serial.available()) { 54 | yield(); 55 | } 56 | 57 | if (!sd.begin(SD_CONFIG)) { 58 | sd.initErrorHalt(); 59 | } 60 | 61 | if (!file.open("SoftSPI.txt", O_RDWR | O_CREAT)) { 62 | sd.errorHalt(F("open failed")); 63 | } 64 | file.println(F("This line was printed using software SPI.")); 65 | 66 | file.rewind(); 67 | 68 | while (file.available()) { 69 | Serial.write(file.read()); 70 | } 71 | 72 | file.close(); 73 | 74 | Serial.println(F("Done.")); 75 | } 76 | //------------------------------------------------------------------------------ 77 | void loop() {} 78 | #else // SPI_DRIVER_SELECT 79 | #error SPI_DRIVER_SELECT must be two in SdFat/SdFatConfig.h 80 | #endif // SPI_DRIVER_SELECT -------------------------------------------------------------------------------- /examples/SpiLoopBackTest/SpiLoopBackTest.ino: -------------------------------------------------------------------------------- 1 | // This is a simple SPI loop-back test. 2 | // 3 | // Connect SD_MISO to SD_MOSI 4 | // 5 | // Modify these defines for your configuration. 6 | #define SD_SPI SPI 7 | #define SD_MISO MISO 8 | #define SD_MOSI MOSI 9 | 10 | #include "SPI.h" 11 | void setup() { 12 | uint8_t rx, tx; 13 | Serial.begin(9600); 14 | while (!Serial) { 15 | yield(); 16 | } 17 | Serial.println(F("\nType any character to start")); 18 | while (!Serial.available()) { 19 | yield(); 20 | } 21 | Serial.print("Begin, SD_MISO: "); 22 | Serial.print(SD_MISO), Serial.print(", SD_MOSI: "); 23 | Serial.println(SD_MOSI); 24 | pinMode(SD_MISO, INPUT_PULLUP); 25 | pinMode(SD_MOSI, OUTPUT); 26 | digitalWrite(SD_MOSI, HIGH); 27 | if (!digitalRead(SD_MISO)) { 28 | Serial.println("Error: SD_MISO not HIGH"); 29 | goto fail; 30 | } 31 | digitalWrite(SD_MOSI, LOW); 32 | if (digitalRead(SD_MISO)) { 33 | Serial.println("Error: SD_MISO not LOW"); 34 | goto fail; 35 | } 36 | pinMode(SD_MISO, INPUT); 37 | pinMode(SD_MOSI, INPUT); 38 | 39 | // Modify if SD_SPI.begin has arguments and use this style SdFat begin call: 40 | // sd.begin(SdSpiConfig(CS_PIN, USER_SPI_BEGIN | , &SD_SPI)); 41 | SD_SPI.begin(); 42 | 43 | // Start with a 400 kHz clock. Try full speed if success for 400 kHz. 44 | SD_SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0)); 45 | tx = 0; 46 | do { 47 | rx = SD_SPI.transfer(tx); 48 | if (tx != rx) { 49 | Serial.print("Error rx: 0x"); 50 | Serial.print(rx, HEX); 51 | Serial.print(" != tx: 0x"); 52 | Serial.println(tx, HEX); 53 | SD_SPI.endTransaction(); 54 | goto fail; 55 | } 56 | } while (tx++ < 255); 57 | SD_SPI.endTransaction(); 58 | Serial.println("Success!"); 59 | return; 60 | 61 | fail: 62 | SD_SPI.endTransaction(); 63 | Serial.println("Is SD_MISO connected to SD_MOSI?"); 64 | Serial.println("Are SD_MISO and SD_MOSI correct?"); 65 | } 66 | void loop() {} -------------------------------------------------------------------------------- /examples/TeensyDmaAdcLogger/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/TeensyDmaAdcLogger/.none.test.only -------------------------------------------------------------------------------- /examples/TeensyRtcTimestamp/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/TeensyRtcTimestamp/.none.test.only -------------------------------------------------------------------------------- /examples/TeensySdioDemo/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/TeensySdioDemo/.none.test.only -------------------------------------------------------------------------------- /examples/TeensySdioLogger/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/TeensySdioLogger/.none.test.only -------------------------------------------------------------------------------- /examples/UnicodeFilenames/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_esp32s2 2 | feather_esp32s3 -------------------------------------------------------------------------------- /examples/UnicodeFilenames/UnicodeFilenames.ino: -------------------------------------------------------------------------------- 1 | // Simple test of Unicode filename. 2 | // Unicode is supported as UTF-8 encoded strings. 3 | #define DISABLE_FS_H_WARNING // Disable warning for type File not defined. 4 | #include "SdFat.h" 5 | 6 | // SD_FAT_TYPE = 0 for SdFat/File as defined in SdFatConfig.h, 7 | // 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT. 8 | #if defined __has_include 9 | #if __has_include() 10 | #define SD_FAT_TYPE 3 // Can't use SdFat/File 11 | #endif // __has_include() 12 | #endif // defined __has_include 13 | 14 | // USE_UTF8_LONG_NAMES must be non-zero in SdFat/src/SdFatCongfig.h 15 | #if USE_UTF8_LONG_NAMES 16 | 17 | #define UTF8_FOLDER u8"😀" 18 | const char* names[] = {u8"россиянин", u8"très élégant", u8"狗.txt", nullptr}; 19 | 20 | // Remove files if non-zero. 21 | #define REMOVE_UTF8_FILES 1 22 | 23 | // SDCARD_SS_PIN is defined for the built-in SD on some boards. 24 | #ifndef SDCARD_SS_PIN 25 | const uint8_t SD_CS_PIN = SS; 26 | #else // SDCARD_SS_PIN 27 | // Assume built-in SD is used. 28 | const uint8_t SD_CS_PIN = SDCARD_SS_PIN; 29 | #endif // SDCARD_SS_PIN 30 | 31 | // Try to select the best SD card configuration. 32 | #if defined(HAS_TEENSY_SDIO) 33 | #define SD_CONFIG SdioConfig(FIFO_SDIO) 34 | #elif defined(RP_CLK_GPIO) && defined(RP_CMD_GPIO) && defined(RP_DAT0_GPIO) 35 | // See the Rp2040SdioSetup example for RP2040/RP2350 boards. 36 | #define SD_CONFIG SdioConfig(RP_CLK_GPIO, RP_CMD_GPIO, RP_DAT0_GPIO) 37 | #elif ENABLE_DEDICATED_SPI 38 | #define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(16)) 39 | #else // HAS_TEENSY_SDIO 40 | #define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(16)) 41 | #endif // HAS_TEENSY_SDIO 42 | 43 | #if SD_FAT_TYPE == 0 44 | SdFat sd; 45 | File file; 46 | #elif SD_FAT_TYPE == 1 47 | SdFat32 sd; 48 | File32 file; 49 | #elif SD_FAT_TYPE == 2 50 | SdExFat sd; 51 | ExFile file; 52 | #elif SD_FAT_TYPE == 3 53 | SdFs sd; 54 | FsFile file; 55 | #else // SD_FAT_TYPE 56 | #error Invalid SD_FAT_TYPE 57 | #endif // SD_FAT_TYPE 58 | 59 | void setup() { 60 | Serial.begin(9600); 61 | while (!Serial) { 62 | yield(); 63 | } 64 | Serial.println("Type any character to begin"); 65 | while (!Serial.available()) { 66 | yield(); 67 | } 68 | if (!sd.begin(SD_CONFIG)) { 69 | sd.initErrorHalt(&Serial); 70 | } 71 | if (!sd.exists(UTF8_FOLDER)) { 72 | if (!sd.mkdir(UTF8_FOLDER)) { 73 | Serial.println("sd.mkdir failed"); 74 | return; 75 | } 76 | } 77 | if (!sd.chdir(UTF8_FOLDER)) { 78 | Serial.println("sd.chdir failed"); 79 | return; 80 | } 81 | for (uint8_t i = 0; names[i]; i++) { 82 | if (!file.open(names[i], O_WRONLY | O_CREAT)) { 83 | Serial.println("file.open failed"); 84 | return; 85 | } 86 | file.println(names[i]); 87 | file.close(); 88 | } 89 | Serial.println("ls:"); 90 | sd.ls("/", LS_SIZE | LS_R); 91 | #if REMOVE_UTF8_FILES // For debug test of remove and rmdir. 92 | for (uint8_t i = 0; names[i]; i++) { 93 | sd.remove(names[i]); 94 | } 95 | sd.chdir(); 96 | sd.rmdir(UTF8_FOLDER); 97 | Serial.println("After remove and rmdir"); 98 | sd.ls(LS_SIZE | LS_R); 99 | #endif // REMOVE_UTF8_FILES 100 | Serial.println("Done!"); 101 | } 102 | void loop() {} 103 | #else // USE_UTF8_LONG_NAMES 104 | #error USE_UTF8_LONG_NAMES must be non-zero in SdFat/src/SdFatCongfig.h 105 | #endif // USE_UTF8_LONG_NAMES -------------------------------------------------------------------------------- /examples/UserChipSelectFunction/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/UserChipSelectFunction/.none.test.only -------------------------------------------------------------------------------- /examples/UserChipSelectFunction/UserChipSelectFunction.ino: -------------------------------------------------------------------------------- 1 | // An example of an external chip select functions. 2 | // Useful for port expanders or replacement of the standard GPIO functions. 3 | // 4 | #include "SdFat.h" 5 | 6 | // SD_CHIP_SELECT_MODE must be set to one or two in SdFat/SdFatConfig.h. 7 | // A value of one allows optional replacement and two requires replacement. 8 | #if SD_CHIP_SELECT_MODE == 1 || SD_CHIP_SELECT_MODE == 2 9 | 10 | // SD chip select pin. 11 | #define SD_CS_PIN SS 12 | 13 | #define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(50)) 14 | 15 | SdFat sd; 16 | 17 | // Stats to verify function calls. 18 | uint32_t initCalls = 0; 19 | uint32_t writeCalls = 0; 20 | //------------------------------------------------------------------------------ 21 | // Modify these functions for your port expander or custom GPIO library. 22 | void sdCsInit(SdCsPin_t pin) { 23 | initCalls++; 24 | pinMode(pin, OUTPUT); 25 | } 26 | void sdCsWrite(SdCsPin_t pin, bool level) { 27 | writeCalls++; 28 | digitalWrite(pin, level); 29 | } 30 | //------------------------------------------------------------------------------ 31 | void setup() { 32 | Serial.begin(9600); 33 | if (!sd.begin(SD_CONFIG)) { 34 | sd.initErrorHalt(&Serial); 35 | } 36 | sd.ls(&Serial, LS_SIZE); 37 | 38 | Serial.print(F("sdCsInit calls: ")); 39 | Serial.println(initCalls); 40 | Serial.print(F("sdCsWrite calls: ")); 41 | Serial.println(writeCalls); 42 | } 43 | //------------------------------------------------------------------------------ 44 | void loop() {} 45 | #else // SD_CHIP_SELECT_MODE == 1 || SD_CHIP_SELECT_MODE == 2 46 | #error SD_CHIP_SELECT_MODE must be one or two in SdFat/SdFatConfig.h 47 | #endif // SD_CHIP_SELECT_MODE == 1 || SD_CHIP_SELECT_MODE == 2 48 | -------------------------------------------------------------------------------- /examples/UserSPIDriver/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/UserSPIDriver/.none.test.only -------------------------------------------------------------------------------- /examples/UserSPIDriver/UserSPIDriver.ino: -------------------------------------------------------------------------------- 1 | // An example of an external SPI driver. 2 | // 3 | #include "SPI.h" // Only required if you use features in the SPI library. 4 | #include "SdFat.h" 5 | 6 | #if SPI_DRIVER_SELECT == 3 // Must be set in SdFat/SdFatConfig.h 7 | 8 | // SD chip select pin. 9 | #define SD_CS_PIN SS 10 | 11 | // This is a simple driver based on the the standard SPI.h library. 12 | // You can write a driver entirely independent of SPI.h. 13 | // It can be optimized for your board or a different SPI port can be used. 14 | // The driver must be derived from SdSpiBaseClass. 15 | // See: SdFat/src/SpiDriver/SdSpiBaseClass.h 16 | class MySpiClass : public SdSpiBaseClass { 17 | public: 18 | // Activate SPI hardware with correct speed and mode. 19 | void activate() { SPI.beginTransaction(m_spiSettings); } 20 | // Initialize the SPI bus. 21 | void begin(SdSpiConfig config) { 22 | (void)config; 23 | SPI.begin(); 24 | } 25 | // Deactivate SPI hardware. 26 | void deactivate() { SPI.endTransaction(); } 27 | // Receive a byte. 28 | uint8_t receive() { return SPI.transfer(0XFF); } 29 | // Receive multiple bytes. 30 | // Replace this function if your board has multiple byte receive. 31 | uint8_t receive(uint8_t* buf, size_t count) { 32 | for (size_t i = 0; i < count; i++) { 33 | buf[i] = SPI.transfer(0XFF); 34 | } 35 | return 0; 36 | } 37 | // Send a byte. 38 | void send(uint8_t data) { SPI.transfer(data); } 39 | // Send multiple bytes. 40 | // Replace this function if your board has multiple byte send. 41 | void send(const uint8_t* buf, size_t count) { 42 | for (size_t i = 0; i < count; i++) { 43 | SPI.transfer(buf[i]); 44 | } 45 | } 46 | // Save SPISettings for new max SCK frequency 47 | void setSckSpeed(uint32_t maxSck) { 48 | m_spiSettings = SPISettings(maxSck, MSBFIRST, SPI_MODE0); 49 | } 50 | 51 | private: 52 | SPISettings m_spiSettings; 53 | } mySpi; 54 | #if ENABLE_DEDICATED_SPI 55 | #define SD_CONFIG SdSpiConfig(SD_CS_PIN, DEDICATED_SPI, SD_SCK_MHZ(50), &mySpi) 56 | #else // ENABLE_DEDICATED_SPI 57 | #define SD_CONFIG SdSpiConfig(SD_CS_PIN, SHARED_SPI, SD_SCK_MHZ(50), &mySpi) 58 | #endif // ENABLE_DEDICATED_SPI 59 | SdFat sd; 60 | 61 | //------------------------------------------------------------------------------ 62 | void setup() { 63 | Serial.begin(9600); 64 | if (!sd.begin(SD_CONFIG)) { 65 | sd.initErrorHalt(&Serial); 66 | } 67 | sd.ls(&Serial, LS_SIZE); 68 | Serial.println("Done"); 69 | } 70 | //------------------------------------------------------------------------------ 71 | void loop() {} 72 | #else // SPI_DRIVER_SELECT 73 | #error SPI_DRIVER_SELECT must be three in SdFat/SdFatConfig.h 74 | #endif // SPI_DRIVER_SELECT 75 | 76 | -------------------------------------------------------------------------------- /examples/debug/CardBusyTest/CardBusyTest.ino: -------------------------------------------------------------------------------- 1 | #include "SdFat.h" 2 | 3 | #ifdef __AVR__ 4 | const uint32_t FILE_SIZE_MiB = 10UL; 5 | #else // __AVR__ 6 | const uint32_t FILE_SIZE_MiB = 100UL; 7 | #endif 8 | 9 | bool waitBusy = true; 10 | 11 | #define SD_CONFIG SdSpiConfig(SS, DEDICATED_SPI) 12 | //#define SD_CONFIG SdSpiConfig(SS, SHARED_SPI) 13 | // Config for Teensy 3.5/3.6 buit-in SD. 14 | //#define SD_CONFIG SdSpiConfig(SDCARD_SS_PIN, DEDICATED_SPI) 15 | //#define SD_CONFIG SdioConfig(FIFO_SDIO) 16 | 17 | //------------------------------------------------------------------------------ 18 | const uint64_t FILE_SIZE = (uint64_t)FILE_SIZE_MiB << 20; 19 | 20 | SdFs sd; 21 | FsFile file; 22 | 23 | uint8_t buf[512]; 24 | 25 | #define error(s) sd.errorHalt(&Serial, F(s)) 26 | //------------------------------------------------------------------------------ 27 | void clearSerialInput() { 28 | uint32_t m = micros(); 29 | do { 30 | if (Serial.read() >= 0) { 31 | m = micros(); 32 | } 33 | } while (micros() - m < 10000); 34 | } 35 | //------------------------------------------------------------------------------ 36 | void setup() { 37 | Serial.begin(9600); 38 | 39 | // Wait for USB Serial 40 | while (!Serial) { 41 | yield(); 42 | } 43 | delay(1000); 44 | //------------------------------------------------------------------------------ 45 | } 46 | void loop() { 47 | clearSerialInput(); 48 | Serial.println(F("\nType any character to start\n")); 49 | while (!Serial.available()) { 50 | yield(); 51 | } 52 | // Initialize the SD card. 53 | if (!sd.begin(SD_CONFIG)) { 54 | sd.initErrorHalt(); 55 | } 56 | if (!file.open("SdBusyTest.bin", O_RDWR | O_CREAT |O_TRUNC)) { 57 | error("file open failed"); 58 | } 59 | if (!file.preAllocate(FILE_SIZE)) { 60 | error("preallocate failed"); 61 | } 62 | Serial.print(F("Starting write of ")); 63 | Serial.print(FILE_SIZE_MiB); 64 | Serial.println(F(" MiB.")); 65 | uint32_t maxWrite = 0; 66 | uint32_t minWrite = 99999999; 67 | uint32_t ms = millis(); 68 | uint32_t maxBusy = 0; 69 | uint32_t minBusy = UINT32_MAX; 70 | 71 | // Write a dummy sector to start a multi-sector write. 72 | if(file.write(buf, sizeof(buf)) != sizeof(buf)) { 73 | error("write failed for first sector"); 74 | } 75 | 76 | while (file.position() < FILE_SIZE) { 77 | uint32_t m = micros(); 78 | if (waitBusy) { 79 | m = micros(); 80 | while (sd.card()->isBusy()) {} 81 | m = micros() - m; 82 | if (m < minBusy) { 83 | minBusy = m; 84 | } 85 | if (m > maxBusy) { 86 | maxBusy = m; 87 | } 88 | } 89 | m = micros(); 90 | if (file.write(buf, sizeof(buf)) != sizeof(buf)) { 91 | error("write failed"); 92 | } 93 | m = micros() - m; 94 | if (m < minWrite) { 95 | minWrite = m; 96 | } 97 | if (m > maxWrite) { 98 | maxWrite = m; 99 | } 100 | } 101 | file.close(); 102 | ms = millis() - ms; 103 | Serial.println(F("\nTimes in micros")); 104 | if (waitBusy) { 105 | Serial.print(F("minBusy: ")); 106 | Serial.println(minBusy); 107 | Serial.print(F("maxBusy: ")); 108 | Serial.println(maxBusy); 109 | } 110 | Serial.print(F("minWrite: ")); 111 | Serial.println(minWrite); 112 | Serial.print(F("maxWrite: ")); 113 | Serial.println(maxWrite); 114 | Serial.print(1e-3*ms); 115 | Serial.println(F(" Seconds")); 116 | Serial.print(1.0*FILE_SIZE/ms); 117 | Serial.println(F(" KB/sec")); 118 | 119 | } -------------------------------------------------------------------------------- /examples/debug/ExFatDbgDmp/ExFatDbgDmp.ino: -------------------------------------------------------------------------------- 1 | #include "SdFat.h" 2 | #define DUMP_RAW 0 3 | #define DUMP_UPCASE 0 4 | const uint8_t CS_PIN = SS; 5 | //#define SD_CONFIG SdioConfig(FIFO_SDIO) 6 | #define SD_CONFIG SdSpiConfig(CS_PIN) 7 | 8 | SdExFat sd; 9 | #define error(s) sd.errorHalt(&Serial, F(s)) 10 | void setup() { 11 | Serial.begin(9600); 12 | while (!Serial) { 13 | yield(); 14 | } 15 | Serial.println(F("Type any character to begin")); 16 | while (!Serial.available()) { 17 | yield(); 18 | } 19 | if (!sd.begin(SD_CONFIG)){ 20 | error("begin failed"); 21 | } 22 | #if DUMP_RAW 23 | sd.dmpSector(&Serial, 0); 24 | for (uint8_t i = 0; i < 24; i++) { 25 | sd.dmpSector(&Serial, 0X8000 + i); 26 | Serial.println(); 27 | } 28 | return; 29 | #endif // DUMP_RAW 30 | ExFatFile root; 31 | if (!root.openRoot(&sd)) { 32 | error("openRoot failed"); 33 | } 34 | sd.printDir(&Serial, &root); 35 | // startSector = 0, sectorCount = 1. 36 | sd.dmpFat(&Serial, 0, 1); 37 | sd.dmpBitmap(&Serial); 38 | sd.printVolInfo(&Serial); 39 | 40 | sd.checkUpcase(&Serial); 41 | #if DUMP_UPCASE 42 | sd.printUpcase(&Serial); 43 | #endif // DUMP_UPCASE 44 | // sd.dmpCluster(&Serial, 8, 0, 4); 45 | Serial.println("Done"); 46 | } 47 | 48 | void loop() { 49 | // put your main code here, to run repeatedly: 50 | 51 | } -------------------------------------------------------------------------------- /examples/debug/TestGetName/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_esp32s2 2 | feather_esp32s3 -------------------------------------------------------------------------------- /examples/debug/TestGetName/TestGetName.ino: -------------------------------------------------------------------------------- 1 | #include "SdFat.h" 2 | SdFs sd; 3 | FsFile file; 4 | const char* name[] = { 5 | "SFN.TXT", 6 | "LongFilename.txt", 7 | #if USE_UTF8_LONG_NAMES 8 | u8"très élégant.txt", 9 | #endif // USE_UTF8_LONG_NAMES 10 | nullptr}; 11 | char buf[32]; 12 | void setup() { 13 | Serial.begin(9600); 14 | while (!Serial) {} 15 | Serial.println("Type any character to begin"); 16 | while (!Serial.available()) {} 17 | if (!sd.begin(SS)) { 18 | sd.initErrorHalt(); 19 | } 20 | for (uint8_t i = 0; name[i]; i++) { 21 | if (!file.open(name[i], O_CREAT |O_RDWR)) { 22 | sd.errorHalt("open"); 23 | } 24 | size_t len = strlen(name[i]); 25 | size_t rtn = file.getName(buf, len); 26 | if (rtn != 0) { 27 | Serial.println("fail len"); 28 | } 29 | rtn = file.getName(buf, len + 1); 30 | if (rtn != len) { 31 | Serial.println("fail len + 1"); 32 | } 33 | Serial.print(rtn); 34 | Serial.print(' '); 35 | Serial.println(buf); 36 | if (!file.remove()) { 37 | sd.errorHalt("remove"); 38 | } 39 | } 40 | Serial.println("Done"); 41 | } 42 | 43 | void loop() {} 44 | -------------------------------------------------------------------------------- /examples/debug/TestMkdir/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_rp2040 2 | metro_rp2040 -------------------------------------------------------------------------------- /examples/debug/TestRmdir/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_rp2040 2 | metro_rp2040 -------------------------------------------------------------------------------- /examples/debug/TestRmdir/TestRmdir.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This sketch will remove the files and directories 3 | * created by the SdFatMakeDir.pde sketch. 4 | * 5 | * Performance is erratic due to the large number 6 | * of flash erase operations caused by many random 7 | * writes to file structures. 8 | */ 9 | #include 10 | 11 | const uint8_t SD_CHIP_SELECT = SS; 12 | 13 | SdFat sd; 14 | typedef File file_t; 15 | 16 | // store error strings in flash to save RAM 17 | #define error(s) sd.errorHalt(&Serial, F(s)) 18 | 19 | /* 20 | * remove all files in dir. 21 | */ 22 | void deleteFiles(FatFile* dir) { 23 | char name[32]; 24 | file_t file; 25 | 26 | // open and delete files 27 | for (uint16_t n = 0; ; n++){ 28 | sprintf(name, "%u.TXT", n); 29 | 30 | // open start time 31 | uint32_t t0 = millis(); 32 | 33 | // assume done if open fails 34 | if (!file.open(dir, name, O_WRONLY)) return; 35 | 36 | // open end time and remove start time 37 | uint32_t t1 = millis(); 38 | if (!file.remove()) error("file.remove failed"); 39 | 40 | // remove end time 41 | uint32_t t2 = millis(); 42 | 43 | Serial.print(F("RM ")); 44 | Serial.print(n); 45 | Serial.write(' '); 46 | 47 | // open time 48 | Serial.print(t1 - t0); 49 | Serial.write(' '); 50 | 51 | // remove time 52 | Serial.println(t2 - t1); 53 | } 54 | } 55 | 56 | void setup() { 57 | file_t root; 58 | Serial.begin(9600); 59 | while (!Serial) {} // wait for Leonardo 60 | Serial.println(F("Type any character to start")); 61 | while (Serial.read() <= 0) {} 62 | delay(200); // Catch Due reset problem 63 | 64 | // initialize the SD card at SPI_FULL_SPEED for best performance. 65 | // try lower speed if bus errors occur. 66 | if (!sd.begin(SD_CHIP_SELECT, SPI_FULL_SPEED)) { 67 | sd.initErrorHalt(&Serial); 68 | } 69 | root.openRoot(&sd); 70 | // delete files in root if not FAT16. 71 | if (sd.fatType() != 16) { 72 | Serial.println(F("Remove files in root")); 73 | deleteFiles(&root); 74 | } 75 | 76 | // open SUB1 and delete files 77 | file_t sub1; 78 | if (!sub1.open("SUB1", O_RDONLY)) error("open SUB1 failed"); 79 | Serial.println(F("Remove files in SUB1")); 80 | deleteFiles(&sub1); 81 | 82 | // open SUB2 and delete files 83 | file_t sub2; 84 | if (!sub2.open(&sub1, "SUB2", O_RDONLY)) error("open SUB2 failed"); 85 | Serial.println(F("Remove files in SUB2")); 86 | deleteFiles(&sub2); 87 | 88 | // remove SUB2 89 | if (!sub2.rmdir()) error("sub2.rmdir failed"); 90 | Serial.println(F("SUB2 removed")); 91 | 92 | // remove SUB1 93 | if (!sub1.rmdir()) error("sub1.rmdir failed"); 94 | Serial.println(F("SUB1 removed")); 95 | 96 | Serial.println(F("Done")); 97 | } 98 | 99 | void loop() { } -------------------------------------------------------------------------------- /examples/examplesV1/#attic/BaseExtCaseTest/BaseExtCaseTest.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Program to test Short File Name character case flags. 3 | */ 4 | #include 5 | #include "SdFat.h" 6 | 7 | const uint8_t chipSelect = SS; 8 | 9 | SdFat sd; 10 | 11 | SdFile file; 12 | const char* name[] = { 13 | "low.low", "low.Mix", "low.UP", 14 | "Mix.low", "Mix.Mix", "Mix.UP", 15 | "UP.low", "UP.Mix", "UP.UP" 16 | }; 17 | //------------------------------------------------------------------------------ 18 | void setup() { 19 | Serial.begin(9600); 20 | 21 | // Wait for USB Serial 22 | while (!Serial) { 23 | yield(); 24 | } 25 | Serial.println("type any character to start"); 26 | while (!Serial.available()) { 27 | yield(); 28 | } 29 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 30 | Serial.println("begin failed"); 31 | return; 32 | } 33 | for (uint8_t i = 0; i < 9; i++) { 34 | sd.remove(name[i]); 35 | if (!file.open(name[i], O_RDWR | O_CREAT | O_EXCL)) { 36 | sd.errorHalt(name[i]); 37 | } 38 | file.println(name[i]); 39 | 40 | file.close(); 41 | } 42 | sd.ls(LS_DATE|LS_SIZE); 43 | Serial.println("Done"); 44 | } 45 | //------------------------------------------------------------------------------ 46 | void loop() {} 47 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/HelloWorld/HelloWorld.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "SdFat.h" 3 | #include "sdios.h" 4 | 5 | // create a serial output stream 6 | ArduinoOutStream cout(Serial); 7 | 8 | void setup() { 9 | Serial.begin(9600); 10 | 11 | // Wait for USB Serial 12 | while (!Serial) { 13 | yield(); 14 | } 15 | delay(2000); 16 | 17 | cout << "Hello, World!\n"; 18 | } 19 | 20 | void loop() {} 21 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/MiniSerial/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/examplesV1/#attic/MiniSerial/.none.test.only -------------------------------------------------------------------------------- /examples/examplesV1/#attic/MiniSerial/MiniSerial.ino: -------------------------------------------------------------------------------- 1 | // This example illustrates use of SdFat's 2 | // minimal unbuffered AVR Serial support. 3 | // 4 | // This is useful for debug and saves RAM 5 | // Will not work on Due, Leonardo, or Teensy 6 | 7 | #include 8 | #include "SdFat.h" 9 | #include "FreeStack.h" 10 | #ifdef UDR0 // Must be AVR with serial port zero. 11 | #include "MinimumSerial.h" 12 | 13 | MinimumSerial MiniSerial; 14 | 15 | void setup() { 16 | MiniSerial.begin(9600); 17 | MiniSerial.println(FreeStack()); 18 | } 19 | void loop() { 20 | int c; 21 | MiniSerial.println(F("Type any Character")); 22 | while ((c = MiniSerial.read()) < 0) {} 23 | MiniSerial.print(F("Read: ")); 24 | MiniSerial.println((char)c); 25 | while (MiniSerial.read() >= 0) {} 26 | } 27 | #else // UDR0 28 | #error no AVR serial port 0 29 | #endif // UDR0 -------------------------------------------------------------------------------- /examples/examplesV1/#attic/PrintBenchmarkSD/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_rp2040 2 | metro_rp2040 -------------------------------------------------------------------------------- /examples/examplesV1/#attic/PrintBenchmarkSD/PrintBenchmarkSD.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This program is a simple Print benchmark. 3 | */ 4 | #include 5 | #include 6 | 7 | // SD chip select pin 8 | const uint8_t chipSelect = SS; 9 | 10 | // number of lines to print 11 | const uint16_t N_PRINT = 20000; 12 | 13 | 14 | // test file 15 | File file; 16 | 17 | //------------------------------------------------------------------------------ 18 | void error(const char* s) { 19 | Serial.println(s); 20 | while (1) { 21 | yield(); 22 | } 23 | } 24 | //------------------------------------------------------------------------------ 25 | void setup() { 26 | Serial.begin(9600); 27 | 28 | // Wait for USB Serial 29 | while (!Serial) { 30 | yield(); 31 | } 32 | } 33 | //------------------------------------------------------------------------------ 34 | void loop() { 35 | uint32_t maxLatency; 36 | uint32_t minLatency; 37 | uint32_t totalLatency; 38 | 39 | // Read any existing Serial data. 40 | do { 41 | delay(10); 42 | } while (Serial.available() && Serial.read() >= 0); 43 | 44 | // F() stores strings in flash to save RAM 45 | Serial.println(F("Type any character to start")); 46 | while (!Serial.available()) { 47 | yield(); 48 | } 49 | 50 | // initialize the SD card 51 | if (!SD.begin(chipSelect)) { 52 | error("begin"); 53 | } 54 | 55 | Serial.println(F("Starting print test. Please wait.\n")); 56 | 57 | // do write test 58 | for (int test = 0; test < 2; test++) { 59 | file = SD.open("bench.txt", FILE_WRITE); 60 | 61 | if (!file) { 62 | error("open failed"); 63 | } 64 | switch(test) { 65 | case 0: 66 | Serial.println(F("Test of println(uint16_t)")); 67 | break; 68 | 69 | case 1: 70 | Serial.println(F("Test of println(double)")); 71 | break; 72 | } 73 | maxLatency = 0; 74 | minLatency = 999999; 75 | totalLatency = 0; 76 | uint32_t t = millis(); 77 | for (uint16_t i = 0; i < N_PRINT; i++) { 78 | uint32_t m = micros(); 79 | 80 | switch(test) { 81 | case 0: 82 | file.println(i); 83 | break; 84 | 85 | case 1: 86 | file.println((double)0.01*i); 87 | break; 88 | } 89 | 90 | if (file.getWriteError()) { 91 | error("write failed"); 92 | } 93 | m = micros() - m; 94 | if (maxLatency < m) { 95 | maxLatency = m; 96 | } 97 | if (minLatency > m) { 98 | minLatency = m; 99 | } 100 | totalLatency += m; 101 | } 102 | file.flush(); 103 | t = millis() - t; 104 | double s = file.size(); 105 | Serial.print(F("Time ")); 106 | Serial.print(0.001*t); 107 | Serial.println(F(" sec")); 108 | Serial.print(F("File size ")); 109 | Serial.print(0.001*s); 110 | Serial.print(F(" KB\n")); 111 | Serial.print(F("Write ")); 112 | Serial.print(s/t); 113 | Serial.print(F(" KB/sec\n")); 114 | Serial.print(F("Maximum latency: ")); 115 | Serial.print(maxLatency); 116 | Serial.print(F(" usec, Minimum Latency: ")); 117 | Serial.print(minLatency); 118 | Serial.print(F(" usec, Avg Latency: ")); 119 | Serial.print(totalLatency/N_PRINT); 120 | Serial.println(F(" usec\n")); 121 | SD.remove("bench.txt"); 122 | } 123 | file.close(); 124 | Serial.println(F("Done!\n")); 125 | } -------------------------------------------------------------------------------- /examples/examplesV1/#attic/SD_Size/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_rp2040 2 | metro_rp2040 -------------------------------------------------------------------------------- /examples/examplesV1/#attic/SD_Size/SD_Size.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Program to compare size of Arduino SD library with SdFat. 3 | * See SdFatSize.ino for SdFat program. 4 | */ 5 | #include 6 | #include 7 | 8 | File file; 9 | //------------------------------------------------------------------------------ 10 | void setup() { 11 | Serial.begin(9600); 12 | 13 | // Wait for USB Serial 14 | while (!Serial) { 15 | yield(); 16 | } 17 | 18 | if (!SD.begin()) { 19 | Serial.println("begin failed"); 20 | return; 21 | } 22 | file = SD.open("TEST_SD.TXT", FILE_WRITE); 23 | 24 | file.println("Hello"); 25 | 26 | file.close(); 27 | Serial.println("Done"); 28 | } 29 | //------------------------------------------------------------------------------ 30 | void loop() {} 31 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/SdFatSize/SdFatSize.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Program to compare size of SdFat with Arduino SD library. 3 | * See SD_Size.ino for Arduino SD program. 4 | * 5 | */ 6 | #include 7 | #include "SdFat.h" 8 | 9 | SdFat sd; 10 | 11 | SdFile file; 12 | //------------------------------------------------------------------------------ 13 | void setup() { 14 | Serial.begin(9600); 15 | 16 | // Wait for USB Serial 17 | while (!Serial) { 18 | yield(); 19 | } 20 | 21 | if (!sd.begin()) { 22 | Serial.println("begin failed"); 23 | return; 24 | } 25 | file.open("SizeTest.txt", O_RDWR | O_CREAT | O_AT_END); 26 | 27 | file.println("Hello"); 28 | 29 | file.close(); 30 | Serial.println("Done"); 31 | } 32 | //------------------------------------------------------------------------------ 33 | void loop() {} 34 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/StreamParseInt/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_rp2040 2 | metro_rp2040 -------------------------------------------------------------------------------- /examples/examplesV1/#attic/StreamParseInt/StreamParseInt.ino: -------------------------------------------------------------------------------- 1 | // Simple demo of the Stream parsInt() member function. 2 | #include 3 | // The next two lines replace #include . 4 | #include "SdFat.h" 5 | SdFat SD; 6 | 7 | // SD card chip select pin - Modify the value of csPin for your SD module. 8 | const uint8_t csPin = SS; 9 | 10 | File file; 11 | //------------------------------------------------------------------------------ 12 | void setup() { 13 | Serial.begin(9600); 14 | // Wait for USB Serial. 15 | while(!Serial) { 16 | yield(); 17 | } 18 | Serial.println(F("Type any character to start")); 19 | while (!Serial.available()) { 20 | yield(); 21 | } 22 | // Initialize the SD. 23 | if (!SD.begin(csPin)) { 24 | Serial.println(F("begin error")); 25 | return; 26 | } 27 | // Create and open the file. Use flag to truncate an existing file. 28 | file = SD.open("stream.txt", O_RDWR|O_CREAT|O_TRUNC); 29 | if (!file) { 30 | Serial.println(F("open error")); 31 | return; 32 | } 33 | // Write a test number to the file. 34 | file.println("12345"); 35 | 36 | // Rewind the file and read the number with parseInt(). 37 | file.seek(0); 38 | int i = file.parseInt(); 39 | Serial.print(F("parseInt: ")); 40 | Serial.println(i); 41 | file.close(); 42 | } 43 | 44 | void loop() {} -------------------------------------------------------------------------------- /examples/examplesV1/#attic/append/append.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Append Example 3 | * 4 | * This program shows how to use open for append. 5 | * The program will append 100 line each time it opens the file. 6 | * The program will open and close the file 100 times. 7 | */ 8 | #include 9 | #include "SdFat.h" 10 | #include "sdios.h" 11 | 12 | // SD chip select pin 13 | const uint8_t chipSelect = SS; 14 | 15 | // file system object 16 | SdFat sd; 17 | 18 | // create Serial stream 19 | ArduinoOutStream cout(Serial); 20 | 21 | // store error strings in flash to save RAM 22 | #define error(s) sd.errorHalt(F(s)) 23 | //------------------------------------------------------------------------------ 24 | void setup() { 25 | // filename for this example 26 | char name[] = "append.txt"; 27 | 28 | Serial.begin(9600); 29 | 30 | // Wait for USB Serial 31 | while (!Serial) { 32 | yield(); 33 | } 34 | // F() stores strings in flash to save RAM 35 | cout << endl << F("Type any character to start\n"); 36 | while (!Serial.available()) { 37 | yield(); 38 | } 39 | 40 | // Initialize at the highest speed supported by the board that is 41 | // not over 50 MHz. Try a lower speed if SPI errors occur. 42 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 43 | sd.initErrorHalt(); 44 | } 45 | 46 | cout << F("Appending to: ") << name; 47 | 48 | for (uint8_t i = 0; i < 100; i++) { 49 | // open stream for append 50 | ofstream sdout(name, ios::out | ios::app); 51 | if (!sdout) { 52 | error("open failed"); 53 | } 54 | 55 | // append 100 lines to the file 56 | for (uint8_t j = 0; j < 100; j++) { 57 | // use int() so byte will print as decimal number 58 | sdout << "line " << int(j) << " of pass " << int(i); 59 | sdout << " millis = " << millis() << endl; 60 | } 61 | // close the stream 62 | sdout.close(); 63 | 64 | if (!sdout) { 65 | error("append data failed"); 66 | } 67 | 68 | // output progress indicator 69 | if (i % 25 == 0) { 70 | cout << endl; 71 | } 72 | cout << '.'; 73 | } 74 | cout << endl << "Done" << endl; 75 | } 76 | //------------------------------------------------------------------------------ 77 | void loop() {} 78 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/average/average.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Calculate the sum and average of a list of floating point numbers 3 | */ 4 | #include 5 | #include "SdFat.h" 6 | #include "sdios.h" 7 | 8 | // SD chip select pin 9 | const uint8_t chipSelect = SS; 10 | 11 | // object for the SD file system 12 | SdFat sd; 13 | 14 | // define a serial output stream 15 | ArduinoOutStream cout(Serial); 16 | //------------------------------------------------------------------------------ 17 | void writeTestFile() { 18 | // open the output file 19 | ofstream sdout("AvgTest.txt"); 20 | 21 | // write a series of float numbers 22 | for (int16_t i = -1001; i < 2000; i += 13) { 23 | sdout << 0.1 * i << endl; 24 | } 25 | if (!sdout) { 26 | sd.errorHalt("sdout failed"); 27 | } 28 | 29 | sdout.close(); 30 | } 31 | //------------------------------------------------------------------------------ 32 | void calcAverage() { 33 | uint16_t n = 0; // count of input numbers 34 | double num; // current input number 35 | double sum = 0; // sum of input numbers 36 | 37 | // open the input file 38 | ifstream sdin("AvgTest.txt"); 39 | 40 | // check for an open failure 41 | if (!sdin) { 42 | sd.errorHalt("sdin failed"); 43 | } 44 | 45 | // read and sum the numbers 46 | while (sdin >> num) { 47 | n++; 48 | sum += num; 49 | } 50 | 51 | // print the results 52 | cout << "sum of " << n << " numbers = " << sum << endl; 53 | cout << "average = " << sum/n << endl; 54 | } 55 | //------------------------------------------------------------------------------ 56 | void setup() { 57 | Serial.begin(9600); 58 | 59 | // Wait for USB Serial 60 | while (!Serial) { 61 | yield(); 62 | } 63 | // F() stores strings in flash to save RAM 64 | cout << F("Type any character to start\n"); 65 | while (!Serial.available()) { 66 | yield(); 67 | } 68 | 69 | // Initialize at the highest speed supported by the board that is 70 | // not over 50 MHz. Try a lower speed if SPI errors occur. 71 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 72 | sd.initErrorHalt(); 73 | } 74 | 75 | // write the test file 76 | writeTestFile(); 77 | 78 | // read the test file and calculate the average 79 | calcAverage(); 80 | } 81 | //------------------------------------------------------------------------------ 82 | void loop() {} 83 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/benchSD/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_rp2040 2 | metro_rp2040 3 | feather_esp32s2 4 | feather_esp32s3 5 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/bufstream/bufstream.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Use of ibufsteam to parse a line and obufstream to format a line 3 | */ 4 | #include 5 | #include "SdFat.h" 6 | #include "sdios.h" 7 | 8 | // create a serial output stream 9 | ArduinoOutStream cout(Serial); 10 | //------------------------------------------------------------------------------ 11 | void setup() { 12 | char buf[20]; // buffer for formatted line 13 | int i, j, k; // values from parsed line 14 | 15 | Serial.begin(9600); 16 | 17 | // Wait for USB Serial 18 | while (!Serial) { 19 | yield(); 20 | } 21 | delay(2000); 22 | 23 | // initialize input string 24 | ibufstream bin("123 456 789"); 25 | 26 | // parse the string "123 456 789" 27 | bin >> i >> j >> k; 28 | 29 | // initialize output buffer 30 | obufstream bout(buf, sizeof(buf)); 31 | 32 | // format the output string 33 | bout << k << ',' << j << ',' << i << endl; 34 | 35 | // write the string to serial 36 | cout << buf; 37 | } 38 | 39 | void loop() {} 40 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/cin_cout/cin_cout.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Demo of ArduinoInStream and ArduinoOutStream 3 | */ 4 | #include 5 | #include "SdFat.h" 6 | #include "sdios.h" 7 | 8 | // create serial output stream 9 | ArduinoOutStream cout(Serial); 10 | 11 | // input line buffer 12 | char cinBuf[40]; 13 | 14 | // create serial input stream 15 | ArduinoInStream cin(Serial, cinBuf, sizeof(cinBuf)); 16 | //------------------------------------------------------------------------------ 17 | void setup() { 18 | Serial.begin(9600); 19 | // Wait for USB Serial 20 | while (!Serial) { 21 | yield(); 22 | } 23 | } 24 | //------------------------------------------------------------------------------ 25 | void loop() { 26 | int32_t n = 0; 27 | 28 | cout << "\nenter an integer\n"; 29 | 30 | cin.readline(); 31 | 32 | if (cin >> n) { 33 | cout << "The number is: " << n; 34 | } else { 35 | // will fail if no digits or not in range [-2147483648, 2147483647] 36 | cout << "Invalid input: " << cinBuf; 37 | } 38 | cout << endl; 39 | } 40 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/eventlog/eventlog.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Append a line to a file - demo of pathnames and streams 3 | */ 4 | #include 5 | #include "SdFat.h" 6 | #include "sdios.h" 7 | // SD chip select pin 8 | const uint8_t chipSelect = SS; 9 | 10 | // file system object 11 | SdFat sd; 12 | 13 | // define a serial output stream 14 | ArduinoOutStream cout(Serial); 15 | //------------------------------------------------------------------------------ 16 | /* 17 | * Append a line to logfile.txt 18 | */ 19 | void logEvent(const char *msg) { 20 | // create dir if needed 21 | sd.mkdir("logs/2014/Jan"); 22 | 23 | // create or open a file for append 24 | ofstream sdlog("logs/2014/Jan/logfile.txt", ios::out | ios::app); 25 | 26 | // append a line to the file 27 | sdlog << msg << endl; 28 | 29 | // check for errors 30 | if (!sdlog) { 31 | sd.errorHalt("append failed"); 32 | } 33 | 34 | sdlog.close(); 35 | } 36 | //------------------------------------------------------------------------------ 37 | void setup() { 38 | Serial.begin(9600); 39 | // Wait for USB Serial 40 | while (!Serial) { 41 | yield(); 42 | } 43 | // F() stores strings in flash to save RAM 44 | cout << F("Type any character to start\n"); 45 | while (!Serial.available()) { 46 | yield(); 47 | } 48 | delay(400); // catch Due reset problem 49 | 50 | // Initialize at the highest speed supported by the board that is 51 | // not over 50 MHz. Try a lower speed if SPI errors occur. 52 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 53 | sd.initErrorHalt(); 54 | } 55 | 56 | // append a line to the logfile 57 | logEvent("Another line for the logfile"); 58 | 59 | cout << F("Done - check /logs/2014/Jan/logfile.txt on the SD") << endl; 60 | } 61 | //------------------------------------------------------------------------------ 62 | void loop() {} 63 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/fgetsRewrite/fgetsRewrite.ino: -------------------------------------------------------------------------------- 1 | // Demo of rewriting a line read by fgets 2 | #include 3 | #include "SdFat.h" 4 | #include "sdios.h" 5 | 6 | // SD card chip select pin 7 | const uint8_t chipSelect = SS; 8 | 9 | // file system 10 | SdFat sd; 11 | 12 | // print stream 13 | ArduinoOutStream cout(Serial); 14 | //------------------------------------------------------------------------------ 15 | // store error strings in flash memory 16 | #define error(s) sd.errorHalt(F(s)) 17 | //------------------------------------------------------------------------------ 18 | void demoFgets() { 19 | char line[25]; 20 | int c; 21 | uint32_t pos; 22 | 23 | // open test file 24 | SdFile rdfile("fgets.txt", O_RDWR); 25 | 26 | // check for open error 27 | if (!rdfile.isOpen()) { 28 | error("demoFgets"); 29 | } 30 | 31 | // list file 32 | cout << F("-----Before Rewrite\r\n"); 33 | while ((c = rdfile.read()) >= 0) { 34 | Serial.write(c); 35 | } 36 | 37 | rdfile.rewind(); 38 | // read lines from the file to get position 39 | while (1) { 40 | pos = rdfile.curPosition(); 41 | if (rdfile.fgets(line, sizeof(line)) < 0) { 42 | error("Line not found"); 43 | } 44 | // find line that contains "Line C" 45 | if (strstr(line, "Line C")) { 46 | break; 47 | } 48 | } 49 | 50 | // rewrite line with 'C' 51 | if (!rdfile.seekSet(pos)) { 52 | error("seekSet"); 53 | } 54 | rdfile.println("Line R"); 55 | rdfile.rewind(); 56 | 57 | // list file 58 | cout << F("\r\n-----After Rewrite\r\n"); 59 | while ((c = rdfile.read()) >= 0) { 60 | Serial.write(c); 61 | } 62 | 63 | // close so rewrite is not lost 64 | rdfile.close(); 65 | } 66 | //------------------------------------------------------------------------------ 67 | void makeTestFile() { 68 | // create or open test file 69 | SdFile wrfile("fgets.txt", O_WRONLY | O_CREAT | O_TRUNC); 70 | 71 | // check for open error 72 | if (!wrfile.isOpen()) { 73 | error("MakeTestFile"); 74 | } 75 | 76 | // write test file 77 | wrfile.print(F( 78 | "Line A\r\n" 79 | "Line B\r\n" 80 | "Line C\r\n" 81 | "Line D\r\n" 82 | "Line E\r\n" 83 | )); 84 | wrfile.close(); 85 | } 86 | //------------------------------------------------------------------------------ 87 | void setup() { 88 | Serial.begin(9600); 89 | 90 | // Wait for USB Serial 91 | while (!Serial) { 92 | yield(); 93 | } 94 | cout << F("Type any character to start\n"); 95 | while (!Serial.available()) { 96 | yield(); 97 | } 98 | 99 | // Initialize at the highest speed supported by the board that is 100 | // not over 50 MHz. Try a lower speed if SPI errors occur. 101 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 102 | sd.initErrorHalt(); 103 | } 104 | 105 | makeTestFile(); 106 | 107 | demoFgets(); 108 | 109 | cout << F("\nDone\n"); 110 | } 111 | void loop() {} 112 | -------------------------------------------------------------------------------- /examples/examplesV1/#attic/readlog/readlog.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Read the logfile created by the eventlog.ino example. 3 | * Demo of pathnames and working directories 4 | */ 5 | #include 6 | #include "SdFat.h" 7 | #include "sdios.h" 8 | 9 | // SD chip select pin 10 | const uint8_t chipSelect = SS; 11 | 12 | // file system object 13 | SdFat sd; 14 | 15 | // define a serial output stream 16 | ArduinoOutStream cout(Serial); 17 | //------------------------------------------------------------------------------ 18 | void setup() { 19 | int c; 20 | Serial.begin(9600); 21 | 22 | // Wait for USB Serial 23 | while (!Serial) { 24 | yield(); 25 | } 26 | // Initialize at the highest speed supported by the board that is 27 | // not over 50 MHz. Try a lower speed if SPI errors occur. 28 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 29 | sd.initErrorHalt(); 30 | } 31 | 32 | // set current working directory 33 | if (!sd.chdir("logs/2014/Jan/")) { 34 | sd.errorHalt("chdir failed. Did you run eventlog.ino?"); 35 | } 36 | // open file in current working directory 37 | ifstream file("logfile.txt"); 38 | 39 | if (!file.is_open()) { 40 | sd.errorHalt("open failed"); 41 | } 42 | 43 | // copy the file to Serial 44 | while ((c = file.get()) >= 0) { 45 | cout << (char)c; 46 | } 47 | 48 | cout << "Done" << endl; 49 | } 50 | //------------------------------------------------------------------------------ 51 | void loop() {} -------------------------------------------------------------------------------- /examples/examplesV1/#attic/readme.txt: -------------------------------------------------------------------------------- 1 | Old and debug examples. 2 | 3 | AnalogLogger - A simple data logger for one or more analog pins. 4 | 5 | append - This sketch creates a large file by successive 6 | open/write/close operations. 7 | 8 | average - A demonstration of parsing floating point numbers. 9 | 10 | BaseExtCaseTest - Long file name test. 11 | 12 | benchSD - A read/write benchmark for the standard Arduino SD.h library. 13 | 14 | bufstream - ibufsteam to parse a line and obufstream to format a line. 15 | 16 | cin_cout - Demo of ArduinoInStream and ArduinoOutStream. 17 | 18 | eventlog - Append a line to a file - demo of pathnames and streams. 19 | 20 | fgetsRewrite - Demo of rewriting a line read by fgets. 21 | 22 | HelloWorld - Create a serial output stream. 23 | 24 | MiniSerial - SdFat minimal serial support for debug. 25 | 26 | PrintBenchmarkSD - Bench mark SD.h print. 27 | 28 | readlog - Read file. Demo of pathnames and current working directory. 29 | 30 | SD_Size - Determine flash used by SD.h example. 31 | 32 | SdFatSize - Determine flash used by SdFat. 33 | 34 | StreamParseInt - Simple demo of the Stream parsInt() member function. 35 | -------------------------------------------------------------------------------- /examples/examplesV1/AnalogBinLogger/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/examplesV1/AnalogBinLogger/.none.test.only -------------------------------------------------------------------------------- /examples/examplesV1/AnalogBinLogger/AnalogBinLogger.h: -------------------------------------------------------------------------------- 1 | #ifndef AnalogBinLogger_h 2 | #define AnalogBinLogger_h 3 | //------------------------------------------------------------------------------ 4 | // First block of file. 5 | struct metadata_t { 6 | unsigned long adcFrequency; // ADC clock frequency 7 | unsigned long cpuFrequency; // CPU clock frequency 8 | unsigned long sampleInterval; // Sample interval in CPU cycles. 9 | unsigned long recordEightBits; // Size of ADC values, nonzero for 8-bits. 10 | unsigned long pinCount; // Number of analog pins in a sample. 11 | unsigned long pinNumber[123]; // List of pin numbers in a sample. 12 | }; 13 | //------------------------------------------------------------------------------ 14 | // Data block for 8-bit ADC mode. 15 | const size_t DATA_DIM8 = 508; 16 | struct block8_t { 17 | unsigned short count; // count of data values 18 | unsigned short overrun; // count of overruns since last block 19 | unsigned char data[DATA_DIM8]; 20 | }; 21 | //------------------------------------------------------------------------------ 22 | // Data block for 10-bit ADC mode. 23 | const size_t DATA_DIM16 = 254; 24 | struct block16_t { 25 | unsigned short count; // count of data values 26 | unsigned short overrun; // count of overruns since last block 27 | unsigned short data[DATA_DIM16]; 28 | }; 29 | //------------------------------------------------------------------------------ 30 | // Data block for PC use 31 | struct adcdata_t { 32 | unsigned short count; // count of data values 33 | unsigned short overrun; // count of overruns since last block 34 | union { 35 | unsigned char u8[DATA_DIM8]; 36 | unsigned short u16[DATA_DIM16]; 37 | } data; 38 | }; 39 | #endif // AnalogBinLogger_h -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/LongFileName.ino: -------------------------------------------------------------------------------- 1 | // Example use of lfnOpenNext and open by index. 2 | // You can use test files located in 3 | // SdFat/examples/LongFileName/testFiles. 4 | #include 5 | #include "SdFat.h" 6 | #include "FreeStack.h" 7 | 8 | // SD card chip select pin. 9 | const uint8_t SD_CS_PIN = SS; 10 | 11 | SdFat sd; 12 | SdFile file; 13 | SdFile dirFile; 14 | 15 | // Number of files found. 16 | uint16_t n = 0; 17 | 18 | // Max of ten files since files are selected with a single digit. 19 | const uint16_t nMax = 10; 20 | 21 | // Position of file's directory entry. 22 | uint16_t dirIndex[nMax]; 23 | //------------------------------------------------------------------------------ 24 | void setup() { 25 | Serial.begin(9600); 26 | while (!Serial) {} 27 | delay(1000); 28 | 29 | // Print the location of some test files. 30 | Serial.println(F("\r\n" 31 | "You can use test files located in\r\n" 32 | "SdFat/examples/LongFileName/testFiles")); 33 | 34 | // Initialize at the highest speed supported by the board that is 35 | // not over 50 MHz. Try a lower speed if SPI errors occur. 36 | if (!sd.begin(SD_CS_PIN, SD_SCK_MHZ(50))) { 37 | sd.initErrorHalt(); 38 | } 39 | Serial.print(F("FreeStack: ")); 40 | Serial.println(FreeStack()); 41 | Serial.println(); 42 | 43 | // List files in root directory. 44 | if (!dirFile.open("/", O_RDONLY)) { 45 | sd.errorHalt("open root failed"); 46 | } 47 | while (n < nMax && file.openNext(&dirFile, O_RDONLY)) { 48 | 49 | // Skip directories and hidden files. 50 | if (!file.isSubDir() && !file.isHidden()) { 51 | 52 | // Save dirIndex of file in directory. 53 | dirIndex[n] = file.dirIndex(); 54 | 55 | // Print the file number and name. 56 | Serial.print(n++); 57 | Serial.write(' '); 58 | file.printName(&Serial); 59 | Serial.println(); 60 | } 61 | file.close(); 62 | } 63 | } 64 | //------------------------------------------------------------------------------ 65 | void loop() { 66 | int c; 67 | 68 | // Read any existing Serial data. 69 | do { 70 | delay(10); 71 | } while (Serial.available() && Serial.read() >= 0); 72 | Serial.print(F("\r\nEnter File Number: ")); 73 | 74 | while (!Serial.available()) { 75 | yield(); 76 | } 77 | c = Serial.read(); 78 | uint8_t i = c - '0'; 79 | if (!isdigit(c) || i >= n) { 80 | Serial.println(F("Invald number")); 81 | return; 82 | } 83 | Serial.println(i); 84 | if (!file.open(&dirFile, dirIndex[i], O_RDONLY)) { 85 | sd.errorHalt(F("open")); 86 | } 87 | Serial.println(); 88 | 89 | char last = 0; 90 | 91 | // Copy up to 500 characters to Serial. 92 | for (int k = 0; k < 500 && (c = file.read()) > 0; k++) { 93 | Serial.write(last = (char)c); 94 | } 95 | // Add new line if missing from last line. 96 | if (last != '\n') { 97 | Serial.println(); 98 | } 99 | file.close(); 100 | Serial.flush(); 101 | delay(100); 102 | } -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/testFiles/A long name can be 255 characters.txt: -------------------------------------------------------------------------------- 1 | This is "A long name can be 255 characters.txt" 2 | This file has a typical Long File Name. 3 | 4 | The maximum length of a Long File Name is 255 characters. 5 | -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/testFiles/LFN,NAME.TXT: -------------------------------------------------------------------------------- 1 | LFN,NAME.TXT is not 8.3 since it has a comma. -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/testFiles/MIXCASE.txt: -------------------------------------------------------------------------------- 1 | MIXCASE.txt does not have a Long File Name. 2 | 3 | Starting with NT, file names of this form, 4 | have the basename and extension character case 5 | encoded in two bits of the 8.3 directory entry. 6 | -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/testFiles/Not_8_3.txt: -------------------------------------------------------------------------------- 1 | Not_8_3.txt has a Long File Name 2 | since the basename is mixed case. -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/testFiles/OK%83.TXT: -------------------------------------------------------------------------------- 1 | OK%83.TXT is a valid 8.3 name. -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/testFiles/STD_8_3.TXT: -------------------------------------------------------------------------------- 1 | STD_8_3.TXT - a vanilla 8.3 name. -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/testFiles/With Blank.txt: -------------------------------------------------------------------------------- 1 | With Blank.txt 2 | Just another example of a Long File Name. 3 | -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/testFiles/With.Two dots.txt: -------------------------------------------------------------------------------- 1 | "With Two.dots.txt" 2 | Lots of reasons this is a Long File Name. 3 | -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/testFiles/lower.txt: -------------------------------------------------------------------------------- 1 | lower.txt does not have a Long File Name. 2 | 3 | Starting with NT, file names of this form, 4 | have the basename and extension character case 5 | encoded in two bits of the 8.3 directory entry. 6 | -------------------------------------------------------------------------------- /examples/examplesV1/LongFileName/testFiles/mixed.TXT: -------------------------------------------------------------------------------- 1 | mixed.TXT does not have a Long File Name. 2 | 3 | Starting with NT, file names of this form, 4 | have the basename and extension character case 5 | encoded in two bits of the 8.3 directory entry. -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLogger/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/examplesV1/LowLatencyLogger/.none.test.only -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLogger/UserFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "UserTypes.h" 2 | // User data functions. Modify these functions for your data items. 3 | 4 | // Start time for data 5 | static uint32_t startMicros; 6 | 7 | // Acquire a data record. 8 | void acquireData(data_t* data) { 9 | data->time = micros(); 10 | for (int i = 0; i < ADC_DIM; i++) { 11 | data->adc[i] = analogRead(i); 12 | } 13 | } 14 | 15 | // Print a data record. 16 | void printData(Print* pr, data_t* data) { 17 | if (startMicros == 0) { 18 | startMicros = data->time; 19 | } 20 | pr->print(data->time - startMicros); 21 | for (int i = 0; i < ADC_DIM; i++) { 22 | pr->write(','); 23 | pr->print(data->adc[i]); 24 | } 25 | pr->println(); 26 | } 27 | 28 | // Print data header. 29 | void printHeader(Print* pr) { 30 | startMicros = 0; 31 | pr->print(F("micros")); 32 | for (int i = 0; i < ADC_DIM; i++) { 33 | pr->print(F(",adc")); 34 | pr->print(i); 35 | } 36 | pr->println(); 37 | } 38 | 39 | // Sensor setup 40 | void userSetup() { 41 | } 42 | -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLogger/UserTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef UserTypes_h 2 | #define UserTypes_h 3 | #include "Arduino.h" 4 | // User data types. Modify for your data items. 5 | #define FILE_BASE_NAME "adc4pin" 6 | const uint8_t ADC_DIM = 4; 7 | struct data_t { 8 | uint32_t time; 9 | uint16_t adc[ADC_DIM]; 10 | }; 11 | void acquireData(data_t* data); 12 | void printData(Print* pr, data_t* data); 13 | void printHeader(Print* pr); 14 | void userSetup(); 15 | #endif // UserTypes_h 16 | -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLoggerADXL345/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/examplesV1/LowLatencyLoggerADXL345/.none.test.only -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLoggerADXL345/LowLatencyLoggerADXL345.ino: -------------------------------------------------------------------------------- 1 | // Empty file with name LowLatencyLoggerADXL345.ino to make IDE happy. -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLoggerADXL345/UserFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "UserTypes.h" 2 | // User data functions. Modify these functions for your data items. 3 | 4 | // Start time for data 5 | static uint32_t startMicros; 6 | 7 | const uint8_t ADXL345_CS = 9; 8 | 9 | const uint8_t POWER_CTL = 0x2D; //Power Control Register 10 | const uint8_t DATA_FORMAT = 0x31; 11 | const uint8_t DATAX0 = 0x32; //X-Axis Data 0 12 | const uint8_t DATAX1 = 0x33; //X-Axis Data 1 13 | const uint8_t DATAY0 = 0x34; //Y-Axis Data 0 14 | const uint8_t DATAY1 = 0x35; //Y-Axis Data 1 15 | const uint8_t DATAZ0 = 0x36; //Z-Axis Data 0 16 | const uint8_t DATAZ1 = 0x37; //Z-Axis Data 1 17 | 18 | void writeADXL345Register(const uint8_t registerAddress, const uint8_t value) { 19 | // Max SPI clock frequency is 5 MHz with CPOL = 1 and CPHA = 1. 20 | SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE3)); 21 | digitalWrite(ADXL345_CS, LOW); 22 | SPI.transfer(registerAddress); 23 | SPI.transfer(value); 24 | digitalWrite(ADXL345_CS, HIGH); 25 | SPI.endTransaction(); 26 | } 27 | 28 | void userSetup() { 29 | SPI.begin(); 30 | pinMode(ADXL345_CS, OUTPUT); 31 | digitalWrite(ADXL345_CS, HIGH); 32 | //Put the ADXL345 into +/- 4G range by writing the value 0x01 to the DATA_FORMAT register. 33 | writeADXL345Register(DATA_FORMAT, 0x01); 34 | //Put the ADXL345 into Measurement Mode by writing 0x08 to the POWER_CTL register. 35 | writeADXL345Register(POWER_CTL, 0x08); //Measurement mode 36 | } 37 | 38 | // Acquire a data record. 39 | void acquireData(data_t* data) { 40 | // Max SPI clock frequency is 5 MHz with CPOL = 1 and CPHA = 1. 41 | SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE3)); 42 | data->time = micros(); 43 | digitalWrite(ADXL345_CS, LOW); 44 | // Read multiple bytes so or 0XC0 with address. 45 | SPI.transfer(DATAX0 | 0XC0); 46 | data->accel[0] = SPI.transfer(0) | (SPI.transfer(0) << 8); 47 | data->accel[1] = SPI.transfer(0) | (SPI.transfer(0) << 8); 48 | data->accel[2] = SPI.transfer(0) | (SPI.transfer(0) << 8); 49 | digitalWrite(ADXL345_CS, HIGH); 50 | SPI.endTransaction(); 51 | } 52 | 53 | // Print a data record. 54 | void printData(Print* pr, data_t* data) { 55 | if (startMicros == 0) { 56 | startMicros = data->time; 57 | } 58 | pr->print(data->time - startMicros); 59 | for (int i = 0; i < ACCEL_DIM; i++) { 60 | pr->write(','); 61 | pr->print(data->accel[i]); 62 | } 63 | pr->println(); 64 | } 65 | 66 | // Print data header. 67 | void printHeader(Print* pr) { 68 | startMicros = 0; 69 | pr->println(F("micros,ax,ay,az")); 70 | } 71 | -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLoggerADXL345/UserTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef UserTypes_h 2 | #define UserTypes_h 3 | #include "Arduino.h" 4 | #include "SPI.h" 5 | #define USE_SHARED_SPI 1 6 | #define FILE_BASE_NAME "ADXL4G" 7 | // User data types. Modify for your data items. 8 | const uint8_t ACCEL_DIM = 3; 9 | struct data_t { 10 | uint32_t time; 11 | int16_t accel[ACCEL_DIM]; 12 | }; 13 | void acquireData(data_t* data); 14 | void printData(Print* pr, data_t* data); 15 | void printHeader(Print* pr); 16 | void userSetup(); 17 | #endif // UserTypes_h 18 | -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLoggerADXL345/readme.txt: -------------------------------------------------------------------------------- 1 | Test of shared SPI for LowLatencyLogger. -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLoggerMPU6050/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/examplesV1/LowLatencyLoggerMPU6050/.none.test.only -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLoggerMPU6050/LowLatencyLoggerMPU6050.ino: -------------------------------------------------------------------------------- 1 | // Empty file with name LowLatencyLoggerMPU6050.ino to make IDE happy. 2 | 3 | -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLoggerMPU6050/UserFunctions.cpp: -------------------------------------------------------------------------------- 1 | // User data functions. Modify these functions for your data items. 2 | #include "UserTypes.h" 3 | #include "Wire.h" 4 | #include "I2Cdev.h" 5 | #include "MPU6050.h" 6 | //------------------------------------------------------------------------------ 7 | MPU6050 mpu; 8 | static uint32_t startMicros; 9 | // Acquire a data record. 10 | void acquireData(data_t* data) { 11 | data->time = micros(); 12 | mpu.getMotion6(&data->ax, &data->ay, &data->az, 13 | &data->gx, &data->gy, &data->gz); 14 | } 15 | 16 | // setup AVR I2C 17 | void userSetup() { 18 | #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE 19 | Wire.begin(); 20 | Wire.setClock(400000); 21 | #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE 22 | Fastwire::setup(400, true); 23 | #endif 24 | mpu.initialize(); 25 | } 26 | 27 | // Print a data record. 28 | void printData(Print* pr, data_t* data) { 29 | if (startMicros == 0) { 30 | startMicros = data->time; 31 | } 32 | pr->print(data->time- startMicros); 33 | pr->write(','); 34 | pr->print(data->ax); 35 | pr->write(','); 36 | pr->print(data->ay); 37 | pr->write(','); 38 | pr->print(data->az); 39 | pr->write(','); 40 | pr->print(data->gx); 41 | pr->write(','); 42 | pr->print(data->gy); 43 | pr->write(','); 44 | pr->println(data->gz); 45 | } 46 | 47 | // Print data header. 48 | void printHeader(Print* pr) { 49 | startMicros = 0; 50 | pr->println(F("micros,ax,ay,az,gx,gy,gz")); 51 | } 52 | -------------------------------------------------------------------------------- /examples/examplesV1/LowLatencyLoggerMPU6050/UserTypes.h: -------------------------------------------------------------------------------- 1 | #ifndef UserTypes_h 2 | #define UserTypes_h 3 | #include "Arduino.h" 4 | #define FILE_BASE_NAME "mpuraw" 5 | struct data_t { 6 | unsigned long time; 7 | int16_t ax; 8 | int16_t ay; 9 | int16_t az; 10 | int16_t gx; 11 | int16_t gy; 12 | int16_t gz; 13 | }; 14 | void acquireData(data_t* data); 15 | void printData(Print* pr, data_t* data); 16 | void printHeader(Print* pr); 17 | void userSetup(); 18 | #endif // UserTypes_h 19 | -------------------------------------------------------------------------------- /examples/examplesV1/RawWrite/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/examplesV1/RawWrite/.none.test.only -------------------------------------------------------------------------------- /examples/examplesV1/ReadCsv/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_rp2040 2 | metro_rp2040 -------------------------------------------------------------------------------- /examples/examplesV1/ReadCsvArray/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_rp2040 2 | metro_rp2040 -------------------------------------------------------------------------------- /examples/examplesV1/ReadCsvStream/ReadCsvStream.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This example reads a simple CSV, comma-separated values, file. 3 | * Each line of the file has a label and three values, a long and two floats. 4 | */ 5 | #include 6 | #include "SdFat.h" 7 | #include "sdios.h" 8 | 9 | // SD chip select pin 10 | const uint8_t chipSelect = SS; 11 | 12 | // file system object 13 | SdFat sd; 14 | 15 | // create Serial stream 16 | ArduinoOutStream cout(Serial); 17 | 18 | char fileName[] = "testfile.csv"; 19 | //------------------------------------------------------------------------------ 20 | // store error strings in flash to save RAM 21 | #define error(s) sd.errorHalt(F(s)) 22 | //------------------------------------------------------------------------------ 23 | // read and print CSV test file 24 | void readFile() { 25 | long lg = 0; 26 | float f1, f2; 27 | char text[10]; 28 | char c1, c2, c3; // space for commas. 29 | 30 | // open input file 31 | ifstream sdin(fileName); 32 | 33 | // check for open error 34 | if (!sdin.is_open()) { 35 | error("open"); 36 | } 37 | 38 | // read until input fails 39 | while (1) { 40 | // Get text field. 41 | sdin.get(text, sizeof(text), ','); 42 | 43 | // Assume EOF if fail. 44 | if (sdin.fail()) { 45 | break; 46 | } 47 | 48 | // Get commas and numbers. 49 | sdin >> c1 >> lg >> c2 >> f1 >> c3 >> f2; 50 | 51 | // Skip CR/LF. 52 | sdin.skipWhite(); 53 | 54 | if (sdin.fail()) { 55 | error("bad input"); 56 | } 57 | 58 | // error in line if not commas 59 | if (c1 != ',' || c2 != ',' || c3 != ',') { 60 | error("comma"); 61 | } 62 | 63 | // print in six character wide columns 64 | cout << text << setw(6) << lg << setw(6) << f1 << setw(6) << f2 << endl; 65 | } 66 | // Error in an input line if file is not at EOF. 67 | if (!sdin.eof()) { 68 | error("readFile"); 69 | } 70 | } 71 | //------------------------------------------------------------------------------ 72 | // write test file 73 | void writeFile() { 74 | 75 | // create or open and truncate output file 76 | ofstream sdout(fileName); 77 | 78 | // write file from string stored in flash 79 | sdout << F( 80 | "Line 1,1,2.3,4.5\n" 81 | "Line 2,6,7.8,9.0\n" 82 | "Line 3,9,8.7,6.5\n" 83 | "Line 4,-4,-3.2,-1\n") << flush; 84 | 85 | // check for any errors 86 | if (!sdout) { 87 | error("writeFile"); 88 | } 89 | 90 | sdout.close(); 91 | } 92 | //------------------------------------------------------------------------------ 93 | void setup() { 94 | Serial.begin(9600); 95 | 96 | // Wait for USB Serial 97 | while (!Serial) { 98 | yield(); 99 | } 100 | cout << F("Type any character to start\n"); 101 | while (!Serial.available()) { 102 | yield(); 103 | } 104 | 105 | // Initialize at the highest speed supported by the board that is 106 | // not over 50 MHz. Try a lower speed if SPI errors occur. 107 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 108 | sd.initErrorHalt(); 109 | } 110 | 111 | // create test file 112 | writeFile(); 113 | 114 | cout << endl; 115 | 116 | // read and print test 117 | readFile(); 118 | 119 | cout << "\nDone!" << endl; 120 | } 121 | void loop() {} -------------------------------------------------------------------------------- /examples/examplesV1/ReadWrite/.skip.txt: -------------------------------------------------------------------------------- 1 | feather_rp2040 2 | metro_rp2040 -------------------------------------------------------------------------------- /examples/examplesV1/ReadWrite/ReadWrite.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card read/write 3 | 4 | This example shows how to read and write data to and from an SD card file 5 | The circuit: 6 | * SD card attached to SPI bus as follows: 7 | ** MOSI - pin 11 8 | ** MISO - pin 12 9 | ** CLK - pin 13 10 | 11 | created Nov 2010 12 | by David A. Mellis 13 | modified 9 Apr 2012 14 | by Tom Igoe 15 | 16 | This example code is in the public domain. 17 | 18 | */ 19 | 20 | #include 21 | //#include 22 | #include "SdFat.h" 23 | SdFat SD; 24 | 25 | #define SD_CS_PIN SS 26 | File myFile; 27 | 28 | void setup() { 29 | // Open serial communications and wait for port to open: 30 | Serial.begin(9600); 31 | while (!Serial) { 32 | ; // wait for serial port to connect. Needed for native USB port only 33 | } 34 | 35 | 36 | Serial.print("Initializing SD card..."); 37 | 38 | if (!SD.begin(SD_CS_PIN)) { 39 | Serial.println("initialization failed!"); 40 | return; 41 | } 42 | Serial.println("initialization done."); 43 | 44 | // open the file. note that only one file can be open at a time, 45 | // so you have to close this one before opening another. 46 | myFile = SD.open("test.txt", FILE_WRITE); 47 | 48 | // if the file opened okay, write to it: 49 | if (myFile) { 50 | Serial.print("Writing to test.txt..."); 51 | myFile.println("testing 1, 2, 3."); 52 | // close the file: 53 | myFile.close(); 54 | Serial.println("done."); 55 | } else { 56 | // if the file didn't open, print an error: 57 | Serial.println("error opening test.txt"); 58 | } 59 | 60 | // re-open the file for reading: 61 | myFile = SD.open("test.txt"); 62 | if (myFile) { 63 | Serial.println("test.txt:"); 64 | 65 | // read from the file until there's nothing else in it: 66 | while (myFile.available()) { 67 | Serial.write(myFile.read()); 68 | } 69 | // close the file: 70 | myFile.close(); 71 | } else { 72 | // if the file didn't open, print an error: 73 | Serial.println("error opening test.txt"); 74 | } 75 | } 76 | 77 | void loop() { 78 | // nothing happens after setup 79 | } 80 | 81 | 82 | -------------------------------------------------------------------------------- /examples/examplesV1/STM32Test/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/examplesV1/STM32Test/.none.test.only -------------------------------------------------------------------------------- /examples/examplesV1/VolumeFreeSpace/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/examplesV1/VolumeFreeSpace/.none.test.only -------------------------------------------------------------------------------- /examples/examplesV1/VolumeFreeSpace/VolumeFreeSpace.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This program demonstrates the freeClusterCount() call. 3 | */ 4 | #include 5 | #include "SdFat.h" 6 | #include "sdios.h" 7 | /* 8 | * SD chip select pin. Common values are: 9 | * 10 | * Arduino Ethernet shield, pin 4. 11 | * SparkFun SD shield, pin 8. 12 | * Adafruit Datalogging shield, pin 10. 13 | * Default SD chip select is the SPI SS pin. 14 | */ 15 | const uint8_t chipSelect = SS; 16 | 17 | #define TEST_FILE "Cluster.test" 18 | // file system 19 | SdFat sd; 20 | 21 | // test file 22 | SdFile file; 23 | 24 | // Serial output stream 25 | ArduinoOutStream cout(Serial); 26 | //------------------------------------------------------------------------------ 27 | void printFreeSpace() { 28 | cout << F("freeClusterCount() call time: "); 29 | uint32_t m = micros(); 30 | uint32_t volFree = sd.vol()->freeClusterCount(); 31 | cout << micros() - m << F(" micros\n"); 32 | cout << F("freeClusters: ") << volFree << setprecision(3) << endl; 33 | float fs = 0.000512*volFree*sd.vol()->blocksPerCluster(); 34 | cout << F("freeSpace: ") << fs << F(" MB (MB = 1,000,000 bytes)\n\n"); 35 | } 36 | //------------------------------------------------------------------------------ 37 | void setup() { 38 | Serial.begin(9600); 39 | // Wait for USB Serial 40 | while (!Serial) { 41 | yield(); 42 | } 43 | if (!MAINTAIN_FREE_CLUSTER_COUNT) { 44 | cout << F("Please edit SdFatConfig.h and set\n"); 45 | cout << F("MAINTAIN_FREE_CLUSTER_COUNT nonzero for\n"); 46 | cout << F("maximum freeClusterCount() performance.\n\n"); 47 | } 48 | // F stores strings in flash to save RAM 49 | cout << F("Type any character to start\n"); 50 | while (!Serial.available()) { 51 | yield(); 52 | } 53 | // Initialize at the highest speed supported by the board that is 54 | // not over 50 MHz. Try a lower speed if SPI errors occur. 55 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 56 | sd.initErrorHalt(); 57 | } 58 | // Insure no TEST_FILE. 59 | sd.remove(TEST_FILE); 60 | 61 | cout << F("\nFirst call to freeClusterCount scans the FAT.\n\n"); 62 | printFreeSpace(); 63 | 64 | cout << F("Create and write to ") << TEST_FILE << endl; 65 | if (!file.open(TEST_FILE, O_WRONLY | O_CREAT)) { 66 | sd.errorHalt(F("Create failed")); 67 | } 68 | file.print(F("Cause a cluster to be allocated")); 69 | file.close(); 70 | 71 | cout << F("\nSecond freeClusterCount call is faster if\n"); 72 | cout << F("MAINTAIN_FREE_CLUSTER_COUNT is nonzero.\n\n"); 73 | 74 | printFreeSpace(); 75 | 76 | cout << F("Remove ") << TEST_FILE << endl << endl; 77 | sd.remove(TEST_FILE); 78 | printFreeSpace(); 79 | cout << F("Done") << endl; 80 | } 81 | //------------------------------------------------------------------------------ 82 | void loop() {} -------------------------------------------------------------------------------- /examples/examplesV1/fgets/fgets.ino: -------------------------------------------------------------------------------- 1 | // Demo of fgets function to read lines from a file. 2 | #include 3 | #include "SdFat.h" 4 | #include "sdios.h" 5 | 6 | // SD chip select pin 7 | const uint8_t chipSelect = SS; 8 | 9 | SdFat sd; 10 | // print stream 11 | ArduinoOutStream cout(Serial); 12 | //------------------------------------------------------------------------------ 13 | // store error strings in flash memory 14 | #define error(s) sd.errorHalt(F(s)) 15 | //------------------------------------------------------------------------------ 16 | void demoFgets() { 17 | char line[25]; 18 | int n; 19 | // open test file 20 | SdFile rdfile("fgets.txt", O_RDONLY); 21 | 22 | // check for open error 23 | if (!rdfile.isOpen()) { 24 | error("demoFgets"); 25 | } 26 | 27 | cout << endl << F( 28 | "Lines with '>' end with a '\\n' character\n" 29 | "Lines with '#' do not end with a '\\n' character\n" 30 | "\n"); 31 | 32 | // read lines from the file 33 | while ((n = rdfile.fgets(line, sizeof(line))) > 0) { 34 | if (line[n - 1] == '\n') { 35 | cout << '>' << line; 36 | } else { 37 | cout << '#' << line << endl; 38 | } 39 | } 40 | } 41 | //------------------------------------------------------------------------------ 42 | void makeTestFile() { 43 | // create or open test file 44 | SdFile wrfile("fgets.txt", O_WRONLY | O_CREAT | O_TRUNC); 45 | 46 | // check for open error 47 | if (!wrfile.isOpen()) { 48 | error("MakeTestFile"); 49 | } 50 | 51 | // write test file 52 | wrfile.print(F( 53 | "Line with CRLF\r\n" 54 | "Line with only LF\n" 55 | "Long line that will require an extra read\n" 56 | "\n" // empty line 57 | "Line at EOF without NL" 58 | )); 59 | wrfile.close(); 60 | } 61 | //------------------------------------------------------------------------------ 62 | void setup(void) { 63 | Serial.begin(9600); 64 | 65 | // Wait for USB Serial 66 | while (!Serial) { 67 | yield(); 68 | } 69 | 70 | cout << F("Type any character to start\n"); 71 | while (!Serial.available()) { 72 | yield(); 73 | } 74 | delay(400); // catch Due reset problem 75 | 76 | // Initialize at the highest speed supported by the board that is 77 | // not over 50 MHz. Try a lower speed if SPI errors occur. 78 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 79 | sd.initErrorHalt(); 80 | } 81 | 82 | makeTestFile(); 83 | 84 | demoFgets(); 85 | 86 | cout << F("\nDone\n"); 87 | } 88 | void loop(void) {} 89 | -------------------------------------------------------------------------------- /examples/examplesV1/formatting/formatting.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Print a table with various formatting options 3 | * Format dates 4 | */ 5 | #include 6 | #include "SdFat.h" 7 | #include "sdios.h" 8 | 9 | // create Serial stream 10 | ArduinoOutStream cout(Serial); 11 | //------------------------------------------------------------------------------ 12 | // print a table to demonstrate format manipulators 13 | void example(void) { 14 | const int max = 10; 15 | const int width = 4; 16 | 17 | for (int row = 1; row <= max; row++) { 18 | for (int col = 1; col <= max; col++) { 19 | cout << setw(width) << row * col << (col == max ? '\n' : ' '); 20 | } 21 | } 22 | cout << endl; 23 | } 24 | //------------------------------------------------------------------------------ 25 | // print a date as mm/dd/yyyy with zero fill in mm and dd 26 | // shows how to set and restore the fill character 27 | void showDate(int m, int d, int y) { 28 | // convert two digit year 29 | if (y < 100) { 30 | y += 2000; 31 | } 32 | 33 | // set new fill to '0' save old fill character 34 | char old = cout.fill('0'); 35 | 36 | // print date 37 | cout << setw(2) << m << '/' << setw(2) << d << '/' << y << endl; 38 | 39 | // restore old fill character 40 | cout.fill(old); 41 | } 42 | //------------------------------------------------------------------------------ 43 | void setup(void) { 44 | Serial.begin(9600); 45 | 46 | // Wait for USB Serial 47 | while (!Serial) { 48 | yield(); 49 | } 50 | delay(2000); 51 | 52 | cout << endl << "default formatting" << endl; 53 | example(); 54 | 55 | cout << showpos << "showpos" << endl; 56 | example(); 57 | 58 | cout << hex << left << showbase << "hex left showbase" << endl; 59 | example(); 60 | 61 | cout << internal << setfill('0') << uppercase; 62 | cout << "uppercase hex internal showbase fill('0')" < 10 | #include "SdFat.h" 11 | #include "sdios.h" 12 | 13 | // SD chip select pin 14 | const uint8_t chipSelect = SS; 15 | 16 | // file system object 17 | SdFat sd; 18 | 19 | // create a serial stream 20 | ArduinoOutStream cout(Serial); 21 | //------------------------------------------------------------------------------ 22 | void makeTestFile() { 23 | ofstream sdout("getline.txt"); 24 | // use flash for text to save RAM 25 | sdout << F( 26 | "short line\n" 27 | "\n" 28 | "17 character line\n" 29 | "too long for buffer\n" 30 | "line with no nl"); 31 | 32 | sdout.close(); 33 | } 34 | //------------------------------------------------------------------------------ 35 | void testGetline() { 36 | const int line_buffer_size = 18; 37 | char buffer[line_buffer_size]; 38 | ifstream sdin("getline.txt"); 39 | int line_number = 0; 40 | 41 | while (sdin.getline(buffer, line_buffer_size, '\n') || sdin.gcount()) { 42 | int count = sdin.gcount(); 43 | if (sdin.fail()) { 44 | cout << "Partial long line"; 45 | sdin.clear(sdin.rdstate() & ~ios_base::failbit); 46 | } else if (sdin.eof()) { 47 | cout << "Partial final line"; // sdin.fail() is false 48 | } else { 49 | count--; // Don’t include newline in count 50 | cout << "Line " << ++line_number; 51 | } 52 | cout << " (" << count << " chars): " << buffer << endl; 53 | } 54 | } 55 | //------------------------------------------------------------------------------ 56 | void setup(void) { 57 | Serial.begin(9600); 58 | 59 | // Wait for USB Serial 60 | while (!Serial) { 61 | yield(); 62 | } 63 | 64 | // F stores strings in flash to save RAM 65 | cout << F("Type any character to start\n"); 66 | while (!Serial.available()) { 67 | yield(); 68 | } 69 | 70 | // Initialize at the highest speed supported by the board that is 71 | // not over 50 MHz. Try a lower speed if SPI errors occur. 72 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 73 | sd.initErrorHalt(); 74 | } 75 | 76 | // make the test file 77 | makeTestFile(); 78 | 79 | // run the example 80 | testGetline(); 81 | cout << "\nDone!\n"; 82 | } 83 | //------------------------------------------------------------------------------ 84 | void loop(void) {} 85 | -------------------------------------------------------------------------------- /examples/examplesV1/wipe/.none.test.only: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/examples/examplesV1/wipe/.none.test.only -------------------------------------------------------------------------------- /examples/examplesV1/wipe/wipe.ino: -------------------------------------------------------------------------------- 1 | // Example to wipe all data from an already formatted SD. 2 | #error wipe is not supported in SdFat V2. Use bool format(print_t* pr = nullptr). 3 | #include 4 | #include "SdFat.h" 5 | const int chipSelect = SS; 6 | 7 | SdFat sd; 8 | 9 | void setup() { 10 | int c; 11 | Serial.begin(9600); 12 | // Wait for USB Serial 13 | while (!Serial) { 14 | yield(); 15 | } 16 | Serial.println("Type 'Y' to wipe all data."); 17 | while (!Serial.available()) { 18 | yield(); 19 | } 20 | c = Serial.read(); 21 | if (c != 'Y') { 22 | sd.errorHalt("Quitting, you did not type 'Y'."); 23 | } 24 | // Initialize at the highest speed supported by the board that is 25 | // not over 50 MHz. Try a lower speed if SPI errors occur. 26 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 27 | sd.initErrorHalt(); 28 | } 29 | // Use wipe() for no dot progress indicator. 30 | if (!sd.wipe(&Serial)) { 31 | sd.errorHalt("Wipe failed."); 32 | } 33 | // Must reinitialize after wipe. 34 | // Initialize at the highest speed supported by the board that is 35 | // not over 50 MHz. Try a lower speed if SPI errors occur. 36 | if (!sd.begin(chipSelect, SD_SCK_MHZ(50))) { 37 | sd.errorHalt("Second init failed."); 38 | } 39 | Serial.println("Done"); 40 | } 41 | 42 | void loop() { 43 | } -------------------------------------------------------------------------------- /extras/USB_Host_Shield/USB_Host_Shield_2.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/extras/USB_Host_Shield/USB_Host_Shield_2.0.zip -------------------------------------------------------------------------------- /extras/USB_Host_Shield/UsbHostShieldDiff.txt: -------------------------------------------------------------------------------- 1 | master/masstorage.cpp" 2022-10-18 08:48:03.639503200 -0700 2 | @@ -796,6 +796,7 @@ 3 | buf[i] = 0x00; 4 | } 5 | WriteOk[lun] = true; 6 | + return 0; // WHG - Many USB keys don't respond. 7 | uint8_t rc = ModeSense6(lun, 0, 0x3f, 0, 192, buf); 8 | if(!rc) { 9 | WriteOk[lun] = ((buf[2] & 0x80) == 0); 10 | 11 | -------------------------------------------------------------------------------- /extras/USB_Host_Shield/readme.txt: -------------------------------------------------------------------------------- 1 | This zip file was downloaded on 10/18/2022 from 2 | 3 | https://github.com/felis/USB_Host_Shield_2.0 4 | 5 | A line was added to fix a problem with sensing read only status, 6 | see UsbHostShieldDiff.txt. -------------------------------------------------------------------------------- /extras/attic/PrintBasic.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2020 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "PrintBasic.h" 26 | #if ENABLE_ARDUINO_FEATURES == 0 27 | #include 28 | 29 | size_t PrintBasic::print(long n, uint8_t base) { 30 | if (n < 0 && base == 10) { 31 | return print('-') + printNum(-n, base); 32 | } 33 | return printNum(n, base); 34 | } 35 | size_t PrintBasic::printNum(unsigned long n, uint8_t base) { 36 | const uint8_t DIM = 8 * sizeof(long); 37 | char buf[DIM]; 38 | char *str = &buf[DIM]; 39 | 40 | if (base < 2) return 0; 41 | 42 | do { 43 | char c = n % base; 44 | n /= base; 45 | *--str = c + (c < 10 ? '0' : 'A' - 10); 46 | } while (n); 47 | return write(str, &buf[DIM] - str); 48 | } 49 | 50 | size_t PrintBasic::printDouble(double n, uint8_t prec) { 51 | // Max printable 32-bit floating point number. AVR uses 32-bit double. 52 | const double maxfp = static_cast(0XFFFFFF00UL); 53 | size_t rtn = 0; 54 | 55 | if (isnan(n)) { 56 | return write("NaN"); 57 | } 58 | if (n < 0) { 59 | n = -n; 60 | rtn += print('-'); 61 | } 62 | if (isinf(n)) { 63 | return rtn + write("Inf"); 64 | } 65 | if (n > maxfp) { 66 | return rtn + write("Ovf"); 67 | } 68 | 69 | double round = 0.5; 70 | for (uint8_t i = 0; i < prec; ++i) { 71 | round *= 0.1; 72 | } 73 | 74 | n += round; 75 | 76 | uint32_t whole = (uint32_t)n; 77 | rtn += print(whole); 78 | 79 | if (prec) { 80 | rtn += print('.'); 81 | double fraction = n - static_cast(whole); 82 | for (uint8_t i = 0; i < prec; i++) { 83 | fraction *= 10.0; 84 | uint8_t digit = fraction; 85 | rtn += print(digit); 86 | fraction -= digit; 87 | } 88 | } 89 | return rtn; 90 | } 91 | #endif // ENABLE_ARDUINO_FEATURES == 0 92 | -------------------------------------------------------------------------------- /extras/attic/SysCallBareUno.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2020 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "SysCall.h" 26 | #if 0 // defined(__AVR_ATmega328P__) && !ENABLE_ARDUINO_FEATURES 27 | #include 28 | 29 | // ISR for timer 2 Compare A interrupt 30 | volatile uint16_t timer2 = 0; 31 | ISR(TIMER2_COMPA_vect) { 32 | timer2++; 33 | } 34 | SdMillis_t SysCall::curTimeMS() { 35 | if (TIMSK2 != (1 << OCIE2A)) { 36 | // use system clock (clkI/O). 37 | ASSR &= ~(1 << AS2); 38 | // Clear Timer on Compare Match (CTC) mode 39 | TCCR2A = (1 << WGM21); 40 | // Only need 64x prescale bits in TCCR2B 41 | TCCR2B = (1 << CS22); 42 | // set TOP so timer period is 1 ms. 43 | #if F_CPU/64000 > 250 44 | #error F_CPU too large. 45 | #endif // F_CPU/64000 > 250 46 | OCR2A = F_CPU/64000UL - 1; 47 | // Enable interrupt. 48 | TIMSK2 = (1 << OCIE2A); 49 | } 50 | cli(); 51 | uint16_t rtn = timer2; 52 | sei(); 53 | return rtn; 54 | } 55 | #endif // defined(__AVR_ATmega328P__) && !ENABLE_ARDUINO_FEATURES 56 | -------------------------------------------------------------------------------- /extras/cpplint.bat: -------------------------------------------------------------------------------- 1 | bash cpplint.sh 2 | pause -------------------------------------------------------------------------------- /extras/cpplint.sh: -------------------------------------------------------------------------------- 1 | #! /usr/bin/bash 2 | ./cpplint.py ../src/*.cpp ../src/*.h ../src/*/*.cpp ../src/*/*.h ../src/SdCard/*/*.cpp ../src/SdCard/*/*.h 2>cpplint.txt -------------------------------------------------------------------------------- /extras/fmt_src.bat: -------------------------------------------------------------------------------- 1 | pause 2 | clang-format --style=Google -i *.cpp *.h 3 | rem clang-format --style=Google -i DigitalIO/*.h 4 | rem clang-format --style=Google -i DigitalIO/boards/*.h 5 | clang-format --style=Google -i common/*.cpp common/*.h 6 | clang-format --style=Google -i ExFatLib/*.cpp ExFatLib/*.h 7 | clang-format --style=Google -i FatLib/*.cpp FatLib/*.h 8 | clang-format --style=Google -i FsLib/*.cpp FsLib/*.h 9 | clang-format --style=Google -i iostream/*.cpp iostream/*.h 10 | clang-format --style=Google -i SdCard/*.cpp SdCard/*.h 11 | clang-format --style=Google -i SdCard/*/*.cpp SdCard/*/*.h 12 | clang-format --style=Google -i SpiDriver/*.cpp SpiDriver/*.h 13 | pause 14 | -------------------------------------------------------------------------------- /images/SdioSpi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/images/SdioSpi.jpg -------------------------------------------------------------------------------- /images/picowbell.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adafruit/SdFat/27e40de668fd26e8f21fa358c78219f9dfef1494/images/picowbell.jpg -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=SdFat - Adafruit Fork 2 | version=2.3.52 3 | license=MIT 4 | author=Bill Greiman 5 | maintainer=Adafruit 6 | sentence=Provides access to SD memory cards and (Q)SPI Flash. 7 | paragraph=The SdFat library supports FAT12, FAT16, FAT32, and exFAT file systems on Standard SD, SDHC, SDXC cards and (Q)SPI Flash. 8 | category=Data Storage 9 | url=https://github.com/adafruit/SdFat 10 | repository=https://github.com/adafruit/SdFat.git 11 | architectures=rp2040,nrf52,samd,esp32,* 12 | includes=SdFat_Adafruit_Fork.h 13 | -------------------------------------------------------------------------------- /src/.clang-format-ignore: -------------------------------------------------------------------------------- 1 | SdCard/Rp2040Sdio/PioSdioCard.pio.h -------------------------------------------------------------------------------- /src/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | filter=-build/include,-runtime/references,-build/header_guard 2 | filter=-whitespace/indent_namespace 3 | exclude_files=SdFatDebugConfig.h -------------------------------------------------------------------------------- /src/DigitalIO/boards/AvrDevelopersGpioPinMap.h: -------------------------------------------------------------------------------- 1 | #ifndef AvrDevelopersGpioPinMap_h 2 | #define AvrDevelopersGpioPinMap_h 3 | static const GpioPinMap_t GpioPinMap[] = { 4 | GPIO_PIN(B, 0), // D0 5 | GPIO_PIN(B, 1), // D1 6 | GPIO_PIN(B, 2), // D2 7 | GPIO_PIN(B, 3), // D3 8 | GPIO_PIN(B, 4), // D4 9 | GPIO_PIN(B, 5), // D5 10 | GPIO_PIN(B, 6), // D6 11 | GPIO_PIN(B, 7), // D7 12 | GPIO_PIN(D, 0), // D8 13 | GPIO_PIN(D, 1), // D9 14 | GPIO_PIN(D, 2), // D10 15 | GPIO_PIN(D, 3), // D11 16 | GPIO_PIN(D, 4), // D12 17 | GPIO_PIN(D, 5), // D13 18 | GPIO_PIN(D, 6), // D14 19 | GPIO_PIN(D, 7), // D15 20 | GPIO_PIN(C, 0), // D16 21 | GPIO_PIN(C, 1), // D17 22 | GPIO_PIN(C, 2), // D18 23 | GPIO_PIN(C, 3), // D19 24 | GPIO_PIN(C, 4), // D20 25 | GPIO_PIN(C, 5), // D21 26 | GPIO_PIN(C, 6), // D22 27 | GPIO_PIN(C, 7), // D23 28 | GPIO_PIN(A, 7), // D24 29 | GPIO_PIN(A, 6), // D25 30 | GPIO_PIN(A, 5), // D26 31 | GPIO_PIN(A, 4), // D27 32 | GPIO_PIN(A, 3), // D28 33 | GPIO_PIN(A, 2), // D29 34 | GPIO_PIN(A, 1), // D30 35 | GPIO_PIN(A, 0) // D31 36 | }; 37 | #endif // AvrDevelopersGpioPinMap_h -------------------------------------------------------------------------------- /src/DigitalIO/boards/BobuinoGpioPinMap.h: -------------------------------------------------------------------------------- 1 | #ifndef BobuinoGpioPinMap_h 2 | #define BobuinoGpioPinMap_h 3 | static const GpioPinMap_t GpioPinMap[] = { 4 | GPIO_PIN(B, 0), // D0 5 | GPIO_PIN(B, 1), // D1 6 | GPIO_PIN(B, 2), // D2 7 | GPIO_PIN(B, 3), // D3 8 | GPIO_PIN(B, 4), // D4 9 | GPIO_PIN(B, 5), // D5 10 | GPIO_PIN(B, 6), // D6 11 | GPIO_PIN(B, 7), // D7 12 | GPIO_PIN(D, 0), // D8 13 | GPIO_PIN(D, 1), // D9 14 | GPIO_PIN(D, 2), // D10 15 | GPIO_PIN(D, 3), // D11 16 | GPIO_PIN(D, 4), // D12 17 | GPIO_PIN(D, 5), // D13 18 | GPIO_PIN(D, 6), // D14 19 | GPIO_PIN(D, 7), // D15 20 | GPIO_PIN(C, 0), // D16 21 | GPIO_PIN(C, 1), // D17 22 | GPIO_PIN(C, 2), // D18 23 | GPIO_PIN(C, 3), // D19 24 | GPIO_PIN(C, 4), // D20 25 | GPIO_PIN(C, 5), // D21 26 | GPIO_PIN(C, 6), // D22 27 | GPIO_PIN(C, 7), // D23 28 | GPIO_PIN(A, 0), // D24 29 | GPIO_PIN(A, 1), // D25 30 | GPIO_PIN(A, 2), // D26 31 | GPIO_PIN(A, 3), // D27 32 | GPIO_PIN(A, 4), // D28 33 | GPIO_PIN(A, 5), // D29 34 | GPIO_PIN(A, 6), // D30 35 | GPIO_PIN(A, 7) // D31 36 | }; 37 | #endif // BobuinoGpioPinMap_h -------------------------------------------------------------------------------- /src/DigitalIO/boards/GpioPinMap.h: -------------------------------------------------------------------------------- 1 | /* Arduino DigitalIO Library 2 | * Copyright (C) 2013 by William Greiman 3 | * 4 | * This file is part of the Arduino DigitalIO Library 5 | * 6 | * This Library is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This Library is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with the Arduino DigitalIO Library. If not, see 18 | * . 19 | */ 20 | #ifndef GpioPinMap_h 21 | #define GpioPinMap_h 22 | #if defined(__AVR_ATmega168__)\ 23 | ||defined(__AVR_ATmega168P__)\ 24 | ||defined(__AVR_ATmega328P__) 25 | // 168 and 328 Arduinos 26 | #include "UnoGpioPinMap.h" 27 | #elif defined(__AVR_ATmega1280__)\ 28 | || defined(__AVR_ATmega2560__) 29 | // Mega ADK 30 | #include "MegaGpioPinMap.h" 31 | #elif defined(__AVR_ATmega32U4__) 32 | #ifdef CORE_TEENSY 33 | #include "Teensy2GpioPinMap.h" 34 | #else // CORE_TEENSY 35 | // Leonardo or Yun 36 | #include "LeonardoGpioPinMap.h" 37 | #endif // CORE_TEENSY 38 | #elif defined(__AVR_AT90USB646__)\ 39 | || defined(__AVR_AT90USB1286__) 40 | // Teensy++ 1.0 & 2.0 41 | #include "Teensy2ppGpioPinMap.h" 42 | #elif defined(__AVR_ATmega1284P__)\ 43 | || defined(__AVR_ATmega1284__)\ 44 | || defined(__AVR_ATmega644P__)\ 45 | || defined(__AVR_ATmega644__)\ 46 | || defined(__AVR_ATmega64__)\ 47 | || defined(__AVR_ATmega32__)\ 48 | || defined(__AVR_ATmega324__)\ 49 | || defined(__AVR_ATmega16__) 50 | #ifdef ARDUINO_1284P_AVR_DEVELOPERS 51 | #include "AvrDevelopersGpioPinMap.h" 52 | #elif defined(ARDUINO_1284P_BOBUINO) 53 | #include "BobuinoGpioPinMap.h" 54 | #elif defined(ARDUINO_1284P_SLEEPINGBEAUTY) 55 | #include "SleepingBeautyGpioPinMap.h" 56 | #elif defined(ARDUINO_1284P_STANDARD) 57 | #include "Standard1284GpioPinMap.h" 58 | #else // ARDUINO_1284P_SLEEPINGBEAUTY 59 | #error Undefined variant 1284, 644, 324 60 | #endif // ARDUINO_1284P_SLEEPINGBEAUTY 61 | #else // 1284P, 1284, 644 62 | #error Unknown board type. 63 | #endif // end all boards 64 | #endif // GpioPinMap_h 65 | -------------------------------------------------------------------------------- /src/DigitalIO/boards/LeonardoGpioPinMap.h: -------------------------------------------------------------------------------- 1 | #ifndef LeonardoGpioPinMap_h 2 | #define LeonardoGpioPinMap_h 3 | static const GpioPinMap_t GpioPinMap[] = { 4 | GPIO_PIN(D, 2), // D0 5 | GPIO_PIN(D, 3), // D1 6 | GPIO_PIN(D, 1), // D2 7 | GPIO_PIN(D, 0), // D3 8 | GPIO_PIN(D, 4), // D4 9 | GPIO_PIN(C, 6), // D5 10 | GPIO_PIN(D, 7), // D6 11 | GPIO_PIN(E, 6), // D7 12 | GPIO_PIN(B, 4), // D8 13 | GPIO_PIN(B, 5), // D9 14 | GPIO_PIN(B, 6), // D10 15 | GPIO_PIN(B, 7), // D11 16 | GPIO_PIN(D, 6), // D12 17 | GPIO_PIN(C, 7), // D13 18 | GPIO_PIN(B, 3), // D14 19 | GPIO_PIN(B, 1), // D15 20 | GPIO_PIN(B, 2), // D16 21 | GPIO_PIN(B, 0), // D17 22 | GPIO_PIN(F, 7), // D18 23 | GPIO_PIN(F, 6), // D19 24 | GPIO_PIN(F, 5), // D20 25 | GPIO_PIN(F, 4), // D21 26 | GPIO_PIN(F, 1), // D22 27 | GPIO_PIN(F, 0), // D23 28 | GPIO_PIN(D, 4), // D24 29 | GPIO_PIN(D, 7), // D25 30 | GPIO_PIN(B, 4), // D26 31 | GPIO_PIN(B, 5), // D27 32 | GPIO_PIN(B, 6), // D28 33 | GPIO_PIN(D, 6) // D29 34 | }; 35 | #endif // LeonardoGpioPinMap_h 36 | -------------------------------------------------------------------------------- /src/DigitalIO/boards/MegaGpioPinMap.h: -------------------------------------------------------------------------------- 1 | #ifndef MegaGpioPinMap_h 2 | #define MegaGpioPinMap_h 3 | static const GpioPinMap_t GpioPinMap[] = { 4 | GPIO_PIN(E, 0), // D0 5 | GPIO_PIN(E, 1), // D1 6 | GPIO_PIN(E, 4), // D2 7 | GPIO_PIN(E, 5), // D3 8 | GPIO_PIN(G, 5), // D4 9 | GPIO_PIN(E, 3), // D5 10 | GPIO_PIN(H, 3), // D6 11 | GPIO_PIN(H, 4), // D7 12 | GPIO_PIN(H, 5), // D8 13 | GPIO_PIN(H, 6), // D9 14 | GPIO_PIN(B, 4), // D10 15 | GPIO_PIN(B, 5), // D11 16 | GPIO_PIN(B, 6), // D12 17 | GPIO_PIN(B, 7), // D13 18 | GPIO_PIN(J, 1), // D14 19 | GPIO_PIN(J, 0), // D15 20 | GPIO_PIN(H, 1), // D16 21 | GPIO_PIN(H, 0), // D17 22 | GPIO_PIN(D, 3), // D18 23 | GPIO_PIN(D, 2), // D19 24 | GPIO_PIN(D, 1), // D20 25 | GPIO_PIN(D, 0), // D21 26 | GPIO_PIN(A, 0), // D22 27 | GPIO_PIN(A, 1), // D23 28 | GPIO_PIN(A, 2), // D24 29 | GPIO_PIN(A, 3), // D25 30 | GPIO_PIN(A, 4), // D26 31 | GPIO_PIN(A, 5), // D27 32 | GPIO_PIN(A, 6), // D28 33 | GPIO_PIN(A, 7), // D29 34 | GPIO_PIN(C, 7), // D30 35 | GPIO_PIN(C, 6), // D31 36 | GPIO_PIN(C, 5), // D32 37 | GPIO_PIN(C, 4), // D33 38 | GPIO_PIN(C, 3), // D34 39 | GPIO_PIN(C, 2), // D35 40 | GPIO_PIN(C, 1), // D36 41 | GPIO_PIN(C, 0), // D37 42 | GPIO_PIN(D, 7), // D38 43 | GPIO_PIN(G, 2), // D39 44 | GPIO_PIN(G, 1), // D40 45 | GPIO_PIN(G, 0), // D41 46 | GPIO_PIN(L, 7), // D42 47 | GPIO_PIN(L, 6), // D43 48 | GPIO_PIN(L, 5), // D44 49 | GPIO_PIN(L, 4), // D45 50 | GPIO_PIN(L, 3), // D46 51 | GPIO_PIN(L, 2), // D47 52 | GPIO_PIN(L, 1), // D48 53 | GPIO_PIN(L, 0), // D49 54 | GPIO_PIN(B, 3), // D50 55 | GPIO_PIN(B, 2), // D51 56 | GPIO_PIN(B, 1), // D52 57 | GPIO_PIN(B, 0), // D53 58 | GPIO_PIN(F, 0), // D54 59 | GPIO_PIN(F, 1), // D55 60 | GPIO_PIN(F, 2), // D56 61 | GPIO_PIN(F, 3), // D57 62 | GPIO_PIN(F, 4), // D58 63 | GPIO_PIN(F, 5), // D59 64 | GPIO_PIN(F, 6), // D60 65 | GPIO_PIN(F, 7), // D61 66 | GPIO_PIN(K, 0), // D62 67 | GPIO_PIN(K, 1), // D63 68 | GPIO_PIN(K, 2), // D64 69 | GPIO_PIN(K, 3), // D65 70 | GPIO_PIN(K, 4), // D66 71 | GPIO_PIN(K, 5), // D67 72 | GPIO_PIN(K, 6), // D68 73 | GPIO_PIN(K, 7) // D69 74 | }; 75 | #endif // MegaGpioPinMap_h 76 | -------------------------------------------------------------------------------- /src/DigitalIO/boards/SleepingBeautyGpioPinMap.h: -------------------------------------------------------------------------------- 1 | #ifndef SleepingBeautyGpioPinMap_h 2 | #define SleepingBeautyGpioPinMap_h 3 | static const GpioPinMap_t GpioPinMap[] = { 4 | GPIO_PIN(D, 0), // D0 5 | GPIO_PIN(D, 1), // D1 6 | GPIO_PIN(D, 2), // D2 7 | GPIO_PIN(D, 3), // D3 8 | GPIO_PIN(B, 0), // D4 9 | GPIO_PIN(B, 1), // D5 10 | GPIO_PIN(B, 2), // D6 11 | GPIO_PIN(B, 3), // D7 12 | GPIO_PIN(D, 6), // D8 13 | GPIO_PIN(D, 5), // D9 14 | GPIO_PIN(B, 4), // D10 15 | GPIO_PIN(B, 5), // D11 16 | GPIO_PIN(B, 6), // D12 17 | GPIO_PIN(B, 7), // D13 18 | GPIO_PIN(C, 7), // D14 19 | GPIO_PIN(C, 6), // D15 20 | GPIO_PIN(A, 5), // D16 21 | GPIO_PIN(A, 4), // D17 22 | GPIO_PIN(A, 3), // D18 23 | GPIO_PIN(A, 2), // D19 24 | GPIO_PIN(A, 1), // D20 25 | GPIO_PIN(A, 0), // D21 26 | GPIO_PIN(D, 4), // D22 27 | GPIO_PIN(D, 7), // D23 28 | GPIO_PIN(C, 2), // D24 29 | GPIO_PIN(C, 3), // D25 30 | GPIO_PIN(C, 4), // D26 31 | GPIO_PIN(C, 5), // D27 32 | GPIO_PIN(C, 1), // D28 33 | GPIO_PIN(C, 0), // D29 34 | GPIO_PIN(A, 6), // D30 35 | GPIO_PIN(A, 7) // D31 36 | }; 37 | #endif // SleepingBeautyGpioPinMap_h -------------------------------------------------------------------------------- /src/DigitalIO/boards/Standard1284GpioPinMap.h: -------------------------------------------------------------------------------- 1 | #ifndef Standard1284GpioPinMap_h 2 | #define Standard1284GpioPinMap_h 3 | static const GpioPinMap_t GpioPinMap[] = { 4 | GPIO_PIN(B, 0), // D0 5 | GPIO_PIN(B, 1), // D1 6 | GPIO_PIN(B, 2), // D2 7 | GPIO_PIN(B, 3), // D3 8 | GPIO_PIN(B, 4), // D4 9 | GPIO_PIN(B, 5), // D5 10 | GPIO_PIN(B, 6), // D6 11 | GPIO_PIN(B, 7), // D7 12 | GPIO_PIN(D, 0), // D8 13 | GPIO_PIN(D, 1), // D9 14 | GPIO_PIN(D, 2), // D10 15 | GPIO_PIN(D, 3), // D11 16 | GPIO_PIN(D, 4), // D12 17 | GPIO_PIN(D, 5), // D13 18 | GPIO_PIN(D, 6), // D14 19 | GPIO_PIN(D, 7), // D15 20 | GPIO_PIN(C, 0), // D16 21 | GPIO_PIN(C, 1), // D17 22 | GPIO_PIN(C, 2), // D18 23 | GPIO_PIN(C, 3), // D19 24 | GPIO_PIN(C, 4), // D20 25 | GPIO_PIN(C, 5), // D21 26 | GPIO_PIN(C, 6), // D22 27 | GPIO_PIN(C, 7), // D23 28 | GPIO_PIN(A, 0), // D24 29 | GPIO_PIN(A, 1), // D25 30 | GPIO_PIN(A, 2), // D26 31 | GPIO_PIN(A, 3), // D27 32 | GPIO_PIN(A, 4), // D28 33 | GPIO_PIN(A, 5), // D29 34 | GPIO_PIN(A, 6), // D30 35 | GPIO_PIN(A, 7) // D31 36 | }; 37 | #endif // Standard1284GpioPinMap_h -------------------------------------------------------------------------------- /src/DigitalIO/boards/Teensy2GpioPinMap.h: -------------------------------------------------------------------------------- 1 | #ifndef Teensy2GpioPinMap_h 2 | #define Teensy2GpioPinMap_h 3 | static const GpioPinMap_t GpioPinMap[] = { 4 | GPIO_PIN(B, 0), // D0 5 | GPIO_PIN(B, 1), // D1 6 | GPIO_PIN(B, 2), // D2 7 | GPIO_PIN(B, 3), // D3 8 | GPIO_PIN(B, 7), // D4 9 | GPIO_PIN(D, 0), // D5 10 | GPIO_PIN(D, 1), // D6 11 | GPIO_PIN(D, 2), // D7 12 | GPIO_PIN(D, 3), // D8 13 | GPIO_PIN(C, 6), // D9 14 | GPIO_PIN(C, 7), // D10 15 | GPIO_PIN(D, 6), // D11 16 | GPIO_PIN(D, 7), // D12 17 | GPIO_PIN(B, 4), // D13 18 | GPIO_PIN(B, 5), // D14 19 | GPIO_PIN(B, 6), // D15 20 | GPIO_PIN(F, 7), // D16 21 | GPIO_PIN(F, 6), // D17 22 | GPIO_PIN(F, 5), // D18 23 | GPIO_PIN(F, 4), // D19 24 | GPIO_PIN(F, 1), // D20 25 | GPIO_PIN(F, 0), // D21 26 | GPIO_PIN(D, 4), // D22 27 | GPIO_PIN(D, 5), // D23 28 | GPIO_PIN(E, 6), // D24 29 | }; 30 | #endif // Teensy2GpioPinMap_h 31 | -------------------------------------------------------------------------------- /src/DigitalIO/boards/Teensy2ppGpioPinMap.h: -------------------------------------------------------------------------------- 1 | #ifndef Teensypp2GpioPinMap_h 2 | #define Teensypp2GpioPinMap_h 3 | static const GpioPinMap_t GpioPinMap[] = { 4 | GPIO_PIN(D, 0), // D0 5 | GPIO_PIN(D, 1), // D1 6 | GPIO_PIN(D, 2), // D2 7 | GPIO_PIN(D, 3), // D3 8 | GPIO_PIN(D, 4), // D4 9 | GPIO_PIN(D, 5), // D5 10 | GPIO_PIN(D, 6), // D6 11 | GPIO_PIN(D, 7), // D7 12 | GPIO_PIN(E, 0), // D8 13 | GPIO_PIN(E, 1), // D9 14 | GPIO_PIN(C, 0), // D10 15 | GPIO_PIN(C, 1), // D11 16 | GPIO_PIN(C, 2), // D12 17 | GPIO_PIN(C, 3), // D13 18 | GPIO_PIN(C, 4), // D14 19 | GPIO_PIN(C, 5), // D15 20 | GPIO_PIN(C, 6), // D16 21 | GPIO_PIN(C, 7), // D17 22 | GPIO_PIN(E, 6), // D18 23 | GPIO_PIN(E, 7), // D19 24 | GPIO_PIN(B, 0), // D20 25 | GPIO_PIN(B, 1), // D21 26 | GPIO_PIN(B, 2), // D22 27 | GPIO_PIN(B, 3), // D23 28 | GPIO_PIN(B, 4), // D24 29 | GPIO_PIN(B, 5), // D25 30 | GPIO_PIN(B, 6), // D26 31 | GPIO_PIN(B, 7), // D27 32 | GPIO_PIN(A, 0), // D28 33 | GPIO_PIN(A, 1), // D29 34 | GPIO_PIN(A, 2), // D30 35 | GPIO_PIN(A, 3), // D31 36 | GPIO_PIN(A, 4), // D32 37 | GPIO_PIN(A, 5), // D33 38 | GPIO_PIN(A, 6), // D34 39 | GPIO_PIN(A, 7), // D35 40 | GPIO_PIN(E, 4), // D36 41 | GPIO_PIN(E, 5), // D37 42 | GPIO_PIN(F, 0), // D38 43 | GPIO_PIN(F, 1), // D39 44 | GPIO_PIN(F, 2), // D40 45 | GPIO_PIN(F, 3), // D41 46 | GPIO_PIN(F, 4), // D42 47 | GPIO_PIN(F, 5), // D43 48 | GPIO_PIN(F, 6), // D44 49 | GPIO_PIN(F, 7), // D45 50 | }; 51 | #endif // Teensypp2GpioPinMap_h 52 | -------------------------------------------------------------------------------- /src/DigitalIO/boards/UnoGpioPinMap.h: -------------------------------------------------------------------------------- 1 | #ifndef UnoGpioPinMap_h 2 | #define UnoGpioPinMap_h 3 | static const GpioPinMap_t GpioPinMap[] = { 4 | GPIO_PIN(D, 0), // D0 5 | GPIO_PIN(D, 1), // D1 6 | GPIO_PIN(D, 2), // D2 7 | GPIO_PIN(D, 3), // D3 8 | GPIO_PIN(D, 4), // D4 9 | GPIO_PIN(D, 5), // D5 10 | GPIO_PIN(D, 6), // D6 11 | GPIO_PIN(D, 7), // D7 12 | GPIO_PIN(B, 0), // D8 13 | GPIO_PIN(B, 1), // D9 14 | GPIO_PIN(B, 2), // D10 15 | GPIO_PIN(B, 3), // D11 16 | GPIO_PIN(B, 4), // D12 17 | GPIO_PIN(B, 5), // D13 18 | GPIO_PIN(C, 0), // D14 19 | GPIO_PIN(C, 1), // D15 20 | GPIO_PIN(C, 2), // D16 21 | GPIO_PIN(C, 3), // D17 22 | GPIO_PIN(C, 4), // D18 23 | GPIO_PIN(C, 5) // D19 24 | }; 25 | #endif // UnoGpioPinMap_h -------------------------------------------------------------------------------- /src/DigitalIO/readme.txt: -------------------------------------------------------------------------------- 1 | Selected files from the DigitalIO library. 2 | 3 | https://github.com/greiman/DigitalIO -------------------------------------------------------------------------------- /src/ExFatLib/ExFatFormatter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #pragma once 26 | #include "../common/FsBlockDevice.h" 27 | /** 28 | * \class ExFatFormatter 29 | * \brief Format an exFAT volume. 30 | */ 31 | class ExFatFormatter { 32 | public: 33 | /** Constructor. */ 34 | ExFatFormatter() = default; // cppcheck-suppress uninitMemberVar 35 | /** 36 | * Format an exFAT volume. 37 | * 38 | * \param[in] dev Block device for volume. 39 | * \param[in] secBuf buffer for writing to volume. 40 | * \param[in] pr Print device for progress output. 41 | * 42 | * \return true for success or false for failure. 43 | */ 44 | bool format(FsBlockDevice* dev, uint8_t* secBuf, print_t* pr = nullptr); 45 | 46 | private: 47 | bool syncUpcase(); 48 | bool writeUpcase(uint32_t sector); 49 | bool writeUpcaseByte(uint8_t b); 50 | bool writeUpcaseUnicode(uint16_t unicode); 51 | uint32_t m_upcaseSector; 52 | uint32_t m_upcaseChecksum; 53 | uint32_t m_upcaseSize; 54 | FsBlockDevice* m_dev; 55 | uint8_t* m_secBuf; 56 | }; 57 | -------------------------------------------------------------------------------- /src/ExFatLib/ExFatLib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef ExFatLib_h 26 | #define ExFatLib_h 27 | #include "ExFatFormatter.h" 28 | #include "ExFatVolume.h" 29 | #endif // ExFatLib_h 30 | -------------------------------------------------------------------------------- /src/ExFatLib/ExFatVolume.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #define DBG_FILE "ExFatVolume.cpp" 26 | #include "../common/DebugMacros.h" 27 | #include "ExFatLib.h" 28 | ExFatVolume* ExFatVolume::m_cwv = nullptr; 29 | //----------------------------------------------------------------------------- 30 | bool ExFatVolume::chdir(const char* path) { 31 | ExFatFile dir; 32 | if (!dir.open(vwd(), path, O_RDONLY)) { 33 | DBG_FAIL_MACRO; 34 | goto fail; 35 | } 36 | if (!dir.isDir()) { 37 | DBG_FAIL_MACRO; 38 | goto fail; 39 | } 40 | m_vwd.copy(&dir); 41 | return true; 42 | 43 | fail: 44 | return false; 45 | } 46 | -------------------------------------------------------------------------------- /src/FatLib/FatFormatter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #pragma once 26 | #include "../common/FsBlockDevice.h" 27 | #include "../common/SysCall.h" 28 | /** 29 | * \class FatFormatter 30 | * \brief Format a FAT volume. 31 | */ 32 | class FatFormatter { 33 | public: 34 | /** Constructor. */ 35 | FatFormatter() = default; // cppcheck-suppress uninitMemberVar 36 | /** 37 | * Format a FAT volume. 38 | * 39 | * \param[in] dev Block device for volume. 40 | * \param[in] secBuffer buffer for writing to volume. 41 | * \param[in] pr Print device for progress output. 42 | * 43 | * \return true for success or false for failure. 44 | */ 45 | bool format(FsBlockDevice* dev, uint8_t* secBuffer, print_t* pr = nullptr); 46 | 47 | private: 48 | bool initFatDir(uint8_t fatType, uint32_t sectorCount); 49 | void initPbs(); 50 | bool makeFat16(); 51 | bool makeFat32(); 52 | bool writeMbr(); 53 | uint32_t m_capacityMB; 54 | uint32_t m_dataStart; 55 | uint32_t m_fatSize; 56 | uint32_t m_fatStart; 57 | uint32_t m_relativeSectors; 58 | uint32_t m_sectorCount; 59 | uint32_t m_totalSectors; 60 | FsBlockDevice* m_dev; 61 | print_t* m_pr; 62 | uint8_t* m_secBuf; 63 | uint16_t m_reservedSectorCount; 64 | uint8_t m_partType; 65 | uint8_t m_sectorsPerCluster; 66 | }; 67 | -------------------------------------------------------------------------------- /src/FatLib/FatLib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #pragma once 26 | #include "FatFormatter.h" 27 | #include "FatVolume.h" 28 | -------------------------------------------------------------------------------- /src/FatLib/FatVolume.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #define DBG_FILE "FatVolume.cpp" 26 | #include "../common/DebugMacros.h" 27 | #include "FatLib.h" 28 | FatVolume* FatVolume::m_cwv = nullptr; 29 | //------------------------------------------------------------------------------ 30 | bool FatVolume::chdir(const char* path) { 31 | FatFile dir; 32 | if (!dir.open(vwd(), path, O_RDONLY)) { 33 | DBG_FAIL_MACRO; 34 | goto fail; 35 | } 36 | if (!dir.isDir()) { 37 | DBG_FAIL_MACRO; 38 | goto fail; 39 | } 40 | m_vwd.copy(&dir); 41 | return true; 42 | 43 | fail: 44 | return false; 45 | } 46 | -------------------------------------------------------------------------------- /src/FreeStack.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #define FREE_STACK_CPP 26 | #include "FreeStack.h" 27 | #if defined(HAS_UNUSED_STACK) && HAS_UNUSED_STACK 28 | //------------------------------------------------------------------------------ 29 | inline char* stackBegin() { 30 | #if defined(__AVR__) 31 | return __brkval ? __brkval : &__bss_end; 32 | #elif defined(__IMXRT1062__) 33 | return reinterpret_cast(&_ebss); 34 | #elif defined(__arm__) 35 | return reinterpret_cast(sbrk(0)); 36 | #else // defined(__AVR__) 37 | #error "undefined stackBegin" 38 | #endif // defined(__AVR__) 39 | } 40 | //------------------------------------------------------------------------------ 41 | inline char* stackPointer() { 42 | #if defined(__AVR__) 43 | return reinterpret_cast(SP); 44 | #elif defined(__arm__) 45 | register uint32_t sp asm("sp"); 46 | return reinterpret_cast(sp); 47 | #else // defined(__AVR__) 48 | #error "undefined stackPointer" 49 | #endif // defined(__AVR__) 50 | } 51 | //------------------------------------------------------------------------------ 52 | /** Stack fill pattern. */ 53 | const char FILL = 0x55; 54 | void FillStack() { 55 | char* p = stackBegin(); 56 | const char* top = stackPointer(); 57 | while (p < top) { 58 | *p++ = FILL; 59 | } 60 | } 61 | //------------------------------------------------------------------------------ 62 | // May fail if malloc or new is used. 63 | int UnusedStack() { 64 | char* h = stackBegin(); 65 | const char* top = stackPointer(); 66 | int n; 67 | 68 | for (n = 0; (h + n) < top; n++) { 69 | if (h[n] != FILL) { 70 | if (n >= 16) { 71 | break; 72 | } 73 | // Attempt to skip used heap. 74 | h += n; 75 | n = 0; 76 | } 77 | } 78 | return n; 79 | } 80 | #endif // defined(HAS_UNUSED_STACK) && HAS_UNUSED_STACK 81 | -------------------------------------------------------------------------------- /src/FreeStack.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #pragma once 26 | /** 27 | * \file 28 | * \brief FreeStack() function. 29 | */ 30 | #include 31 | #if defined(__AVR__) || defined(DOXYGEN) 32 | #include 33 | /** Indicate FillStack() and UnusedStack() are available. */ 34 | #define HAS_UNUSED_STACK 1 35 | /** boundary between stack and heap. */ 36 | extern char* __brkval; 37 | /** End of bss section.*/ 38 | extern char __bss_end; 39 | /** Amount of free stack space. 40 | * \return The number of free bytes. 41 | */ 42 | inline int FreeStack() { 43 | const char* sp = reinterpret_cast(SP); 44 | return __brkval ? sp - __brkval : sp - &__bss_end; 45 | } 46 | #elif defined(ARDUINO_ARCH_APOLLO3) 47 | #define HAS_UNUSED_STACK 0 48 | #elif defined(PLATFORM_ID) // Particle board 49 | #include "Arduino.h" 50 | inline int FreeStack() { return System.freeMemory(); } 51 | #elif defined(__IMXRT1062__) 52 | #define HAS_UNUSED_STACK 1 53 | extern uint8_t _ebss; 54 | inline int FreeStack() { 55 | register uint32_t sp asm("sp"); 56 | return reinterpret_cast(sp) - reinterpret_cast(&_ebss); 57 | } 58 | #elif defined(__arm__) 59 | #define HAS_UNUSED_STACK 1 60 | extern "C" char* sbrk(int incr); 61 | inline int FreeStack() { 62 | register uint32_t sp asm("sp"); 63 | return reinterpret_cast(sp) - reinterpret_cast(sbrk(0)); 64 | } 65 | #else // defined(__AVR__) || defined(DOXYGEN) 66 | #ifndef FREE_STACK_CPP 67 | #warning FreeStack is not defined for this system. 68 | #endif // FREE_STACK_CPP 69 | inline int FreeStack() { return 0; } 70 | #endif // defined(__AVR__) || defined(DOXYGEN) 71 | #if defined(HAS_UNUSED_STACK) || defined(DOXYGEN) 72 | /** Fill stack with 0x55 pattern */ 73 | void FillStack(); 74 | /** 75 | * Determine the amount of unused stack. 76 | * 77 | * FillStack() must be called to fill the stack with a 0x55 pattern. 78 | * 79 | * UnusedStack() may fail if malloc() or new is use. 80 | * 81 | * \return number of bytes with 0x55 pattern. 82 | */ 83 | int UnusedStack(); 84 | #else // HAS_UNUSED_STACK 85 | #define HAS_UNUSED_STACK 0 86 | inline void FillStack() {} 87 | inline int UnusedStack() { return 0; } 88 | #endif // defined(HAS_UNUSED_STACK) 89 | -------------------------------------------------------------------------------- /src/FsLib/FsFormatter.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef FsFormatter_h 26 | #define FsFormatter_h 27 | #include "ExFatLib/ExFatLib.h" 28 | #include "FatLib/FatLib.h" 29 | /** 30 | * \class FsFormatter 31 | * \brief Format a exFAT/FAT volume. 32 | */ 33 | class FsFormatter { 34 | public: 35 | /** Constructor. */ 36 | FsFormatter() = default; 37 | /** 38 | * Format a FAT volume. 39 | * 40 | * \param[in] dev Block device for volume. 41 | * \param[in] secBuffer buffer for writing to volume. 42 | * \param[in] pr Print device for progress output. 43 | * 44 | * \return true for success or false for failure. 45 | */ 46 | bool format(FsBlockDevice* dev, uint8_t* secBuffer, print_t* pr = nullptr) { 47 | uint32_t sectorCount = dev->sectorCount(); 48 | if (sectorCount == 0) { 49 | return false; 50 | } 51 | return sectorCount <= 67108864 ? m_fFmt.format(dev, secBuffer, pr) 52 | : m_xFmt.format(dev, secBuffer, pr); 53 | } 54 | 55 | private: 56 | FatFormatter m_fFmt; 57 | ExFatFormatter m_xFmt; 58 | }; 59 | #endif // FsFormatter_h 60 | -------------------------------------------------------------------------------- /src/FsLib/FsLib.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef FsLib_h 26 | #define FsLib_h 27 | /** 28 | * \file 29 | * \brief FsLib include file. 30 | */ 31 | #include "FsFile.h" 32 | #include "FsFormatter.h" 33 | #include "FsVolume.h" 34 | #endif // FsLib_h 35 | -------------------------------------------------------------------------------- /src/FsLib/FsNew.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "FsNew.h" 26 | void* operator new(size_t size, newalign_t* ptr) { 27 | (void)size; 28 | return ptr; 29 | } 30 | -------------------------------------------------------------------------------- /src/FsLib/FsNew.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #pragma once 26 | #include 27 | #include 28 | 29 | /** 32-bit alignment */ 30 | typedef uint32_t newalign_t; 31 | 32 | /** Size required for exFAT or FAT class. */ 33 | #define FS_SIZE(etype, ftype) \ 34 | (sizeof(ftype) < sizeof(etype) ? sizeof(etype) : sizeof(ftype)) 35 | 36 | /** Dimension of aligned area. */ 37 | #define NEW_ALIGN_DIM(n) \ 38 | ((static_cast(n) + sizeof(newalign_t) - 1U) / sizeof(newalign_t)) 39 | 40 | /** Dimension of aligned area for etype or ftype class. */ 41 | #define FS_ALIGN_DIM(etype, ftype) NEW_ALIGN_DIM(FS_SIZE(etype, ftype)) 42 | 43 | /** Custom new placement operator */ 44 | void* operator new(size_t size, newalign_t* ptr); 45 | -------------------------------------------------------------------------------- /src/FsLib/FsVolume.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "FsLib.h" 26 | FsVolume* FsVolume::m_cwv = nullptr; 27 | //------------------------------------------------------------------------------ 28 | bool FsVolume::begin(FsBlockDevice* blockDev, bool setCwv, uint8_t part, 29 | uint32_t volStart) { 30 | m_fVol = nullptr; 31 | m_xVol = new (m_volMem) ExFatVolume; 32 | if (m_xVol && m_xVol->begin(blockDev, false, part, volStart)) { 33 | goto done; 34 | } 35 | m_xVol = nullptr; 36 | m_fVol = new (m_volMem) FatVolume; 37 | if (m_fVol && m_fVol->begin(blockDev, false, part, volStart)) { 38 | goto done; 39 | } 40 | m_fVol = nullptr; 41 | return false; 42 | 43 | done: 44 | if (setCwv || !m_cwv) { 45 | m_cwv = this; 46 | } 47 | return true; 48 | } 49 | //------------------------------------------------------------------------------ 50 | bool FsVolume::ls(print_t* pr, const char* path, uint8_t flags) { 51 | FsBaseFile dir; 52 | return dir.open(this, path, O_RDONLY) && dir.ls(pr, flags); 53 | } 54 | //------------------------------------------------------------------------------ 55 | FsFile FsVolume::open(const char* path, oflag_t oflag) { 56 | FsFile tmpFile; 57 | tmpFile.open(this, path, oflag); 58 | return tmpFile; 59 | } 60 | #if ENABLE_ARDUINO_STRING 61 | //------------------------------------------------------------------------------ 62 | FsFile FsVolume::open(const String& path, oflag_t oflag) { 63 | return open(path.c_str(), oflag); 64 | } 65 | #endif // ENABLE_ARDUINO_STRING 66 | -------------------------------------------------------------------------------- /src/MinimumSerial.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "MinimumSerial.h" 26 | #if defined(UDR0) || defined(DOXYGEN) 27 | const uint16_t MIN_2X_BAUD = F_CPU / (4 * (2 * 0XFFF + 1)) + 1; 28 | //------------------------------------------------------------------------------ 29 | int MinimumSerial::available() { return UCSR0A & (1 << RXC0) ? 1 : 0; } 30 | //------------------------------------------------------------------------------ 31 | void MinimumSerial::begin(uint32_t baud) { 32 | uint16_t baud_setting; 33 | // don't worry, the compiler will squeeze out F_CPU != 16000000UL 34 | if ((F_CPU != 16000000UL || baud != 57600) && baud > MIN_2X_BAUD) { 35 | // Double the USART Transmission Speed 36 | UCSR0A = 1 << U2X0; 37 | baud_setting = (F_CPU / 4 / baud - 1) / 2; 38 | } else { 39 | // hardcoded exception for compatibility with the bootloader shipped 40 | // with the Duemilanove and previous boards and the firmware on the 8U2 41 | // on the Uno and Mega 2560. 42 | UCSR0A = 0; 43 | baud_setting = (F_CPU / 8 / baud - 1) / 2; 44 | } 45 | // assign the baud_setting 46 | UBRR0H = baud_setting >> 8; 47 | UBRR0L = baud_setting; 48 | // enable transmit and receive 49 | UCSR0B |= (1 << TXEN0) | (1 << RXEN0); 50 | } 51 | //------------------------------------------------------------------------------ 52 | void MinimumSerial::flush() { 53 | while (((1 << UDRIE0) & UCSR0B) || !(UCSR0A & (1 << UDRE0))) { 54 | } 55 | } 56 | //------------------------------------------------------------------------------ 57 | int MinimumSerial::read() { 58 | if (UCSR0A & (1 << RXC0)) { 59 | return UDR0; 60 | } 61 | return -1; 62 | } 63 | //------------------------------------------------------------------------------ 64 | size_t MinimumSerial::write(uint8_t b) { 65 | while (((1 << UDRIE0) & UCSR0B) || !(UCSR0A & (1 << UDRE0))) { 66 | } 67 | UDR0 = b; 68 | return 1; 69 | } 70 | #endif // defined(UDR0) || defined(DOXYGEN) 71 | -------------------------------------------------------------------------------- /src/MinimumSerial.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | /** 26 | * \file 27 | * \brief Minimal AVR Serial driver. 28 | */ 29 | #ifndef MinimumSerial_h 30 | #define MinimumSerial_h 31 | #include "common/SysCall.h" 32 | //============================================================================== 33 | /** 34 | * \class MinimumSerial 35 | * \brief mini serial class for the %SdFat library. 36 | */ 37 | class MinimumSerial : public print_t { 38 | public: 39 | /** \return true for hardware serial */ 40 | operator bool() { return true; } 41 | /** 42 | * \return one if data is available. 43 | */ 44 | int available(); 45 | /** 46 | * Set baud rate for serial port zero and enable in non interrupt mode. 47 | * Do not call this function if you use another serial library. 48 | * \param[in] baud rate 49 | */ 50 | void begin(uint32_t baud); 51 | /** Wait for write done. */ 52 | void flush(); 53 | /** 54 | * Unbuffered read 55 | * \return -1 if no character is available or an available character. 56 | */ 57 | int read(); 58 | /** 59 | * Unbuffered write 60 | * 61 | * \param[in] b byte to write. 62 | * \return 1 63 | */ 64 | size_t write(uint8_t b); 65 | using print_t::write; 66 | }; 67 | #endif // MinimumSerial_h 68 | -------------------------------------------------------------------------------- /src/SdCard/Rp2040Sdio/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | exclude_files=PioSdioCard.pio.h 2 | -------------------------------------------------------------------------------- /src/SdCard/Rp2040Sdio/PioDbgInfo.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #pragma once 26 | #include 27 | 28 | #include "DbgLog.h" 29 | //------------------------------------------------------------------------------ 30 | static inline void gpioStatus(uint gpio) { 31 | logmsgln("gpio", gpio, " drive: ", gpio_get_drive_strength(gpio)); 32 | // logmsgln("gpio", gpio, 33 | // " drive: ", static_cast(gpio_get_drive_strength(gpio))); 34 | logmsgln("gpio", gpio, " slew: ", gpio_get_slew_rate(gpio)); 35 | logmsgln("gpio", gpio, " hyst: ", gpio_is_input_hysteresis_enabled(gpio)); 36 | logmsgln("gpio", gpio, " pull: ", gpio_is_pulled_up(gpio)); 37 | } 38 | //------------------------------------------------------------------------------ 39 | static inline void pioRegs(PIO pio) { 40 | logmsgln("ctrl: 0b", Bin(pio->ctrl)); 41 | logmsgln("fstat: 0b", Bin(pio->fstat)); 42 | logmsgln("fdebug: 0b", Bin(pio->fdebug)); 43 | logmsgln("flevel: 0b", Bin(pio->flevel)); 44 | logmsgln("padout: 0b", Bin(pio->dbg_padout)); 45 | logmsgln("padoe: 0b", Bin(pio->dbg_padoe)); 46 | logmsgln("cfginfo: 0x", Hex(pio->dbg_cfginfo)); 47 | logmsgln("sync_bypass: 0b", Bin(pio->input_sync_bypass)); 48 | } 49 | //------------------------------------------------------------------------------ 50 | static inline void pioSmRegs(PIO pio, uint sm) { 51 | logmsgln("sm", sm, " clkdiv: 0x", Hex(pio->sm[sm].clkdiv)); 52 | logmsgln("sm", sm, " execctrl: 0x", Hex(pio->sm[sm].execctrl)); 53 | logmsgln("sm", sm, " shiftctrl: 0x", Hex(pio->sm[sm].shiftctrl)); 54 | logmsgln("sm", sm, " addr: 0x", Hex(pio->sm[sm].addr)); 55 | logmsgln("sm", sm, " pinctrl: 0x", Hex(pio->sm[sm].pinctrl)); 56 | } 57 | -------------------------------------------------------------------------------- /src/SdCard/Rp2040Sdio/Rp2040SdioConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #pragma once 26 | /** 27 | * \class SdioConfig 28 | * \brief SDIO card configuration. 29 | */ 30 | class SdioConfig { 31 | public: 32 | /** 33 | * SdioConfig constructor. 34 | * \param[in] clkPin gpio pin for SDIO CLK. 35 | * \param[in] cmdPin gpio pin for SDIO CMD. 36 | * \param[in] dat0Pin gpio start pin for SDIO DAT[4]. 37 | */ 38 | SdioConfig(uint clkPin, uint cmdPin, uint dat0Pin) 39 | : m_clkPin(clkPin), m_cmdPin(cmdPin), m_dat0Pin(dat0Pin) {} 40 | /** \return gpio for SDIO CLK */ 41 | uint clkPin() { return m_clkPin; } 42 | /** \return gpio for SDIO CMD */ 43 | uint cmdPin() { return m_cmdPin; } 44 | /** \return gpio for SDIO DAT0 */ 45 | uint dat0Pin() { return m_dat0Pin; } 46 | 47 | private: 48 | SdioConfig() : m_clkPin(31u), m_cmdPin(31u), m_dat0Pin(31u) {} 49 | const uint8_t m_clkPin; 50 | const uint8_t m_cmdPin; 51 | const uint8_t m_dat0Pin; 52 | }; 53 | -------------------------------------------------------------------------------- /src/SdCard/SdCard.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | /** 26 | * \file 27 | * \brief Top level include for SPI and SDIO cards. 28 | */ 29 | #pragma once 30 | #include "SdSpiCard.h" 31 | #include "SdioCard.h" 32 | #if HAS_SDIO_CLASS 33 | /** Type for both SPI and SDIO cards. */ 34 | typedef SdCardInterface SdCard; 35 | #else // HAS_SDIO_CLASS 36 | /** Type for SPI card. */ 37 | typedef SdSpiCard SdCard; 38 | #endif // HAS_SDIO_CLASS 39 | /** Determine card configuration type. 40 | * 41 | * \param[in] cfg Card configuration. 42 | * \return true if SPI. 43 | */ 44 | inline bool isSpi(SdSpiConfig cfg) { 45 | (void)cfg; 46 | return true; 47 | } 48 | /** Determine card configuration type. 49 | * 50 | * \param[in] cfg Card configuration. 51 | * \return true if SPI. 52 | */ 53 | inline bool isSpi(SdioConfig cfg) { 54 | (void)cfg; 55 | return false; 56 | } 57 | /** 58 | * \class SdCardFactory 59 | * \brief Setup a SPI card or SDIO card. 60 | */ 61 | class SdCardFactory { 62 | public: 63 | /** Initialize SPI card. 64 | * 65 | * \param[in] config SPI configuration. 66 | * \return generic card pointer or nullptr if failure. 67 | */ 68 | SdCard* newCard(SdSpiConfig config) { 69 | m_spiCard.begin(config); 70 | return &m_spiCard; 71 | } 72 | /** Initialize SDIO card. 73 | * 74 | * \param[in] config SDIO configuration. 75 | * \return generic card pointer or nullptr if SDIO is not supported. 76 | */ 77 | SdCard* newCard(SdioConfig config) { 78 | #if HAS_SDIO_CLASS 79 | m_sdioCard.begin(config); 80 | return &m_sdioCard; 81 | #else // HAS_SDIO_CLASS 82 | (void)config; 83 | return nullptr; 84 | #endif // HAS_SDIO_CLASS 85 | } 86 | 87 | private: 88 | #if HAS_SDIO_CLASS 89 | SdioCard m_sdioCard; 90 | #endif // HAS_SDIO_CLASS 91 | SdSpiCard m_spiCard; 92 | }; 93 | -------------------------------------------------------------------------------- /src/SdCard/SdCardInfo.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "SdCardInfo.h" 26 | //------------------------------------------------------------------------------ 27 | #undef SD_CARD_ERROR 28 | #define SD_CARD_ERROR(e, m) \ 29 | case SD_CARD_ERROR_##e: \ 30 | pr->print(F(#e)); \ 31 | break; 32 | void printSdErrorSymbol(print_t* pr, uint8_t code) { 33 | pr->print(F("SD_CARD_ERROR_")); 34 | switch (code) { 35 | SD_ERROR_CODE_LIST 36 | default: 37 | pr->print(F("UNKNOWN")); 38 | } 39 | } 40 | //------------------------------------------------------------------------------ 41 | #undef SD_CARD_ERROR 42 | #define SD_CARD_ERROR(e, m) \ 43 | case SD_CARD_ERROR_##e: \ 44 | pr->print(F(m)); \ 45 | break; 46 | void printSdErrorText(print_t* pr, uint8_t code) { 47 | switch (code) { 48 | SD_ERROR_CODE_LIST 49 | default: 50 | pr->print(F("Unknown error")); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/SdCard/TeensySdio/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | exclude_files=TeensySdioDefs.h 2 | -------------------------------------------------------------------------------- /src/SdCard/TeensySdio/TeensySdioConfig.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #pragma once 26 | /** Use programmed I/O with FIFO. */ 27 | #define FIFO_SDIO 0 28 | /** Use programmed I/O with DMA. */ 29 | #define DMA_SDIO 1 30 | /** 31 | * \class SdioConfig 32 | * \brief SDIO card configuration. 33 | */ 34 | class SdioConfig { 35 | public: 36 | SdioConfig() {} 37 | /** 38 | * SdioConfig constructor. 39 | * \param[in] opt SDIO options. 40 | */ 41 | explicit SdioConfig(uint8_t opt) : m_options(opt) {} 42 | /** \return SDIO card options. */ 43 | uint8_t options() { return m_options; } 44 | /** \return true if DMA_SDIO. */ 45 | bool useDma() { return m_options & DMA_SDIO; } 46 | 47 | private: 48 | uint8_t m_options = FIFO_SDIO; 49 | }; 50 | -------------------------------------------------------------------------------- /src/SdFatDebugConfig.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // File to be included in SdFatConfig.h for debug definitions. 3 | #if defined(ARDUINO_ADAFRUIT_METRO_RP2040) 4 | #define RP_CLK_GPIO 18 5 | #define RP_CMD_GPIO 19 6 | #define RP_DAT0_GPIO 20 // DAT1: GPIO21, DAT2: GPIO22, DAT3: GPIO23. 7 | #elif defined(ARDUINO_RASPBERRY_PI_PICO) || defined(ARDUINO_RASPBERRY_PI_PICO_2) 8 | #define RP_CLK_GPIO 16 9 | #define RP_CMD_GPIO 17 10 | #define RP_DAT0_GPIO 18 // DAT1: GPIO19, DAT2: GPIO20, DAT3: GPIO21. 11 | #elif defined(ARDUINO_ADAFRUIT_FEATHER_RP2350_HSTX) 12 | #define RP_CLK_GPIO 11 13 | #define RP_CMD_GPIO 10 14 | #define RP_DAT0_GPIO 22 // DAT1: GPIO23, DAT2: GPIO24, DAT3: GPIO25. 15 | #endif // defined(ARDUINO_ADAFRUIT_METRO_RP2040)) 16 | -------------------------------------------------------------------------------- /src/SdFat_Adafruit_Fork.h: -------------------------------------------------------------------------------- 1 | #ifndef SDFAT_ADAFRUIT_FORK_H 2 | #define SDFAT_ADAFRUIT_FORK_H 3 | 4 | #include "SdFat.h" 5 | 6 | #endif // SDFAT_ADAFRUIT_FORK_H 7 | -------------------------------------------------------------------------------- /src/SpiDriver/SdSpiArtemis.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "SdSpiDriver.h" 26 | #if defined(SD_USE_CUSTOM_SPI) && defined(ARDUINO_ARCH_APOLLO3) 27 | //------------------------------------------------------------------------------ 28 | void SdSpiArduinoDriver::activate() { m_spi->beginTransaction(m_spiSettings); } 29 | //------------------------------------------------------------------------------ 30 | void SdSpiArduinoDriver::begin(SdSpiConfig spiConfig) { 31 | if (spiConfig.spiPort) { 32 | m_spi = spiConfig.spiPort; 33 | } else { 34 | m_spi = &SPI; 35 | } 36 | m_spi->begin(); 37 | } 38 | //------------------------------------------------------------------------------ 39 | void SdSpiArduinoDriver::deactivate() { m_spi->endTransaction(); } 40 | //------------------------------------------------------------------------------ 41 | void SdSpiArduinoDriver::end() { m_spi->end(); } 42 | //------------------------------------------------------------------------------ 43 | uint8_t SdSpiArduinoDriver::receive() { return m_spi->transfer(0XFF); } 44 | //------------------------------------------------------------------------------ 45 | uint8_t SdSpiArduinoDriver::receive(uint8_t* buf, size_t count) { 46 | memset(buf, 0XFF, count); 47 | m_spi->transfer(buf, count); 48 | return 0; 49 | } 50 | //------------------------------------------------------------------------------ 51 | void SdSpiArduinoDriver::send(uint8_t data) { m_spi->transfer(data); } 52 | //------------------------------------------------------------------------------ 53 | void SdSpiArduinoDriver::send(const uint8_t* buf, size_t count) { 54 | // If not a multiple of four. Command with CRC used six byte send. 55 | while (count % 4) { 56 | send(*buf++); 57 | count--; 58 | } 59 | // Convert byte array to 4 byte array. 60 | uint32_t myArray[count / 4]; // NOLINT 61 | for (int x = 0; x < count / 4; x++) { 62 | myArray[x] = ((uint32_t)buf[(x * 4) + 3] << (8 * 3)) | 63 | ((uint32_t)buf[(x * 4) + 2] << (8 * 2)) | 64 | ((uint32_t)buf[(x * 4) + 1] << (8 * 1)) | 65 | ((uint32_t)buf[(x * 4) + 0] << (8 * 0)); 66 | } 67 | m_spi->transfer(reinterpret_cast(myArray), count); 68 | } 69 | #endif // defined(SD_USE_CUSTOM_SPI) && defined(ARDUINO_ARCH_APOLLO3) 70 | -------------------------------------------------------------------------------- /src/SpiDriver/SdSpiBaseClass.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | /** 26 | * \file 27 | * \brief Base class for external SPI driver. 28 | */ 29 | #ifndef SdSpiBaseClass_h 30 | #define SdSpiBaseClass_h 31 | /** 32 | * \class SdSpiBaseClass 33 | * \brief Base class for external SPI drivers 34 | */ 35 | class SdSpiBaseClass { 36 | public: 37 | /** Activate SPI hardware. */ 38 | virtual void activate() {} 39 | /** Initialize the SPI bus. 40 | * 41 | * \param[in] config SPI configuration. 42 | */ 43 | virtual void begin(SdSpiConfig config) = 0; 44 | /** Deactivate SPI hardware. */ 45 | virtual void deactivate() {} 46 | /** deactivate SPI driver. */ 47 | virtual void end() {} 48 | /** Receive a byte. 49 | * 50 | * \return The byte. 51 | */ 52 | virtual uint8_t receive() = 0; 53 | /** Receive multiple bytes. 54 | * 55 | * \param[out] buf Buffer to receive the data. 56 | * \param[in] count Number of bytes to receive. 57 | * 58 | * \return Zero for no error or nonzero error code. 59 | */ 60 | virtual uint8_t receive(uint8_t* buf, size_t count) = 0; 61 | /** Send a byte. 62 | * 63 | * \param[in] data Byte to send 64 | */ 65 | virtual void send(uint8_t data) = 0; 66 | /** Send multiple bytes. 67 | * 68 | * \param[in] buf Buffer for data to be sent. 69 | * \param[in] count Number of bytes to send. 70 | */ 71 | virtual void send(const uint8_t* buf, size_t count) = 0; 72 | /** Save high speed SPISettings after SD initialization. 73 | * 74 | * \param[in] maxSck Maximum SCK frequency. 75 | */ 76 | virtual void setSckSpeed(uint32_t maxSck) { (void)maxSck; } 77 | }; 78 | #endif // SdSpiBaseClass_h 79 | -------------------------------------------------------------------------------- /src/SpiDriver/SdSpiChipSelect.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "SdSpiDriver.h" 26 | #if ENABLE_ARDUINO_FEATURES 27 | #if SD_CHIP_SELECT_MODE == 0 28 | //------------------------------------------------------------------------------ 29 | void sdCsInit(SdCsPin_t pin) { pinMode(pin, OUTPUT); } 30 | //------------------------------------------------------------------------------ 31 | void sdCsWrite(SdCsPin_t pin, bool level) { 32 | digitalWrite(pin, level ? HIGH : LOW); 33 | } 34 | #elif SD_CHIP_SELECT_MODE == 1 35 | //------------------------------------------------------------------------------ 36 | __attribute__((weak)) void sdCsInit(SdCsPin_t pin) { pinMode(pin, OUTPUT); } 37 | //------------------------------------------------------------------------------ 38 | __attribute__((weak)) void sdCsWrite(SdCsPin_t pin, bool level) { 39 | digitalWrite(pin, level ? HIGH : LOW); 40 | } 41 | #endif // SD_CHIP_SELECT_MODE == 0 42 | #endif // ENABLE_ARDUINO_FEATURES 43 | -------------------------------------------------------------------------------- /src/SpiDriver/SdSpiParticle.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "SdSpiDriver.h" 26 | #if defined(SD_USE_CUSTOM_SPI) && defined(PLATFORM_ID) 27 | static volatile bool SPI_DMA_TransferCompleted = false; 28 | //----------------------------------------------------------------------------- 29 | static void SD_SPI_DMA_TransferComplete_Callback() { 30 | SPI_DMA_TransferCompleted = true; 31 | } 32 | //------------------------------------------------------------------------------ 33 | void SdSpiArduinoDriver::activate() { m_spi->beginTransaction(m_spiSettings); } 34 | //------------------------------------------------------------------------------ 35 | void SdSpiArduinoDriver::begin(SdSpiConfig spiConfig) { 36 | if (spiConfig.spiPort) { 37 | m_spi = spiConfig.spiPort; 38 | } else { 39 | m_spi = &SPI; 40 | } 41 | m_spi->begin(); 42 | } 43 | //------------------------------------------------------------------------------ 44 | void SdSpiArduinoDriver::deactivate() { m_spi->endTransaction(); } 45 | //------------------------------------------------------------------------------ 46 | void SdSpiArduinoDriver::end() { m_spi->end(); } 47 | //------------------------------------------------------------------------------ 48 | uint8_t SdSpiArduinoDriver::receive() { return m_spi->transfer(0XFF); } 49 | //------------------------------------------------------------------------------ 50 | uint8_t SdSpiArduinoDriver::receive(uint8_t* buf, size_t count) { 51 | SPI_DMA_TransferCompleted = false; 52 | m_spi->transfer(nullptr, buf, count, SD_SPI_DMA_TransferComplete_Callback); 53 | while (!SPI_DMA_TransferCompleted) { 54 | } 55 | return 0; 56 | } 57 | //------------------------------------------------------------------------------ 58 | void SdSpiArduinoDriver::send(uint8_t data) { m_spi->transfer(data); } 59 | //------------------------------------------------------------------------------ 60 | void SdSpiArduinoDriver::send(const uint8_t* buf, size_t count) { 61 | SPI_DMA_TransferCompleted = false; 62 | 63 | m_spi->transfer(const_cast(buf), nullptr, count, 64 | SD_SPI_DMA_TransferComplete_Callback); 65 | 66 | while (!SPI_DMA_TransferCompleted) { 67 | } 68 | } 69 | #endif // defined(SD_USE_CUSTOM_SPI) && defined(PLATFORM_ID) 70 | -------------------------------------------------------------------------------- /src/SpiDriver/SdSpiSTM32.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | // Driver for: https://github.com/rogerclarkmelbourne/Arduino_STM32 26 | #include "SdSpiDriver.h" 27 | #if defined(SD_USE_CUSTOM_SPI) && (defined(__STM32F1__) || defined(__STM32F4__)) 28 | #if defined(__STM32F1__) 29 | #define USE_STM32_DMA 1 30 | #elif defined(__STM32F4__) 31 | #define USE_STM32_DMA 1 32 | #else // defined(__STM32F1__) 33 | #error Unknown STM32 type 34 | #endif // defined(__STM32F1__) 35 | //------------------------------------------------------------------------------ 36 | void SdSpiArduinoDriver::activate() { m_spi->beginTransaction(m_spiSettings); } 37 | //------------------------------------------------------------------------------ 38 | void SdSpiArduinoDriver::begin(SdSpiConfig spiConfig) { 39 | if (spiConfig.spiPort) { 40 | m_spi = spiConfig.spiPort; 41 | } else { 42 | m_spi = &SPI; 43 | } 44 | m_spi->begin(); 45 | } 46 | //------------------------------------------------------------------------------ 47 | void SdSpiArduinoDriver::deactivate() { m_spi->endTransaction(); } 48 | //------------------------------------------------------------------------------ 49 | void SdSpiArduinoDriver::end() { m_spi->end(); } 50 | //------------------------------------------------------------------------------ 51 | uint8_t SdSpiArduinoDriver::receive() { return m_spi->transfer(0XFF); } 52 | //------------------------------------------------------------------------------ 53 | uint8_t SdSpiArduinoDriver::receive(uint8_t* buf, size_t count) { 54 | #if USE_STM32_DMA 55 | return m_spi->dmaTransfer(nullptr, buf, count); 56 | #else // USE_STM32_DMA 57 | m_spi->read(buf, count); 58 | return 0; 59 | #endif // USE_STM32_DMA 60 | } 61 | //------------------------------------------------------------------------------ 62 | void SdSpiArduinoDriver::send(uint8_t data) { m_spi->transfer(data); } 63 | //------------------------------------------------------------------------------ 64 | void SdSpiArduinoDriver::send(const uint8_t* buf, size_t count) { 65 | #if USE_STM32_DMA 66 | m_spi->dmaTransfer(const_cast(buf), nullptr, count); 67 | #else // USE_STM32_DMA 68 | m_spi->write(const_cast(buf), count); 69 | #endif // USE_STM32_DMA 70 | } 71 | #endif // defined(SD_USE_CUSTOM_SPI) && defined(__STM32F1__) 72 | -------------------------------------------------------------------------------- /src/SpiDriver/SdSpiSTM32Core.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | // Driver for: https://github.com/stm32duino/Arduino_Core_STM32 26 | #include "SdSpiDriver.h" 27 | #if defined(SD_USE_CUSTOM_SPI) && defined(STM32_CORE_VERSION) 28 | //------------------------------------------------------------------------------ 29 | void SdSpiArduinoDriver::activate() { m_spi->beginTransaction(m_spiSettings); } 30 | //------------------------------------------------------------------------------ 31 | void SdSpiArduinoDriver::begin(SdSpiConfig spiConfig) { 32 | if (spiConfig.spiPort) { 33 | m_spi = spiConfig.spiPort; 34 | } else { 35 | m_spi = &SPI; 36 | } 37 | m_spi->begin(); 38 | } 39 | //------------------------------------------------------------------------------ 40 | void SdSpiArduinoDriver::deactivate() { m_spi->endTransaction(); } 41 | //------------------------------------------------------------------------------ 42 | void SdSpiArduinoDriver::end() { m_spi->end(); } 43 | //------------------------------------------------------------------------------ 44 | uint8_t SdSpiArduinoDriver::receive() { return m_spi->transfer(0XFF); } 45 | //------------------------------------------------------------------------------ 46 | uint8_t SdSpiArduinoDriver::receive(uint8_t* buf, size_t count) { 47 | // Must send 0XFF - SD looks at send data for command. 48 | memset(buf, 0XFF, count); 49 | m_spi->transfer(buf, count); 50 | return 0; 51 | } 52 | //------------------------------------------------------------------------------ 53 | void SdSpiArduinoDriver::send(uint8_t data) { m_spi->transfer(data); } 54 | //------------------------------------------------------------------------------ 55 | void SdSpiArduinoDriver::send(const uint8_t* buf, size_t count) { 56 | // Avoid stack overflow if bad count. This should cause a write error. 57 | if (count > 512) { 58 | return; 59 | } 60 | // Not easy to avoid receive so use tmp RX buffer. 61 | uint8_t rxBuf[512]; 62 | // Discard const - STM32 not const correct. 63 | m_spi->transfer(const_cast(buf), rxBuf, count); 64 | } 65 | #endif // defined(SD_USE_CUSTOM_SPI) && defined(STM32_CORE_VERSION) 66 | -------------------------------------------------------------------------------- /src/common/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | exclude_files=PrintBasic.cpp 2 | exclude_files=PrintBasic.h 3 | exclude_files=PrintTemplates.h 4 | -------------------------------------------------------------------------------- /src/common/DebugMacros.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2024 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #pragma once 26 | #include "SysCall.h" 27 | 28 | // 0 - disable, 1 - fail, halt 2 - fail, halt, warn 29 | #define USE_DBG_MACROS 0 30 | 31 | #if USE_DBG_MACROS 32 | #include "Arduino.h" 33 | #ifndef DBG_FILE 34 | #error DBG_FILE not defined 35 | #endif // DBG_FILE 36 | 37 | __attribute__((unused)) static void dbgFail(uint16_t line) { 38 | Serial.print(F("DBG_FAIL: ")); 39 | Serial.print(F(DBG_FILE)); 40 | Serial.write('.'); 41 | Serial.println(line); 42 | } 43 | __attribute__((unused)) static void dbgHalt(uint16_t line) { 44 | Serial.print(F("DBG_HALT: ")); 45 | Serial.print(F(DBG_FILE)); 46 | Serial.write('.'); 47 | Serial.println(line); 48 | while (true) { 49 | } 50 | } 51 | #define DBG_FAIL_MACRO dbgFail(__LINE__) 52 | #define DBG_HALT_MACRO dbgHalt(__LINE__) 53 | #define DBG_HALT_IF(b) \ 54 | if (b) { \ 55 | dbgHalt(__LINE__); \ 56 | } 57 | 58 | #else // USE_DBG_MACROS 59 | #define DBG_FAIL_MACRO 60 | #define DBG_HALT_MACRO 61 | #define DBG_HALT_IF(b) 62 | #endif // USE_DBG_MACROS 63 | 64 | #if USE_DBG_MACROS > 1 65 | __attribute__((unused)) static void dbgWarn(uint16_t line) { 66 | Serial.print(F("DBG_WARN: ")); 67 | Serial.print(F(DBG_FILE)); 68 | Serial.write('.'); 69 | Serial.println(line); 70 | } 71 | #define DBG_WARN_MACRO dbgWarn(__LINE__) 72 | #define DBG_WARN_IF(b) \ 73 | if (b) { \ 74 | dbgWarn(__LINE__); \ 75 | } 76 | #else // USE_DBG_MACROS > 1 77 | #define DBG_WARN_MACRO 78 | #define DBG_WARN_IF(b) 79 | #endif // USE_DBG_MACROS > 1 80 | -------------------------------------------------------------------------------- /src/common/FmtNumber.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef FmtNumber_h 26 | #define FmtNumber_h 27 | #include 28 | #include 29 | #include 30 | inline bool isDigit(char c) { return '0' <= (c) && (c) <= '9'; } 31 | inline bool isSpace(char c) { return (c) == ' ' || (0X9 <= (c) && (c) <= 0XD); } 32 | char* fmtBase10(char* str, uint16_t n); 33 | char* fmtBase10(char* str, uint32_t n); 34 | char* fmtDouble(char* str, double d, uint8_t prec, bool altFmt); 35 | char* fmtDouble(char* str, double d, uint8_t prec, bool altFmt, char expChar); 36 | char* fmtHex(char* str, uint32_t n); 37 | char* fmtSigned(char* str, int32_t n, uint8_t base, bool caps); 38 | char* fmtUnsigned(char* str, uint32_t n, uint8_t base, bool caps); 39 | #endif // FmtNumber_h 40 | -------------------------------------------------------------------------------- /src/common/FsApiConstants.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef FsApiConstants_h 26 | #define FsApiConstants_h 27 | #include "SysCall.h" 28 | #if USE_FCNTL_H 29 | #include 30 | /* values for GNU Arm Embedded Toolchain. 31 | * O_RDONLY: 0x0 32 | * O_WRONLY: 0x1 33 | * O_RDWR: 0x2 34 | * O_ACCMODE: 0x3 35 | * O_APPEND: 0x8 36 | * O_CREAT: 0x200 37 | * O_TRUNC: 0x400 38 | * O_EXCL: 0x800 39 | * O_SYNC: 0x2000 40 | * O_NONBLOCK: 0x4000 41 | */ 42 | /** Use O_NONBLOCK for open at EOF */ 43 | #define O_AT_END O_NONBLOCK ///< Open at EOF. 44 | typedef int oflag_t; 45 | #else // USE_FCNTL_H 46 | #define O_RDONLY 0X00 ///< Open for reading only. 47 | #define O_WRONLY 0X01 ///< Open for writing only. 48 | #define O_RDWR 0X02 ///< Open for reading and writing. 49 | #define O_AT_END 0X04 ///< Open at EOF. 50 | #define O_APPEND 0X08 ///< Set append mode. 51 | #define O_CREAT 0x10 ///< Create file if it does not exist. 52 | #define O_TRUNC 0x20 ///< Truncate file to zero length. 53 | #define O_EXCL 0x40 ///< Fail if the file exists. 54 | #define O_SYNC 0x80 ///< Synchronized write I/O operations. 55 | 56 | #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) ///< Mask for access mode. 57 | typedef uint8_t oflag_t; 58 | #endif // USE_FCNTL_H 59 | 60 | #define O_READ O_RDONLY 61 | #define O_WRITE O_WRONLY 62 | 63 | inline bool isWriteMode(oflag_t oflag) { 64 | oflag &= O_ACCMODE; 65 | return oflag == O_WRONLY || oflag == O_RDWR; 66 | } 67 | 68 | // flags for ls() 69 | /** ls() flag for list all files including hidden. */ 70 | const uint8_t LS_A = 1; 71 | /** ls() flag to print modify. date */ 72 | const uint8_t LS_DATE = 2; 73 | /** ls() flag to print file size. */ 74 | const uint8_t LS_SIZE = 4; 75 | /** ls() flag for recursive list of subdirectories */ 76 | const uint8_t LS_R = 8; 77 | 78 | // flags for time-stamp 79 | /** set the file's last access date */ 80 | const uint8_t T_ACCESS = 1; 81 | /** set the file's creation date and time */ 82 | const uint8_t T_CREATE = 2; 83 | /** Set the file's write date and time */ 84 | const uint8_t T_WRITE = 4; 85 | #endif // FsApiConstants_h 86 | -------------------------------------------------------------------------------- /src/common/FsBlockDevice.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef FsBlockDevice_h 26 | #define FsBlockDevice_h 27 | #include "SdCard/SdCard.h" 28 | #if HAS_SDIO_CLASS || USE_BLOCK_DEVICE_INTERFACE 29 | typedef FsBlockDeviceInterface FsBlockDevice; 30 | #else 31 | typedef SdCard FsBlockDevice; 32 | #endif 33 | #endif // FsBlockDevice_h 34 | -------------------------------------------------------------------------------- /src/common/FsCache.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #define DBG_FILE "FsCache.cpp" 26 | #include "FsCache.h" 27 | 28 | #include "DebugMacros.h" 29 | //------------------------------------------------------------------------------ 30 | uint8_t* FsCache::prepare(uint32_t sector, uint8_t option) { 31 | if (!m_blockDev) { 32 | DBG_FAIL_MACRO; 33 | goto fail; 34 | } 35 | if (m_sector != sector) { 36 | if (!sync()) { 37 | DBG_FAIL_MACRO; 38 | goto fail; 39 | } 40 | if (!(option & CACHE_OPTION_NO_READ)) { 41 | if (!m_blockDev->readSector(sector, m_buffer)) { 42 | DBG_FAIL_MACRO; 43 | goto fail; 44 | } 45 | } 46 | m_status = 0; 47 | m_sector = sector; 48 | } 49 | m_status |= option & CACHE_STATUS_MASK; 50 | return m_buffer; 51 | 52 | fail: 53 | return nullptr; 54 | } 55 | //------------------------------------------------------------------------------ 56 | bool FsCache::sync() { 57 | if (m_status & CACHE_STATUS_DIRTY) { 58 | if (!m_blockDev->writeSector(m_sector, m_buffer)) { 59 | DBG_FAIL_MACRO; 60 | goto fail; 61 | } 62 | // mirror second FAT 63 | if (m_status & CACHE_STATUS_MIRROR_FAT) { 64 | if (!m_blockDev->writeSector(m_sector + m_mirrorOffset, m_buffer)) { 65 | DBG_FAIL_MACRO; 66 | goto fail; 67 | } 68 | } 69 | m_status &= ~CACHE_STATUS_DIRTY; 70 | } 71 | return true; 72 | 73 | fail: 74 | return false; 75 | } 76 | -------------------------------------------------------------------------------- /src/common/FsName.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "FsName.h" 26 | 27 | #include "FsUtf.h" 28 | #if USE_UTF8_LONG_NAMES 29 | uint16_t FsName::get16() { 30 | uint16_t rtn; 31 | if (ls) { 32 | rtn = ls; 33 | ls = 0; 34 | } else if (next >= end) { 35 | rtn = 0; 36 | } else { 37 | uint32_t cp; 38 | const char* ptr = FsUtf::mbToCp(next, end, &cp); 39 | if (!ptr) { 40 | goto fail; 41 | } 42 | next = ptr; 43 | if (cp <= 0XFFFF) { 44 | rtn = cp; 45 | } else { 46 | ls = FsUtf::lowSurrogate(cp); 47 | rtn = FsUtf::highSurrogate(cp); 48 | } 49 | } 50 | return rtn; 51 | 52 | fail: 53 | return 0XFFFF; 54 | } 55 | #endif // USE_UTF8_LONG_NAMES 56 | -------------------------------------------------------------------------------- /src/common/FsName.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef FsName_h 26 | #define FsName_h 27 | #include 28 | 29 | #include "SysCall.h" 30 | /** 31 | * \file 32 | * \brief FsName class. 33 | */ 34 | /** 35 | * \class FsName 36 | * \brief Handle UTF-8 file names. 37 | */ 38 | class FsName { 39 | public: 40 | /** Beginning of LFN. */ 41 | const char* begin; 42 | /** Next LFN character of end. */ 43 | const char* next; 44 | /** Position one beyond last LFN character. */ 45 | const char* end; 46 | #if !USE_UTF8_LONG_NAMES 47 | /** \return true if at end. */ 48 | bool atEnd() { return next == end; } 49 | /** Reset to start of LFN. */ 50 | void reset() { next = begin; } 51 | /** \return next char of LFN. */ 52 | char getch() { return atEnd() ? 0 : *next++; } 53 | /** \return next UTF-16 unit of LFN. */ 54 | uint16_t get16() { return atEnd() ? 0 : *next++; } 55 | #else // !USE_UTF8_LONG_NAMES 56 | uint16_t ls = 0; 57 | bool atEnd() { return !ls && next == end; } 58 | void reset() { 59 | next = begin; 60 | ls = 0; // lowSurrogate 61 | } 62 | uint16_t get16(); 63 | #endif // !USE_UTF8_LONG_NAMES 64 | }; 65 | #endif // FsName_h 66 | -------------------------------------------------------------------------------- /src/common/FsStructs.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "FsStructs.h" 26 | // bgnLba = relSector; 27 | // endLba = relSector + partSize - 1; 28 | void lbaToMbrChs(uint8_t* chs, uint32_t capacityMB, uint32_t lba) { 29 | uint32_t c; 30 | uint8_t h; 31 | uint8_t s; 32 | 33 | uint8_t numberOfHeads; 34 | uint8_t sectorsPerTrack = capacityMB <= 256 ? 32 : 63; 35 | if (capacityMB <= 16) { 36 | numberOfHeads = 2; 37 | } else if (capacityMB <= 32) { 38 | numberOfHeads = 4; 39 | } else if (capacityMB <= 128) { 40 | numberOfHeads = 8; 41 | } else if (capacityMB <= 504) { 42 | numberOfHeads = 16; 43 | } else if (capacityMB <= 1008) { 44 | numberOfHeads = 32; 45 | } else if (capacityMB <= 2016) { 46 | numberOfHeads = 64; 47 | } else if (capacityMB <= 4032) { 48 | numberOfHeads = 128; 49 | } else { 50 | numberOfHeads = 255; 51 | } 52 | c = lba / (numberOfHeads * sectorsPerTrack); 53 | if (c <= 1023) { 54 | h = (lba % (numberOfHeads * sectorsPerTrack)) / sectorsPerTrack; 55 | s = (lba % sectorsPerTrack) + 1; 56 | } else { 57 | c = 1023; 58 | h = 254; 59 | s = 63; 60 | } 61 | chs[0] = h; 62 | chs[1] = ((c >> 2) & 0XC0) | s; 63 | chs[2] = c; 64 | } 65 | -------------------------------------------------------------------------------- /src/common/PrintBasic.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2020 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #include "PrintBasic.h" 26 | #if ENABLE_ARDUINO_FEATURES == 0 27 | #include 28 | 29 | size_t PrintBasic::print(long n, uint8_t base) { 30 | if (n < 0 && base == 10) { 31 | return print('-') + printNum(-n, base); 32 | } 33 | return printNum(n, base); 34 | } 35 | size_t PrintBasic::printNum(unsigned long n, uint8_t base) { 36 | const uint8_t DIM = 8 * sizeof(long); 37 | char buf[DIM]; 38 | char *str = &buf[DIM]; 39 | 40 | if (base < 2) return 0; 41 | 42 | do { 43 | char c = n % base; 44 | n /= base; 45 | *--str = c + (c < 10 ? '0' : 'A' - 10); 46 | } while (n); 47 | return write(str, &buf[DIM] - str); 48 | } 49 | 50 | size_t PrintBasic::printDouble(double n, uint8_t prec) { 51 | // Max printable 32-bit floating point number. AVR uses 32-bit double. 52 | const double maxfp = static_cast(0XFFFFFF00UL); 53 | size_t rtn = 0; 54 | 55 | if (isnan(n)) { 56 | return write("NaN"); 57 | } 58 | if (n < 0) { 59 | n = -n; 60 | rtn += print('-'); 61 | } 62 | if (isinf(n)) { 63 | return rtn + write("Inf"); 64 | } 65 | if (n > maxfp) { 66 | return rtn + write("Ovf"); 67 | } 68 | 69 | double round = 0.5; 70 | for (uint8_t i = 0; i < prec; ++i) { 71 | round *= 0.1; 72 | } 73 | 74 | n += round; 75 | 76 | uint32_t whole = (uint32_t)n; 77 | rtn += print(whole); 78 | 79 | if (prec) { 80 | rtn += print('.'); 81 | double fraction = n - static_cast(whole); 82 | for (uint8_t i = 0; i < prec; i++) { 83 | fraction *= 10.0; 84 | uint8_t digit = fraction; 85 | rtn += print(digit); 86 | fraction -= digit; 87 | } 88 | } 89 | return rtn; 90 | } 91 | #endif // ENABLE_ARDUINO_FEATURES == 0 92 | -------------------------------------------------------------------------------- /src/common/SysCall.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | /** 26 | * \file 27 | * \brief SysCall class 28 | */ 29 | #ifndef SysCall_h 30 | #define SysCall_h 31 | #include 32 | #include 33 | 34 | #include "../SdFatConfig.h" 35 | #if __cplusplus < 201103 36 | #warning nullptr defined 37 | /** Define nullptr if not C++11 */ 38 | #define nullptr NULL 39 | #endif // __cplusplus < 201103 40 | //------------------------------------------------------------------------------ 41 | #if ENABLE_ARDUINO_FEATURES 42 | #if defined(ARDUINO) 43 | /** Use Arduino Print. */ 44 | typedef Print print_t; 45 | /** Use Arduino Stream. */ 46 | typedef Stream stream_t; 47 | #else // defined(ARDUINO) 48 | #error "Unknown system" 49 | #endif // defined(ARDUINO) 50 | //------------------------------------------------------------------------------ 51 | #ifndef F 52 | /** Define macro for strings stored in flash. */ 53 | #define F(str) (str) 54 | #endif // F 55 | //------------------------------------------------------------------------------ 56 | #else // ENABLE_ARDUINO_FEATURES 57 | #include "PrintBasic.h" 58 | /** If not Arduino */ 59 | typedef PrintBasic print_t; 60 | /** If not Arduino */ 61 | typedef PrintBasic stream_t; 62 | #endif // ENABLE_ARDUINO_FEATURES 63 | #endif // SysCall_h 64 | -------------------------------------------------------------------------------- /src/common/upcase.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef upcase_h 26 | #define upcase_h 27 | #include 28 | uint16_t toUpcase(uint16_t chr); 29 | uint32_t upcaseChecksum(uint16_t unicode, uint32_t checksum); 30 | #endif // upcase_h 31 | -------------------------------------------------------------------------------- /src/fmt_src.bat: -------------------------------------------------------------------------------- 1 | clang-format --style=Google -i *.cpp *.h 2 | rem clang-format --style=Google -i DigitalIO/*.h 3 | rem clang-format --style=Google -i DigitalIO/boards/*.h 4 | clang-format --style=Google -i common/*.cpp common/*.h 5 | clang-format --style=Google -i ExFatLib/*.cpp ExFatLib/*.h 6 | clang-format --style=Google -i FatLib/*.cpp FatLib/*.h 7 | clang-format --style=Google -i FsLib/*.cpp FsLib/*.h 8 | clang-format --style=Google -i iostream/*.cpp iostream/*.h 9 | clang-format --style=Google -i SdCard/*.cpp SdCard/*.h 10 | rem clang-format --style=Google -i SdCard/Rp2040Sdio/DbgLogMsg.h SdCard/Rp2040Sdio/PioDbgInfo.h 11 | rem clang-format --style=Google -i SdCard/Rp2040Sdio/PioSdioCard.h SdCard/Rp2040Sdio/Rp2040SdioConfig.h 12 | clang-format --style=Google -i SdCard/Rp2040Sdio/*.cpp SdCard/Rp2040Sdio/*.h 13 | clang-format --style=Google -i SdCard/TeensySdio/*.cpp SdCard/TeensySdio/*.h 14 | clang-format --style=Google -i SpiDriver/*.cpp SpiDriver/*.h 15 | pause 16 | -------------------------------------------------------------------------------- /src/sdios.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2011-2022 Bill Greiman 3 | * This file is part of the SdFat library for SD memory cards. 4 | * 5 | * MIT License 6 | * 7 | * Permission is hereby granted, free of charge, to any person obtaining a 8 | * copy of this software and associated documentation files (the "Software"), 9 | * to deal in the Software without restriction, including without limitation 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 | * and/or sell copies of the Software, and to permit persons to whom the 12 | * Software is furnished to do so, subject to the following conditions: 13 | * 14 | * The above copyright notice and this permission notice shall be included 15 | * in all copies or substantial portions of the Software. 16 | * 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | #ifndef sdios_h 26 | #define sdios_h 27 | /** 28 | * \file 29 | * \brief C++ IO Streams features. 30 | */ 31 | #include "iostream/ArduinoStream.h" 32 | #include "iostream/StdioStream.h" 33 | #include "iostream/fstream.h" 34 | #endif // sdios_h 35 | --------------------------------------------------------------------------------