1 /*
2 * Copyright (c) 2006-2021, RT-Thread Development Team
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Change Logs:
7 * Date Author Notes
8 * 2021-10-18 Meco Man The first version
9 * 2021-12-24 Rb Refresh using dma2d
10 */
11 #include <lvgl.h>
12 #include "drv_lcd.h"
13
14 /*A static or global variable to store the buffers*/
15 static lv_disp_draw_buf_t disp_buf;
16 static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
17
18 #define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX)
19
20 static const lv_color_t * buf_to_flush;
21
22 static lv_disp_drv_t g_disp_drv;
23 static lv_color_t lv_disp_buf1[DISP_BUF_SIZE];
24
lcd_fb_flush(lv_disp_drv_t * disp_drv,const lv_area_t * area,lv_color_t * color_p)25 static void lcd_fb_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
26 {
27 LCD_DisplayWindows(area->x1, area->y1, area->x2, area->y2, (uint16_t*) color_p);
28 lv_disp_flush_ready(disp_drv);
29 }
30
lv_port_disp_init(void)31 void lv_port_disp_init(void)
32 {
33 rt_err_t result;
34
35 SPI_Init();
36 LCD_Init(HORIZONTAL);
37
38 /*Initialize `disp_buf` with the buffer(s).*/
39 lv_disp_draw_buf_init(&disp_buf, lv_disp_buf1, RT_NULL, DISP_BUF_SIZE);
40
41 lv_disp_drv_init(&disp_drv); /*Basic initialization*/
42
43 /*Set the resolution of the display*/
44 disp_drv.hor_res = LV_VER_RES_MAX;
45 disp_drv.ver_res = LV_HOR_RES_MAX;
46
47 /*Set a display buffer*/
48 disp_drv.draw_buf = &disp_buf;
49
50 /*Used to copy the buffer's content to the display*/
51 disp_drv.flush_cb = lcd_fb_flush;
52
53 /*Finally register the driver*/
54 lv_disp_drv_register(&disp_drv);
55
56 g_disp_drv = disp_drv;
57 }
58