mainpage.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /**
  2. * Copyright (c) 2011-2021 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. \mainpage Arduino %SdFat Library
  27. \section Warn Warnings for SdFat V2
  28. This is a major new version of SdFat. It is mostly
  29. backward compatible with SdFat Version 1 for FAT16/FAT32 cards.
  30. You should edit SdFatConfig.h to select features. The default version of
  31. SdFatConfig.h is suitable for UNO and other small AVR boards.
  32. \section Intro Introduction
  33. The Arduino %SdFat library supports FAT16, FAT32, and exFAT file systems
  34. on Standard SD, SDHC, and SDXC cards.
  35. In %SdFat version 1, SdFat and File are the main classes.
  36. In %SdFat version 2, SdFat and File are defined by typedefs in terms of the
  37. following classes.
  38. The file system classes in the %SdFat library are SdFat32, SdExFat, and SdFs.
  39. SdFat32 supports FAT16 and FAT32. SdExFat supports exFAT, SdFs supports
  40. FAT16, FAT32, and exFAT.
  41. The corresponding file classes are File32, ExFile, and FsFile.
  42. The types for SdFat and File are defined in SdFatConfig.h. This version
  43. uses FAT16/FAT32 for small AVR boards and FAT16/FAT32/exFAT for all other
  44. boards.
  45. \code{.cpp}
  46. // File types for SdFat, File, SdFile, SdBaseFile, fstream,
  47. // ifstream, and ofstream.
  48. //
  49. // Set SDFAT_FILE_TYPE to:
  50. // 1 for FAT16/FAT32, 2 for exFAT, 3 for FAT16/FAT32 and exFAT.
  51. //
  52. #if defined(__AVR__) && FLASHEND < 0X8000
  53. // FAT16/FAT32 for 32K AVR boards.
  54. #define SDFAT_FILE_TYPE 1
  55. #else // defined(__AVR__) && FLASHEND < 0X8000
  56. // FAT16/FAT32 and exFAT for all other boards.
  57. #define SDFAT_FILE_TYPE 3
  58. #endif // defined(__AVR__) && FLASHEND < 0X8000
  59. \endcode
  60. It is possible to use option three, support or FAT16/FAT32 and exFat
  61. on an Uno or other AVR board with 32KB flash and 2KB SRAM but memory
  62. will be very limited.
  63. Uno memory use for a simple data logger is:
  64. > option 1, FAT16/FAT32, 11902 bytes of flash and 855 bytes of SRAM.
  65. >
  66. > option 2, exFAT, 14942 bytes of flash and 895 bytes of SRAM.
  67. >
  68. > option 3, FAT16/FAT32 and exFAT, 21834 bytes of flash and 908 bytes of SRAM.
  69. Please read documentation under the above classes tab for more information.
  70. A number of example are provided in the %SdFat/examples folder. These were
  71. developed to test %SdFat and illustrate its use.
  72. \section exFAT exFAT Features
  73. exFAT has many features not available in FAT16/FAT32.
  74. Files larger than 4GiB, 64-bit file size and file position.
  75. Free space allocation performance improved by using a free space bitmap.
  76. Removal of the physical "." and ".." directory entries that appear in
  77. FAT16/FAT32 subdirectories.
  78. Better support for large flash pages with boundary alignment offsets
  79. for the FAT table and data region.
  80. exFAT files have two separate 64-bit length fields. The DataLength
  81. field indicate how much space is allocate to the file. The ValidDataLength
  82. field indicates how much actual data has been written to the file.
  83. An exFAT file can be contiguous with pre-allocate clusters and bypass the
  84. use of the FAT table. In this case the contiguous flag is set in the
  85. directory entry. This allows an entire file to be written as one large
  86. multi-block write.
  87. \section SDPath Paths and Working Directories
  88. Relative paths in %SdFat are resolved in a manner similar to Windows.
  89. Each instance of SdFat32, SdExFat, and SdFs has a current directory.
  90. This directory is called the volume working directory, vwd.
  91. Initially this directory is the root directory for the volume.
  92. The volume working directory is changed by calling the chdir(path).
  93. The call sd.chdir("/2014") will change the volume working directory
  94. for sd to "/2014", assuming "/2014" exists.
  95. Relative paths for member functions are resolved by starting at
  96. the volume working directory.
  97. For example, the call sd.mkdir("April") will create the directory
  98. "/2014/April" assuming the volume working directory is "/2014".
  99. There is current working directory, cwd, that is used to resolve paths
  100. for file.open() calls.
  101. For a single SD card, the current working directory is always the volume
  102. working directory for that card.
  103. For multiple SD cards the current working directory is set to the volume
  104. working directory of a card by calling the chvol() member function.
  105. The chvol() call is like the Windows \<drive letter>: command.
  106. The call sd2.chvol() will set the current working directory to the volume
  107. working directory for sd2.
  108. If the volume working directory for sd2 is "/music" the call
  109. file.open("BigBand.wav", O_READ);
  110. will open "/music/BigBand.wav" on sd2.
  111. \section Install Installation
  112. You must manually install %SdFat by renaming the download folder %SdFat
  113. and copy the %SdFat folder to the Arduino libraries folder in your
  114. sketchbook folder.
  115. It will be necessary to unzip and rename the folder if you download a zip
  116. file from GitHub.
  117. See the Manual installation section of this guide.
  118. http://arduino.cc/en/Guide/Libraries
  119. \section SDconfig SdFat Configuration
  120. Several configuration options may be changed by editing the SdFatConfig.h
  121. file in the %SdFat/src folder.
  122. Here are a few of the key options.
  123. If the symbol ENABLE_DEDICATED_SPI is nonzero, multi-block SD I/O may
  124. be used for better performance. The SPI bus may not be shared with
  125. other devices in this mode.
  126. The symbol SPI_DRIVER_SELECT is used to select the SPI driver.
  127. > If the symbol SPI_DRIVER_SELECT is:
  128. >
  129. > 0 - An optimized custom SPI driver is used if it exists
  130. > else the standard library driver is used.
  131. >
  132. > 1 - The standard library driver is always used.
  133. >
  134. > 2 - The software SPI driver is always used.
  135. >
  136. > 3 - An external SPI driver derived from SdSpiBaseClass is always used.
  137. To enable SD card CRC checking in SPI mode set USE_SD_CRC nonzero.
  138. See SdFatConfig.h for other options.
  139. \section Hardware Hardware Configuration
  140. The hardware interface to the SD card should not use a resistor based level
  141. shifter. Resistor based level shifters results in signal rise times that are
  142. too slow for many newer SD cards.
  143. \section HowTo How to format SD Cards
  144. The best way to restore an SD card's format on a PC or Mac is to use
  145. SDFormatter which can be downloaded from:
  146. http://www.sdcard.org/downloads
  147. A formatter program, SdFormatter.ino, is included in the
  148. %SdFat/examples/SdFormatter directory. This program attempts to
  149. emulate SD Association's SDFormatter.
  150. SDFormatter aligns flash erase boundaries with file
  151. system structures which reduces write latency and file system overhead.
  152. The PC/Mac SDFormatter does not have an option for FAT type so it may format
  153. very small cards as FAT12. Use the %SdFormatter example to force FAT16
  154. formatting of small cards.
  155. Do not format the SD card with an OS utility, OS utilities do not format SD
  156. cards in conformance with the SD standard.
  157. You should use a freshly formatted SD card for best performance. FAT
  158. file systems become slower if many files have been created and deleted.
  159. This is because the directory entry for a deleted file is marked as deleted,
  160. but is not deleted. When a new file is created, these entries must be scanned
  161. before creating the file. Also files can become
  162. fragmented which causes reads and writes to be slower.
  163. \section ExampleFiles Examples
  164. A number of examples are provided in the SdFat/examples folder.
  165. To access these examples from the Arduino development environment
  166. go to: %File -> Examples -> %SdFat -> \<program Name\>
  167. Compile, upload to your Arduino and click on Serial Monitor to run
  168. the example.
  169. Here is a list:
  170. AvrAdcLogger - Fast AVR ADC logger using Timer/ADC interrupts.
  171. BackwardCompatibility - Demonstrate SD.h compatibility with %SdFat.h.
  172. bench - A read/write benchmark.
  173. %BufferedPrint - Demo a buffered print class for AVR loggers.
  174. debug folder - Some of my debug programs - will be remove in the future.
  175. DirectoryFunctions - Use of chdir(), ls(), mkdir(), and rmdir().
  176. examplesV1 folder - Examples from SdFat V1 for compatibility tests.
  177. ExFatLogger - A data-logger optimized for exFAT features.
  178. MinimumSizeSdReader - Example of small file reader for FAT16/FAT32.
  179. OpenNext - Open all files in the root dir and print their filename.
  180. QuickStart - Quick hardware test for SPI card access.
  181. ReadCsvFile - Function to read a CSV text file one field at a time.
  182. rename - demonstrates use of rename().
  183. RtcTimestampTest - Demonstration of timestamps with RTClib.
  184. SdErrorCodes - Produce a list of error codes.
  185. SdFormatter - This program will format an SD, SDHC, or SDXC card.
  186. SdInfo - Initialize an SD card and analyze its structure for trouble shooting.
  187. SoftwareSpi - Demo of limited Software SPI support in SdFat V2.
  188. STM32Test - Example use of two SPI ports on an STM32 board.
  189. TeensyDmaAdcLogger - Fast logger using DMA ADC.
  190. TeensyRtcTimestamp - %File timestamps for Teensy3.
  191. TeensySdioDemo - Demo of SDIO and SPI modes for the Teensy 3.5/3.6 built-in SD.
  192. TeensySdioLogger - Fast logger using a ring buffer.
  193. UnicodeFilenames - Test program for Unicode file names.
  194. UserChipSelectFunction - Useful for port expanders or replacement of the standard GPIO functions.
  195. UserSPIDriver - An example of an external SPI driver.
  196. */