aboutsummaryrefslogtreecommitdiffstats
path: root/src/gfile/gfile_fs_chibios.c
diff options
context:
space:
mode:
authorinmarket <andrewh@inmarket.com.au>2014-08-20 17:44:40 +1000
committerinmarket <andrewh@inmarket.com.au>2014-08-20 17:44:40 +1000
commit2b47a0708602b45b0b5db120a496bf92232aa4b1 (patch)
tree6c5965b6bf1d109b853efe64777bbc7ee5548882 /src/gfile/gfile_fs_chibios.c
parentc06bff3304ed234c3a7f96fd049755ac59228ef7 (diff)
parent0f3f8f68f87233bf59c3fa68c3dfe1f492a1a478 (diff)
downloaduGFX-2b47a0708602b45b0b5db120a496bf92232aa4b1.tar.gz
uGFX-2b47a0708602b45b0b5db120a496bf92232aa4b1.tar.bz2
uGFX-2b47a0708602b45b0b5db120a496bf92232aa4b1.zip
Merge branch 'master' into newmouse
Diffstat (limited to 'src/gfile/gfile_fs_chibios.c')
-rw-r--r--src/gfile/gfile_fs_chibios.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/gfile/gfile_fs_chibios.c b/src/gfile/gfile_fs_chibios.c
new file mode 100644
index 00000000..72826e28
--- /dev/null
+++ b/src/gfile/gfile_fs_chibios.c
@@ -0,0 +1,68 @@
+/*
+ * 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
+ */
+
+/********************************************************
+ * The ChibiOS BaseFileStream file-system
+ ********************************************************/
+
+#include "gfx.h"
+
+#if GFX_USE_GFILE && GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS
+
+#include "gfile_fs.h"
+
+static void ChibiOSBFSClose(GFILE *f);
+static int ChibiOSBFSRead(GFILE *f, void *buf, int size);
+static int ChibiOSBFSWrite(GFILE *f, const void *buf, int size);
+static bool_t ChibiOSBFSSetpos(GFILE *f, long int pos);
+static long int ChibiOSBFSGetsize(GFILE *f);
+static bool_t ChibiOSBFSEof(GFILE *f);
+
+static const GFILEVMT FsCHIBIOSVMT = {
+ GFSFLG_SEEKABLE|GFSFLG_WRITEABLE, // flags
+ 0, // prefix
+ 0, 0, 0, 0,
+ 0, ChibiOSBFSClose, ChibiOSBFSRead, ChibiOSBFSWrite,
+ ChibiOSBFSSetpos, ChibiOSBFSGetsize, ChibiOSBFSEof,
+ 0, 0, 0,
+ #if GFILE_NEED_FILELISTS
+ 0, 0, 0,
+ #endif
+};
+
+static void ChibiOSBFSClose(GFILE *f) {
+ chFileStreamClose(((BaseFileStream *)f->obj));
+}
+static int ChibiOSBFSRead(GFILE *f, void *buf, int size) {
+ return chSequentialStreamRead(((BaseFileStream *)f->obj), (uint8_t *)buf, size);
+}
+static int ChibiOSBFSWrite(GFILE *f, const void *buf, int size) {
+ return chSequentialStreamWrite(((BaseFileStream *)f->obj), (uint8_t *)buf, size);
+}
+static bool_t ChibiOSBFSSetpos(GFILE *f, long int pos) {
+ chFileStreamSeek(((BaseFileStream *)f->obj), pos);
+ return TRUE;
+}
+static long int ChibiOSBFSGetsize(GFILE *f) { return chFileStreamGetSize(((BaseFileStream *)f->obj)); }
+static bool_t ChibiOSBFSEof(GFILE *f) { return f->pos >= chFileStreamGetSize(((BaseFileStream *)f->obj)); }
+
+GFILE * gfileOpenBaseFileStream(void *BaseFileStreamPtr, const char *mode) {
+ GFILE * f;
+
+ // Get an empty file and set the flags
+ if (!(f = _gfileFindSlot(mode)))
+ return 0;
+
+ // File is open - fill in all the details
+ f->vmt = &FsCHIBIOSVMT;
+ f->obj = BaseFileStreamPtr;
+ f->pos = 0;
+ f->flags |= GFILEFLG_OPEN|GFILEFLG_CANSEEK;
+ return f;
+}
+
+#endif //GFX_USE_GFILE && GFILE_NEED_CHIBIOSFS && GFX_USE_OS_CHIBIOS