1 /*
2  * Copyright (c) 2006-2023, RT-Thread Development Team
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Change Logs:
7  * Date           Author       Notes
8  * 2021-11-24     Rbb666       The first version
9  */
10 #include <lvgl.h>
11 #include "hal_data.h"
12 
13 #ifdef PKG_USING_ILI9341
14     #include "lcd_ili9341.h"
15 #endif
16 
17 #define COLOR_BUFFER  (LV_HOR_RES_MAX * LV_VER_RES_MAX / 4)
18 
19 /*A static or global variable to store the buffers*/
20 static lv_disp_draw_buf_t disp_buf;
21 
22 /*Descriptor of a display driver*/
23 static lv_disp_drv_t disp_drv;
24 
25 /*Static or global buffer(s). The second buffer is optional*/
26 // 0x1FFE0000    0x20040000
27 static lv_color_t buf_1[COLOR_BUFFER];
28 static lv_color_t buf_2[COLOR_BUFFER];
29 
disp_flush(lv_disp_drv_t * disp_drv,const lv_area_t * area,lv_color_t * color_p)30 static void disp_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
31 {
32 #ifdef PKG_USING_ILI9341
33     lcd_fill_array_spi(area->x1, area->y1, area->x2, area->y2, color_p);
34 #endif
35     lv_disp_flush_ready(disp_drv);
36 }
37 
lv_port_disp_init(void)38 void lv_port_disp_init(void)
39 {
40 #ifdef PKG_USING_ILI9341
41     spi_lcd_init(20);
42 #endif
43     /*Initialize `disp_buf` with the buffer(s). With only one buffer use NULL instead buf_2 */
44     lv_disp_draw_buf_init(&disp_buf, buf_1, buf_2, COLOR_BUFFER);
45 
46     lv_disp_drv_init(&disp_drv); /*Basic initialization*/
47 
48     /*Set the resolution of the display*/
49     disp_drv.hor_res = LV_HOR_RES_MAX;
50     disp_drv.ver_res = LV_VER_RES_MAX;
51 
52     /*Set a display buffer*/
53     disp_drv.draw_buf = &disp_buf;
54 
55     /*Used to copy the buffer's content to the display*/
56     disp_drv.flush_cb = disp_flush;
57 
58     /*Finally register the driver*/
59     lv_disp_drv_register(&disp_drv);
60 }
61