How to use the File Explorer with embedded FS like MicroSd

  1. Port filesystem in esp-idf, example(I usually use fatfs): https://github.com/espressif/esp-idf/tree/master/examples/storage/ext_flash_fatfs
  2. open filesystem in lv_conf.h(idf.py menuconfig):
#define LV_USE_FS_FATFS 1
#if LV_USE_FS_FATFS
    #define LV_FS_FATFS_LETTER 'A'     /* Important! Set an upper cased letter on which the drive will accessible (e.g. 'A')*/
    #define LV_FS_FATFS_CACHE_SIZE 0    /*>0 to cache this number of bytes in lv_fs_read()*/
#endif
  1. File system test:
lv_fs_read_file("A:/lv_fs_test.txt");

static void lv_fs_read_file(char * fn)
{
	lv_fs_file_t f;
	lv_fs_res_t res;

	//   LV_FS_MODE_RD or  LV_FS_MODE_WR
	res = lv_fs_open(&f, fn, LV_FS_MODE_RD);

	if(res != LV_FS_RES_OK) {
		LV_LOG_USER("Open error! Error code: %d", res);
		return;
	}

	uint32_t read_num;
	uint8_t buf[8];

	while (1) {
		res = lv_fs_read(&f, buf, 8, &read_num);
		if(res != LV_FS_RES_OK) {
			LV_LOG_USER("Read error! Error code: %d", res);
			break;
		}

		//printf("%s", buf);
                LV_LOG_USER("%s", buf);

		if (read_num != 8)	break;
	}

	lv_fs_close(&f);
}
  1. Test lv_ file_explorer example:
{
    lv_obj_t * file_explorer = lv_file_explorer_create(lv_screen_active());
    lv_file_explorer_open_dir(file_explorer, "A:/");
}

Important Notes

1 Like