Skip to content

Commit

Permalink
chore(fatfs): support FatFs library 4.0.0
Browse files Browse the repository at this point in the history
based on R0.15.

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
  • Loading branch information
fpistm committed Sep 24, 2024
1 parent 6bdc8fd commit ac3768f
Show file tree
Hide file tree
Showing 3 changed files with 318 additions and 12 deletions.
22 changes: 11 additions & 11 deletions src/SD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ File SDClass::open(const char *filepath, uint8_t mode /* = FA_READ */)
Error_Handler();
}

#if _FATFS == 68300
#if (_FATFS == 68300) || (_FATFS == 80286)
file._fil->obj.fs = 0;
file._dir.obj.fs = 0;
#else
Expand Down Expand Up @@ -209,7 +209,7 @@ void File::ls(uint8_t flags, uint8_t indent)
char *fn;

#if _USE_LFN
#if _FATFS == 68300
#if (_FATFS == 68300) || (_FATFS == 80286)
/* altname */
#else
static char lfn[_MAX_LFN];
Expand All @@ -226,7 +226,7 @@ void File::ls(uint8_t flags, uint8_t indent)
if (fno.fname[0] == '.') {
continue;
}
#if _USE_LFN && _FATFS != 68300
#if _USE_LFN && (_FATFS != 68300 && _FATFS != 80286)
fn = *fno.lfname ? fno.lfname : fno.fname;
#else
fn = fno.fname;
Expand Down Expand Up @@ -360,7 +360,7 @@ int File::read(void *buf, size_t len)
void File::close()
{
if (_name) {
#if _FATFS == 68300
#if (_FATFS == 68300) || (_FATFS == 80286)
if (_fil) {
if (_fil->obj.fs != 0) {
#else
Expand All @@ -377,7 +377,7 @@ void File::close()
_fil = NULL;
}

#if _FATFS == 68300
#if (_FATFS == 68300) || (_FATFS == 80286)
if (_dir.obj.fs != 0) {
#else
if (_dir.fs != 0) {
Expand Down Expand Up @@ -459,7 +459,7 @@ uint32_t File::size()

File::operator bool()
{
#if _FATFS == 68300
#if (_FATFS == 68300) || (_FATFS == 80286)
return !((_name == NULL) || ((_fil == NULL) && (_dir.obj.fs == 0)) || ((_fil != NULL) && (_fil->obj.fs == 0) && (_dir.obj.fs == 0)));
#else
return !((_name == NULL) || ((_fil == NULL) && (_dir.fs == 0)) || ((_fil != NULL) && (_fil->fs == 0) && (_dir.fs == 0)));
Expand Down Expand Up @@ -523,13 +523,13 @@ bool File::isDirectory()
if (_name == NULL) {
Error_Handler();
}
#if _FATFS == 68300
#if (_FATFS == 68300) || (_FATFS == 80286)
if (_dir.obj.fs != 0)
#else
if (_dir.fs != 0)
#endif
return true;
#if _FATFS == 68300
#if (_FATFS == 68300) || (_FATFS == 80286)
else if (_fil->obj.fs != 0)
#else
else if (_fil->fs != 0)
Expand All @@ -550,7 +550,7 @@ File File::openNextFile(uint8_t mode)
FRESULT res = FR_OK;
FILINFO fno;
char *fn;
#if _USE_LFN && _FATFS != 68300
#if _USE_LFN && (_FATFS != 68300 && _FATFS != 80286)
static char lfn[_MAX_LFN];
fno.lfname = lfn;
fno.lfsize = sizeof(lfn);
Expand All @@ -563,7 +563,7 @@ File File::openNextFile(uint8_t mode)
if (fno.fname[0] == '.') {
continue;
}
#if _USE_LFN && _FATFS != 68300
#if _USE_LFN && (_FATFS != 68300 && _FATFS != 80286)
fn = *fno.lfname ? fno.lfname : fno.fname;
#else
fn = fno.fname;
Expand All @@ -589,7 +589,7 @@ File File::openNextFile(uint8_t mode)
void File::rewindDirectory(void)
{
if (isDirectory()) {
#if _FATFS == 68300
#if (_FATFS == 68300) || (_FATFS == 80286)
if (_dir.obj.fs != 0) {
#else
if (_dir.fs != 0) {
Expand Down
12 changes: 11 additions & 1 deletion src/ffconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@
#if __has_include("ffconf_custom.h")
#include "ffconf_custom.h"
#else
#if _FATFS == 68300
#if defined(FF_DEFINED) && !defined(_FATFS)
#define _FATFS FF_DEFINED
#endif

#if _FATFS == 80286
/* Ensure backward compatibility with release prior to FatFs 0.14 */
/* Those flags are */
#define _USE_WRITE 1
#define _USE_IOCTL 1
#include "ffconf_default_80286.h"
#elif _FATFS == 68300
#include "ffconf_default_68300.h"
#else
#include "ffconf_default_32020.h"
Expand Down
Loading

0 comments on commit ac3768f

Please sign in to comment.