Support ChibiOS V3 changes to the FileStream API
This commit is contained in:
parent
865b7887d0
commit
84ae564bfc
3 changed files with 26 additions and 14 deletions
|
@ -307,20 +307,21 @@ extern "C" {
|
||||||
|
|
||||||
#if (GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS) || defined(__DOXYGEN__)
|
#if (GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS) || defined(__DOXYGEN__)
|
||||||
/**
|
/**
|
||||||
* @brief Open file from a ChibiOS BaseFileStream
|
* @brief Open file from a ChibiOS FileStream
|
||||||
*
|
*
|
||||||
* @param[in] BaseFileStreamPtr The BaseFileStream to open as a GFILE
|
* @param[in] FileStreamPtr The BaseFileStream (ChibiOS V2) or FileStream (ChibiOS V3) to open as a GFILE
|
||||||
* @param[in] mode The mode.
|
* @param[in] mode The mode.
|
||||||
*
|
*
|
||||||
* @return Valid GFILE on success, 0 otherwise
|
* @return Valid GFILE on success, 0 otherwise
|
||||||
*
|
*
|
||||||
* @note The modes are the same modes as in @p gfileOpen(). The
|
* @note The modes are the same modes as in @p gfileOpen(). The
|
||||||
* open mode is NOT compared against the BaseFileStream capabilities.
|
* open mode is NOT compared against the FileStream capabilities.
|
||||||
* @note Supported operations are: read, write, getpos, setpos, eof and getsize
|
* @note Supported operations are: read, write, getpos, setpos, eof and getsize
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode);
|
GFILE * gfileOpenChibiOSFileStream(void *FileStreamPtr, const char *mode);
|
||||||
|
#define gfileOpenBaseFileStream(f,m) gfileOpenChibiOSFileStream(f,m)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GFILE_NEED_MEMFS || defined(__DOXYGEN__)
|
#if GFILE_NEED_MEMFS || defined(__DOXYGEN__)
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/********************************************************
|
/********************************************************
|
||||||
* The ChibiOS BaseFileStream file-system
|
* The ChibiOS FileStream file-system
|
||||||
********************************************************/
|
********************************************************/
|
||||||
|
|
||||||
#include "gfx.h"
|
#include "gfx.h"
|
||||||
|
@ -34,23 +34,32 @@ static const GFILEVMT FsCHIBIOSVMT = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if CH_KERNEL_MAJOR == 2
|
||||||
|
#define FileStream BaseFileStream
|
||||||
|
#define fileStreamClose chFileStreamClose
|
||||||
|
#define fileStreamRead chSequentialStreamRead
|
||||||
|
#define fileStreamWrite chSequentialStreamWrite
|
||||||
|
#define fileStreamSeek chFileStreamSeek
|
||||||
|
#define fileStreamGetSize chFileStreamGetSize
|
||||||
|
#endif
|
||||||
|
|
||||||
static void ChibiOSBFSClose(GFILE *f) {
|
static void ChibiOSBFSClose(GFILE *f) {
|
||||||
chFileStreamClose(((BaseFileStream *)f->obj));
|
fileStreamClose(((FileStream *)f->obj));
|
||||||
}
|
}
|
||||||
static int ChibiOSBFSRead(GFILE *f, void *buf, int size) {
|
static int ChibiOSBFSRead(GFILE *f, void *buf, int size) {
|
||||||
return chSequentialStreamRead(((BaseFileStream *)f->obj), (uint8_t *)buf, size);
|
return fileStreamRead(((FileStream *)f->obj), (uint8_t *)buf, size);
|
||||||
}
|
}
|
||||||
static int ChibiOSBFSWrite(GFILE *f, const void *buf, int size) {
|
static int ChibiOSBFSWrite(GFILE *f, const void *buf, int size) {
|
||||||
return chSequentialStreamWrite(((BaseFileStream *)f->obj), (uint8_t *)buf, size);
|
return fileStreamWrite(((FileStream *)f->obj), (uint8_t *)buf, size);
|
||||||
}
|
}
|
||||||
static bool_t ChibiOSBFSSetpos(GFILE *f, long int pos) {
|
static bool_t ChibiOSBFSSetpos(GFILE *f, long int pos) {
|
||||||
chFileStreamSeek(((BaseFileStream *)f->obj), pos);
|
fileStreamSeek(((FileStream *)f->obj), pos);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
static long int ChibiOSBFSGetsize(GFILE *f) { return chFileStreamGetSize(((BaseFileStream *)f->obj)); }
|
static long int ChibiOSBFSGetsize(GFILE *f) { return fileStreamGetSize(((FileStream *)f->obj)); }
|
||||||
static bool_t ChibiOSBFSEof(GFILE *f) { return f->pos >= chFileStreamGetSize(((BaseFileStream *)f->obj)); }
|
static bool_t ChibiOSBFSEof(GFILE *f) { return f->pos >= fileStreamGetSize(((FileStream *)f->obj)); }
|
||||||
|
|
||||||
GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode) {
|
GFILE * gfileOpenChibiOSFileStream(void *FileStreamPtr, const char *mode) {
|
||||||
GFILE * f;
|
GFILE * f;
|
||||||
|
|
||||||
// Get an empty file and set the flags
|
// Get an empty file and set the flags
|
||||||
|
@ -59,7 +68,7 @@ GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode) {
|
||||||
|
|
||||||
// File is open - fill in all the details
|
// File is open - fill in all the details
|
||||||
f->vmt = &FsCHIBIOSVMT;
|
f->vmt = &FsCHIBIOSVMT;
|
||||||
f->obj = BaseFileStreamPtr;
|
f->obj = FileStreamPtr;
|
||||||
f->pos = 0;
|
f->pos = 0;
|
||||||
f->flags |= GFILEFLG_OPEN|GFILEFLG_CANSEEK;
|
f->flags |= GFILEFLG_OPEN|GFILEFLG_CANSEEK;
|
||||||
return f;
|
return f;
|
||||||
|
|
|
@ -28,7 +28,9 @@
|
||||||
#if !CH_CFG_USE_SEMAPHORES
|
#if !CH_CFG_USE_SEMAPHORES
|
||||||
#error "GOS: CH_CFG_USE_SEMAPHORES must be defined in chconf.h"
|
#error "GOS: CH_CFG_USE_SEMAPHORES must be defined in chconf.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#else
|
||||||
|
#error "GOS: Unsupported version of ChibiOS"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void _gosInit(void)
|
void _gosInit(void)
|
||||||
|
|
Loading…
Add table
Reference in a new issue