Skip to content

feat: enhance fat type support #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions examples/CardInfo/CardInfo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,26 @@ void setup() {

// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!fatFs.init()) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
Serial.println("Could not find FAT partition.\nMake sure you've formatted the card");
return;
}

// print the type and size of the first FAT-type volume
uint64_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(fatFs.fatType(), DEC);
Serial.println();
Serial.print("\nVolume type is ");
uint8_t fatType = fatFs.fatType();
#if defined(FAT_TYPE_EXFAT)
if (fatType == FAT_TYPE_EXFAT) {
Serial.println("exFAT");
} else
#endif
{
if (fatType != FAT_TYPE_UNK) {
Serial.printf("FAT%u\n", fatFs.fatType());
} else {
Serial.println("unknown");
}
}

volumesize = fatFs.blocksPerCluster(); // clusters are collections of blocks
volumesize *= fatFs.clusterCount(); // we'll have a lot of clusters
Expand Down
6 changes: 6 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ setCMD KEYWORD2
setCKIN KEYWORD2
setCDIR KEYWORD2
setDxDIR KEYWORD2
fatType KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################
FILE_READ LITERAL1
FILE_WRITE LITERAL1
FAT_TYPE_EXFAT LITERAL1
FAT_TYPE_FAT12 LITERAL1
FAT_TYPE_FAT16 LITERAL1
FAT_TYPE_FAT32 LITERAL1
FAT_TYPE_UNK LITERAL1
5 changes: 5 additions & 0 deletions src/STM32SD.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ class SDClass {

friend class File;

uint8_t fatType()
{
return _fatFs.fatType();
}

private:
Sd2Card _card;
SdFatFs _fatFs;
Expand Down
18 changes: 14 additions & 4 deletions src/SdFatFs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,24 @@ bool SdFatFs::deinit(void)

uint8_t SdFatFs::fatType(void)
{
uint8_t fatType = FAT_TYPE_UNK;
switch (_SDFatFs.fs_type) {
#if defined(FS_EXFAT)
case FS_EXFAT:
fatType = FAT_TYPE_EXFAT;
break;
#endif
case FS_FAT12:
return 12;
fatType = FAT_TYPE_FAT12;
break;
case FS_FAT16:
return 16;
fatType = FAT_TYPE_FAT16;
break;
case FS_FAT32:
return 32;
fatType = FAT_TYPE_FAT32;
break;
default:
return 0;
fatType = FAT_TYPE_UNK;
}
return fatType;
}
9 changes: 9 additions & 0 deletions src/SdFatFs.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
/* FatFs includes component */
#include "FatFs.h"

/* Filesystem type (FATFS.fs_type) */
#define FAT_TYPE_FAT12 12 // FS_FAT12
#define FAT_TYPE_FAT16 16 // FS_FAT16
#define FAT_TYPE_FAT32 32 // FS_FAT32
#if defined(FS_EXFAT)
#define FAT_TYPE_EXFAT 64 // FS_EXFAT
#endif
#define FAT_TYPE_UNK 0 // Unknown

/* To match Arduino definition*/
#define FILE_WRITE FA_WRITE
#define FILE_READ FA_READ
Expand Down
2 changes: 1 addition & 1 deletion src/ffconf_default_68300.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
/ buffer in the file system object (FATFS) is used for the file data transfer. */


#define _FS_EXFAT 0
#define _FS_EXFAT 1
/* This option switches support of exFAT file system. (0:Disable or 1:Enable)
/ When enable exFAT, also LFN needs to be enabled. (_USE_LFN >= 1)
/ Note that enabling exFAT discards C89 compatibility. */
Expand Down
2 changes: 1 addition & 1 deletion src/ffconf_default_80286.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
/ buffer in the filesystem object (FATFS) is used for the file data transfer. */


#define FF_FS_EXFAT 0
#define FF_FS_EXFAT 1
/* This option switches support for exFAT filesystem. (0:Disable or 1:Enable)
/ To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1)
/ Note that enabling exFAT discards ANSI C (C89) compatibility. */
Expand Down