12
12
#include < display/display_coro_compact_gc9a01.hpp>
13
13
#include < display/display_spi_common_coro.hpp>
14
14
#include < logger/logger_service.hpp>
15
+ #include < utils/CoroUtils.hpp>
15
16
16
17
#include < backends/spi_backend_desktop.hpp>
17
18
#include < spi/spi_wrapper_async_templated.hpp>
18
19
19
20
#include " st7789_draft.hpp"
20
21
22
+ #include < lfs.h>
23
+
21
24
CoroUtils::Task<int > coroutineTask ()
22
25
{
23
26
int b = 32 ;
@@ -31,6 +34,106 @@ void showFlashDeviceId()
31
34
int testValue = co_await task;
32
35
}
33
36
37
+ namespace Internals ::Fs
38
+ {
39
+
40
+ class FilesystemPasskey
41
+ {
42
+ friend class File ;
43
+ friend class Holder ;
44
+
45
+ private:
46
+ FilesystemPasskey ()
47
+ {
48
+ }
49
+ FilesystemPasskey (const FilesystemPasskey&) = default ;
50
+ FilesystemPasskey& operator =(const FilesystemPasskey&) = delete ;
51
+ };
52
+
53
+ class File
54
+ {
55
+ public:
56
+ explicit File (lfs_file_t fileHandle) : m_pFileHandle{fileHandle}
57
+ {
58
+ }
59
+ ~File ()
60
+ {
61
+ Holder::Instance ().close (this );
62
+ }
63
+ CoroUtils::VoidTask write (std::span<const std::uint8_t > dataHolder)
64
+ {
65
+ co_return ;
66
+ }
67
+
68
+ CoroUtils::Task<std::span<std::uint8_t >> read (std::size_t dataSize)
69
+ {
70
+ co_return {};
71
+ }
72
+
73
+ lfs_file_t nativeHandle (const FilesystemPasskey& passkey)
74
+ {
75
+ Meta::UnuseVar (passkey);
76
+ return m_pFileHandle;
77
+ }
78
+
79
+ private:
80
+ lfs_file_t m_pFileHandle;
81
+ };
82
+ class Holder
83
+ {
84
+ public:
85
+ static Holder& Instance ()
86
+ {
87
+ static Holder fsHolder{};
88
+ return fsHolder;
89
+ }
90
+
91
+ CoroUtils::Task<File> openFile (std::string_view path)
92
+ {
93
+ lfs_file_t file{};
94
+ lfs_file_open (&m_fsInstance, &file, " boot_count" , LFS_O_RDWR | LFS_O_CREAT);
95
+ co_return File{file};
96
+ }
97
+
98
+ void close (File* pFile)
99
+ {
100
+ assert (pFile);
101
+ if (!pFile)
102
+ return ;
103
+ auto nativeHandle = pFile->nativeHandle (FilesystemPasskey{});
104
+ lfs_file_close (&m_fsInstance, &nativeHandle);
105
+ }
106
+
107
+ private:
108
+ static constexpr inline lfs_config fsConfig{};
109
+
110
+ private:
111
+ Holder ()
112
+ {
113
+ auto error = lfs_mount (&m_fsInstance, &fsConfig);
114
+ if (error)
115
+ {
116
+ lfs_format (&m_fsInstance, &fsConfig);
117
+ lfs_mount (&m_fsInstance, &fsConfig);
118
+ }
119
+ }
120
+
121
+ private:
122
+ lfs_t m_fsInstance;
123
+ };
124
+ } // namespace Internals::Fs
125
+
126
+ CoroUtils::VoidTask fileTest ()
127
+ {
128
+ auto file = co_await Internals::Fs::Holder::Instance ().openFile (" test.txt" );
129
+ constexpr auto kFileData = std::string_view (" Hello world!" );
130
+ co_await file.write (
131
+ {reinterpret_cast <const std::uint8_t *>(kFileData .data ()), kFileData .size ()});
132
+ auto data = co_await file.read (kFileData .size ());
133
+
134
+ std::cout << std::string_view (reinterpret_cast <const char *>(data.data ()), data.size ());
135
+ }
136
+
34
137
int main ()
35
138
{
36
139
using TSpiBus = Interface::SpiTemplated::SpiBus<Interface::SpiTemplated::SpiBusDesktopBackend>;
@@ -42,6 +145,7 @@ int main()
42
145
TDisplayDriver compactGc9A01;
43
146
compactGc9A01.fillRectangle (0 , 0 , 0 , 0 , nullptr );
44
147
compactGc9A01.initialize ();
148
+
45
149
// ST7789Coroutine displayCoro{
46
150
// Interface::Spi::createSpiBusAsync<Interface::Spi::SpiInstance::M1>()
47
151
// , 240
0 commit comments