mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-25 20:26:41 +00:00
Switch to LittleFS
This commit is contained in:
parent
8adc9ca93f
commit
199dff2c49
@ -12,30 +12,27 @@
|
|||||||
#include "ArduinoLog.h"
|
#include "ArduinoLog.h"
|
||||||
|
|
||||||
#if LV_USE_FS_IF
|
#if LV_USE_FS_IF
|
||||||
#if LV_FS_IF_SPIFFS != '\0'
|
#if LV_FS_IF_SPIFFS != '\0'
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0
|
||||||
#include "SPIFFS.h"
|
#include "SPIFFS.h"
|
||||||
#elif HASP_USE_LITTLEFS > 0
|
#define LV_FS_SPIFFS SPIFFS
|
||||||
#include "LITTLEFS.h"
|
#elif HASP_USE_LITTLEFS > 0
|
||||||
#endif
|
#include "LITTLEFS.h"
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
#define LV_FS_SPIFFS LITTLEFS
|
||||||
// included by default
|
#endif
|
||||||
#endif // ARDUINO_ARCH
|
#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)
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include <Esp.h>
|
#include <Esp.h>
|
||||||
|
#endif // ARDUINO_ARCH
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
#define TAG_LVFS 91
|
||||||
#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
|
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
@ -48,14 +45,14 @@
|
|||||||
/* Create a type to store the required data about your file.*/
|
/* Create a type to store the required data about your file.*/
|
||||||
typedef File lv_spiffs_file_t;
|
typedef File lv_spiffs_file_t;
|
||||||
|
|
||||||
/*Similarly to `file_t` create a type for directory reading too */
|
/*Similarly to `file_t` create a type for directory reading too */
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
typedef File lv_spiffs_dir_t;
|
typedef File lv_spiffs_dir_t;
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
typedef Dir lv_spiffs_dir_t;
|
typedef Dir lv_spiffs_dir_t;
|
||||||
#define FILE_READ "r"
|
#define FILE_READ "r"
|
||||||
#define FILE_WRITE "r+"
|
#define FILE_WRITE "r+"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC PROTOTYPES
|
* 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*/
|
(void)drv; /*Unused*/
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
FSInfo fs_info;
|
FSInfo fs_info;
|
||||||
LV_FS_SPIFFS.info(fs_info);
|
LV_FS_SPIFFS.info(fs_info);
|
||||||
*total_p = (uint32_t)fs_info.totalBytes;
|
*total_p = (uint32_t)fs_info.totalBytes;
|
||||||
*free_p = (uint32_t)fs_info.totalBytes - fs_info.usedBytes;
|
*free_p = (uint32_t)fs_info.totalBytes - fs_info.usedBytes;
|
||||||
return LV_FS_RES_OK;
|
return LV_FS_RES_OK;
|
||||||
|
|
||||||
#elif defined(ARDUINO_ARCH_ESP32)
|
#elif defined(ARDUINO_ARCH_ESP32)
|
||||||
*total_p = (uint32_t)LV_FS_SPIFFS.totalBytes();
|
*total_p = (uint32_t)LV_FS_SPIFFS.totalBytes();
|
||||||
*free_p = (uint32_t)LV_FS_SPIFFS.totalBytes() - LV_FS_SPIFFS.usedBytes();
|
*free_p = (uint32_t)LV_FS_SPIFFS.totalBytes() - LV_FS_SPIFFS.usedBytes();
|
||||||
return LV_FS_RES_OK;
|
return LV_FS_RES_OK;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return LV_FS_RES_NOT_IMP;
|
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;
|
lv_spiffs_dir_t dir;
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
dir = LV_FS_SPIFFS.open(path);
|
dir = LV_FS_SPIFFS.open(path);
|
||||||
if(!dir) {
|
if(!dir) {
|
||||||
return LV_FS_RES_UNKNOWN;
|
return LV_FS_RES_UNKNOWN;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
dir = LV_FS_SPIFFS.openDir(path);
|
dir = LV_FS_SPIFFS.openDir(path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
lv_spiffs_dir_t * dp = (lv_spiffs_dir_t *)dir_p; /*Just avoid the confusing casings*/
|
lv_spiffs_dir_t * dp = (lv_spiffs_dir_t *)dir_p; /*Just avoid the confusing casings*/
|
||||||
*dp = dir;
|
*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*/
|
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();
|
File file = dir.openNextFile();
|
||||||
if(file) {
|
if(file) {
|
||||||
strcpy(fn, file.name());
|
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 {
|
} else {
|
||||||
return LV_FS_RES_UNKNOWN;
|
return LV_FS_RES_UNKNOWN;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266)
|
#if defined(ARDUINO_ARCH_ESP8266)
|
||||||
if(dir.next()) {
|
if(dir.next()) {
|
||||||
strcpy(fn, dir.fileName().c_str());
|
strcpy(fn, dir.fileName().c_str());
|
||||||
return LV_FS_RES_OK;
|
return LV_FS_RES_OK;
|
||||||
} else {
|
} else {
|
||||||
return LV_FS_RES_UNKNOWN;
|
return LV_FS_RES_UNKNOWN;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return LV_FS_RES_NOT_IMP;
|
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;
|
return LV_FS_RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /*LV_USE_FS_IF*/
|
#endif /*LV_USE_FS_IF*/
|
||||||
#endif /*LV_FS_IF_SPIFFS*/
|
#endif /*LV_FS_IF_SPIFFS*/
|
||||||
|
@ -5,24 +5,21 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP32)
|
||||||
#if HASP_USE_SPIFFS > 0
|
#if HASP_USE_SPIFFS > 0
|
||||||
#include "SPIFFS.h"
|
#include "SPIFFS.h"
|
||||||
#elif HASP_USE_LITTLEFS > 0
|
#define FS SPIFFS
|
||||||
#include "LITTLEFS.h"
|
#elif HASP_USE_LITTLEFS > 0
|
||||||
#endif
|
#include "LITTLEFS.h"
|
||||||
|
#define FS LITTLEFS
|
||||||
|
#endif
|
||||||
#elif defined(ARDUINO_ARCH_ESP8266)
|
#elif defined(ARDUINO_ARCH_ESP8266)
|
||||||
// included by default
|
#include "LittleFS.h"
|
||||||
|
#define FS LittleFS
|
||||||
#endif // ARDUINO_ARCH
|
#endif // ARDUINO_ARCH
|
||||||
|
|
||||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <FS.h>
|
#include <FS.h>
|
||||||
#include <Esp.h>
|
#include <Esp.h>
|
||||||
|
|
||||||
#if HASP_USE_SPIFFS > 0
|
|
||||||
#define FS SPIFFS
|
|
||||||
#elif HASP_USE_LITTLEFS > 0
|
|
||||||
#define FS LITTLEFS
|
|
||||||
#endif // HASP_USE
|
|
||||||
#endif // ARDUINO_ARCH
|
#endif // ARDUINO_ARCH
|
||||||
|
|
||||||
#include "lvgl.h"
|
#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
|
lv_zifont_char_t lastCharInfo; // Holds the last Glyph DSC
|
||||||
|
|
||||||
#if ESP32
|
#if ESP32
|
||||||
// static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache
|
// static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache
|
||||||
#define CHAR_CACHE_SIZE 224
|
#define CHAR_CACHE_SIZE 224
|
||||||
#else
|
#else
|
||||||
#define CHAR_CACHE_SIZE 95
|
#define CHAR_CACHE_SIZE 95
|
||||||
// static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache
|
// static lv_zifont_char_t charCache[256 - 32]; // glyphID DSC cache
|
||||||
#endif
|
#endif
|
||||||
static uint8_t * charBitmap_p;
|
static uint8_t * charBitmap_p;
|
||||||
@ -82,7 +79,7 @@ static uint8_t * charBitmap_p;
|
|||||||
* GLOBAL FUNCTIONS
|
* 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 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 uint16_t unicode2codepoint(uint32_t unicode, uint8_t codepage);
|
||||||
// static void printBuffer(uint8_t * charBitmap_p, uint8_t w, uint8_t h);
|
// 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 fileindex = 0;
|
||||||
uint16_t arrindex = 0;
|
uint16_t arrindex = 0;
|
||||||
int k, len = 1; // enter while loop
|
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((fileindex < charInfo->length) && len > 0) { //} && !feof(file)) {
|
||||||
while((arrindex < size * 2) && (len > 0)) { // read untill the bitmap is full, no need for datalength
|
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;
|
fileindex += len;
|
||||||
|
|
||||||
for(k = 0; k < len; k++) {
|
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));
|
// 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) {
|
switch(b >> 5) {
|
||||||
case(0b000):
|
case(0b000):
|
||||||
arrindex += repeats; // repeats are white
|
arrindex += repeats; // repeats are white
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case(0b001):
|
case(0b001):
|
||||||
for(int i = 0; i < repeats; i++) { // repeats are black
|
if(arrindex & 0x1) {
|
||||||
blackAdd(charBitmap_p, arrindex++);
|
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;
|
break;
|
||||||
|
|
||||||
case(0b010):
|
case(0b010):
|
||||||
arrindex += repeats; // repeats are white
|
arrindex += repeats; // repeats are white
|
||||||
blackAdd(charBitmap_p, arrindex++);
|
colorsAdd(charBitmap_p, ColorBlack, arrindex++);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case(0b011):
|
case(0b011):
|
||||||
arrindex += repeats; // repeats are white
|
arrindex += repeats; // repeats are white
|
||||||
blackAdd(charBitmap_p, arrindex++);
|
colorsAdd(charBitmap_p, ColorBlack, arrindex++);
|
||||||
blackAdd(charBitmap_p, arrindex++);
|
colorsAdd(charBitmap_p, ColorBlack, arrindex++);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case(0b100):
|
case(0b100):
|
||||||
case(0b101):
|
case(0b101):
|
||||||
repeats = (uint8_t)((b & (0b111000)) >> 3); /* 3 bits indicate repetition as the same color */
|
repeats = (b & (0b111000)) >> 3; // 3 bits indicate repetition as the same color
|
||||||
color1 = (uint8_t)(b & (0b0111));
|
color1 = (b & (0b000111)) << 1; // << 1 to get 4bpp
|
||||||
arrindex += repeats;
|
arrindex += repeats;
|
||||||
colorsAdd(charBitmap_p, color1, arrindex++);
|
colorsAdd(charBitmap_p, color1, arrindex++);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
color1 = (b & 0b111000) >> 3;
|
color1 = (b & 0b111000) >> 2; // >> 3 first and then << 1 to get 4bpp
|
||||||
color2 = b & 0b000111;
|
color2 = (b & 0b000111) << 1; // << 1 to get 4bpp
|
||||||
colorsAdd(charBitmap_p, color1, arrindex++);
|
colorsAdd(charBitmap_p, color1, arrindex++);
|
||||||
colorsAdd(charBitmap_p, color2, 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos)
|
// static void IRAM_ATTR blackAdd(uint8_t * charBitmap_p, uint16_t pos)
|
||||||
{
|
// {
|
||||||
uint8_t col = pos & 0x0001; // remainder
|
// // uint8_t col = pos & 0x0001; // remainder
|
||||||
uint16_t map_p = pos >> 1; // devide by 2
|
// uint16_t map_p = pos >> 1; // devide by 2
|
||||||
|
|
||||||
if(col == 0) {
|
// if(pos & 0x1)
|
||||||
charBitmap_p[map_p] = 0xf0;
|
// charBitmap_p[map_p] |= ColorBlack;
|
||||||
} else {
|
// else
|
||||||
charBitmap_p[map_p] |= ColorBlack;
|
// charBitmap_p[map_p] = 0xf0;
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
static inline void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos)
|
static inline void IRAM_ATTR colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos)
|
||||||
{
|
{
|
||||||
uint32_t col = pos & 0x0001; // remainder
|
// uint32_t col = pos & 0x0001; // remainder
|
||||||
uint32_t map_p = pos >> 1; // devide by 2
|
uint16_t map_p = pos >> 1; // devide by 2
|
||||||
|
|
||||||
if(col == 0) {
|
if(pos & 0x1)
|
||||||
charBitmap_p[map_p] = color1 << 5;
|
charBitmap_p[map_p] |= color1;
|
||||||
} else {
|
else
|
||||||
charBitmap_p[map_p] |= color1 << 1;
|
charBitmap_p[map_p] = color1 << 4;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user