[Request] lvgl's filesystem for ESP32's SPIFFS?

Description

I would like to use a binary image-source that placed on ESP32’s SPIFFS.
However lvgl needs to create lvgl’s filesystem first.

I have read from the manual, but I don’t know about file and filesystem much
to link between ESP32’ SPIFFS to lvgl’s filesystem by drive-letter F: .

Wish lvgl has the code for SPIFFS’s filesystem too.

Thank you very much.

I have tried to implement spiffs_dir_open(..) , spiffs_dir_read(..) and spiffs_dir_clos(...) for SPIFFS’s filesystem as the following code.

When I call lv_fs_dir_open(...),
the variable dir_p in spiffs_dir_open(..) can opendir(..) correctly,
but the dir_p seems can’t return to variable rddir_p->dir_d in lv_fs_dir_open(...) (in file lv_fs.c) correctly.

Then when call lv_fs_dir_read(...), the result can’t read correctly too.

How to archieve this issue ?

#include <stdio.h>
#include <stdlib.h> 
#include <dirent.h>

#define DRIVE_LETTER   'F'
typedef   FILE          file_t;
typedef   DIR           dir_t;

void lv_spiffs_if_init() {
  /* Add a simple drive to open images */
  lv_fs_drv_t fs_drv;                         /*A driver descriptor*/
  lv_fs_drv_init(&fs_drv);

  //.....
  fs_drv.rddir_size   = sizeof(dir_t);
  fs_drv.dir_close_cb = spiffs_dir_close;
  fs_drv.dir_open_cb  = spiffs_dir_open;
  fs_drv.dir_read_cb  = spiffs_dir_read;

  lv_fs_drv_register(&fs_drv);
}

// SPIFFS's spiffs_dir_open()
static lv_fs_res_t spiffs_dir_open (lv_fs_drv_t * drv, void * dir_p, const char *path) 
{
  dir_p = opendir(path);
  if(dir_p == NULL)  return LV_FS_RES_UNKNOWN;
  return LV_FS_RES_OK;
}

// SPIFFS's spiffs_dir_read()
static lv_fs_res_t spiffs_dir_read(lv_fs_drv_t * drv, void * dir_p, char *fn) 
{

  if(dir_p == NULL) return LV_FS_RES_UNKNOWN;

  static struct dirent *ent;
  ent = readdir ((dir_t*) dir_p); 

  if(ent){
    fn = ent->d_name;
    return LV_FS_RES_OK;
  }else{
    fn = NULL;
    return LV_FS_RES_UNKNOWN;
  }
}

// SPIFFS's spiffs_dir_close()
static lv_fs_res_t spiffs_dir_close(lv_fs_drv_t * drv, void * dir_p) 
{
  closedir((dir_t*) dir_p);
  return LV_FS_RES_OK;
}

Take a look at the PC implementation of this.

dir_p is just an argument to spiffs_dir_open. All you’re doing right now is changing the value of an argument within the function. What you need to do is store the return value of opendir within the memory pointed to by the dir_p pointer.

1 Like

Thank you very much, it’s a great guildline. I will try.