TL-LED 发表于 2024-5-12 15:54

【兆易GD32H759I-EVAL】LVGL移植

本帖最后由 TL-LED 于 2024-5-13 08:30 编辑

<p><span style="font-size:16px;">学习移植LVGL到GD32H759I-EVAL开发板。</span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><strong>一、下载LVGL源码</strong></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">源码下载地址:<a href="https://github.com/lvgl/lvgl/tree/release/v8.3" target="_blank">https://github.com/lvgl/lvgl/tree/release/v8.3</a></span></p>

<p><span style="font-size:16px;"></span></p>

<p>&nbsp;</p>

<p><strong><span style="font-size:16px;">二、复制文件</span></strong></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">将下载的源文件复制到项目工程文件下</span></p>

<p></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;"><strong>三、添加源码到项目工程</strong></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">3.1、将源码按照文件名称添加到项目中</span></p>

<p><span style="font-size:16px;"></span></p>

<p><span style="font-size:16px;">3.2、添加头文件</span></p>

<p></p>

<p>&nbsp;</p>

<p><strong><span style="font-size:16px;">四、程序部分</span></strong></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">移植LVGL主要是显示驱动部分程序。</span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">4.1、添加LCD初始化</span></p>

<p><span style="font-size:16px;"></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">4.2、LCD驱动程序</span></p>

<p><span style="font-size:16px;"></span></p>

<p>&nbsp;</p>

<p><span style="font-size:16px;">4.3、lv_port_disp_template.c</span></p>

<p>&nbsp;</p>

<pre>
<code>/**
* <a href="home.php?mod=space&amp;uid=1307177" target="_blank">@File </a> lv_port_disp_templ.c
*
*/

/*Copy this file as &quot;lv_port_disp.c&quot; and set this value to &quot;1&quot; to enable content*/
#if 1

/*********************
*      INCLUDES
*********************/
#include &quot;lv_port_disp_template.h&quot;
#include &lt;stdbool.h&gt;
#include &quot;lcd/tli_lcd.h&quot;

/*********************
*      DEFINES
*********************/
#ifndef MY_DISP_HOR_RES
    //#warning Please define or replace the macro MY_DISP_HOR_RES with the actual screen width, default value 320 is used for now.
    #define MY_DISP_HOR_RES    480
#endif

#ifndef MY_DISP_VER_RES
    //#warning Please define or replace the macro MY_DISP_HOR_RES with the actual screen height, default value 240 is used for now.
    #define MY_DISP_VER_RES    272
#endif

/**********************
*      TYPEDEFS
**********************/

/**********************
*STATIC PROTOTYPES
**********************/
static void disp_init(void);

static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p);
//static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
//      const lv_area_t * fill_area, lv_color_t color);

/**********************
*STATIC VARIABLES
**********************/

/**********************
*      MACROS
**********************/

/**********************
*   GLOBAL FUNCTIONS
**********************/

void lv_port_disp_init(void)
{
    /*-------------------------
   * Initialize your display
   * -----------------------*/
    disp_init();

    /*-----------------------------
   * Create a buffer for drawing
   *----------------------------*/

    /**
   * LVGL requires a buffer where it internally draws the widgets.
   * Later this buffer will passed to your display driver&#39;s `flush_cb` to copy its content to your display.
   * The buffer has to be greater than 1 display row
   *
   * There are 3 buffering configurations:
   * 1. Create ONE buffer:
   *      LVGL will draw the display&#39;s content here and writes it to your display
   *
   * 2. Create TWO buffer:
   *      LVGL will draw the display&#39;s content to a buffer and writes it your display.
   *      You should use DMA to write the buffer&#39;s content to the display.
   *      It will enable LVGL to draw the next part of the screen to the other buffer while
   *      the data is being sent form the first buffer. It makes rendering and flushing parallel.
   *
   * 3. Double buffering
   *      Set 2 screens sized buffers and set disp_drv.full_refresh = 1.
   *      This way LVGL will always provide the whole rendered screen in `flush_cb`
   *      and you only need to change the frame buffer&#39;s address.
   */

    /* Example for 1) */
    static lv_disp_draw_buf_t draw_buf_dsc_1;
    static lv_color_t buf_1;                        /*A buffer for 10 rows*/
    lv_disp_draw_buf_init(&amp;draw_buf_dsc_1, buf_1, NULL, MY_DISP_HOR_RES * 10);   /*Initialize the display buffer*/

//    /* Example for 2) */
//    static lv_disp_draw_buf_t draw_buf_dsc_2;
//    static lv_color_t buf_2_1;                        /*A buffer for 10 rows*/
//    static lv_color_t buf_2_2;                        /*An other buffer for 10 rows*/
//    lv_disp_draw_buf_init(&amp;draw_buf_dsc_2, buf_2_1, buf_2_2, MY_DISP_HOR_RES * 10);   /*Initialize the display buffer*/

//    /* Example for 3) also set disp_drv.full_refresh = 1 below*/
//    static lv_disp_draw_buf_t draw_buf_dsc_3;
//    static lv_color_t buf_3_1;            /*A screen sized buffer*/
//    static lv_color_t buf_3_2;            /*Another screen sized buffer*/
//    lv_disp_draw_buf_init(&amp;draw_buf_dsc_3, buf_3_1, buf_3_2,
//                        MY_DISP_VER_RES * LV_VER_RES_MAX);   /*Initialize the display buffer*/

    /*-----------------------------------
   * Register the display in LVGL
   *----------------------------------*/

    static lv_disp_drv_t disp_drv;                         /*Descriptor of a display driver*/
    lv_disp_drv_init(&amp;disp_drv);                  /*Basic initialization*/

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

    /*Set the resolution of the display*/
    disp_drv.hor_res = MY_DISP_HOR_RES;
    disp_drv.ver_res = MY_DISP_VER_RES;

    /*Used to copy the buffer&#39;s content to the display*/
    disp_drv.flush_cb = disp_flush;

    /*Set a display buffer*/
    disp_drv.draw_buf = &amp;draw_buf_dsc_1;

    /*Required for Example 3)*/
    //disp_drv.full_refresh = 1;

    /* Fill a memory array with a color if you have GPU.
   * Note that, in lv_conf.h you can enable GPUs that has built-in support in LVGL.
   * But if you have a different GPU you can use with this callback.*/
    //disp_drv.gpu_fill_cb = gpu_fill;

    /*Finally register the driver*/
    lv_disp_drv_register(&amp;disp_drv);
}

/**********************
*   STATIC FUNCTIONS
**********************/

/*Initialize your display and the required peripherals.*/
static void disp_init(void)
{
    /*You code here*/
                init_lcd();
                LCDDisplayDir(LCD_SCREEN_HORIZONTAL);
                LCDClear(LCD_COLOR_WHITE);
}

volatile bool disp_flush_enabled = true;

/* Enable updating the screen (the flushing process) when disp_flush() is called by LVGL
*/
void disp_enable_update(void)
{
    disp_flush_enabled = true;
}

/* Disable updating the screen (the flushing process) when disp_flush() is called by LVGL
*/
void disp_disable_update(void)
{
    disp_flush_enabled = false;
}

/*Flush the content of the internal buffer the specific area on the display
*You can use DMA or any hardware acceleration to do this operation in the background but
*&#39;lv_disp_flush_ready()&#39; has to be called when finished.*/
static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
{
    if(disp_flush_enabled) {
      /*The most simple case (but also the slowest) to put all pixels to the screen one-by-one*/

      int32_t x;
      int32_t y;
      for(y = area-&gt;y1; y &lt;= area-&gt;y2; y++) {
            for(x = area-&gt;x1; x &lt;= area-&gt;x2; x++) {
                /*Put a pixel to the display. For example:*/
                /*put_px(x, y, *color_p)*/
                                                                LCDDrawPoint(x, y, color_p-&gt;full);
                color_p++;
            }
      }
    }

    /*IMPORTANT!!!
   *Inform the graphics library that you are ready with the flushing*/
    lv_disp_flush_ready(disp_drv);
}

/*OPTIONAL: GPU INTERFACE*/

/*If your MCU has hardware accelerator (GPU) then you can use it to fill a memory with a color*/
//static void gpu_fill(lv_disp_drv_t * disp_drv, lv_color_t * dest_buf, lv_coord_t dest_width,
//                  const lv_area_t * fill_area, lv_color_t color)
//{
//    /*It&#39;s an example code which should be done by your GPU*/
//    int32_t x, y;
//    dest_buf += dest_width * fill_area-&gt;y1; /*Go to the first line*/
//
//    for(y = fill_area-&gt;y1; y &lt;= fill_area-&gt;y2; y++) {
//      for(x = fill_area-&gt;x1; x &lt;= fill_area-&gt;x2; x++) {
//            dest_buf = color;
//      }
//      dest_buf+=dest_width;    /*Go to the next line*/
//    }
//}


#else /*Enable this file at the top*/

/*This dummy typedef exists purely to silence -Wpedantic.*/
typedef int keep_pedantic_happy;
#endif
</code></pre>

<p>&nbsp;</p>

<p><span style="font-size:16px;">4.4、main.c</span></p>

<pre>
<code>#include "main.h"
#include "FreeRTOS.h"
#include "lv_demo_widgets.h"
#include "lv_demo_benchmark.h"

void cache_enable(void);

int main(void)
{
        cache_enable();
        systick_config();
       
        exmc_synchronous_dynamic_ram_init(EXMC_SDRAM_DEVICE0);
       
        init_usart(115200);
        lv_init();
        lv_port_disp_init();
       
        //lv_demo_widgets();
        lv_demo_benchmark();
       
        //task_create();
        while(1)
        {
                delay_1ms(5);
                lv_task_handler();
        }
}

void cache_enable(void)
{
    /* enable i-cache */
    SCB_EnableICache();

    /* enable d-cache */
    SCB_EnableDCache();
}</code></pre>

<p>&nbsp;</p>

<p><strong><span style="font-size:16px;">五、程序运行</span></strong></p>

<p>&nbsp;</p>

<p><span style="font-size: 16px;">下载程序复位开发板,显示如下:</span></p>

<p>d09788335dc4efc5816a8334eaf6b754<br />
&nbsp;</p>

lugl4313820 发表于 2024-5-15 07:34

<p>移植成功,这是建立在LCD已经驱动好的前提下的吧。</p>

TL-LED 发表于 2024-5-15 08:44

lugl4313820 发表于 2024-5-15 07:34
移植成功,这是建立在LCD已经驱动好的前提下的吧。

<p>嗯,在LCD测试的基础上增加的。</p>

guanyifei 发表于 2024-11-22 17:28

速度这么快优化过吗?
页: [1]
查看完整版本: 【兆易GD32H759I-EVAL】LVGL移植