GR5526 (4)-Merge Lvgl font bitmaps into bin

[TOC]

1. Use background and description

  • In the Lvgl project used by Goodix GR5526, in order to accelerate the rendering speed of fonts, the native Font rendering layer of Lvgl is adapted to the GPU of GR5526, and the bitmap format (glyph _ bitmap) after adaptation is different from the native bitmap format of Lvgl. Therefore, the font data generated by the lv _ font _ conv. Exe software provided by Lvgl official website is no longer supported. Based on the lv _ font _ conv. Exe tool, we have carried out the corresponding adaptation modification, and introduced the tool GDX _ font _ conv. Exe. For GR5526 Lvgl font rendering.

  • The tool can output two formats that are supported by the Lvgl font renderer:

    • All information such as The bin formatbitmap data and font description information is packaged into a bin file. In this format, the main control unit such as CPU/GPU cannot directly address and access the bitmap, and a bin loader needs to be implemented. The bitmap data and description information of the font are all loaded into the RAM area and then accessed. Bin format access is not currently supported in the GR5526 for two reasons

      • Lvgl source code bin loader is supported after v9.0. The latest version we are currently adapting is v8.31, which does not support bin loader.

      • The bin loader loads the bitmap data and description information of the entire bin into the RAM space, which is a great waste of RAM space and is unacceptable to the GR5526.

    • Lvgl format: a.c source code file will be generated, in which the bitmap array glyph _ bitmap and other font description information are defined. The whole.c source file needs to be compiled in the project, so that all font data are placed in the code space. The current GR5526 SDK reference project uses this method, but this method has a disadvantage that when the font file becomes larger and larger, it will quickly exhaust the source code storage space of GR5526.

  • This article is based on the above Lvgl format for optimization, Lvgl format will occupy the largest space bitmap data (glyph _ bitmap) into the external Flash space, the other description of the font or into the source code space.

2. Lvgl format bitmap data to bin films

2.1How to generate fonts for Lvgl

In the production environment of GR5526 Lvgl, the generation and use of font files need to go through the following steps:

  1. Using a GDX _ font _ conv. Exe tool to generate a plurality of.c source files in the lvgl format with different fonts and different font sizes from font source files in the TTF format and the like

  2. Manually exporting a glyph _ bitmap array in a plurality of font source files into a.txt array file group

  3. Merging the.txt bitmap file group into a goodix _ lvgl _ font. Bin file according to a rule by using the provided goodix _ lvgl _ font _ to _ bin. Py script file, and outputting the basic information of each font bitmap in bin at the same time, Including alignment adjusted length, offset, etc.

  4. Determine the programming offset address of the goodix _ lvgl _ font. Bin file in the external Nor Flash, and use the following formula to determine the offset address of each font bitmap in the bus address space:

    glyph_bitmap_AHB_ADDR = QSPIx_XIP_BASE + Flash_Offset + glyph_bitmap_offset
    
    • The QSPIx _ XIP _ BASE is the logical base address of the Flash mount module, or the QSPI0 _ XIP _ BASE if it is mounted on a QSPI0 module, and so on

    • The Flash _ Offset is the space offset for programming the goodix _ lvgl _ font. Bin to Nor Flash. For example, if programming starts from address 0, it is 0x00000000

    • The glyph _ bitmap _ offset is the offset in the bin file of the glyph _ bitmap data of the current font bitmap file. For example:

      goodix_lvgl_font_to_bin.py 脚本输出信息:
      
      OrderedDict([('file', '.\\raw\\lv_font_montserrat_48_gdx.txt'),
                   ('align_len', 37376),
                   ('offset', 0),
                   ('offset_hex', '0x0')])
      OrderedDict([('file', '.\\raw\\lv_font_msyh_20_gr552x.txt'),
                   ('align_len', 19200),
                   ('offset', 37376),
                   ('offset_hex', '0x9200')])
      OrderedDict([('file', '.\\raw\\lv_font_msyh_26_gr552x.txt'),
                   ('align_len', 25856),
                   ('offset', 56576),
                   ('offset_hex', '0xdd00')])
      
      offset(十进制)或offset_hex(十六进制)的值, 即为glyph_bitmap_offset的值
      
    1. Burn the generated goodix _ lvgl _ font. Bin file to the external Nor Flash. Note that the offset address in the Flash space corresponds to the above-mentioned Flash _ Offset.

    2. The calculated glyph _ bitmap _ AHB _ ADDR address of each font file is re-assigned to the member variable glyph _ bitmap of the lv _ font _ FMT _ txt _ DSC _ t, and the original glyph _ bitmap array is removed.

    3. When you complete the steps above, the glyph _ bitmap is indexed into the Nor Flash address space.

This article applies to the Lvgl project of Goodix Bluetooth SoC GR5526, which is used to convert the bitmap array of Lvgl font

2.2 Generates font resources that conform to the Lvgl specification for GPU adaptation

Step Section 2.11: For the method of generating Lvgl format font resources, please refer to the special article. As follows:

Step Section 2.15 To burn the bin file to Nor Flash, please use the GProgrammer tool and refer to the relevant instructions.

Refer to the following 2.3 Method of generating font bitmap bin filesections for steps Section 2.12 to 4

2.Method of generating font bitmap bin file

  • Get the GoodixLvglFontToBincompressed script package, which contains a goodix _ lvgl _ font _ to _ bin. Py script and the raw directory

  • The raw directory is used to store the glyph _ bitmap bitmap data of each font source file. The general operation recommendations are as follows:

    • Delete the test file in the raw directory (for demonstration purposes, it can be backed up)

    • In the raw directory, name a.txt file with the same name as the.c font source file. For example, the bitmap data file corresponding to the font source file lv _ font _ msyh _ 26 _ gr552 X. C is named lv _ font _ msyh _ 26 _ gr552x.txt

    • Copy the array contents of the static LV _ ATTRIBUTE _ LARGE _ CONST const uint8 _ t glyph _ bitmap [] in the.c source file to the corresponding txt file as follows (copy the contents in { }, excluding { }):

          /* U+0020 " " */
      
          /* U+0021 "!" */
          0xe, 0xf1, 0xe, 0xf1, 0xd, 0xf0, 0xd, 0xf0,
          0xd, 0xf0, 0xc, 0xf0, 0xc, 0xf0, 0xc, 0xf0,
          0xb, 0xe0, 0xb, 0xe0, 0x8, 0xa0, 0x0, 0x0,
          0x3, 0x50, 0x1f, 0xf4, 0xc, 0xe2, 0x0, 0x0,
      
          。。。。。。。。。
      
          /* U+989D "额" */
          0x0, 0x0, 0x51, 0x0, 0x0, 0x0, 0x0, 0x0,
          0x0, 0x0, 0x0, 0x0, 0xe9, 0x0, 0x0, 0x45,
          0x55, 0x55, 0x55, 0x52, 0x3, 0x33, 0x9f, 0x33,
          0x32, 0xef, 0xff, 0xff, 0xff, 0xf6, 0x3f, 0xff,
          0xff, 0xff, 0xfb, 0x0, 0x5, 0xf2, 0x0, 0x0,
          0x3f, 0x16, 0x20, 0x0, 0xcb, 0x0, 0x8, 0xe0,
          0x0, 0x0, 0x18, 0x4f, 0x63, 0x33, 0x85, 0x48,
          0x8d, 0xe8, 0x88, 0x60, 0x0, 0xbf, 0xff, 0xff,
          0xa0, 0x8f, 0xaa, 0xaa, 0xad, 0xc0, 0x6, 0xf2,
          0x0, 0x3f, 0x50, 0x8d, 0x0, 0x10, 0x9, 0xc0,
          0x3f, 0x7a, 0x41, 0xdb, 0x0, 0x8d, 0x1, 0xf5,
          0x9, 0xc0, 0x3a, 0x1a, 0xfe, 0xe1, 0x0, 0x8d,
          0x0, 0xf5, 0x9, 0xc0, 0x0, 0x4, 0xef, 0xfb,
          0x30, 0x8d, 0x1, 0xf4, 0x9, 0xc0, 0x3, 0xaf,
          0xa0, 0x5d, 0xf9, 0x8d, 0x1, 0xf4, 0x9, 0xc0,
          0x8f, 0xe6, 0x22, 0x22, 0x73, 0x8d, 0x3, 0xf3,
          0x9, 0xc0, 0x23, 0xff, 0xff, 0xff, 0x60, 0x8d,
          0x5, 0xf1, 0x9, 0xc0, 0x0, 0xf5, 0x11, 0x1e,
          0x60, 0x8d, 0x9, 0xf0, 0x9, 0xc0, 0x0, 0xf4,
          0x0, 0xe, 0x60, 0x12, 0x2f, 0xfc, 0x21, 0x10,
          0x0, 0xf4, 0x0, 0xe, 0x60, 0x1, 0xdf, 0x5d,
          0xf5, 0x0, 0x0, 0xff, 0xff, 0xff, 0x60, 0x5e,
          0xf4, 0x0, 0xaf, 0x90, 0x0, 0xf7, 0x44, 0x4e,
          0x6c, 0xfc, 0x20, 0x0, 0x7, 0xf8, 0x0, 0x20,
          0x0, 0x0, 0x5, 0x50, 0x0, 0x0, 0x0, 0x40,
      
          /* U+FF0C "," */
          0x2, 0x30, 0xf, 0xc0, 0x2f, 0x70, 0x6f, 0x20,
          0xad, 0x0, 0xd8, 0x0
      
    • Follow the steps above to complete the creation of all.c source file bitmap data files

    • Install the Python environment in advance, and enter the command line into the GoodixLvglFontToBin directory. Execute the script command python goodix_lvgl_font_to_bin.py:

      D:\03_Software\LvglFont\GoodixLvglFontToBin>python goodix_lvgl_font_to_bin.py
      
      Handle Font File : .\raw\lv_font_montserrat_48_gdx.txt
      Handle Font File : .\raw\lv_font_msyh_20_gr552x.txt
      Handle Font File : .\raw\lv_font_msyh_26_gr552x.txt
      
      OrderedDict([('file', '.\\raw\\lv_font_montserrat_48_gdx.txt'),
                   ('align_len', 37376),
                   ('offset', 0),
                   ('offset_hex', '0x0')])
      OrderedDict([('file', '.\\raw\\lv_font_msyh_20_gr552x.txt'),
                   ('align_len', 19200),
                   ('offset', 37376),
                   ('offset_hex', '0x9200')])
      OrderedDict([('file', '.\\raw\\lv_font_msyh_26_gr552x.txt'),
                   ('align_len', 25856),
                   ('offset', 56576),
                   ('offset_hex', '0xdd00')])
      
      Bin File length:82432 bytes, (hex:0x14200)
      
      Genqerate Lvgl Binary-Font File Successful!
      
    • After the script is executed, a goodix _ lvgl _ font. Bin file is generated and the merge information for the file is output.

      • File-Bitmap source file name

      • Align _ len-The length of the source font array after alignment. By default, it is aligned according to Flash Page (256 bytes).

      • Offset and offset _ hex are the starting offset address of the current bitmap in the bin file in decimal/hexadecimal format, respectively, corresponding to the glyph _ bitmap _ offset variable in the previous paragraph Section 2.1

      • Total size of the last output bin file

  • Burn the bin generated above to the external Nor Flash space

  • Update static LV _ ATTRIBUTE _ LARGE _ CONST const uint8 _ t glyph _ bitmap [] variable definition:

    • Delete glyph _ bitmap [] array

    • Redefine glyph _ bitmap:

      const uint8_t * glyph_bitmap = (const uint8_t * ) (QSPIx_XIP_BASE + Flash_Offset + glyph_bitmap_offset)
      
      • If Nor Flash is mounted to QSPI0, the flash programming offset is 0x10000, and the bitmap data offset is 0xdd00. In the X. Txt of the lv _ font _ msyh _ 26 _ gr552. Then:

        const uint8_t * glyph_bitmap = (const uint8_t * ) (QSPI0_XIP_BASE + 0x10000 + 0xdd00)
        
    • The glyph _ bitmap variable update of each font file is the same

2.4 Script Tool Download