summaryrefslogtreecommitdiff
path: root/src/components/fs/FS.h
diff options
context:
space:
mode:
authorKieran Cawthray <kieranc@gmail.com>2021-07-11 16:04:50 +0200
committerKieran Cawthray <kieranc@gmail.com>2021-07-11 16:04:50 +0200
commitf970dc9993d3d1ff108dbe9a70048571d8a6b53e (patch)
tree1293d181ecf545ff404fbb4eb120ff0b1877241d /src/components/fs/FS.h
parentf5639db8ed48a332eeeed48a359a3323b0537d39 (diff)
parent6a91b83b12ef849f68d54f490153b02f0ecf58dc (diff)
Merge remote-tracking branch 'upstream/develop' into pinetimestyle-colorpicker
Diffstat (limited to 'src/components/fs/FS.h')
-rw-r--r--src/components/fs/FS.h71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/components/fs/FS.h b/src/components/fs/FS.h
new file mode 100644
index 00000000..1f2eb7e0
--- /dev/null
+++ b/src/components/fs/FS.h
@@ -0,0 +1,71 @@
+#pragma once
+
+#include <cstdint>
+#include "drivers/SpiNorFlash.h"
+#include <littlefs/lfs.h>
+
+namespace Pinetime {
+ namespace Controllers {
+ class FS {
+ public:
+ FS(Pinetime::Drivers::SpiNorFlash&);
+
+ void Init();
+ void LVGLFileSystemInit();
+
+ int FileOpen(lfs_file_t* file_p, const char* fileName, const int flags);
+ int FileClose(lfs_file_t* file_p);
+ int FileRead(lfs_file_t* file_p, uint8_t* buff, uint32_t size);
+ int FileWrite(lfs_file_t* file_p, const uint8_t* buff, uint32_t size);
+ int FileSeek(lfs_file_t* file_p, uint32_t pos);
+
+ int FileDelete(const char* fileName);
+
+ int DirCreate(const char* path);
+ int DirDelete(const char* path);
+
+ void VerifyResource();
+
+ private:
+
+ Pinetime::Drivers::SpiNorFlash& flashDriver;
+
+ /*
+ * External Flash MAP (4 MBytes)
+ *
+ * 0x000000 +---------------------------------------+
+ * | Bootloader Assets |
+ * | 256 KBytes |
+ * | |
+ * 0x040000 +---------------------------------------+
+ * | OTA |
+ * | 464 KBytes |
+ * | |
+ * | |
+ * | |
+ * 0x0B4000 +---------------------------------------+
+ * | File System |
+ * | |
+ * | |
+ * | |
+ * | |
+ * 0x400000 +---------------------------------------+
+ *
+ */
+ static constexpr size_t startAddress = 0x0B4000;
+ static constexpr size_t size = 0x3C0000;
+ static constexpr size_t blockSize = 4096;
+
+ bool resourcesValid = false;
+ const struct lfs_config lfsConfig;
+
+ lfs_t lfs;
+
+ static int SectorSync(const struct lfs_config* c);
+ static int SectorErase(const struct lfs_config* c, lfs_block_t block);
+ static int SectorProg(const struct lfs_config* c, lfs_block_t block, lfs_off_t off, const void* buffer, lfs_size_t size);
+ static int SectorRead(const struct lfs_config* c, lfs_block_t block, lfs_off_t off, void* buffer, lfs_size_t size);
+
+ };
+ }
+}