{"id":414,"date":"2026-04-23T16:59:05","date_gmt":"2026-04-23T08:59:05","guid":{"rendered":"https:\/\/xuemeng.work\/?p=414"},"modified":"2026-04-23T16:59:38","modified_gmt":"2026-04-23T08:59:38","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8%e5%b1%8f%e5%b9%95%e4%b8%8a%e6%98%be%e7%a4%ba%e6%96%87%e5%ad%97%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/xuemeng.work\/index.php\/2026\/04\/23\/%e5%a6%82%e4%bd%95%e5%9c%a8%e5%b1%8f%e5%b9%95%e4%b8%8a%e6%98%be%e7%a4%ba%e6%96%87%e5%ad%97%ef%bc%9f\/","title":{"rendered":"\u5982\u4f55\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u6587\u5b57\uff1f"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u524d\u8a00<\/h2>\n\n\n\n<p>\u6709\u4eba\u597d\u5947\uff0cXM POWER KIT\u662f\u600e\u4e48\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u6587\u5b57\u7684\uff0c\u5c24\u5176\u662f\u652f\u6301\u5404\u79cd\u5404\u6837\u7684\u5b57\u4f53\uff0c\u4e0b\u9762\u6211\u6765\u8fdb\u884c\u7b80\u5355\u7684\u8bb2\u89e3~<\/p>\n\n\n\n<p>\u786c\u4ef6\u4fe1\u606f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5c4f\u5e55\u9a71\u52a8\uff1aST7789 \uff08\u4e0d\u91cd\u8981\uff0c\u4f60\u80fd\u6210\u529f\u9a71\u52a8\u5c4f\u5e55\u5373\u53ef\uff09<\/li>\n\n\n\n<li>\u6279\u91cf\u5237\u5c4f\u51fd\u6570\uff08\u81f3\u5c11\u4f60\u6709\u4e00\u4e2a\u753b\u70b9\u51fd\u6570\uff09<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u5b9e\u73b0\u903b\u8f91<\/h2>\n\n\n\n<p>\u8981\u5f80\u5c4f\u5e55\u663e\u793a\u6587\u5b57\uff0c\u5f88\u5bb9\u6613\u60f3\u5230\u4e0b\u9762\u8fd9\u6761\u903b\u8f91\u94fe\u6761\uff08\u4ee5\u663e\u793a\u5355\u4e2a\u5b57\u7b26\u4e3a\u4f8b\uff09\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>1. \u4ece\u5b57\u5e93\u4e2d\u627e\u5230\u5b57\u7b26\u6570\u636e\u6240\u5728\u7684\u4f4d\u7f6e<\/li>\n\n\n\n<li>2. \u77e5\u6653\u6b64\u5b57\u7b26\u7684\u53c2\u6570\uff08\u5bbd\u5ea6\u3001\u9ad8\u5ea6\u3001\u989c\u8272\u7b49\uff09<\/li>\n\n\n\n<li>3. \u51c6\u5907\u5b57\u5b57\u7b26\u7684\u6570\u636e<\/li>\n\n\n\n<li>4. \u5c06\u5b57\u7b26\u5237\u5199\u5230\u5c4f\u5e55\u4e0a<\/li>\n<\/ul>\n\n\n\n<p>\u4ece\u4e0a\u9762\u7684\u903b\u8f91\u94fe\u6761\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u77e5\u9053\uff0c\u8981\u5b9e\u73b0\u5b57\u7b26\u663e\u793a\uff0c\u9700\u8981\u5b9e\u73b0\u4e0b\u9762\u8fd9\u4e9b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u600e\u4e48\u5904\u7406\u5f97\u5230\u5b57\u7b26\u7684\u5b57\u5e93\uff1f<\/li>\n\n\n\n<li>\u600e\u4e48\u5b9a\u4f4d\u5b57\u7b26\u5728\u5b57\u5e93\u4e2d\u7684\u4f4d\u7f6e\uff1f<\/li>\n\n\n\n<li>\u600e\u4e48\u5904\u7406\u5b57\u7b26\u7684\u6570\u636e\uff1f\uff08\u600e\u4e48\u5904\u7406\uff1f\u600e\u4e48\u6392\u5217\uff1f\uff09<\/li>\n\n\n\n<li>\u600e\u4e48\u5c06\u5b57\u7b26\u5237\u5199\u5230\u5c4f\u5e55\u4e0a\uff1f<\/li>\n<\/ul>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u4f9d\u6b21\u6765\u8bb2\u89e3\uff1a<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u5f97\u5230\u5b57\u5e93<\/h3>\n\n\n\n<p>\u4e3a\u4e86\u65b9\u4fbf\u7684\u9002\u914d\u5404\u79cd\u5b57\u4f53\uff0c\u6211\u8c03\u6559\u4e86\u534a\u5929\u8c46\u5305+kimi+grok\uff0c\u5199\u51fa\u4e86\u4e0b\u9762\u8fd9\u4e2a\u5b57\u7b26\u53d6\u6a21\u5de5\u5177\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/xuemeng.work\/wp-content\/uploads\/2026\/04\/image-9-1024x648.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"648\" data-original=\"https:\/\/xuemeng.work\/wp-content\/uploads\/2026\/04\/image-9-1024x648.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-416\" style=\"width:714px;height:auto\"  sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<p>\u5728\u5b9e\u73b0\u8fd9\u4e2a\u5e94\u7528\u4e4b\u524d\uff0c\u6211\u4eec\u5fc5\u987b\u5148\u7ea6\u5b9a\u4e00\u4e9b\u4fe1\u606f\uff0c\u624d\u80fd\u8ba9STM32\u80fd\u6b63\u786e\u4f7f\u7528\u5230\u5bfc\u51fa\u7684\u5b57\u5e93\uff1a<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.1 \u5b57\u7b26\u7f16\u7801<\/h4>\n\n\n\n<p>\u4f17\u6240\u5468\u77e5\uff0c\u6bcf\u4e00\u4e2a\u5b57\u7b26\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u7f16\u7801\u6765\u8868\u793a\u5b83\uff0c\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6211\u4eec\u9009\u62e9UTF8\u7f16\u7801\uff1aUTF-8 \u662f Unicode \u7684\u53d8\u957f\u5b57\u7b26\u7f16\u7801\uff0c\u4e92\u8054\u7f51\u5e38\u7528\uff0c\u517c\u5bb9 ASCII\uff0c\u5b57\u7b26\u957f\u5ea6 1 &#8211; 4 \u5b57\u8282\u53ef\u53d8\uff0c\u4e0d\u540c\u5b57\u8282\u6570\u5bf9\u5e94\u4e0d\u540c\u5b57\u7b26\u8303\u56f4\u3002<\/p>\n\n\n\n<p>\u6b64\u5916\uff0cUTF-8 <strong>\u4f9d\u9760\u6bcf\u4e2a\u5b57\u8282\u7684\u9ad8\u4f4d\u56fa\u5b9a\u524d\u7f00<\/strong>\u6765\u5224\u65ad\u5f53\u524d\u5b57\u7b26\u7684UTF8\u7f16\u7801\u6709\u51e0\u4f4d\uff0c\u6bd4\u5982\u7b2c\u4e00\u4f4d\u7f16\u7801\uff1a0xxxxxxx\u8868\u793a\u53ea\u67091\u4f4d\uff0c110xxxxx\u8868\u793a2\u4f4d\u957f\uff0c1110xxxx\u8868\u4e09\u4f4d\u957f&#8230;.<\/p>\n\n\n\n<p>\u4e3e\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ascii\u5b57\u7b26\u201cA\u201d\uff1a{ 0x41, 0x00, 0x00, 0x00 }<\/li>\n\n\n\n<li>\u5bf9\u4e8e\u4e2d\u6587\u201c\u56fd\u201d\uff1a{0xE7,0xBD,0x8A,0x00}<\/li>\n<\/ul>\n\n\n\n<p>ascii\u5b57\u7b26\u201cA\u201d\uff0c\u7531\u4e8e\u4f7f\u7528ascii\u5b57\u7b26\uff0c\u5b83\u53ea\u5360\u75281\u5b57\u8282\u7684\u7a7a\u95f4\uff0c\u5269\u4e0b\u7684\u5b57\u8282\u586b0\uff1b\u5bf9\u4e8e\u4e2d\u6587\u201c\u56fd\u201d\uff0c\u4f7f\u7528\u4e09\u4e2a\u5b57\u8282\u6765\u7f16\u7801\uff0c\u5269\u4e0b\u7684\u4e5f\u662f\u586b0 \u3002\u800c\u5728C\u8bed\u8a00\u91cc\uff0c\u83b7\u53d6\u5b57\u7b26\u7684UTF8\u7f16\u7801\u975e\u5e38\u7b80\u5355\uff0c\u6bd4\u5982\u5b57\u7b26char msg = &#8220;\u56fd&#8221;\uff0c\u6211\u4eec\u76f4\u63a5*msg\u5c31\u80fd\u5b9a\u4f4d\u5230\u6b64\u5b57\u7b26\u7f16\u7801\u7684\u9996\u5b57\u7b26\uff0c\uff08\u524d\u63d0\u662f\u4f60\u7684\u7f16\u8bd1\u5668\u7528\u7684UTF8\u7f16\u7801\uff09\u3002<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0c\u6211\u4eec\u5728STM32\u7aef\u5c31\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684\u51fd\u6570\u6765\u5224\u65ad\u6b64\u5b57\u7b26\u7684\u7f16\u7801\u957f\u5ea6\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>static inline uint8_t get_utf8_len(const char *str) {\n    uint8_t len = 0;\n    if ((*str &amp; 0x80) == 0) {\n        len = 1; \/\/ ASCII\n    } else if ((*str &amp; 0xE0) == 0xC0) {\n        len = 2; \/\/ 2\u5b57\u8282UTF-8\n    } else if ((*str &amp; 0xF0) == 0xE0) {\n        len = 3; \/\/ 3\u5b57\u8282UTF-8\n    } else if ((*str &amp; 0xF8) == 0xF0) {\n        len = 4; \/\/ 4\u5b57\u8282UTF-8\n    }\n    return len;\n}<\/code><\/pre>\n\n\n\n<p>\u7efc\u4e0a\u6240\u8ff0\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5728\u751f\u6210\u5b57\u5e93\u7684\u65f6\u5019\uff0c\u8bb0\u5f55\u4e0b\u6bcf\u4e2a\u5b57\u7b26\u4ee3\u7801\u7684UTF8\u7f16\u7801\uff0c\u5c31\u8fd1\u4e4e\u53ef\u4ee5\u786e\u8ba4\u5b83\u5728\u5b57\u5e93\u4e2d\u7684\u4f4d\u7f6e\u4e86,\u5982\u4e0b\u4ee3\u7801\u3002\uff08\u8fd8\u9700\u8981\u6bcf\u4e2a\u5b57\u7b26\u7684\u6570\u636e\u957f\u5ea6\u7b49\u4fe1\u606f\uff0c\u4e0b\u9762\u4f1a\u8bb2\uff09.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const uint8_t font_map_JetBrainsMono16x22&#91;]&#91;4] = {\n    { 0x56, 0x00, 0x00, 0x00 },  \/* V *\/\n    { 0x41, 0x00, 0x00, 0x00 },  \/* A *\/\n    { 0x57, 0x00, 0x00, 0x00 },  \/* W *\/\n    { 0x4B, 0x00, 0x00, 0x00 },  \/* K *\/\n    { 0xCE, 0xA9, 0x00, 0x00 },  \/* \u03a9 *\/\n};<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">1.2 \u5b57\u7b26\u53d6\u6a21<\/h4>\n\n\n\n<p>\u9996\u5148\uff0c\u6211\u4eec\u8981\u89c4\u5b9a\u53d6\u6a21\u7684\u65b9\u5411\u3002\u6211\u4eec\u53ef\u4ee5\u5c06\u4e00\u4e2a\u5b57\u7b26\u5212\u5206\u4e3an*m\u5404\u5c0f\u683c\u5b50\uff08\u5982\u524d\u56fe\uff09\uff0c\u53d6\u6a21\u65b9\u5411\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u662f\u4ece\u4e0a\u5f80\u4e0b\uff0c\u4ece\u5de6\u5f80\u53f3 \u884c\u4f18\u5148\u8fd9\u6837\u5b50<strong>\u4e00\u884c\u4e00\u884c\u53d6\u6a21<\/strong>\uff0c\u8fd8\u662f\u8bf4\u4ece\u4e0a\u5230\u4e0b\uff0c\u4ece\u5de6\u5230\u53f3 \u5217\u4f18\u5148\u8fd9\u6837<strong>\u4e00\u5217\u4e00\u5217\u53d6\u6a21<\/strong>\u3002\u6211\u4eec\u770b\u5927\u591a\u6570\u7684\u5c4f\u5e55\u9a71\u52a8\uff08ST7789 ,ILI9341\u7b49\uff09\uff0c\u5728\u5237\u65b0\u5c4f\u5e55\u7684\u65f6\u5019\u90fd\u662f<strong>\u884c\u4f18\u5148<\/strong>\uff0c\u6240\u4ee5\u6211\u4eec\u9009\u53d6\u7b2c\u4e00\u79cd\u65b9\u6848\u3002<\/p>\n\n\n\n<p>\u5176\u6b21\uff0c\u4e3a\u4e86\u65b9\u4fbf\uff0c\u6211\u4eec\u89c4\u5b9a\uff1a\u6211\u4eec\u53ea\u4fdd\u7559\u5b57\u4f53\u6570\u636e\uff0c\u4e24\u4e2a\u5b57\u4f53\u95f4\u7684\u6570\u636e\u7d27\u6328\u7740\u4e00\u8d77\u3002\u4ec0\u4e48\u610f\u601d\u5462\uff1f\u5c31\u662f\u6211\u4eec\u4e0d\u4f1a\u5b58\u7559\u4efb\u4f55\u6587\u4ef6\u5934\u554a\u4e4b\u7c7b\u7684\u6570\u636e\uff0c\u6bd4\u5982\u8bf4\u4f60\u7684\u5b57\u4f53\u5927\u5c0f\u662f16*16\uff0c\u67095\u4e2a\u5b57\u7b26\uff0c\u90a3\u4e48\u5b57\u5e93\u5927\u5c0f\u5c31\u662f\uff1a<\/p>\n\n\n\n<div class=\"wp-block-math\"><math display=\"block\"><semantics><mrow><mn>16<\/mn><mo>\u00d7<\/mo><mn>16<\/mn><mo>\u00d7<\/mo><mn>5<\/mn><mo>=<\/mo><mn>1280<\/mn><mtext>&nbsp;\u5b57\u8282<\/mtext><\/mrow><annotation encoding=\"application\/x-tex\">16 \\times 16 \\times 5 = 1280 \\text{ \u5b57\u8282}\n<\/annotation><\/semantics><\/math><\/div>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u79cd\u65b9\u5f0f\u9700\u8981<strong>\u5916\u90e8\u8bb0\u5f55\u5b57\u7b26\u6392\u5217\u7684\u987a\u5e8f<\/strong>\u3002\u5426\u5219\u6211\u4eec\u6ca1\u6cd5\u77e5\u9053\u67d0\u4e00\u5757\u6570\u636e\u8868\u793a\u4ec0\u4e48\u5b57\u7b26\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">1.3 \u5b57\u5e93\u4fdd\u5b58<\/h4>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4e3a\u4e86\u6297\u952f\u9f7f\uff0c\u6bcf\u4e00\u4e2a\u683c\u5b50\u5c31\u4e0d\u518d\u4f7f\u75281bit\u6765\u5b58\u50a8\uff08\u53ea\u80fd\u8868\u793a\u4eae\u706d\uff09\uff0c\u800c\u662f1\u4e2a\u50cf\u7d20\u75288bit\u6765\u8868\u793a\uff0c\u8fd9\u6837\u5c31\u6709256\u79cd\u4eae\u5ea6\u4e86\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u5c06\u6240\u6709\u5b57\u7b26\u53d6\u6a21\uff0c\u7d27\u6328\u7740\u62fc\u63a5\u5728\u4e00\u8d77\uff0c\u5bfc\u51fa\u6210xxx.bin\u6587\u4ef6\u6765\u5b58\u50a8\u3002\u6211\u4eec\u53ea\u9700\u8981\u5c06\u5b83\u79fb\u52a8\u5230FLASH\u4e2d\u5373\u53ef\uff0cSTM32\u53ef\u4ee5\u4f7f\u7528FATFS\u8fd9\u6837\u7684\u6587\u4ef6\u7cfb\u7edf\u6765\u8bfb\u53d6\u5b83\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5b9a\u4f4d\u5b57\u7b26\u4f4d\u7f6e<\/h3>\n\n\n\n<p>\u524d\u6587\u63d0\u5230\uff0c\u6211\u4eec\u73b0\u5728\u5df2\u7ecf\u62ff\u5230\u4e86\u53d6\u6a21\u51fa\u7684\u5b57\u5e93\uff0c\u63a5\u4e0b\u6765\u5c31\u662fSTM32\u7aef\u7684\u4e3b\u573a\u4e86\uff0c\u6211\u4eec\u6765\u601d\u8003\u600e\u4e48\u5b9a\u4f4d\u5230\u5b57\u7b26\u6570\u636e\u3002<\/p>\n\n\n\n<p>\u6211\u4eec\u6765\u60f3\u4e00\u60f3\uff0c\u6bcf\u4e2a\u5b57\u7b26\u7684\u6570\u636e\u662f\u7d27\u5bc6\u6392\u5217\u7684\uff0c\u800c\u4e14\u6bcf\u4e2a\u5b57\u7b26\u7684\u5c3a\u5bf8\u662f\u56fa\u5b9a\u7684\uff08\u957f*\u5bbd\uff09\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u6839\u636e\u8fd9\u4e2a\u6765\u5224\u65ad\uff01<\/p>\n\n\n\n<p>\u6211\u4eec\u5b9a\u4e49\u4e0b\u9762\u8fd9\u6837\u4e00\u4e2a\u7ed3\u6784\u4f53\uff0c\u6765\u5b58\u50a8\u6bcf\u4e00\u79cd\u5b57\u4f53\u7684\u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5b57\u4f53\u4fe1\u606f\u7ed3\u6784\u4f53\ntypedef struct {\n    uint8_t         font_width;                      \/\/ \u5b57\u4f53\u5bbd\u5ea6\n    uint8_t         font_height;                     \/\/ \u5b57\u4f53\u9ad8\u5ea6\n    uint16_t        font_num;                        \/\/ \u5b57\u7b26\u4e2a\u6570\n    char            path&#91;FONT_PATH_MAX];             \/\/ \u5b8c\u6574\u8def\u5f84\uff0c\u4f8b\u5982 \"0:\/fonts\/font16x16.bin\"\n    const uint8_t   (*font_map)&#91;4];                  \/\/ \u67e5\u627e\u8868\u6307\u9488\n} FontInfo;<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u8bb0\u5f55\u4e86\u6b64\u5b57\u4f53\u7684\u957f\u5bbd\u3001\u6570\u91cf\u3001\u4ee5\u53caUTF8\u67e5\u627e\u8868\u3002\u90a3\u4e48\u4e00\u4e2a\u6807\u51c6\u7684\u5b57\u5e93\u5c31\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/*========== JetBrainsMono\u5b57\u4f5326\u53f7 ==========*\/\nconst uint8_t font_map_JetBrainsMono16x22&#91;]&#91;4] = {\n    { 0x56, 0x00, 0x00, 0x00 },  \/* V *\/\n    { 0x41, 0x00, 0x00, 0x00 },  \/* A *\/\n    { 0x57, 0x00, 0x00, 0x00 },  \/* W *\/\n    { 0x4B, 0x00, 0x00, 0x00 },  \/* K *\/\n    { 0xCE, 0xA9, 0x00, 0x00 },  \/* \u03a9 *\/\n};\n\nconst FontInfo JetBrainsMono16x22 = {\n    .font_width  = 16,\n    .font_height = 22,\n    .font_num    = 5,\n    .path        = \"0:\/font\/JetBrainsMono16x22.bin\",\n    .font_map    = font_map_JetBrainsMono16x22\n};<\/code><\/pre>\n\n\n\n<p>UTF8\u67e5\u627e\u8868 + \u7ed3\u6784\u4f53\uff01\u6211\u4eec\u5c31\u53ef\u4ee5\u8868\u793a\u51fa\u4e00\u4e2a\u5b57\u5e93\u6211\u4eec\u6240\u9700\u8981\u7684\u4fe1\u606f\u4e86\uff01<\/p>\n\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u6765\u6f14\u793a\u4e00\u4e0b\u600e\u4e48\u67e5\u627e\u5b57\u5e93\u4e2d\u67d0\u4e2a\u5b57\u7b26\uff0c\u6bd4\u5982\u201cW\u201d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u5728\u5b57\u4f53\u6620\u5c04\u8868\u4e2d\u67e5\u627e\u5b57\u7b26\u7684\u7d22\u5f15\nstatic int16_t find_char_index(const FontInfo *font, const char *string) {\n    uint8_t len = get_utf8_len(string);\n    if (len == 0) return 0;\n\n    for (uint16_t i = 0; i &lt; font->font_num; i++) {\n        uint8_t *head = (uint8_t *) font->font_map&#91;i];\n        if (memcmp(head, string, len) == 0) {\n            return i;\n        }\n    }\n    return -1; \/\/ \u672a\u627e\u5230\uff0c\u8fd4\u56de-1\n}<\/code><\/pre>\n\n\n\n<p>\u6211\u4eec\u770b\u6b64\u51fd\u6570\uff0c\u5b83\u7684\u4f5c\u7528\u5f88\u7b80\u5355\uff0c\u62ff\u7740\u201cW\u201d\u5b57\u7b26\u7684UTF8\u6570\u636e\u53bb\u67e5\u627e\u8868\u4f9d\u6b21\u6bd4\u8f83\uff0c\u6bd4\u8f83\u6210\u529f\u5c31\u8fd4\u56de\u5b83\u5728\u67e5\u627e\u8868\u4e2d\u662f\u7b2c\u51e0\u4f4d\u3002\u6bd4\u5982\u8bf4&#8221;W&#8221;\uff0c\u6b64\u51fd\u6570\u5c31\u4f1a\u8fd4\u56dei = 2\uff1b\uff08\u7b2c\u4e09\u4e2a\uff09\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u5c31\u53ef\u4ee5\u5b9a\u4f4d\u5230\u201cW\u201d\u5728\u5b57\u5e93\u4e2d\u6570\u636e\u7684\u9996\u4f4d\u4e86\uff0c\u5f88\u7b80\u5355\uff0c<strong>i * .font_width * .font_height<\/strong> \u5373\u53ef\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u51c6\u5907\u5b57\u7b26\u6570\u636e<\/h3>\n\n\n\n<p>\u627e\u5230\u4e86\u5b57\u7b26\u6570\u636e\u6240\u5728\u7684\u8d77\u59cb\u4f4d\u7f6e\u5c31\u5f88\u7b80\u5355\u4e86\uff0c\u6211\u4eec\u53ea\u9700\u8981\u51c6\u5907\u4e00\u4e2a\u8db3\u591f\u5927\u7684\u7f13\u51b2\u533a\uff0c\u4eceFLASH\u4e2d\u8bfb\u53d6 <strong>.font_width * .font_height<\/strong> \u4e2a\u5b57\u8282\u7684\u6570\u636e\u5230\u7f13\u51b2\u533a\u91cc\u5373\u53ef\u3002\u5982\u679c\u5b57\u7b26\u5f88\u5927\uff0c\u90a3\u4e48\u5199\u4e00\u4e2a\u5206\u5757\u903b\u8f91\u5c31\u884c\u3002<\/p>\n\n\n\n<p>\u6b64\u5916\uff0c\u6211\u4eec\u8fd8\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u5904\u7406\uff0c\u56e0\u4e3a\u73b0\u5728\u8bfb\u5230\u7f13\u51b2\u533a\u7684\u8fd8\u662f\u7070\u5ea6\u6570\u636e\uff0c\u662f\u6ca1\u6709\u989c\u8272\u7684\uff01\u6211\u4eec\u53ef\u4ee5\u4f20\u5165\u5b57\u4f53\u989c\u8272\u548c\u5e95\u8272\uff0c\u8fdb\u884c\u4e00\u4e2a\u7b80\u5355\u7684alpha\u6df7\u5408\uff1a\u5c31\u53ef\u4ee5\u5f88\u5927\u7a0b\u5ea6\u7684\u6539\u5584\u663e\u793a\u6548\u679c\uff0c\u907f\u514d\u952f\u9f7f\uff01<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ RGB565\u901a\u9053\u62c6\u5206\/\u5408\u5e76\u5b8f\n#define RGB565_GET_R(color)    (((color) >> 11) &amp; 0x1F)\n#define RGB565_GET_G(color)    (((color) >> 5)  &amp; 0x3F)\n#define RGB565_GET_B(color)    ((color) &amp; 0x1F)\n#define RGB565_MERGE(r, g, b)  (((r &amp; 0x1F) &lt;&lt; 11) | ((g &amp; 0x3F) &lt;&lt; 5) | (b &amp; 0x1F))\n\n\/\/ \u6279\u91cf\u7070\u5ea6\u56fe\u8f6cRGB565\nstatic void batch_gray_to_rgb565(const uint8_t *gray_buf, uint16_t *flush_buf, uint32_t pixel_num, uint16_t ftColor,\n                                 uint16_t bgColor) {\n    register uint8_t ft_r = RGB565_GET_R(ftColor);\n    register uint8_t ft_g = RGB565_GET_G(ftColor);\n    register uint8_t ft_b = RGB565_GET_B(ftColor);\n    register uint8_t bg_r = RGB565_GET_R(bgColor);\n    register uint8_t bg_g = RGB565_GET_G(bgColor);\n    register uint8_t bg_b = RGB565_GET_B(bgColor);\n\n    volatile uint32_t i;\n    uint32_t remain = pixel_num % 4; \/\/ \u5904\u7406\u4e0d\u80fd\u88ab4\u6574\u9664\u7684\u5269\u4f59\u50cf\u7d20\n    uint32_t main_num = pixel_num - remain;\n\n    \/\/ \u4e3b\u5faa\u73af\uff1a\u6bcf\u6b21\u5904\u74064\u4e2a\u50cf\u7d20\uff0c\u51cf\u5c11\u5faa\u73af\u6b21\u6570\n    for (i = 0; i &lt; main_num; i += 4) {\n        \/\/ \u50cf\u7d201\n        uint8_t g1 = gray_buf&#91;i];\n        uint32_t r1 = bg_r * (255 - g1) + ft_r * g1;\n        uint32_t g1_ = bg_g * (255 - g1) + ft_g * g1;\n        uint32_t b1 = bg_b * (255 - g1) + ft_b * g1;\n        flush_buf&#91;i] = RGB565_MERGE((r1+127)\/255, (g1_+127)\/255, (b1+127)\/255);\n\n        \/\/ \u50cf\u7d202\n        uint8_t g2 = gray_buf&#91;i + 1];\n        uint32_t r2 = bg_r * (255 - g2) + ft_r * g2;\n        uint32_t g2_ = bg_g * (255 - g2) + ft_g * g2;\n        uint32_t b2 = bg_b * (255 - g2) + ft_b * g2;\n        flush_buf&#91;i + 1] = RGB565_MERGE((r2+127)\/255, (g2_+127)\/255, (b2+127)\/255);\n\n        \/\/ \u50cf\u7d203\n        uint8_t g3 = gray_buf&#91;i + 2];\n        uint32_t r3 = bg_r * (255 - g3) + ft_r * g3;\n        uint32_t g3_ = bg_g * (255 - g3) + ft_g * g3;\n        uint32_t b3 = bg_b * (255 - g3) + ft_b * g3;\n        flush_buf&#91;i + 2] = RGB565_MERGE((r3+127)\/255, (g3_+127)\/255, (b3+127)\/255);\n\n        \/\/ \u50cf\u7d204\n        uint8_t g4 = gray_buf&#91;i + 3];\n        uint32_t r4 = bg_r * (255 - g4) + ft_r * g4;\n        uint32_t g4_ = bg_g * (255 - g4) + ft_g * g4;\n        uint32_t b4 = bg_b * (255 - g4) + ft_b * g4;\n        flush_buf&#91;i + 3] = RGB565_MERGE((r4+127)\/255, (g4_+127)\/255, (b4+127)\/255);\n    }\n\n    \/\/ \u5904\u7406\u5269\u4f59\u50cf\u7d20\n    for (; i &lt; pixel_num; i++) {\n        uint8_t g = gray_buf&#91;i];\n        uint32_t r = bg_r * (255 - g) + ft_r * g;\n        uint32_t g_ = bg_g * (255 - g) + ft_g * g;\n        uint32_t b = bg_b * (255 - g) + ft_b * g;\n        flush_buf&#91;i] = RGB565_MERGE((r+127)\/255, (g_+127)\/255, (b+127)\/255);\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u522b\u770b\u7740\u5f88\u957f\uff0c\u5176\u5b9e\u662f\u4e3a\u4e86\u6548\u7387\u624d\u8fd9\u4e48\u5199\u7684\uff0c\u4e00\u6b21\u6027\u5904\u74064\u4e2a\u50cf\u7d20\uff0c\u4fbf\u4e8e\u7f16\u8bd1\u5668\u4f18\u5316~<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u5237\u65b0\u5c4f\u5e55<\/h3>\n\n\n\n<p>\u73b0\u5728\u5c31\u5f88\u7b80\u5355\u4e86\uff0c\u6211\u4eec\u5728\u7b2c\u4e09\u6b65\u4ee5\u53ca\u5f97\u5230\u4e86\u5b58\u50a8\u7740RGB565\u6570\u636e\u7684\u7f13\u51b2\u533a\uff0c\u6211\u4eec\u53ea\u9700\u8981\u8bbe\u7f6e\u597d\u5c4f\u5e55\u7684\u5237\u65b0\u8303\u56f4\uff0c\u7136\u540e\u5c06\u7f13\u51b2\u533a\u6570\u636e\u4e00\u80a1\u8111\u5237\u4e0a\u53bb\u5c31\u884c~<\/p>\n\n\n\n<p>\u81f3\u4e8e\u6570\u636e\u7684\u6392\u5217\u987a\u5e8f\uff0c\u6211\u4eec\u5728\u53d6\u6a21\u5bfc\u51fa\u7684\u65f6\u5019\u5c31\u5df2\u7ecf\u5904\u7406\u597d\u4e86\uff0c\u8fd9\u91cc\u5c31\u4e0d\u9700\u8981\u505a\u4efb\u4f55\u5904\u7406\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001\u603b\u7ed3<\/h2>\n\n\n\n<p>\u7efc\u4e0a\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u6b65\u9aa4\u5408\u5e76\u6210\u4e00\u4e2a\u51fd\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u7ed8\u5236\u5355\u4e2a\u5b57\u7b26(\u4f5c\u4e3a\u7ed8\u5236\u5b57\u7b26\u4e32\u7684\u5e95\u5c42\u51fd\u6570\uff0c\u5916\u90e8\u63a5\u53e3\u4e3a GFX_DrawString)\nstatic void GFX_DrawChar(FIL *FIL, uint16_t x, uint16_t y, const char *ch, const FontInfo *font,\n                         uint16_t ftColor, uint16_t bgColor, uint8_t *gray_buffer, uint16_t *flush_buffer) {\n    int16_t index = find_char_index(font, ch); \/\/ \u83b7\u53d6\u5b57\u7b26\u7d22\u5f15\n    if (index == -1) { return; } \/\/ \u5b57\u7b26\u672a\u627e\u5230\uff0c\u76f4\u63a5\u8fd4\u56de\n\n    uint32_t pixel_num = font->font_width * font->font_height; \/\/ \u8ba1\u7b97\u50cf\u7d20\u603b\u6570\n\n    if (FIL == NULL || gray_buffer == NULL || flush_buffer == NULL) {\n        return; \/\/ \u53c2\u6570\u68c0\u67e5\uff0c\u786e\u4fdd\u6307\u9488\u6709\u6548\n    }\n\n    \/\/ \u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5b57\u6a21\u6570\u636e\u5230\u7070\u5ea6\u7f13\u51b2\u533a\n    res = f_lseek(FIL, index * pixel_num); \/\/ \u5b9a\u4f4d\u5230\u5b57\u6a21\u6570\u636e\u4f4d\u7f6e\n    if (res != FR_OK) { return; }\n\n    res = f_read(FIL, gray_buffer, pixel_num, &amp;br); \/\/ \u8bfb\u53d6\u5b57\u6a21\u6570\u636e\n    if (res != FR_OK || br != pixel_num) { return; } \/\/ \u8bfb\u53d6\u5931\u8d25\u6216\u5b57\u8282\u6570\u4e0d\u5339\u914d\n\n    \/\/ \u6839\u636e\u7070\u5ea6\u6570\u636e\uff0c\u878d\u5408\u524d\u666f\u8272\u548c\u80cc\u666f\u8272\u751f\u6210\u6700\u7ec8\u7684RGB565\u6570\u636e\u5230Flush_Buffer\n    batch_gray_to_rgb565(gray_buffer, flush_buffer, pixel_num, ftColor, bgColor);\n\n    \/\/ \u8bbe\u7f6eLCD\u7a97\u53e3\u5e76\u4f7f\u7528DMA\u53d1\u9001Flush_Buffer\u6570\u636e\u5230LCD\n    LCD_SET_WINDOWS(x, y, x + font->font_width - 1, y + font->font_height - 1);\n    LCD_FLUSH_DMA((uint32_t) flush_buffer, pixel_num);\n}<\/code><\/pre>\n\n\n\n<p>\u5982\u679c\u662f\u5b57\u7b26\u4e32\uff0c\u5faa\u73af\u4e0a\u9762\u7684\u7ed8\u5236\u5355\u4e2a\u5b57\u7b26\u7684\u4ee3\u7801\u5c31\u884c\u4e86~<\/p>\n\n\n\n<p>\u8fd9\u91cc\u7684\u53c2\u6570\u610f\u4e49\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b57\u7b26\u4e32\u5de6\u4e0a\u89d2\u7684\u5750\u6807\uff08x , y\uff09<\/li>\n\n\n\n<li>\u4f60\u8981\u6253\u5370\u7684\u5b57\u7b26\u4e32\u6307\u9488 str<\/li>\n\n\n\n<li>\u4f60\u9009\u7528\u7684\u5b57\u4f53\u7ed3\u6784\u4f53 font<\/li>\n\n\n\n<li>\u5b57\u4f53\u989c\u8272 ftColor<\/li>\n\n\n\n<li>\u80cc\u666f\u989c\u8272 bgColor<\/li>\n\n\n\n<li>\u5b57\u7b26\u95f4\u8ddd spacing<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>void GFX_DrawString(uint16_t x, uint16_t y, const char *str, const FontInfo *font,<br>                    uint16_t ftColor, uint16_t bgColor, int8_t spacing) {<br>    if (str == NULL || font == NULL) {<br>        return; \/\/ \u53c2\u6570\u68c0\u67e5\uff0c\u786e\u4fdd\u6307\u9488\u6709\u6548<br>    }<br><br>    res = f_open(&amp;fil, font-&gt;path, FA_READ);<br>    if (res != <em>FR_OK<\/em>) {<br>        return; \/\/ \u6253\u5f00\u5b57\u4f53\u6587\u4ef6\u5931\u8d25<br>    }<br><br>    uint32_t pixel_num = font-&gt;font_width * font-&gt;font_height;<br>    uint8_t *gray_buffer = malloc(pixel_num); \/\/ \u5b57\u6a21\u7070\u5ea6\u7f13\u51b2\u533a<br>    uint16_t *flush_buffer = malloc(pixel_num * 2); \/\/ RGB565\u7f13\u51b2\u533a<br><br>    if (gray_buffer == NULL || flush_buffer == NULL) {<br>        f_close(&amp;fil);<br>        if (gray_buffer) free(gray_buffer);<br>        if (flush_buffer) free(flush_buffer);<br>        return; \/\/ \u5185\u5b58\u5206\u914d\u5931\u8d25<br>    }<br><br>    uint16_t cursor_x = x;<br>    const char *p = str;<br><br>    while (*p) {<br>        uint8_t utf8_len = get_utf8_len(p);<br>        if (utf8_len == 0) break; \/\/ \u65e0\u6548UTF-8\u7f16\u7801\uff0c\u505c\u6b62\u5904\u7406<br><br>        \/\/ 1. \u5148\u83b7\u53d6\u5b57\u7b26\u7d22\u5f15\uff08\u63d0\u524d\u5224\u65ad\u662f\u5426\u627e\u5230\u5b57\u7b26\uff09<br>        int16_t char_index = find_char_index(font, p);<br>        \/\/ 2. \u5224\u65ad\u662f\u5426\u4e3a\u5c0f\u6570\u70b9\uff08.\uff09\uff1a\u4ec5\u5355\u5b57\u8282ASCII 0x2E<br>        uint8_t is_dot = (utf8_len == 1 &amp;&amp; (uint8_t) *p == 0x2E) ? 1 : 0;<br>        uint16_t char_step = 0; \/\/ \u521d\u59cb\u5316\u5b57\u7b26\u6b65\u8fdb\u503c<br><br>        \/\/ 3. \u6838\u5fc3\u903b\u8f91\uff1a\u6839\u636e\u5b57\u7b26\u662f\u5426\u627e\u5230 + \u662f\u5426\u4e3a\u5c0f\u6570\u70b9\uff0c\u8ba1\u7b97\u6b65\u8fdb\u503c<br>        if (char_index == -1) {<br>            \/\/ \u5b57\u7b26\u672a\u627e\u5230\uff1a\u6b65\u8fdb\u503c = 0.7 * \u5b57\u4f53\u5bbd\u5ea6 \u5411\u4e0a\u53d6\u6574<br>            char_step = (uint16_t) ceil(font-&gt;font_width * 0.7f);<br>        } else if (is_dot) {<br>            \/\/ \u5c0f\u6570\u70b9\uff1a\u4f7f\u7528\u539f\u6709\u6709\u6548\u5bbd\u5ea6<br>            char_step = get_dot_effective_width(font);<br>        } else {<br>            \/\/ \u666e\u901a\u5b57\u7b26\uff08\u627e\u5230\uff09\uff1a\u4f7f\u7528\u539f\u6709\u5b8c\u6574\u5bbd\u5ea6<br>            char_step = font-&gt;font_width;<br>        }<br><br>        \/\/ 4. \u4ec5\u5f53\u5b57\u7b26\u627e\u5230\u65f6\uff0c\u624d\u7ed8\u5236\u5b57\u7b26<br>        if (char_index != -1) {<br>            if (is_dot) {<br>                GFX_DrawDotChar(&amp;fil, cursor_x, y, p, font, ftColor, bgColor, gray_buffer, flush_buffer);<br>            } else {<br>                GFX_DrawChar(&amp;fil, cursor_x, y, p, font, ftColor, bgColor, gray_buffer, flush_buffer);<br>            }<br>        }<br><br>        \/\/ 5. \u5b57\u4f53\u95f4\u9694\u7ed8\u5236\uff08\u539f\u6709\u903b\u8f91\u4fdd\u7559\uff09<br>        if (spacing &gt; 0 &amp;&amp; *(p + utf8_len) != '\\0') {<br>            int16_t spacing_x1 = cursor_x + char_step;<br>            int16_t spacing_x2 = spacing_x1 + spacing - 1;<br>            uint16_t spacing_y1 = y;<br>            uint16_t spacing_y2 = y + font-&gt;font_height - 1;<br><br>            GFX_DrawRect(spacing_x1, spacing_y1, spacing_x2, spacing_y2, bgColor, 1);<br>        }<br><br>        \/\/ 6. \u79fb\u52a8\u6e38\u6807\uff1a\u5b57\u7b26\u6b65\u8fdb\u503c + \u5b57\u95f4\u8ddd\uff08\u517c\u5bb9\u6b63\u8d1f\uff09<br>        cursor_x += (char_step + spacing);<br>        p += utf8_len; \/\/ \u79fb\u52a8\u5230\u4e0b\u4e00\u4e2aUTF-8\u5b57\u7b26<br>    }<br><br>    free(gray_buffer);<br>    free(flush_buffer);<br>    f_close(&amp;fil);<br>}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>\u597d\u4e86\uff0c\u7b80\u5355\u8fc7\u4e86\u4e00\u904d\uff0c\u5927\u4f53\u7684\u903b\u8f91\u5c31\u662f\u8fd9\u6837\u5b50\uff0c\u7ec6\u8282\u7684\u8bdd\u53ef\u4ee5\u770b\u770b\u539f\u4ee3\u7801~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u524d\u8a00 \u6709\u4eba\u597d\u5947\uff0cXM POWER KIT\u662f\u600e\u4e48\u5728\u5c4f\u5e55\u4e0a\u663e\u793a\u6587\u5b57\u7684\uff0c\u5c24\u5176\u662f\u652f\u6301\u5404\u79cd\u5404\u6837\u7684\u5b57\u4f53\uff0c\u4e0b\u9762\u6211\u6765\u8fdb\u884c\u7b80 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":420,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,10,13],"tags":[24,22,26],"class_list":["post-414","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-xm-power-kit","category-10","category-13","tag-clion","tag-stm32","tag-xm-power-kit"],"_links":{"self":[{"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/posts\/414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/comments?post=414"}],"version-history":[{"count":4,"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/posts\/414\/revisions"}],"predecessor-version":[{"id":421,"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/posts\/414\/revisions\/421"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/media\/420"}],"wp:attachment":[{"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/media?parent=414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/categories?post=414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xuemeng.work\/index.php\/wp-json\/wp\/v2\/tags?post=414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}