sonicfirr 发表于 2022-4-8 20:04

【平头哥Sipeed LicheeRV 86 Panel测评】九、lvgl再使用

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">上篇编译</font><font face="Times New Roman">lvgl</font><font face="宋体">案例,使用的是&ldquo;</font><font face="Times New Roman">d1</font><font face="宋体">阿里小程序</font><font face="Times New Roman">_SDK</font><font face="宋体">&rdquo;中的工具链,当时这个工具链是配置在</font><font face="Times New Roman">Ubuntu</font><font face="宋体">虚机之上,今天将工具链部署在</font><font face="Times New Roman">WSL</font><font face="宋体">上再做尝试。</font></span></span></span></span></span></p>

<h2 style="text-align:justify"><span style="font-size:14pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-weight:bold"><b><span style="font-size:14.0000pt"><span style="font-family:宋体"><span style="font-weight:bold"><font face="Times New Roman">1</font><font face="宋体">、</font><font face="Times New Roman">WSL</font><font face="宋体">搭建</font><font face="Times New Roman">lvgl</font><font face="宋体">工具链</font></span></span></span></b></span></span></span></span></h2>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="Times New Roman">Windows</font><font face="宋体">环境中下载</font><font face="Times New Roman">d1</font><font face="宋体">阿里小程序</font><font face="Times New Roman">_SDK</font><font face="宋体">,导出其中的工具链&ldquo;</font><font face="Times New Roman">d1-sdk.tar.xz</font><font face="宋体">&rdquo;到</font><font face="Times New Roman">D</font><font face="宋体">盘根目录(方便</font><font face="Times New Roman">WSL</font><font face="宋体">访问)。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">9-1 </font></span></span><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="Times New Roman">WSL</font><font face="宋体">中路径就是</font><font face="Times New Roman">/mnt/d/d1-sdk.tar.xz</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="Times New Roman">WSL</font><font face="宋体">中拷贝工具链压缩包到主目录(做完后觉得可以不要这步,直接将</font><font face="Times New Roman">D</font><font face="宋体">盘工具链解压到</font><font face="Times New Roman">WSL</font><font face="宋体">的主目录就行)。然后就是执行命令解压&ldquo;</font><font face="Times New Roman">tar xvg d1-sdk.tar.xz</font><font face="宋体">&rdquo;,得到目录&ldquo;</font><font face="Times New Roman">d1-sdk/</font><font face="宋体">&rdquo;,包含四个文件。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">9-2 </font></span></span><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">拷贝工具链压缩包</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">9-3 </font></span></span><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">解压工具链压缩包</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">接着还是要建立</font>&ldquo;<font face="Times New Roman">~/.local/riscv64-toolchain</font><font face="宋体">&rdquo;目录,因为这是工具链的默认安装位置,然后就是执行</font><font face="Times New Roman">sh</font><font face="宋体">文件,执行解压和安装的过程。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">9-4 </font></span></span><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">安装工具链</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">9-5 </font></span></span><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">每次使用前在安装路径生效环境变量</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">这个工具链的环境变量是通过</font>&ldquo;<font face="Times New Roman">source</font><font face="宋体">&rdquo;命令来临时生效的,每次使用时需要做一下,才能在当前控制台注册环境变量。接着,就可以利用&ldquo;</font><font face="Times New Roman">$CC</font><font face="宋体">&rdquo;来进行编译了。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">再次尝试编译,这里使用了</font><font face="Times New Roman">VScode</font><font face="宋体">,因为可以开启</font><font face="Times New Roman">WSL</font><font face="宋体">控制台,所以将</font><font face="Times New Roman">Windows</font><font face="宋体">良好的编辑操作性和</font><font face="Times New Roman">Linux</font><font face="宋体">的工具能力相结合。通过修改顶层</font><font face="Times New Roman">Makefile</font><font face="宋体">,确定了编译工具就是</font><font face="Times New Roman">$CC</font><font face="宋体">,而输出文件这里随便改名为&ldquo;</font><font face="Times New Roman">aa_demo</font><font face="宋体">&rdquo;。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">至于下载和执行效果,这里就不展示,有不清楚的朋友可以看我的上篇(</font><font face="Times New Roman">https://bbs.eeworld.com.cn/thread-1198006-1-1.html</font><font face="宋体">)。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">9-6 </font></span></span><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">修改环境变量和编译</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<h2 style="text-align:justify"><span style="font-size:14pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-weight:bold"><b><span style="font-size:14.0000pt"><span style="font-family:宋体"><span style="font-weight:bold"><font face="Times New Roman">2</font><font face="宋体">、</font><font face="Times New Roman">lvgl</font><font face="宋体">按钮点击测试</font></span></span></span></b></span></span></span></span></h2>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">对于在下这种</font><font face="Times New Roman">API</font><font face="宋体">党来说,看文档学编程是主要技能,不过</font><font face="Times New Roman">lvgl</font><font face="宋体">的文档总感觉组织结构上条理性不好,看了半天虽谈不上一头雾水,也算是雾里看花。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">于是转而从两个方向进行借鉴,快速搭建一个按钮案例。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">一个方向是论坛的博主</font><font face="Times New Roman">manhuami2007</font><font face="宋体">的文章&ldquo;【平头哥</font><font face="Times New Roman">Sipeed LicheeRV 86 Panel</font><font face="宋体">测评】 </font><font face="Times New Roman">4-</font><font face="宋体">移植</font><font face="Times New Roman">lvgl-</font><font face="宋体">增加触控(</font><font face="Times New Roman">https://bbs.eeworld.com.cn/thread-1198282-1-1.html</font><font face="宋体">)&rdquo;。这位大神已经提供了两篇</font><font face="Times New Roman">lvgl</font><font face="宋体">在</font><font face="Times New Roman">86</font><font face="宋体">板上的移植方法。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">另一个方向就是百问网(韦东山老师)提供的</font><font face="Times New Roman">Demo</font><font face="宋体">(</font><font face="Times New Roman">https://gitee.com/weidongshan/imx6ull-lvgl/blob/master/lv_100ask/src/lv_100ask_demo/lv_100ask_demo.c</font><font face="宋体">)。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">整个开发也是不断试错的过程,这里就不再赘述,直接放代码</font>&mdash;&mdash;案例是基于博主<font face="Times New Roman">manhuami2007</font><font face="宋体">共享的工程,不清楚的朋友可以看本人的上一篇帖子。</font></span></span></span></span></span></p>

<p style="text-indent:24.0000pt; text-align:justify">&nbsp;</p>

<p align="center" style="text-align:center"> &nbsp;</p>

<p align="center" style="text-align:center"><span style="font-size:12pt"><span style="125%"><span style="font-family:&quot;Times New Roman&quot;"><span style="font-size:10.5000pt"><span style="font-family:宋体"><font face="宋体">图</font><font face="Times New Roman">9-7 </font></span></span><span style="font-size:12.0000pt"><span style="font-family:宋体"><font face="宋体">选择</font><font face="Times New Roman">lvgl</font><font face="宋体">的输入设备</font></span></span></span></span></span></p>

<p align="center" style="text-align:center">&nbsp;</p>

<pre>
<code>#include "lvgl/lvgl.h"
#include "lv_drivers/display/fbdev.h"
#include "lv_drivers/indev/evdev.h"
#include &lt;stdio.h&gt;
#include &lt;unistd.h&gt;
#include &lt;pthread.h&gt;
#include &lt;time.h&gt;
#include &lt;sys/time.h&gt;

#define DISP_BUF_SIZE (128 * 1024)

//by author. declare event callback
LV_EVENT_CB_DECLARE(test_btn_click_cb);
//by author. the button's label
lv_obj_t * test_btn_label;
int i = 0;
//by author. the event callback -- make console output &amp; change button's label
void test_btn_click_cb(lv_event_t *e) {
    char buf;
    sprintf(buf, "Clicked %d times", i++);
    printf("%s\n", buf);
    lv_label_set_text(test_btn_label, buf);
}

int main(void)
{
    /*LittlevGL init*/
    lv_init();

    /*Linux frame buffer device init*/
    fbdev_init(); //by author. initialize framebuffer device for display
    evdev_init(); //by author. initialize event device for touchpad

    /*A small buffer for LittlevGL to draw the screen's content*/
    static lv_color_t buf;

    /*Initialize a descriptor for the buffer*/
    static lv_disp_draw_buf_t disp_buf;
    lv_disp_draw_buf_init(&amp;disp_buf, buf, NULL, DISP_BUF_SIZE);

    /*Initialize and register a display driver*/
    static lv_disp_drv_t disp_drv;
    lv_disp_drv_init(&amp;disp_drv);
    disp_drv.draw_buf   = &amp;disp_buf;
    disp_drv.flush_cb   = fbdev_flush;
    disp_drv.hor_res    = 480;
    disp_drv.ver_res    = 480;
    lv_disp_drv_register(&amp;disp_drv);

    //by author. initialize and register event device
    lv_indev_drv_t indev_drv;
    lv_indev_drv_init(&amp;indev_drv);
    indev_drv.type = LV_INDEV_TYPE_POINTER; //by author. input device type, choice touchpad here
    indev_drv.read_cb = evdev_read;         //by author. callback to read input device data
    lv_indev_t *my_indev = lv_indev_drv_register(&amp;indev_drv);

    /*Create a Demo*/
    lv_obj_t *parent = lv_obj_create(lv_scr_act());
    lv_obj_set_size(parent,480,480);

    lv_obj_t * head_lable = lv_label_create(parent);
    lv_label_set_text(head_lable,"LVGL Test With WSL &amp; $CC Toolchain");
    lv_obj_align(head_lable,LV_ALIGN_TOP_MID,0,50);

    lv_obj_t * test_btn = lv_btn_create(parent);
    lv_obj_set_pos(test_btn, 10, 10);
    lv_obj_set_size(test_btn, 200, 50);
    lv_obj_align(test_btn, LV_ALIGN_CENTER,0,50);
    //by author. register clicked-event callback for the "test_btn" object
    lv_obj_add_event_cb(test_btn, test_btn_click_cb, LV_EVENT_CLICKED, NULL);
    test_btn_label = lv_label_create(test_btn);
    lv_label_set_text(test_btn_label, "Click");
    //by author. as you seen, the button's text actually is a label object attached to the button
    lv_obj_center(test_btn_label);

    /*Handle LitlevGL tasks (tickless mode)*/
    while(1) {
      lv_task_handler();
      usleep(5000);
    }

    return 0;
}</code></pre>

<p> &nbsp;</p>

manhuami2007 发表于 2022-4-9 17:02

看你的帖子,感觉WSL比虚拟机好用,之后要尝试一下

Jacktang 发表于 2022-4-9 17:05

<p>确实同感,<span style="color:#333333">WSL搭建lvgl工具链方法看来挺好用</span></p>

sonicfirr 发表于 2022-4-9 20:41

manhuami2007 发表于 2022-4-9 17:02
看你的帖子,感觉WSL比虚拟机好用,之后要尝试一下

<p>是啊,也是最近通过Waft手册才了解到这个东西,听说现在已经有WSA了,Android子系统。</p>

<p>关键是文件的无障碍访问,windows良好的编辑环境。</p>

sonicfirr 发表于 2022-4-10 15:37

后续测试发现“LV_EVENT_CB_DECLARE(test_btn_click_cb);”可以不用
页: [1]
查看完整版本: 【平头哥Sipeed LicheeRV 86 Panel测评】九、lvgl再使用