-
Notifications
You must be signed in to change notification settings - Fork 3
/
SpiFlashFont.cpp
110 lines (89 loc) · 3.19 KB
/
SpiFlashFont.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "SpiFlashResources.h"
#ifdef USE_SPI_FLASH_FONT
#include <SerialFlash.h>
static uint32_t glyph_dsc_size = sizeof(lv_font_glyph_dsc_t);
static lv_font_glyph_dsc_t tempGlyphDsc;
static const lv_font_t * tempDscFont = NULL;
static uint32_t TempDscLetter;
static uint8_t tempBitMap[40*40];
static const lv_font_t * tempMapFont = NULL;
static uint32_t tempMapLetter;
static void getTempGlyphDsc(const lv_font_t * font, uint32_t unicode_letter , uint32_t idx)
{
static uint8_t * temp_addr = (uint8_t*)&tempGlyphDsc;
if( tempDscFont != font || TempDscLetter != unicode_letter )
{
SerialFlash.read((uintptr_t)(font->glyph_dsc + idx) , temp_addr , glyph_dsc_size);
tempDscFont = font;
TempDscLetter = unicode_letter;
}
}
static bool isTempGlyphDsc(const lv_font_t * font, uint32_t unicode_letter)
{
return tempDscFont == font && TempDscLetter == unicode_letter;
}
static void getTempBitMap(const lv_font_t * font, uint32_t unicode_letter, lv_font_glyph_dsc_t glyph_dsc)
{
if( tempMapFont != font || tempMapLetter != unicode_letter )
{
SerialFlash.read((uintptr_t)(font->glyph_bitmap + glyph_dsc.glyph_index) , tempBitMap , font->h_px * glyph_dsc.w_px);
tempMapFont = font;
tempMapLetter = unicode_letter;
}
}
static bool isTempBitMap(const lv_font_t * font, uint32_t unicode_letter)
{
return tempMapFont == font && tempMapLetter == unicode_letter;
}
/**
* Generic bitmap get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
* @param font pointer to font
* @param unicode_letter an unicode letter which bitmap should be get
* @return pointer to the bitmap or NULL if not found
*/
const uint8_t * lv_font_get_spiflash_bitmap_sparse(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return NULL;
if(isTempBitMap( font, unicode_letter))
{
return tempBitMap;
}
else if(isTempGlyphDsc(font,unicode_letter))
{
getTempBitMap(font, unicode_letter,tempGlyphDsc);
return tempBitMap;
}
uint32_t i;
for(i = 0; font->unicode_list[i] != 0; i++) {
if(font->unicode_list[i] == unicode_letter) {
getTempGlyphDsc(font, unicode_letter , i);
getTempBitMap(font, unicode_letter , tempGlyphDsc);
return tempBitMap;
}
}
return NULL;
}
/**
* Generic glyph width get function used in 'font->get_bitmap' when the font NOT contains all characters in the range (sparse)
* @param font pointer to font
* @param unicode_letter an unicode letter which width should be get
* @return width of the glyph or -1 if not found
*/
int16_t lv_font_get_spiflash_width_sparse(const lv_font_t * font, uint32_t unicode_letter)
{
/*Check the range*/
if(unicode_letter < font->unicode_first || unicode_letter > font->unicode_last) return -1;
/* is cache ok */
if(isTempGlyphDsc(font,unicode_letter))
return tempGlyphDsc.w_px;
uint32_t i;
for(i = 0; font->unicode_list[i] != 0; i++) {
if(font->unicode_list[i] == unicode_letter) {
getTempGlyphDsc(font, unicode_letter , i);
return tempGlyphDsc.w_px;
}
}
return -1;
}
#endif