Skip to content

Commit 9bbd2dd

Browse files
JF002Riksu9000
authored andcommitted
LVGL / FS : Initialize the LVGL FS driver in LittleVgl (instead of FS).
Previously, the LVGL driver for the filesystem was initialized in the class FS. However, since 6f942e2, the order of the initializations was incorrect : the driver was initialized (FS::LVGLFileSystemInit()) before LVGL (LittleVgl.Init()), which means that the driver registration was probably dropped when LVGL was initialized. The LVGL driver is now initialized in LittleVgl.Init(), which seems to make much more sense, since all LVGL drivers are initialized there. This way, we ensure that the initialization of the drivers is consistent.
1 parent ce2277c commit 9bbd2dd

File tree

5 files changed

+62
-67
lines changed

5 files changed

+62
-67
lines changed

src/components/fs/FS.cpp

-63
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ void FS::Init() {
4545

4646
#ifndef PINETIME_IS_RECOVERY
4747
VerifyResource();
48-
LVGLFileSystemInit();
4948
#endif
5049
}
5150

@@ -139,65 +138,3 @@ int FS::SectorRead(const struct lfs_config* c, lfs_block_t block, lfs_off_t off,
139138
lfs.flashDriver.Read(address, static_cast<uint8_t*>(buffer), size);
140139
return 0;
141140
}
142-
143-
/*
144-
145-
----------- LVGL filesystem integration -----------
146-
147-
*/
148-
149-
namespace {
150-
lv_fs_res_t lvglOpen(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t /*mode*/) {
151-
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
152-
FS* filesys = static_cast<FS*>(drv->user_data);
153-
int res = filesys->FileOpen(file, path, LFS_O_RDONLY);
154-
if (res == 0) {
155-
if (file->type == 0) {
156-
return LV_FS_RES_FS_ERR;
157-
} else {
158-
return LV_FS_RES_OK;
159-
}
160-
}
161-
return LV_FS_RES_NOT_EX;
162-
}
163-
164-
lv_fs_res_t lvglClose(lv_fs_drv_t* drv, void* file_p) {
165-
FS* filesys = static_cast<FS*>(drv->user_data);
166-
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
167-
filesys->FileClose(file);
168-
169-
return LV_FS_RES_OK;
170-
}
171-
172-
lv_fs_res_t lvglRead(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br) {
173-
FS* filesys = static_cast<FS*>(drv->user_data);
174-
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
175-
filesys->FileRead(file, static_cast<uint8_t*>(buf), btr);
176-
*br = btr;
177-
return LV_FS_RES_OK;
178-
}
179-
180-
lv_fs_res_t lvglSeek(lv_fs_drv_t* drv, void* file_p, uint32_t pos) {
181-
FS* filesys = static_cast<FS*>(drv->user_data);
182-
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
183-
filesys->FileSeek(file, pos);
184-
return LV_FS_RES_OK;
185-
}
186-
}
187-
188-
void FS::LVGLFileSystemInit() {
189-
190-
lv_fs_drv_t fs_drv;
191-
lv_fs_drv_init(&fs_drv);
192-
193-
fs_drv.file_size = sizeof(lfs_file_t);
194-
fs_drv.letter = 'F';
195-
fs_drv.open_cb = lvglOpen;
196-
fs_drv.close_cb = lvglClose;
197-
fs_drv.read_cb = lvglRead;
198-
fs_drv.seek_cb = lvglSeek;
199-
200-
fs_drv.user_data = this;
201-
202-
lv_fs_drv_register(&fs_drv);
203-
}

src/components/fs/FS.h

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace Pinetime {
1111
FS(Pinetime::Drivers::SpiNorFlash&);
1212

1313
void Init();
14-
void LVGLFileSystemInit();
1514

1615
int FileOpen(lfs_file_t* file_p, const char* fileName, const int flags);
1716
int FileClose(lfs_file_t* file_p);

src/displayapp/DisplayApp.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
9191
brightnessController {brightnessController},
9292
touchHandler {touchHandler},
9393
filesystem {filesystem},
94-
lvgl {lcd} {
94+
lvgl {lcd, filesystem} {
9595
}
9696

9797
void DisplayApp::Start(System::BootErrors error) {

src/displayapp/LittleVgl.cpp

+57-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <FreeRTOS.h>
55
#include <task.h>
66
#include "drivers/St7789.h"
7+
#include "littlefs/lfs.h"
8+
#include "components/fs/FS.h"
79

810
using namespace Pinetime::Components;
911

@@ -12,6 +14,43 @@ namespace {
1214
lv_theme_t* theme = lv_pinetime_theme_init();
1315
lv_theme_set_act(theme);
1416
}
17+
18+
lv_fs_res_t lvglOpen(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t /*mode*/) {
19+
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
20+
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
21+
int res = filesys->FileOpen(file, path, LFS_O_RDONLY);
22+
if (res == 0) {
23+
if (file->type == 0) {
24+
return LV_FS_RES_FS_ERR;
25+
} else {
26+
return LV_FS_RES_OK;
27+
}
28+
}
29+
return LV_FS_RES_NOT_EX;
30+
}
31+
32+
lv_fs_res_t lvglClose(lv_fs_drv_t* drv, void* file_p) {
33+
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
34+
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
35+
filesys->FileClose(file);
36+
37+
return LV_FS_RES_OK;
38+
}
39+
40+
lv_fs_res_t lvglRead(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br) {
41+
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
42+
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
43+
filesys->FileRead(file, static_cast<uint8_t*>(buf), btr);
44+
*br = btr;
45+
return LV_FS_RES_OK;
46+
}
47+
48+
lv_fs_res_t lvglSeek(lv_fs_drv_t* drv, void* file_p, uint32_t pos) {
49+
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
50+
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
51+
filesys->FileSeek(file, pos);
52+
return LV_FS_RES_OK;
53+
}
1554
}
1655

1756
static void disp_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) {
@@ -34,14 +73,15 @@ bool touchpad_read(lv_indev_drv_t* indev_drv, lv_indev_data_t* data) {
3473
return lvgl->GetTouchPadInfo(data);
3574
}
3675

37-
LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd) : lcd {lcd} {
76+
LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Controllers::FS& filesystem) : lcd {lcd}, filesystem {filesystem} {
3877
}
3978

4079
void LittleVgl::Init() {
4180
lv_init();
4281
InitTheme();
4382
InitDisplay();
4483
InitTouchpad();
84+
InitFileSystem();
4585
}
4686

4787
void LittleVgl::InitDisplay() {
@@ -75,6 +115,22 @@ void LittleVgl::InitTouchpad() {
75115
lv_indev_drv_register(&indev_drv);
76116
}
77117

118+
void LittleVgl::InitFileSystem() {
119+
lv_fs_drv_t fs_drv;
120+
lv_fs_drv_init(&fs_drv);
121+
122+
fs_drv.file_size = sizeof(lfs_file_t);
123+
fs_drv.letter = 'F';
124+
fs_drv.open_cb = lvglOpen;
125+
fs_drv.close_cb = lvglClose;
126+
fs_drv.read_cb = lvglRead;
127+
fs_drv.seek_cb = lvglSeek;
128+
129+
fs_drv.user_data = &filesystem;
130+
131+
lv_fs_drv_register(&fs_drv);
132+
}
133+
78134
void LittleVgl::SetFullRefresh(FullRefreshDirections direction) {
79135
if (scrollDirection == FullRefreshDirections::None) {
80136
scrollDirection = direction;

src/displayapp/LittleVgl.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <lvgl/lvgl.h>
4+
#include <components/fs/FS.h>
45

56
namespace Pinetime {
67
namespace Drivers {
@@ -11,7 +12,7 @@ namespace Pinetime {
1112
class LittleVgl {
1213
public:
1314
enum class FullRefreshDirections { None, Up, Down, Left, Right, LeftAnim, RightAnim };
14-
LittleVgl(Pinetime::Drivers::St7789& lcd);
15+
LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Controllers::FS& filesystem);
1516

1617
LittleVgl(const LittleVgl&) = delete;
1718
LittleVgl& operator=(const LittleVgl&) = delete;
@@ -37,8 +38,10 @@ namespace Pinetime {
3738
private:
3839
void InitDisplay();
3940
void InitTouchpad();
41+
void InitFileSystem();
4042

4143
Pinetime::Drivers::St7789& lcd;
44+
Pinetime::Controllers::FS& filesystem;
4245

4346
lv_disp_buf_t disp_buf_2;
4447
lv_color_t buf2_1[LV_HOR_RES_MAX * 4];

0 commit comments

Comments
 (0)