Fatfs Cleanup

ugfx_release_2.6
inmarket 2014-06-27 23:04:01 +10:00
parent c2a27f3e7c
commit a9f1520e02
10 changed files with 433 additions and 413 deletions

View File

@ -219,7 +219,7 @@
// #define GFILE_ALLOW_FLOATS FALSE // #define GFILE_ALLOW_FLOATS FALSE
// #define GFILE_ALLOW_DEVICESPECIFIC FALSE // #define GFILE_ALLOW_DEVICESPECIFIC FALSE
// #define GFILE_MAX_GFILES 3 // #define GFILE_MAX_GFILES 3
//#define GFILE_NEED_AUTOMOUNT FALSE //#define GFILE_NEED_NOAUTOMOUNT FALSE
//#define GFILE_NEED_MEMFS FALSE //#define GFILE_NEED_MEMFS FALSE
//#define GFILE_NEED_ROMFS FALSE //#define GFILE_NEED_ROMFS FALSE

View File

@ -0,0 +1,20 @@
/*
* This file is subject to the terms of the GFX License. If a copy of
* the license was not distributed with this file, you can obtain one at:
*
* http://ugfx.org/license.html
*/
/**
* @file src/gfile/fatfs/fatfs.c
* @brief GFILE FATFS wrapper.
*
*/
#include "gfx.h"
#if GFX_USE_GFILE && GFILE_NEED_FATFS
#include "src/ff.c"
#endif // GFX_USE_GFILE && GFILE_NEED_FATFS

View File

@ -1,6 +1,6 @@
GFXSRC += $(GFXLIB)/src/gfile/fatfs/src/ff.c \ GFXSRC += $(GFXLIB)/src/gfile/fatfs/fatfs.c \
$(GFXLIB)/src/gfile/fatfs/src/chibios_fatfs_diskio.c \ $(GFXLIB)/src/gfile/fatfs/fatfs_syscall.c \
$(GFXLIB)/src/gfile/fatfs/src/syscall.c $(GFXLIB)/src/gfile/fatfs/fatfs_chibios_diskio.c
GFXINC += $(GFXLIB)/src/gfile/fatfs/src GFXINC += $(GFXLIB)/src/gfile/fatfs/src

View File

@ -5,8 +5,10 @@
/* disk I/O modules and attach it to FatFs module with common interface. */ /* disk I/O modules and attach it to FatFs module with common interface. */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
#include "ch.h" #include "gfx.h"
#include "hal.h"
#if GFX_USE_GFILE && GFILE_NEED_FATFS && GFX_USE_OS_CHIBIOS
#include "ffconf.h" #include "ffconf.h"
#include "diskio.h" #include "diskio.h"
@ -250,5 +252,6 @@ DWORD get_fattime(void) {
#endif #endif
} }
#endif // GFX_USE_GFILE && GFILE_NEED_FATFS && GFX_USE_OS_CHIBIOS

View File

@ -6,6 +6,9 @@
*/ */
#include "gfx.h" #include "gfx.h"
#if GFX_USE_GFILE && GFILE_NEED_FATFS
#include "ff.h" #include "ff.h"
#if _FS_REENTRANT #if _FS_REENTRANT
@ -73,3 +76,5 @@ void ff_memfree(void *mblock)
} }
#endif /* _USE_LFN == 3 */ #endif /* _USE_LFN == 3 */
#endif // GFX_USE_GFILE && GFILE_NEED_FATFS

View File

@ -477,7 +477,6 @@ bool_t gfileEOF(GFILE *f) {
return f->vmt->eof(f); return f->vmt->eof(f);
} }
#if GFILE_NEED_FATFS
bool_t gfileMount(char fs, const char* drive) { bool_t gfileMount(char fs, const char* drive) {
const GFILEVMT *p; const GFILEVMT *p;
@ -505,7 +504,6 @@ bool_t gfileEOF(GFILE *f) {
} }
return FALSE; return FALSE;
} }
#endif
/******************************************************** /********************************************************
* String VMT routines * String VMT routines

View File

@ -56,20 +56,21 @@ static const GFILEVMT FsFatFSVMT = {
static bool_t fatfs_mounted = FALSE; static bool_t fatfs_mounted = FALSE;
static FATFS fatfs_fs; static FATFS fatfs_fs;
static void _flags2mode(GFILE* f, BYTE* mode) static BYTE fatfs_flags2mode(GFILE* f)
{ {
*mode = 0; BYTE mode = 0;
if (f->flags & GFILEFLG_READ) if (f->flags & GFILEFLG_READ)
*mode |= FA_READ; mode |= FA_READ;
if (f->flags & GFILEFLG_WRITE) if (f->flags & GFILEFLG_WRITE)
*mode |= FA_WRITE; mode |= FA_WRITE;
if (f->flags & GFILEFLG_APPEND) if (f->flags & GFILEFLG_APPEND)
*mode |= 0; // ToDo mode |= 0; // ToDo
if (f->flags & GFILEFLG_TRUNC) if (f->flags & GFILEFLG_TRUNC)
*mode |= FA_CREATE_ALWAYS; mode |= FA_CREATE_ALWAYS;
/* ToDo - Complete */ /* ToDo - Complete */
return mode;
} }
static bool_t fatfsDel(const char* fname) static bool_t fatfsDel(const char* fname)
@ -121,19 +122,16 @@ static bool_t fatfsRename(const char* oldname, const char* newname)
static bool_t fatfsOpen(GFILE* f, const char* fname) static bool_t fatfsOpen(GFILE* f, const char* fname)
{ {
FIL* fd; FIL* fd;
BYTE mode;
FRESULT ferr; #if !GFILE_NEED_NOAUTOMOUNT
/*
if (!fatfs_mounted && !fatfsMount("")) if (!fatfs_mounted && !fatfsMount(""))
return FALSE; return FALSE;
*/ #endif
if (!(fd = gfxAlloc(sizeof(FIL)))) if (!(fd = gfxAlloc(sizeof(FIL))))
return FALSE; return FALSE;
_flags2mode(f, &mode); if (f_open(fd, fname, fatfs_flags2mode(f)) != FR_OK) {
ferr = f_open(fd, fname, mode);
if (ferr != FR_OK) {
gfxFree(fd); gfxFree(fd);
f->obj = 0; f->obj = 0;

View File

@ -51,7 +51,7 @@ static const GFILEVMT FsNativeVMT = {
#undef GFILE_CHAINHEAD #undef GFILE_CHAINHEAD
#define GFILE_CHAINHEAD &FsNativeVMT #define GFILE_CHAINHEAD &FsNativeVMT
static void flags2mode(char *buf, uint16_t flags) { static void Native_flags2mode(char *buf, uint16_t flags) {
if (flags & GFILEFLG_MUSTEXIST) if (flags & GFILEFLG_MUSTEXIST)
*buf = 'r'; *buf = 'r';
else if (flags & GFILEFLG_APPEND) else if (flags & GFILEFLG_APPEND)
@ -90,7 +90,7 @@ static bool_t NativeOpen(GFILE *f, const char *fname) {
FILE *fd; FILE *fd;
char mode[5]; char mode[5];
flags2mode(mode, f->flags); Native_flags2mode(mode, f->flags);
if (!(fd = fopen(fname, mode))) if (!(fd = fopen(fname, mode)))
return FALSE; return FALSE;
f->obj = (void *)fd; f->obj = (void *)fd;

View File

@ -197,15 +197,6 @@ extern "C" {
*/ */
bool_t gfileEOF(GFILE *f); bool_t gfileEOF(GFILE *f);
#if GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS
GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode);
#endif
#if GFILE_NEED_MEMFS
GFILE * gfileOpenMemory(void *memptr, const char *mode);
#endif
#if GFILE_NEED_FATFS
/** /**
* @brief Mount a logical drive (aka partition) * @brief Mount a logical drive (aka partition)
* *
@ -234,6 +225,13 @@ extern "C" {
* @api * @api
*/ */
bool_t gfileUnmount(char fs, const char *drive); bool_t gfileUnmount(char fs, const char *drive);
#if GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS
GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode);
#endif
#if GFILE_NEED_MEMFS
GFILE * gfileOpenMemory(void *memptr, const char *mode);
#endif #endif
#if GFILE_NEED_PRINTG #if GFILE_NEED_PRINTG

View File

@ -21,16 +21,14 @@
* @{ * @{
*/ */
/** /**
* @brief Should the filesystem be mounted automatically * @brief Should the filesystem not be mounted automatically
* @details The filesystem will be mounted automatically if the * @details The filesystem is normally mounted automatically if the
* user does not do it manually. * user does not do it manually. This option turns that off
* so the user must manually mount the file-system first.
* @details Defaults to FALSE * @details Defaults to FALSE
*
* @note Only available for filesystems that actually implement a
* mounting routine.
*/ */
#ifndef GFILE_NEED_AUTOMOUNT #ifndef GFILE_NEED_NOAUTOMOUNT
#define GFILE_NEED_AUTOMOUNT FALSE #define GFILE_NEED_NOAUTOMOUNT FALSE
#endif #endif
/** /**
* @brief Include printg, fprintg etc functions * @brief Include printg, fprintg etc functions