mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-27 13:16:45 +00:00
Migration to lvgl7
This commit is contained in:
parent
43befd8d14
commit
2531cdc221
@ -87,9 +87,9 @@ static uint8_t * charBitmap_p;
|
|||||||
* GLOBAL FUNCTIONS
|
* GLOBAL FUNCTIONS
|
||||||
**********************/
|
**********************/
|
||||||
|
|
||||||
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);
|
||||||
void colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos);
|
static void colorsAdd(uint8_t * charBitmap_p, uint8_t color1, uint16_t pos);
|
||||||
uint16_t unicode2codepoint(uint32_t unicode, uint8_t codepage);
|
static uint16_t unicode2codepoint(uint32_t unicode, uint8_t codepage);
|
||||||
|
|
||||||
int lv_zifont_init(void)
|
int lv_zifont_init(void)
|
||||||
{
|
{
|
||||||
@ -97,71 +97,58 @@ int lv_zifont_init(void)
|
|||||||
return LV_RES_OK; // OK
|
return LV_RES_OK; // OK
|
||||||
}
|
}
|
||||||
|
|
||||||
bool openFont(File & file, const char * filename)
|
static inline bool IRAM_ATTR openFont(File & file, const char * filename)
|
||||||
{
|
{
|
||||||
file = SPIFFS.open(filename, "r");
|
file = SPIFFS.open(filename, "r");
|
||||||
if(!file) {
|
if(!file) {
|
||||||
Log.error(F("FONT: %sOpening font: %s"), filename);
|
// Log.error(F("FONT: %sOpening font: %s"), filename);
|
||||||
return false;
|
// return false;
|
||||||
}
|
}
|
||||||
return true;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initCharacterFrame(size_t size)
|
static inline void initCharacterFrame(size_t size)
|
||||||
{
|
{
|
||||||
if(size > lv_mem_get_size(charBitmap_p)) {
|
if(size > lv_mem_get_size(charBitmap_p)) {
|
||||||
if(charBitmap_p) lv_mem_free(charBitmap_p);
|
if(charBitmap_p) lv_mem_free(charBitmap_p);
|
||||||
charBitmap_p = (uint8_t *)lv_mem_alloc(size);
|
charBitmap_p = (uint8_t *)lv_mem_alloc(size);
|
||||||
}
|
}
|
||||||
memset(charBitmap_p, 0, size); // init the bitmap to white}
|
memset(charBitmap_p, 0, size); // init the bitmap to white
|
||||||
}
|
}
|
||||||
|
|
||||||
int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size)
|
int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size)
|
||||||
{
|
{
|
||||||
charInBuffer = 0; // invalidate any previous cache
|
charInBuffer = 0; // invalidate any previous cache
|
||||||
|
|
||||||
Log.trace("ZI: start");
|
|
||||||
|
|
||||||
if(!*font) {
|
if(!*font) {
|
||||||
*font = (lv_font_t *)lv_mem_alloc(sizeof(lv_font_t));
|
*font = (lv_font_t *)lv_mem_alloc(sizeof(lv_font_t));
|
||||||
LV_ASSERT_MEM(*font);
|
LV_ASSERT_MEM(*font);
|
||||||
lv_memset(*font, 0x00, sizeof(lv_font_t)); // lv_mem_alloc might be dirty
|
lv_memset(*font, 0x00, sizeof(lv_font_t)); // lv_mem_alloc might be dirty
|
||||||
}
|
}
|
||||||
Log.trace("ZI: struct ptr OK");
|
|
||||||
|
|
||||||
lv_font_fmt_zifont_dsc_t * dsc;
|
lv_font_fmt_zifont_dsc_t * dsc;
|
||||||
if(!(*font)->dsc) {
|
if(!(*font)->dsc) {
|
||||||
dsc = (lv_font_fmt_zifont_dsc_t *)lv_mem_alloc(sizeof(lv_font_fmt_zifont_dsc_t));
|
dsc = (lv_font_fmt_zifont_dsc_t *)lv_mem_alloc(sizeof(lv_font_fmt_zifont_dsc_t));
|
||||||
LV_ASSERT_MEM(dsc);
|
LV_ASSERT_MEM(dsc);
|
||||||
lv_memset(dsc, 0x00, sizeof(lv_font_fmt_zifont_dsc_t)); // lv_mem_alloc might be dirty
|
lv_memset(dsc, 0x00, sizeof(lv_font_fmt_zifont_dsc_t)); // lv_mem_alloc might be dirty
|
||||||
Log.trace("ZI: created new font dsc");
|
|
||||||
} else {
|
} else {
|
||||||
dsc = (lv_font_fmt_zifont_dsc_t *)(*font)->dsc;
|
dsc = (lv_font_fmt_zifont_dsc_t *)(*font)->dsc;
|
||||||
Log.trace("ZI: font dsc exists");
|
|
||||||
}
|
}
|
||||||
LV_ASSERT_MEM(dsc);
|
LV_ASSERT_MEM(dsc);
|
||||||
Log.trace("ZI: struct dsc OK");
|
|
||||||
if(!dsc) return ZIFONT_ERROR_OUT_OF_MEMORY;
|
if(!dsc) return ZIFONT_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
/* Initialize Last Glyph DSC */
|
/* Initialize Last Glyph DSC */
|
||||||
dsc->last_glyph_dsc = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t));
|
dsc->last_glyph_dsc = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t));
|
||||||
lv_memset(dsc->last_glyph_dsc, 0x00, sizeof(lv_zifont_char_t)); // lv_mem_alloc might be dirty
|
lv_memset(dsc->last_glyph_dsc, 0x00, sizeof(lv_zifont_char_t)); // lv_mem_alloc might be dirty
|
||||||
|
|
||||||
Log.trace("ZI: glyph dsc A");
|
|
||||||
if(dsc->last_glyph_dsc == NULL) return ZIFONT_ERROR_OUT_OF_MEMORY;
|
if(dsc->last_glyph_dsc == NULL) return ZIFONT_ERROR_OUT_OF_MEMORY;
|
||||||
Log.trace("ZI: glyph dsc B");
|
|
||||||
dsc->last_glyph_dsc->width = 0;
|
dsc->last_glyph_dsc->width = 0;
|
||||||
Log.trace("ZI: glyph dsc C");
|
dsc->last_glyph_id = 0;
|
||||||
dsc->last_glyph_id = 0;
|
|
||||||
|
|
||||||
Log.trace("ZI: glyph dsc OK");
|
|
||||||
|
|
||||||
/* Open the font for reading */
|
/* Open the font for reading */
|
||||||
File file;
|
File file;
|
||||||
if(!openFont(file, font_path)) return ZIFONT_ERROR_OPENING_FILE;
|
if(!openFont(file, font_path)) return ZIFONT_ERROR_OPENING_FILE;
|
||||||
|
|
||||||
Log.trace("ZI: font open OK");
|
|
||||||
|
|
||||||
/* Read file header as dsc */
|
/* Read file header as dsc */
|
||||||
zi_font_header_t header;
|
zi_font_header_t header;
|
||||||
size_t readSize = file.readBytes((char *)&header, sizeof(zi_font_header_t));
|
size_t readSize = file.readBytes((char *)&header, sizeof(zi_font_header_t));
|
||||||
@ -180,8 +167,6 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
|
|||||||
return ZIFONT_ERROR_UNKNOWN_HEADER;
|
return ZIFONT_ERROR_UNKNOWN_HEADER;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.trace("ZI: headers OK");
|
|
||||||
|
|
||||||
dsc->CharHeight = header.CharHeight;
|
dsc->CharHeight = header.CharHeight;
|
||||||
dsc->CharWidth = header.CharWidth;
|
dsc->CharWidth = header.CharWidth;
|
||||||
dsc->Maximumnumchars = header.Maximumnumchars;
|
dsc->Maximumnumchars = header.Maximumnumchars;
|
||||||
@ -190,8 +175,6 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
|
|||||||
dsc->Startdataaddress = header.Startdataaddress + header.Descriptionlength;
|
dsc->Startdataaddress = header.Startdataaddress + header.Descriptionlength;
|
||||||
dsc->Fontdataadd8byte = header.Fontdataadd8byte;
|
dsc->Fontdataadd8byte = header.Fontdataadd8byte;
|
||||||
|
|
||||||
Log.trace("ZI: dsc info OK");
|
|
||||||
|
|
||||||
if(!dsc->ascii_glyph_dsc) {
|
if(!dsc->ascii_glyph_dsc) {
|
||||||
dsc->ascii_glyph_dsc = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE);
|
dsc->ascii_glyph_dsc = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE);
|
||||||
LV_ASSERT_MEM(dsc->ascii_glyph_dsc);
|
LV_ASSERT_MEM(dsc->ascii_glyph_dsc);
|
||||||
@ -202,7 +185,6 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
|
|||||||
file.close();
|
file.close();
|
||||||
return ZIFONT_ERROR_OUT_OF_MEMORY;
|
return ZIFONT_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
Log.trace("ZI: ascii glyph dsc OK");
|
|
||||||
|
|
||||||
/* read charmap into cache */
|
/* read charmap into cache */
|
||||||
file.seek(0 * sizeof(zi_font_header_t) + dsc->Startdataaddress, SeekSet);
|
file.seek(0 * sizeof(zi_font_header_t) + dsc->Startdataaddress, SeekSet);
|
||||||
@ -248,15 +230,11 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
|
|||||||
/* header data struct */ /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
|
/* header data struct */ /*The custom font data. Will be accessed by `get_glyph_bitmap/dsc` */
|
||||||
(*font)->subpx = 0;
|
(*font)->subpx = 0;
|
||||||
|
|
||||||
Log.trace("ZI: font dsc data OK");
|
|
||||||
|
|
||||||
if((*font)->user_data != (char *)font_path) {
|
if((*font)->user_data != (char *)font_path) {
|
||||||
if((*font)->user_data) free((*font)->user_data);
|
if((*font)->user_data) free((*font)->user_data);
|
||||||
(*font)->user_data = (char *)font_path;
|
(*font)->user_data = (char *)font_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.trace("ZI: font load OK");
|
|
||||||
|
|
||||||
return ZIFONT_NO_ERROR;
|
return ZIFONT_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +248,7 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
|
|||||||
* @param unicode_letter an unicode letter which bitmap should be get
|
* @param unicode_letter an unicode letter which bitmap should be get
|
||||||
* @return pointer to the bitmap or NULL if not found
|
* @return pointer to the bitmap or NULL if not found
|
||||||
*/
|
*/
|
||||||
const uint8_t * lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, uint32_t unicode_letter)
|
const uint8_t * IRAM_ATTR lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, uint32_t unicode_letter)
|
||||||
{
|
{
|
||||||
/* Bitmap still in buffer */
|
/* Bitmap still in buffer */
|
||||||
if(charInBuffer == unicode_letter && charBitmap_p) {
|
if(charInBuffer == unicode_letter && charBitmap_p) {
|
||||||
@ -315,7 +293,7 @@ const uint8_t * lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, uint32_t u
|
|||||||
Serial.print("%");
|
Serial.print("%");
|
||||||
/* Read Character Table */
|
/* Read Character Table */
|
||||||
charInfo = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t));
|
charInfo = (lv_zifont_char_t *)lv_mem_alloc(sizeof(lv_zifont_char_t));
|
||||||
lv_memset(charInfo, 0x00, sizeof(lv_zifont_char_t)); // lv_mem_alloc might be dirty
|
// lv_memset(charInfo, 0x00, sizeof(lv_zifont_char_t)); // lv_mem_alloc might be dirty
|
||||||
uint32_t char_position = glyphID * sizeof(lv_zifont_char_t) + charmap_position;
|
uint32_t char_position = glyphID * sizeof(lv_zifont_char_t) + charmap_position;
|
||||||
file.seek(char_position, SeekSet);
|
file.seek(char_position, SeekSet);
|
||||||
size_t readSize = file.readBytes((char *)charInfo, sizeof(lv_zifont_char_t));
|
size_t readSize = file.readBytes((char *)charInfo, sizeof(lv_zifont_char_t));
|
||||||
@ -538,7 +516,7 @@ bool IRAM_ATTR lv_font_get_glyph_dsc_fmt_zifont(const lv_font_t * font, lv_font_
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void 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)
|
||||||
{
|
{
|
||||||
uint16_t map_p = pos >> 1; // devide by 2
|
uint16_t map_p = pos >> 1; // devide by 2
|
||||||
uint8_t col = pos % 2; // remainder
|
uint8_t col = pos % 2; // remainder
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
#ifndef LV_ZIFONT_H
|
#ifndef LV_ZIFONT_H
|
||||||
#define LV_ZIFONT_H
|
#define LV_ZIFONT_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "lvgl.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -13,9 +16,7 @@ extern "C" {
|
|||||||
/*********************
|
/*********************
|
||||||
* INCLUDES
|
* INCLUDES
|
||||||
*********************/
|
*********************/
|
||||||
#include <Arduino.h>
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "lvgl.h"
|
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
|
Loading…
x
Reference in New Issue
Block a user