1# Renesas 2The [HMI-Board](https://bit.ly/3I9nfUo) development board SDK now comes with LVGL integration for quick evaluation. Simply download the [SDK](https://github.com/RT-Thread-Studio/sdk-bsp-ra6m3-hmi-board/tree/main/projects/hmi-board-lvgl) for the supported motherboard and you’ll be on your way to creating your next GUI application in no time. For more information, check out the [Software design description](https://github.com/RT-Thread-Studio/sdk-bsp-ra6m3-hmi-board/blob/main/projects/hmi-board-lvgl/README.md). 3 4## Creating new project with LVGL 5It is recommended to start your project by downloading the HMI-Board SDK example project. It comes fully equipped with LVGL and dave-2d support (if the modules are present), so you won’t need to do any additional integration work. 6 7## HW acceleration for Renesas RA6M3 platforms 8For RA6M3 platforms, hardware acceleration can be achieved using the dave-2d GPU, depending on the platform used. Each accelerator has its own context, allowing them to be used individually or simultaneously in LVGL’s multithreading mode. 9 10### Dave-2d accelerator 11LVGL can offload several drawing features to the dave-2d engine, freeing up the CPU for other operations while dave-2d runs. An RTOS is required to block the LVGL drawing thread and switch to another task or suspend the CPU for power savings. Supported draw callbacks can be found in “src/draw/renesas/lv_gpu_d2_ra6m3.c”. 12 13LVGL can offload several drawing features to the dave-2d engine, freeing up the CPU for other operations while dave-2d runs. An RTOS is required to block the LVGL drawing thread and switch to another task or suspend the CPU for power savings. Supported draw callbacks can be found in “src/draw/renesas/lv_gpu_d2_ra6m3.c”. 14 15```c 16 ra_2d_draw_ctx->blend = lv_draw_ra6m3_2d_blend; 17 ra_2d_draw_ctx->base_draw.draw_img_decoded = lv_port_gpu_img_decoded; 18 ra_2d_draw_ctx->base_draw.wait_for_finish = lv_port_gpu_wait; 19 ra_2d_draw_ctx->base_draw.draw_letter = lv_draw_gpu_letter; 20``` 21 22### Features supported: 23 All operations can be used in conjunction with optional transparency. 24 25 - RGB565 and ARGB8888 color formats 26 - Area fill with color 27 - BLIT (BLock Image Transfer) 28 - Color conversion 29 - Rotate and scale 30 - Alpha blending 31 - Bilinear filtering 32 - RTOS integration layer 33 - Default RT-Thread code provided 34 - Subpixel exact placement 35 36### Basic configuration: 37 - Select Renesas dave-2d engine in lv_conf.h: Set `LV_USE_GPU_RA6M3_G2D` to 1 38 - Set referenced header file in lv_conf.h: `#define LV_GPU_RA6M3_G2D_INCLUDE "hal_data.h"` 39 40### RT-Thread Example: 41 42```c 43#define COLOR_BUFFER (LV_HOR_RES_MAX * LV_VER_RES_MAX) 44 45static lv_disp_drv_t disp_drv; 46 47/*A static or global variable to store the buffers*/ 48static lv_color_t buf_1[COLOR_BUFFER]; 49``` 50 51- After initializing your peripherals (such as SPI, GPIOs, and LCD) in the `lv_port_disp_init()` function, you can initialize LVGL using [`lv_init()`.](https://docs.lvgl.io/master/API/core/lv_obj.html#_CPPv47lv_initv) Next, register the frame buffers using `lv_disp_draw_buf_init()` and create a new display driver using `lv_disp_drv_init()`. 52 53```c 54/*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */ 55lv_disp_draw_buf_init(&disp_buf, buf_1, RT_NULL, COLOR_BUFFER); 56lv_disp_drv_init(&disp_drv); /*Basic initialization*/ 57 58/*Set the resolution of the display*/ 59disp_drv.hor_res = LV_HOR_RES_MAX; 60disp_drv.ver_res = LV_VER_RES_MAX; 61 62/*Set a display buffer*/ 63disp_drv.draw_buf = &disp_buf; 64 65/*Used to copy the buffer's content to the display*/ 66disp_drv.flush_cb = disp_flush; 67 68/* Initialize GPU module */ 69lv_port_gpu_hw_init(); 70 71/*Finally register the driver*/ 72lv_disp_drv_register(&disp_drv); 73``` 74 75* To run LVGL, you’ll need to create a thread. You can find examples of how to do this using RT-Thread in the `env_support/rt-thread/lv_rt_thread_port.c` file. 76 77```c 78static void lvgl_thread_entry(void *parameter) 79{ 80#if LV_USE_LOG 81 lv_log_register_print_cb(lv_rt_log); 82#endif /* LV_USE_LOG */ 83 lv_init(); 84 lv_port_disp_init(); 85 lv_port_indev_init(); 86 lv_user_gui_init(); 87 88 /* handle the tasks of LVGL */ 89 while(1) 90 { 91 lv_task_handler(); 92 rt_thread_mdelay(LV_DISP_DEF_REFR_PERIOD); 93 } 94} 95 96static int lvgl_thread_init(void) 97{ 98 rt_err_t err; 99 100 /* create lvgl thread */ 101 err = rt_thread_init(&lvgl_thread, "LVGL", lvgl_thread_entry, RT_NULL, 102 &lvgl_thread_stack[0], sizeof(lvgl_thread_stack), PKG_LVGL_THREAD_PRIO, 10); 103 if(err != RT_EOK) 104 { 105 LOG_E("Failed to create LVGL thread"); 106 return -1; 107 } 108 rt_thread_startup(&lvgl_thread); 109 110 return 0; 111} 112INIT_ENV_EXPORT(lvgl_thread_init); 113``` 114 115- The last step is to create a function to output the frame buffer to your LCD. The specifics of this function will depend on the features of your MCU. Here’s an example for a typical MCU interface: `my_flush_cb`. 116 117```c 118static void my_flush_cb(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p) 119{ 120#ifdef PKG_USING_ILI9341 121 lcd_fill_array_spi(area->x1, area->y1, area->x2, area->y2, color_p); 122#elif LV_USE_GPU_RA6M3_G2D 123 lv_port_gpu_blit(area->x1, area->y1, color_p, area); 124#else 125 ...... 126#endif 127 lv_disp_flush_ready(disp_drv); 128} 129``` 130