update font loader to the new FS API

This commit is contained in:
Gabor Kiss-Vamosi
2020-09-02 10:25:46 +02:00
parent 7cf51010b0
commit 572974b5e0
3 changed files with 35 additions and 32 deletions

View File

@@ -28,23 +28,21 @@ int main(void)
#if LV_USE_FILESYSTEM
static lv_fs_res_t open_cb(struct _lv_fs_drv_t * drv, void * file_p, const char * path, lv_fs_mode_t mode)
static void * open_cb(struct _lv_fs_drv_t * drv, const char * path, lv_fs_mode_t mode)
{
(void) drv;
(void) mode;
FILE * fp = fopen(path, "rb"); // only reading is supported
*((FILE **)file_p) = fp;
return NULL == fp ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
return fp;
}
static lv_fs_res_t close_cb(struct _lv_fs_drv_t * drv, void * file_p)
{
(void) drv;
FILE * fp = *((FILE **) file_p);
fclose(fp);
fclose(file_p);
return LV_FS_RES_OK;
}
@@ -52,17 +50,30 @@ static lv_fs_res_t read_cb(struct _lv_fs_drv_t * drv, void * file_p, void * buf,
{
(void) drv;
FILE * fp = *((FILE **) file_p);
*br = fread(buf, 1, btr, fp);
*br = fread(buf, 1, btr, file_p);
return (*br <= 0) ? LV_FS_RES_UNKNOWN : LV_FS_RES_OK;
}
static lv_fs_res_t seek_cb(struct _lv_fs_drv_t * drv, void * file_p, uint32_t pos)
static lv_fs_res_t seek_cb(struct _lv_fs_drv_t * drv, void * file_p, uint32_t pos, lv_fs_whence_t w)
{
(void) drv;
FILE * fp = *((FILE **) file_p);
fseek (fp, pos, SEEK_SET);
uint32_t w2;
switch(w) {
case LV_FS_SEEK_SET:
w2 = SEEK_SET;
break;
case LV_FS_SEEK_CUR:
w2 = SEEK_CUR;
break;
case LV_FS_SEEK_END:
w2 = SEEK_END;
break;
default:
w2 = SEEK_SET;
}
fseek (file_p, pos, w2);
return LV_FS_RES_OK;
}
@@ -71,17 +82,11 @@ static lv_fs_res_t tell_cb(struct _lv_fs_drv_t * drv, void * file_p, uint32_t *
{
(void) drv;
FILE * fp = *((FILE **) file_p);
*pos_p = ftell(fp);
*pos_p = ftell(file_p);
return LV_FS_RES_OK;
}
static bool ready_cb(struct _lv_fs_drv_t * drv)
{
(void) drv;
return true;
}
#endif
static void hal_init(void)
@@ -101,9 +106,7 @@ static void hal_init(void)
lv_fs_drv_t drv;
lv_fs_drv_init(&drv); /*Basic initialization*/
drv.letter = 'f'; /*An uppercase letter to identify the drive */
drv.file_size = sizeof(FILE *); /*Size required to store a file object*/
drv.ready_cb = ready_cb; /*Callback to tell if the drive is ready to use */
drv.letter = 'F'; /*An uppercase letter to identify the drive */
drv.open_cb = open_cb; /*Callback to open a file */
drv.close_cb = close_cb; /*Callback to close a file */
drv.read_cb = read_cb; /*Callback to read a file */