mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-09-11 13:55:59 +03:00
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.
This commit is contained in:
parent
ce2277cbca
commit
9bbd2ddbc4
@ -45,7 +45,6 @@ void FS::Init() {
|
||||
|
||||
#ifndef PINETIME_IS_RECOVERY
|
||||
VerifyResource();
|
||||
LVGLFileSystemInit();
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -139,65 +138,3 @@ int FS::SectorRead(const struct lfs_config* c, lfs_block_t block, lfs_off_t off,
|
||||
lfs.flashDriver.Read(address, static_cast<uint8_t*>(buffer), size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
----------- LVGL filesystem integration -----------
|
||||
|
||||
*/
|
||||
|
||||
namespace {
|
||||
lv_fs_res_t lvglOpen(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t /*mode*/) {
|
||||
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
|
||||
FS* filesys = static_cast<FS*>(drv->user_data);
|
||||
int res = filesys->FileOpen(file, path, LFS_O_RDONLY);
|
||||
if (res == 0) {
|
||||
if (file->type == 0) {
|
||||
return LV_FS_RES_FS_ERR;
|
||||
} else {
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
}
|
||||
return LV_FS_RES_NOT_EX;
|
||||
}
|
||||
|
||||
lv_fs_res_t lvglClose(lv_fs_drv_t* drv, void* file_p) {
|
||||
FS* filesys = static_cast<FS*>(drv->user_data);
|
||||
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
|
||||
filesys->FileClose(file);
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
lv_fs_res_t lvglRead(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br) {
|
||||
FS* filesys = static_cast<FS*>(drv->user_data);
|
||||
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
|
||||
filesys->FileRead(file, static_cast<uint8_t*>(buf), btr);
|
||||
*br = btr;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
lv_fs_res_t lvglSeek(lv_fs_drv_t* drv, void* file_p, uint32_t pos) {
|
||||
FS* filesys = static_cast<FS*>(drv->user_data);
|
||||
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
|
||||
filesys->FileSeek(file, pos);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
}
|
||||
|
||||
void FS::LVGLFileSystemInit() {
|
||||
|
||||
lv_fs_drv_t fs_drv;
|
||||
lv_fs_drv_init(&fs_drv);
|
||||
|
||||
fs_drv.file_size = sizeof(lfs_file_t);
|
||||
fs_drv.letter = 'F';
|
||||
fs_drv.open_cb = lvglOpen;
|
||||
fs_drv.close_cb = lvglClose;
|
||||
fs_drv.read_cb = lvglRead;
|
||||
fs_drv.seek_cb = lvglSeek;
|
||||
|
||||
fs_drv.user_data = this;
|
||||
|
||||
lv_fs_drv_register(&fs_drv);
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ namespace Pinetime {
|
||||
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);
|
||||
|
@ -91,7 +91,7 @@ DisplayApp::DisplayApp(Drivers::St7789& lcd,
|
||||
brightnessController {brightnessController},
|
||||
touchHandler {touchHandler},
|
||||
filesystem {filesystem},
|
||||
lvgl {lcd} {
|
||||
lvgl {lcd, filesystem} {
|
||||
}
|
||||
|
||||
void DisplayApp::Start(System::BootErrors error) {
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
#include "drivers/St7789.h"
|
||||
#include "littlefs/lfs.h"
|
||||
#include "components/fs/FS.h"
|
||||
|
||||
using namespace Pinetime::Components;
|
||||
|
||||
@ -12,6 +14,43 @@ namespace {
|
||||
lv_theme_t* theme = lv_pinetime_theme_init();
|
||||
lv_theme_set_act(theme);
|
||||
}
|
||||
|
||||
lv_fs_res_t lvglOpen(lv_fs_drv_t* drv, void* file_p, const char* path, lv_fs_mode_t /*mode*/) {
|
||||
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
|
||||
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
|
||||
int res = filesys->FileOpen(file, path, LFS_O_RDONLY);
|
||||
if (res == 0) {
|
||||
if (file->type == 0) {
|
||||
return LV_FS_RES_FS_ERR;
|
||||
} else {
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
}
|
||||
return LV_FS_RES_NOT_EX;
|
||||
}
|
||||
|
||||
lv_fs_res_t lvglClose(lv_fs_drv_t* drv, void* file_p) {
|
||||
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
|
||||
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
|
||||
filesys->FileClose(file);
|
||||
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
lv_fs_res_t lvglRead(lv_fs_drv_t* drv, void* file_p, void* buf, uint32_t btr, uint32_t* br) {
|
||||
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
|
||||
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
|
||||
filesys->FileRead(file, static_cast<uint8_t*>(buf), btr);
|
||||
*br = btr;
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
|
||||
lv_fs_res_t lvglSeek(lv_fs_drv_t* drv, void* file_p, uint32_t pos) {
|
||||
Pinetime::Controllers::FS* filesys = static_cast<Pinetime::Controllers::FS*>(drv->user_data);
|
||||
lfs_file_t* file = static_cast<lfs_file_t*>(file_p);
|
||||
filesys->FileSeek(file, pos);
|
||||
return LV_FS_RES_OK;
|
||||
}
|
||||
}
|
||||
|
||||
static void disp_flush(lv_disp_drv_t* disp_drv, const lv_area_t* area, lv_color_t* color_p) {
|
||||
@ -34,7 +73,7 @@ bool touchpad_read(lv_indev_drv_t* indev_drv, lv_indev_data_t* data) {
|
||||
return lvgl->GetTouchPadInfo(data);
|
||||
}
|
||||
|
||||
LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd) : lcd {lcd} {
|
||||
LittleVgl::LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Controllers::FS& filesystem) : lcd {lcd}, filesystem {filesystem} {
|
||||
}
|
||||
|
||||
void LittleVgl::Init() {
|
||||
@ -42,6 +81,7 @@ void LittleVgl::Init() {
|
||||
InitTheme();
|
||||
InitDisplay();
|
||||
InitTouchpad();
|
||||
InitFileSystem();
|
||||
}
|
||||
|
||||
void LittleVgl::InitDisplay() {
|
||||
@ -75,6 +115,22 @@ void LittleVgl::InitTouchpad() {
|
||||
lv_indev_drv_register(&indev_drv);
|
||||
}
|
||||
|
||||
void LittleVgl::InitFileSystem() {
|
||||
lv_fs_drv_t fs_drv;
|
||||
lv_fs_drv_init(&fs_drv);
|
||||
|
||||
fs_drv.file_size = sizeof(lfs_file_t);
|
||||
fs_drv.letter = 'F';
|
||||
fs_drv.open_cb = lvglOpen;
|
||||
fs_drv.close_cb = lvglClose;
|
||||
fs_drv.read_cb = lvglRead;
|
||||
fs_drv.seek_cb = lvglSeek;
|
||||
|
||||
fs_drv.user_data = &filesystem;
|
||||
|
||||
lv_fs_drv_register(&fs_drv);
|
||||
}
|
||||
|
||||
void LittleVgl::SetFullRefresh(FullRefreshDirections direction) {
|
||||
if (scrollDirection == FullRefreshDirections::None) {
|
||||
scrollDirection = direction;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <components/fs/FS.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Drivers {
|
||||
@ -11,7 +12,7 @@ namespace Pinetime {
|
||||
class LittleVgl {
|
||||
public:
|
||||
enum class FullRefreshDirections { None, Up, Down, Left, Right, LeftAnim, RightAnim };
|
||||
LittleVgl(Pinetime::Drivers::St7789& lcd);
|
||||
LittleVgl(Pinetime::Drivers::St7789& lcd, Pinetime::Controllers::FS& filesystem);
|
||||
|
||||
LittleVgl(const LittleVgl&) = delete;
|
||||
LittleVgl& operator=(const LittleVgl&) = delete;
|
||||
@ -37,8 +38,10 @@ namespace Pinetime {
|
||||
private:
|
||||
void InitDisplay();
|
||||
void InitTouchpad();
|
||||
void InitFileSystem();
|
||||
|
||||
Pinetime::Drivers::St7789& lcd;
|
||||
Pinetime::Controllers::FS& filesystem;
|
||||
|
||||
lv_disp_buf_t disp_buf_2;
|
||||
lv_color_t buf2_1[LV_HOR_RES_MAX * 4];
|
||||
|
Loading…
Reference in New Issue
Block a user