Switch to LittleFS

This commit is contained in:
fvanroie 2021-01-20 18:46:07 +01:00
parent 8adc9ca93f
commit 199dff2c49
2 changed files with 86 additions and 87 deletions

View File

@ -12,30 +12,27 @@
#include "ArduinoLog.h"
#if LV_USE_FS_IF
#if LV_FS_IF_SPIFFS != '\0'
#if LV_FS_IF_SPIFFS != '\0'
#if defined(ARDUINO_ARCH_ESP32)
#if HASP_USE_SPIFFS > 0
#include "SPIFFS.h"
#elif HASP_USE_LITTLEFS > 0
#include "LITTLEFS.h"
#endif
#elif defined(ARDUINO_ARCH_ESP8266)
// included by default
#endif // ARDUINO_ARCH
#if defined(ARDUINO_ARCH_ESP32)
#if HASP_USE_SPIFFS > 0
#include "SPIFFS.h"
#define LV_FS_SPIFFS SPIFFS
#elif HASP_USE_LITTLEFS > 0
#include "LITTLEFS.h"
#define LV_FS_SPIFFS LITTLEFS
#endif
#elif defined(ARDUINO_ARCH_ESP8266)
#include "LittleFS.h"
#define LV_FS_SPIFFS LittleFS
#endif // ARDUINO_ARCH
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include <FS.h>
#include <Esp.h>
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include <FS.h>
#include <Esp.h>
#endif // ARDUINO_ARCH
#if HASP_USE_SPIFFS > 0
#define LV_FS_SPIFFS SPIFFS
#elif HASP_USE_LITTLEFS > 0
#define LV_FS_SPIFFS LITTLEFS
#endif // HASP_USE
#endif // ARDUINO_ARCH
#define TAG_LVFS 91
#define TAG_LVFS 91
/*********************
* DEFINES
@ -48,14 +45,14 @@
/* Create a type to store the required data about your file.*/
typedef File lv_spiffs_file_t;
/*Similarly to `file_t` create a type for directory reading too */
#if defined(ARDUINO_ARCH_ESP32)
/*Similarly to `file_t` create a type for directory reading too */
#if defined(ARDUINO_ARCH_ESP32)
typedef File lv_spiffs_dir_t;
#elif defined(ARDUINO_ARCH_ESP8266)
#elif defined(ARDUINO_ARCH_ESP8266)
typedef Dir lv_spiffs_dir_t;
#define FILE_READ "r"
#define FILE_WRITE "r+"
#endif
#define FILE_READ "r"
#define FILE_WRITE "r+"
#endif
/**********************
* STATIC PROTOTYPES
@ -416,19 +413,19 @@ static lv_fs_res_t fs_free(lv_fs_drv_t * drv, uint32_t * total_p, uint32_t * fre
{
(void)drv; /*Unused*/
#if defined(ARDUINO_ARCH_ESP8266)
#if defined(ARDUINO_ARCH_ESP8266)
FSInfo fs_info;
LV_FS_SPIFFS.info(fs_info);
*total_p = (uint32_t)fs_info.totalBytes;
*free_p = (uint32_t)fs_info.totalBytes - fs_info.usedBytes;
return LV_FS_RES_OK;
#elif defined(ARDUINO_ARCH_ESP32)
#elif defined(ARDUINO_ARCH_ESP32)
*total_p = (uint32_t)LV_FS_SPIFFS.totalBytes();
*free_p = (uint32_t)LV_FS_SPIFFS.totalBytes() - LV_FS_SPIFFS.usedBytes();
return LV_FS_RES_OK;
#endif
#endif
return LV_FS_RES_NOT_IMP;
}
@ -444,16 +441,16 @@ static lv_fs_res_t fs_dir_open(lv_fs_drv_t * drv, void * dir_p, const char * pat
{
lv_spiffs_dir_t dir;
#if defined(ARDUINO_ARCH_ESP32)
#if defined(ARDUINO_ARCH_ESP32)
dir = LV_FS_SPIFFS.open(path);
if(!dir) {
return LV_FS_RES_UNKNOWN;
}
#endif
#endif
#if defined(ARDUINO_ARCH_ESP8266)
#if defined(ARDUINO_ARCH_ESP8266)
dir = LV_FS_SPIFFS.openDir(path);
#endif
#endif
lv_spiffs_dir_t * dp = (lv_spiffs_dir_t *)dir_p; /*Just avoid the confusing casings*/
*dp = dir;
@ -472,7 +469,7 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
{
lv_spiffs_dir_t dir = *(lv_spiffs_dir_t *)dir_p; /*Convert type*/
#if defined(ARDUINO_ARCH_ESP32)
#if defined(ARDUINO_ARCH_ESP32)
File file = dir.openNextFile();
if(file) {
strcpy(fn, file.name());
@ -480,16 +477,16 @@ static lv_fs_res_t fs_dir_read(lv_fs_drv_t * drv, void * dir_p, char * fn)
} else {
return LV_FS_RES_UNKNOWN;
}
#endif
#endif
#if defined(ARDUINO_ARCH_ESP8266)
#if defined(ARDUINO_ARCH_ESP8266)
if(dir.next()) {
strcpy(fn, dir.fileName().c_str());
return LV_FS_RES_OK;
} else {
return LV_FS_RES_UNKNOWN;
}
#endif
#endif
return LV_FS_RES_NOT_IMP;
}
@ -505,5 +502,5 @@ static lv_fs_res_t fs_dir_close(lv_fs_drv_t * drv, void * dir_p)
return LV_FS_RES_OK;
}
#endif /*LV_USE_FS_IF*/
#endif /*LV_FS_IF_SPIFFS*/
#endif /*LV_USE_FS_IF*/
#endif /*LV_FS_IF_SPIFFS*/

View File

@ -5,24 +5,21 @@
#include <stdio.h>
#if defined(ARDUINO_ARCH_ESP32)
#if HASP_USE_SPIFFS > 0
#include "SPIFFS.h"
#elif HASP_USE_LITTLEFS > 0
#include "LITTLEFS.h"
#endif
#if HASP_USE_SPIFFS > 0
#include "SPIFFS.h"
#define FS SPIFFS
#elif HASP_USE_LITTLEFS > 0
#include "LITTLEFS.h"
#define FS LITTLEFS
#endif
#elif defined(ARDUINO_ARCH_ESP8266)
// included by default
#include "LittleFS.h"
#define FS LittleFS
#endif // ARDUINO_ARCH
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
#include <FS.h>
#include <Esp.h>
#if HASP_USE_SPIFFS > 0
#define FS SPIFFS
#elif HASP_USE_LITTLEFS > 0
#define FS LITTLEFS
#endif // HASP_USE
#include <FS.h>
#include <Esp.h>
#endif // ARDUINO_ARCH
#include "lvgl.h"
@ -66,10 +63,10 @@ uint32_t charInBuffer = 0; // Last Character ID in the Bitmap Buffer
lv_zifont_char_t lastCharInfo; // Holds the last Glyph DSC
#if ESP32
// static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache
#define CHAR_CACHE_SIZE 224
// static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache
#define CHAR_CACHE_SIZE 224
#else
#define CHAR_CACHE_SIZE 95
#define CHAR_CACHE_SIZE 95
// static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache
#endif
static uint8_t * charBitmap_p;
@ -82,7 +79,7 @@ static uint8_t * charBitmap_p;
* GLOBAL FUNCTIONS
**********************/
static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos);
// static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos);
static void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos);
// static uint16_t unicode2codepoint(uint32_t unicode, uint8_t codepage);
// static void printBuffer(uint8_t * charBitmap_p, uint8_t w, uint8_t h);
@ -362,7 +359,7 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font,
uint16_t fileindex = 0;
uint16_t arrindex = 0;
int k, len = 1; // enter while loop
uint8_t color1, color2;
uint8_t b, repeats, color1, color2;
// while((fileindex < charInfo->length) && len > 0) { //} && !feof(file)) {
while((arrindex < size * 2) && (len > 0)) { // read untill the bitmap is full, no need for datalength
@ -374,43 +371,50 @@ const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font,
fileindex += len;
for(k = 0; k < len; k++) {
uint8_t b = data[k];
b = data[k];
// Serial.printf("%d - %d > %x = %x arrindex:%d\n", fileindex, arrindex, b, ch[0], ftell(file));
uint8_t repeats = b & 0b00011111; /* last 5 bits indicate repetition as the same color */
repeats = b & 0b00011111; /* last 5 bits indicate repetition as the same color */
switch(b >> 5) {
case(0b000):
arrindex += repeats; // repeats are white
break;
case(0b001):
for(int i = 0; i < repeats; i++) { // repeats are black
blackAdd(charBitmap_p, arrindex++);
if(arrindex & 0x1) {
colorsAdd(charBitmap_p, ColorBlack, arrindex++);
repeats--;
}
for(; repeats >= 2; repeats -= 2) { // repeats are black
// colorsAdd(charBitmap_p, ColorBlack, arrindex++);
charBitmap_p[arrindex >> 1] = 0xff;
arrindex += 2;
}
if(repeats & 0x1) colorsAdd(charBitmap_p, ColorBlack, arrindex++);
break;
case(0b010):
arrindex += repeats; // repeats are white
blackAdd(charBitmap_p, arrindex++);
colorsAdd(charBitmap_p, ColorBlack, arrindex++);
break;
case(0b011):
arrindex += repeats; // repeats are white
blackAdd(charBitmap_p, arrindex++);
blackAdd(charBitmap_p, arrindex++);
colorsAdd(charBitmap_p, ColorBlack, arrindex++);
colorsAdd(charBitmap_p, ColorBlack, arrindex++);
break;
case(0b100):
case(0b101):
repeats = (uint8_t)((b & (0b111000)) >> 3); /* 3 bits indicate repetition as the same color */
color1 = (uint8_t)(b & (0b0111));
repeats = (b & (0b111000)) >> 3; // 3 bits indicate repetition as the same color
color1 = (b & (0b000111)) << 1; // << 1 to get 4bpp
arrindex += repeats;
colorsAdd(charBitmap_p, color1, arrindex++);
break;
default:
color1 = (b & 0b111000) >> 3;
color2 = b & 0b000111;
color1 = (b & 0b111000) >> 2; // >> 3 first and then << 1 to get 4bpp
color2 = (b & 0b000111) << 1; // << 1 to get 4bpp
colorsAdd(charBitmap_p, color1, arrindex++);
colorsAdd(charBitmap_p, color2, arrindex++);
}
@ -535,28 +539,26 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_
return true;
}
static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos)
{
uint8_t col = pos & 0x0001; // remainder
uint16_t map_p = pos >> 1; // devide by 2
// static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos)
// {
// // uint8_t col = pos & 0x0001; // remainder
// uint16_t map_p = pos >> 1; // devide by 2
if(col == 0) {
charBitmap_p[map_p] = 0xf0;
} else {
charBitmap_p[map_p] |= ColorBlack;
}
}
// if(pos & 0x1)
// charBitmap_p[map_p] |= ColorBlack;
// else
// charBitmap_p[map_p] = 0xf0;
// }
static inline void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos)
{
uint32_t col = pos & 0x0001; // remainder
uint32_t map_p = pos >> 1; // devide by 2
// uint32_t col = pos & 0x0001; // remainder
uint16_t map_p = pos >> 1; // devide by 2
if(col == 0) {
charBitmap_p[map_p] = color1 << 5;
} else {
charBitmap_p[map_p] |= color1 << 1;
}
if(pos & 0x1)
charBitmap_p[map_p] |= color1;
else
charBitmap_p[map_p] = color1 << 4;
}
/*