CPU: lpc2478
Nor FLASH: mx29lv640eb
typedef __packed struct { U8 XSize; U8 XDist; U8 BytesPerLine; const unsigned char GUI_UNI_PTR * pData;} GUI_CHARINFO;
On my platform, the external nor flash start address is 0x80000000, and its capacity is 8 Mb. The size of the 4-bit anti-sawtooth font generated by the ucgui font tool is MB (this is the size of the calculated font data ). Considering the continuity of the font content, we will allocate a fixed area for the font storage in nor flash. In my project, we will set it to 0x80600000, and there will be 2 MB of storage space starting from this address.
Make the following definitions in the program (the meanings of some numbers in the Code are explained later ):
#define GUI_FONT_HWZS_NORFLASH_BASE (0x80600000)#define GUI_FONT_HWZS_PROP_SIZE (1008)#define GUI_FONT_HWZS_CHARINFO_SIZE (48167)#define GUI_FONT_HWZS_DATA_SIZE (1806048)GUI_FONT_PROP *GUI_Font_hwzs_22AA4_Prop = (GUI_FONT_PROP *)(GUI_FONT_HWZS_NORFLASH_BASE);GUI_CHARINFO *GUI_Font_hwzs_22AA4_CharInfo = (GUI_CHARINFO *)(GUI_FONT_HWZS_NORFLASH_BASE + GUI_FONT_HWZS_PROP_SIZE);char *GUI_Font_hwzs_22AA4_CharData = (char *)(GUI_FONT_HWZS_NORFLASH_BASE + GUI_FONT_HWZS_PROP_SIZE + GUI_FONT_HWZS_CHARINFO_SIZE);GUI_FLASH const GUI_FONT GUI_Font_hwzs_22AA4 = { GUIPROP_AA4_DispChar , GUIPROP_AA4_GetCharDistX , GUIPROP_AA4_GetFontInfo , GUIPROP_AA4_IsInFont , &GUI_ENC_APIList_SJIS , 24 /* height of font */ , 24 /* space of font y */ , 1 /* magnification x */ , 1 /* magnification y */ , (void GUI_FLASH *)((GUI_FONT_PROP *)(GUI_FONT_HWZS_NORFLASH_BASE))};
Visual Studio 2008 is used to generate a font binary file.
Note: The text encoding in the font generated by the ucgui font generation tool is Unicode. You need to use a software to convert the serial number to the gb2312 mode. When we use the Keil software, we write Chinese characters into the code. during compilation, we will recognize it as gb2312 encoding rather than unicode encoding. In addition, the Chinese characters in gb2312 encoding are consecutive, while in Unicode encoding, commonly used Chinese characters may not be consecutive.
Ucgui font files can be divided into several parts:
1. Define the font. Struct type: gui_font. It is the struct gui_font_hwzs_22aa4 defined in the previous article.
2. Define prop. Struct type: gui_font_prop. Is the partition of all text in the current font file. The more dispersed the text, the more prop struct will be generated. These structs constitute a one-way linked list.
3. Define charinfo. Struct type: gui_charinfo. This struct occupies 7 bytes, but when calculating its size, the MDK should return 8. Therefore, modify the definition of this struct and add _ packed.
4. Define the font array. Char array.
With the above multi-level definition, ucgui can quickly locate the array corresponding to the text. If the flash in the MCU is large enough, the data will be linked to a specific address. Therefore, when vs2008 is used to generate the corresponding font file, it is also necessary to simulate the storage of the font data in the falsh file. Here, the content accuracy of gui_font_prop is mainly used.
The name gui_font_hwzs_22aa4 must be defined in the Code, and the prop, charinfo, and font data should be added to the file. Previously, we defined the starting address of the font data in nor flash, which also plays a role here.
The font file first needs to save the content of the first prop struct. The size of gui_font_prop is 12. Let's take a look at the content of the first prop struct generated:
GUI_FLASH const GUI_FONT_PROP GUI_Font_hwzs_24AA4_Prop83 = { 0x0020 ,0x007E ,&GUI_Font_hwzs_24AA4_CharInfo[0] ,(GUI_FONT_PROP GUI_FLASH *)&GUI_Font_hwzs_24AA4_Prop82};
There are 84 partitions in the font file I generated, so the size of the prop area is 84*12, which is the definition of gui_font_hwzs_prop_size.
After the prop area is the charinfo area, the size of this data area is also known. Gui_flash gui_charinfo gui_font_hwzs_24aa4_charinfo [6881] is defined in the generated font text. The size of gui_charinfo is 7 bytes. Note that it is after _ packed. Otherwise, the value obtained by sizeof (gui_font_hwzs_24aa4_charinfo) is incorrect. Of course, you can also fill in one byte in a special way, but that operation will probably destroy the structure of the original ucgui. 6881*7 is the definition of gui_font_hwzs_charinfo_size.
In this way, the address of each data zone is determined. When saving the file, each struct and array are saved in sequence. The correct address must be calculated for all pointer-related locations. The "Address" must be offset according to gui_font_hwzs_norflash_base.
This file can be directly downloaded to the non-release nor flash by using jlink. It can also be read from the USB flash disk and SD card through the file system and written into nor flash.
Before using the font, the font data must have been saved in nor flash. Otherwise, when using the font, The ucgui reads the wrong data and enters an endless loop.
There are no special requirements for the font. The operation is the same as that of other font libraries attached to the internal ucgui. You only need to set the font to display the font correctly.