查看: 4527|回复: 13

[原创] 基于LPC55S69学习GUI-Guider软件分享一 ----- lvgl移植

[复制链接]
  • TA的每日心情
    奋斗
    昨天 14:38
  • 签到天数: 1947 天

    [LV.Master]伴坛终老

    61

    主题

    1万

    帖子

    3

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    17356
    最后登录
    2024-5-3
    发表于 2021-7-5 21:52:13 | 显示全部楼层 |阅读模式
            GUI Guider是恩智浦推出的一个PC端开发工具,专门用于开发LVGL GUI界面的图形化开发工具。LVGL是一个非常不错的开源gui,一直想试一试的。这次主要分享自己移植lvgl,以及利用GUI Guider开发基于lvgl的界面设计。        GUI Guider早就安装了1.0版本,也试着创建项目看了看,发现目前支持的开发板有点少,而且自己还没有那些板子。就一直想着移植到其他板子上玩玩。这次研究了一下,也参考网上的一些资料,成功移到自己的板子上了。现在来分享一下本次研究过程。
            初始计划是先移植lvgl在自己的板子上无OS运行,然后再移植GUI Guider设计的界面代码,再实现输入设备操作。


    本次板子使用的LPC55S69开发板,外带ili9488控制LCD,lcd屏320*480分辨率。lcd驱动已经完成,准备移植lvgl。首先将lvgl代码复制到工程目录下。

    然后在lvgl目录下新建lvgl_app和lvgl_port这2个文件夹,lvgl_app主要放设计的应用文件,lvgl_port主要放需要移植的文件。
    3.jpg


    如下图,将lvgl的example/port目录下移植文件复制到lvgl_port目录下。
    4.jpg
    5.jpg

    参考网上移植方法修改lcd对接lvgl的驱动显示接口文件lv_port_disp_xxxl.c。
    1. void lv_port_disp_init(void)
    2. {
    3.     /*-------------------------
    4.      * Initialize your display
    5.      * -----------------------*/
    6.     disp_init();

    7.     /*-----------------------------
    8.      * Create a buffer for drawing
    9.      *----------------------------*/

    10.     /* LVGL requires a buffer where it draws the objects. The buffer's has to be greater than 1 display row
    11.      *
    12.      * There are three buffering configurations:
    13.      * 1. Create ONE buffer with some rows:
    14.      *      LVGL will draw the display's content here and writes it to your display
    15.      *
    16.      * 2. Create TWO buffer with some rows:
    17.      *      LVGL will draw the display's content to a buffer and writes it your display.
    18.      *      You should use DMA to write the buffer's content to the display.
    19.      *      It will enable LVGL to draw the next part of the screen to the other buffer while
    20.      *      the data is being sent form the first buffer. It makes rendering and flushing parallel.
    21.      *
    22.      * 3. Create TWO screen-sized buffer:
    23.      *      Similar to 2) but the buffer have to be screen sized. When LVGL is ready it will give the
    24.      *      whole frame to display. This way you only need to change the frame buffer's address instead of
    25.      *      copying the pixels.
    26.      * */

    27.     /* Example for 1) */
    28.     static lv_disp_buf_t disp_buf_1;
    29.     static lv_color_t buf1_1[LV_HOR_RES_MAX * 10];                      /*A buffer for 10 rows*/
    30.     lv_disp_buf_init(&disp_buf_1, buf1_1, NULL, LV_HOR_RES_MAX * 10);   /*Initialize the display buffer*/

    31. //    /* Example for 2) */
    32. //    static lv_disp_buf_t disp_buf_2;
    33. //    static lv_color_t buf2_1[LV_HOR_RES_MAX * 10];                        /*A buffer for 10 rows*/
    34. //    static lv_color_t buf2_2[LV_HOR_RES_MAX * 10];                        /*An other buffer for 10 rows*/
    35. //    lv_disp_buf_init(&disp_buf_2, buf2_1, buf2_2, LV_HOR_RES_MAX * 10);   /*Initialize the display buffer*/

    36. //    /* Example for 3) */
    37. //    static lv_disp_buf_t disp_buf_3;
    38. //    static lv_color_t buf3_1[LV_HOR_RES_MAX * LV_VER_RES_MAX];            /*A screen sized buffer*/
    39. //    static lv_color_t buf3_2[LV_HOR_RES_MAX * LV_VER_RES_MAX];            /*An other screen sized buffer*/
    40. //    lv_disp_buf_init(&disp_buf_3, buf3_1, buf3_2, LV_HOR_RES_MAX * LV_VER_RES_MAX);   /*Initialize the display buffer*/


    41.     /*-----------------------------------
    42.      * Register the display in LVGL
    43.      *----------------------------------*/

    44.     lv_disp_drv_t disp_drv;                         /*Descriptor of a display driver*/
    45.     lv_disp_drv_init(&disp_drv);                    /*Basic initialization*/

    46.     /*Set up the functions to access to your display*/

    47.     /*Set the resolution of the display*/
    48.     disp_drv.hor_res = LV_HOR_RES_MAX;
    49.     disp_drv.ver_res = LV_VER_RES_MAX;

    50.     /*Used to copy the buffer's content to the display*/
    51.     disp_drv.flush_cb = disp_flush;

    52.     /*Set a display buffer*/
    53.     disp_drv.buffer = &disp_buf_1;

    54. #if LV_USE_GPU
    55.     /*Optionally add functions to access the GPU. (Only in buffered mode, LV_VDB_SIZE != 0)*/

    56.     /*Blend two color array using opacity*/
    57.     disp_drv.gpu_blend_cb = gpu_blend;

    58.     /*Fill a memory array with a color*/
    59.     disp_drv.gpu_fill_cb = gpu_fill;
    60. #endif

    61.     /*Finally register the driver*/
    62.     lv_disp_drv_register(&disp_drv);
    63. }
    复制代码
    1. static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
    2. {
    3.     /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/

    4. //    int32_t x;
    5. //    int32_t y;
    6. //    for(y = area->y1; y <= area->y2; y++) {
    7. //        for(x = area->x1; x <= area->x2; x++) {
    8. //            /* Put a pixel to the display. For example: */
    9. //            /* put_px(x, y, *color_p)*/
    10. //            color_p++;
    11. //        }
    12. //    }
    13.     lcd_fill_buff(area->x1,area->y1,area->x2,area->y2,(uint8_t *)color_p);
    14.    
    15.     /* IMPORTANT!!!
    16.      * Inform the graphics library that you are ready with the flushing*/
    17.     lv_disp_flush_ready(disp_drv);
    18. }
    复制代码
    主要是这2个函数内容,暂时不用GPU加速之内。
    再就是配置lv_conf.h文件,关于lvgl的一些配置信息。
    主函数修改移植如下:主要是定时器SysTick
    1. void SysTick_Handler(void)
    2. {
    3.     lv_tick_inc(1);
    4. }

    5. void lv_example_btn_1(void)
    6. {
    7.     lv_obj_t * label;

    8.     lv_obj_t * btn1 = lv_btn_create(lv_scr_act(),NULL);
    9.     lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40);

    10.     label = lv_label_create(btn1,NULL);
    11.     lv_label_set_text(label, "Button");

    12.     lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL);
    13.     lv_obj_align(btn2,NULL, LV_ALIGN_CENTER, 0, 40);

    14.     label = lv_label_create(btn2,NULL);
    15.     lv_label_set_text(label, "Toggle");
    16. }
    17. /*******************************************************************************
    18. * Code
    19. ******************************************************************************/
    20. /*!
    21. * @brief Main function
    22. */


    23. int main(void)
    24. {
    25.     char ch;
    26.         int i;

    27.     /* Init board hardware. */
    28.     /* set BOD VBAT level to 1.65V */
    29.     POWER_SetBodVbatLevel(kPOWER_BodVbatLevel1650mv, kPOWER_BodHystLevel50mv, false);
    30.     /* attach main clock divide to FLEXCOMM0 (debug console) */
    31.     CLOCK_AttachClk(BOARD_DEBUG_UART_CLK_ATTACH);

    32.     BOARD_InitPins();
    33.     BOARD_InitBootClocks();
    34.     BOARD_InitDebugConsole();
    35.     init_cycle_counter(false);
    36.     PRINTF("hello world.\r\n");

    37.         lcd_init();
    38.         lcd_clear(0xf800);
    39.    
    40.     lv_init();
    41. extern void lv_port_disp_init(void);
    42.     lv_port_disp_init();
    43.   
    44.     lv_example_btn_1();
    45.    
    46.     while (1)
    47.     {
    48.         lv_task_handler();
    49.     }
    50. }
    复制代码


    现在基本完成了移植,然后准备编译下载看看效果。这里要特别注意:需要配置堆栈大小。我就是在这里遇到坑了。按上面移植之后一直显示不正常,而且程序跑飞了。
    后面参考网上移植的说要配置堆栈至少0x800大小,然后我就去找堆栈配置看看。在这里一般堆栈是在汇编*.s文件中,结果发现汇编文件中没有堆栈配置,最后找到KEIL的配置下修改了堆栈大小。
    6.jpg
    7.jpg
    最后重新编译下载,终于成功显示。


    效果如下
    8.jpg



    移植过程写的比较简单,具体参考如下代码:
    lpc55s69_lcd.rar (7.21 MB, 下载次数: 32)
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

  • TA的每日心情
    无聊
    5 天前
  • 签到天数: 560 天

    [LV.9]以坛为家II

    34

    主题

    5921

    帖子

    2

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    5729
    最后登录
    2024-4-29
    发表于 2021-7-6 08:50:59 | 显示全部楼层

    回帖奖励 +10 NXP金币

    其实我一直很奇怪,这么多代码,咋记住的呢
    哎...今天够累的,签到来了~
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    2024-4-3 08:35
  • 签到天数: 374 天

    [LV.9]以坛为家II

    1

    主题

    1566

    帖子

    1

    金牌会员

    Rank: 6Rank: 6

    积分
    4337
    最后登录
    2024-4-3
    发表于 2021-7-6 08:53:32 | 显示全部楼层

    回帖奖励 +10 NXP金币

    熟能生巧
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

  • TA的每日心情
    奋斗
    昨天 14:38
  • 签到天数: 1947 天

    [LV.Master]伴坛终老

    61

    主题

    1万

    帖子

    3

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    17356
    最后登录
    2024-5-3
     楼主| 发表于 2021-7-6 08:53:35 | 显示全部楼层
    ghost110 发表于 2021-7-6 08:50
    其实我一直很奇怪,这么多代码,咋记住的呢

    工程师的利器:ctrl+c,ctrl+v
    该会员没有填写今日想说内容.
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    2023-1-31 09:34
  • 签到天数: 202 天

    [LV.7]常住居民III

    7

    主题

    1515

    帖子

    0

    金牌会员

    Rank: 6Rank: 6

    积分
    3817
    最后登录
    2024-2-19
    发表于 2021-7-6 08:57:20 来自手机 | 显示全部楼层

    回帖奖励 +10 NXP金币

    很强!威武!多多分享
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    开心
    4 天前
  • 签到天数: 1283 天

    [LV.10]以坛为家III

    21

    主题

    1万

    帖子

    1

    金牌会员

    Rank: 6Rank: 6

    积分
    13265
    最后登录
    2024-4-30
    发表于 2021-7-6 09:02:03 | 显示全部楼层

    回帖奖励 +10 NXP金币

    膜拜大佬!
    跟着日天混 ,三天饱九顿!
    回复

    使用道具 举报

  • TA的每日心情
    慵懒
    2023-8-30 17:43
  • 签到天数: 306 天

    [LV.8]以坛为家I

    14

    主题

    1746

    帖子

    4

    金牌会员

    Rank: 6Rank: 6

    积分
    2538
    最后登录
    2023-8-30
    发表于 2021-7-6 09:04:13 | 显示全部楼层

    回帖奖励 +10 NXP金币

    大佬威武!
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

  • TA的每日心情
    擦汗
    前天 10:52
  • 签到天数: 1786 天

    [LV.Master]伴坛终老

    65

    主题

    7550

    帖子

    1

    金牌会员

    Rank: 6Rank: 6

    积分
    12774
    最后登录
    2024-5-2
    发表于 2021-7-6 09:05:23 | 显示全部楼层

    回帖奖励 +10 NXP金币

    LVGL不错
    回复

    使用道具 举报

  • TA的每日心情
    开心
    2024-3-26 15:16
  • 签到天数: 266 天

    [LV.8]以坛为家I

    3303

    主题

    6550

    帖子

    0

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    32056
    最后登录
    2024-4-30
    发表于 2021-7-6 09:14:58 | 显示全部楼层

    回帖奖励 +10 NXP金币

    流水源 发表于 2021-7-6 08:53
    工程师的利器:ctrl+c,ctrl+v

    真实
    签到签到
    回复 支持 反对

    使用道具 举报

  • TA的每日心情
    慵懒
    21 分钟前
  • 签到天数: 1219 天

    [LV.10]以坛为家III

    22

    主题

    4783

    帖子

    0

    版主

    Rank: 7Rank: 7Rank: 7

    积分
    8117

    活跃会员

    最后登录
    2024-5-3
    发表于 2021-7-6 09:22:03 | 显示全部楼层

    回帖奖励 +10 NXP金币

    谢谢分享
    该会员没有填写今日想说内容.
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /4 下一条

    Archiver|手机版|小黑屋|恩智浦技术社区

    GMT+8, 2024-5-4 00:26 , Processed in 0.144508 second(s), 28 queries , MemCache On.

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.

    快速回复 返回顶部 返回列表