Skip to content

Better-Idea/WordIC-Free

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

WordIC-Free

在开发带 LCD 显示的嵌入式设备时,如果程序要显示的字符串包含了类似汉字这样编码范围庞大的字符,你的第一反应不应该是要选择哪一个字库芯片,而是要存放的字库能不能直接放入片内 flash。
在同系列单片机中选择具有更大片内 flash 的型号比小容量加片外非易失存储器组合那种更划算?
与其在选型上纠结,不如让 WordIC-Free 为你量产的嵌入式设备节省字库空间,你可以通过该脚本自动提取 elf 文件中的字符串并生成你所需要的字库代码。

技术介绍

该脚本将二进制 elf 文件中的字符串提取出来并组成一个无重复字符的有序表,该表是按 unicode 字符序对代码中出现过的字符排序,让后通过二分查找得到字符串中所需字符的位图模型。

要求

运行环境

  • Python3 +
  • Pip3 +
  • Pillow 第三方库
  • PyQt5 + 第三方库
  • C++ 11 +

编译环境

  • utf-8 编码原始字符串的套件
  • objdump

注:

// 要求 str 中的内容在 .rodata 段中应该是以 utf-8 格式编码的
// 若是 gb2312 请另辟蹊径
const char * str = "带中文的字符串";

// 其他编码需要转成 utf-8 字符串后才能识别
const char16_t * ustr = u"unicode 字符串";
const wchar_t * wstr = u"宽字符串";

准备

python -m pip install --upgrade pip
pip install pyqt5 pillow

命令参数

参数 含义
-f 字体名称
-s 字体大小
-m 内存排列模式
-w 字体背景宽度
-h 字体背景高度
-dump 与 (arm-none-eabi-)gcc 配套的 (arm-none-eabi-)objdump 程序
-elf elf 文件的路径
-o 生成代码文件的路径

注:
生成代码中 ascii 字符位图宽度是 unicode 的一半,高度则保持一致

模式 & 内存布局:

================== byte layout    ======================= screen
       | msb ............ lsb     (0,0)  (1,0) ..............
0x00   | 07  ............ 0       (0,1)  (1,1) ..............
0x01   | 15  ............ 8        .      .    ..............
.      |  .  ............ .        .      .    ..............
.      |  .  ............ .        .      .    ..............
.      |  .  ............ .        .      .    ..............
.      |  .  ............ .        .      .    ..............
.      |  .  ............ .        .      .    ..............
.      |  .  ............ .       (0,h)  (1,h) ..............
==============================    ==============================

==============================    ==============================
MODE 0 =======================    MODE 1 =======================
=================== pix layout    =================== pix layout
n - 1 2n - 1 ..............       0     n       .............
.     .      ..............       1     n + 1   .............
.     .      ..............       2     n + 2   .............
.     .      ..............       .     .       .............
2     n + 2  ..............       .     .       .............
1     n + 1  ..............       .     .       .............
0     n      ..............       n - 1 2n - 1  .............
==============================    ==============================

==============================    ==============================
MODE 2 =======================    MODE 3 =======================
=================== pix layout    =================== pix layout
.     .     .     ..... .         0     1     2     ..... n
.     .     .     ..... .         n     n + 1 n + 2 ..... 2n - 1
.     .     .     ..... .         .     .     .     ..... .
.     .     .     ..... .         .     .     .     ..... .
.     .     .     ..... .         .     .     .     ..... .
n     n + 1 n + 2 ..... 2n - 1    .     .     .     ..... .
0     1     2     ..... n         .     .     .     ..... .
==============================    ==============================

用法

以 gcc-arm-none-eabi 套件为例

  • 参数赋值等号两端不能有空格
  • 若要赋值的文件路径包含空格,请用双引号包裹该路径
  • 如果未设置交叉编译工具链的环境变量,可以使用全路径
  • 需要先编译一份 elf 文件以便 make_word_library.py 脚本可以帮助你自动生成字库代码,事后还需要再把生成的代码添加到到你的项目中再重新编译一次
python make_word_library.py                                         \
    -f=宋体                                                         \
    -s=14                                                           \
    -m=0                                                            \
    -w=16                                                           \
    -h=16                                                           \
    -dump=arm-none-eabi-objdump                                     \
    -bin=my_project/path/for/load/binary.elf                        \
    -o=my_project/path/for/save/mixc_libword.hpp

About

Word library IC free when the product just show the fixed string

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages