2021-12-17 17:20:33 +08:00
|
|
|
/*
|
2022-03-29 07:41:16 +08:00
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
2021-12-17 17:20:33 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2021-12-21 19:06:02 +08:00
|
|
|
* 2021-12-17 Wayne The first version
|
2021-12-17 17:20:33 +08:00
|
|
|
*/
|
|
|
|
#include <lvgl.h>
|
2022-01-05 14:38:20 +08:00
|
|
|
#include "mmu.h"
|
2022-12-29 15:15:13 +08:00
|
|
|
#include "lv_gpu_n9h30_ge2d.h"
|
2022-06-03 10:01:15 +08:00
|
|
|
|
2021-12-17 17:20:33 +08:00
|
|
|
#define LOG_TAG "lvgl.disp"
|
|
|
|
#define DBG_ENABLE
|
|
|
|
#define DBG_SECTION_NAME LOG_TAG
|
2022-12-29 15:15:13 +08:00
|
|
|
#define DBG_LEVEL DBG_INFO
|
2021-12-17 17:20:33 +08:00
|
|
|
#define DBG_COLOR
|
|
|
|
#include <rtdbg.h>
|
|
|
|
|
2022-12-29 15:15:13 +08:00
|
|
|
#if !defined(NU_PKG_LVGL_RENDERING_LAYER)
|
|
|
|
#define NU_PKG_LVGL_RENDERING_LAYER "lcd"
|
|
|
|
#endif
|
|
|
|
|
2021-12-17 17:20:33 +08:00
|
|
|
/*A static or global variable to store the buffers*/
|
|
|
|
static lv_disp_draw_buf_t disp_buf;
|
|
|
|
static rt_device_t lcd_device = 0;
|
|
|
|
static struct rt_device_graphic_info info;
|
|
|
|
static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
|
|
|
|
|
2022-01-05 14:38:20 +08:00
|
|
|
static void *buf3_next = RT_NULL;
|
|
|
|
|
2022-01-16 18:43:27 +08:00
|
|
|
static uint32_t u32FirstFlush = 0;
|
|
|
|
|
2022-12-29 15:15:13 +08:00
|
|
|
static uint32_t LV_USE_GPU_N9H30_GE2D = 1;
|
|
|
|
|
2022-01-16 18:43:27 +08:00
|
|
|
static void nu_antitearing(lv_disp_draw_buf_t *draw_buf, lv_color_t *color_p)
|
|
|
|
{
|
|
|
|
if (buf3_next)
|
|
|
|
{
|
|
|
|
/* vsync-none: Use triple screen-sized buffers. */
|
|
|
|
if (draw_buf->buf1 == color_p)
|
|
|
|
draw_buf->buf1 = buf3_next;
|
|
|
|
else
|
|
|
|
draw_buf->buf2 = buf3_next;
|
|
|
|
|
|
|
|
draw_buf->buf_act = buf3_next;
|
|
|
|
buf3_next = color_p;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* vsync-after: Use ping-pong screen-sized buffers only.*/
|
|
|
|
rt_device_control(lcd_device, RTGRAPHIC_CTRL_WAIT_VSYNC, RT_NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-03 10:01:15 +08:00
|
|
|
static void nu_flush_full_refresh(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
|
2021-12-28 13:37:04 +08:00
|
|
|
{
|
2022-06-03 10:01:15 +08:00
|
|
|
if (IS_CACHEABLE_VRAM(color_p))
|
|
|
|
mmu_clean_dcache((uint32_t)color_p, disp_drv->draw_buf->size * sizeof(lv_color_t));
|
2021-12-28 13:37:04 +08:00
|
|
|
|
2022-06-03 10:01:15 +08:00
|
|
|
/* Use PANDISPLAY without H/W copying */
|
2021-12-28 13:37:04 +08:00
|
|
|
rt_device_control(lcd_device, RTGRAPHIC_CTRL_PAN_DISPLAY, color_p);
|
|
|
|
|
2022-01-16 18:43:27 +08:00
|
|
|
nu_antitearing(disp_drv->draw_buf, color_p);
|
|
|
|
|
|
|
|
if (!u32FirstFlush)
|
|
|
|
{
|
|
|
|
/* Enable backlight at first flushing. */
|
|
|
|
rt_device_control(lcd_device, RTGRAPHIC_CTRL_POWERON, RT_NULL);
|
|
|
|
u32FirstFlush = 1;
|
|
|
|
}
|
2021-12-28 13:37:04 +08:00
|
|
|
|
|
|
|
lv_disp_flush_ready(disp_drv);
|
|
|
|
}
|
2021-12-17 17:20:33 +08:00
|
|
|
|
2022-06-03 10:01:15 +08:00
|
|
|
static void nu_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
|
2021-12-17 17:20:33 +08:00
|
|
|
{
|
2022-12-29 15:15:13 +08:00
|
|
|
int32_t area_w = lv_area_get_width(area);
|
|
|
|
int32_t area_h = lv_area_get_height(area);
|
|
|
|
|
2022-06-03 10:01:15 +08:00
|
|
|
lv_draw_sw_blend_dsc_t blend_flush = {0};
|
|
|
|
lv_draw_ctx_t draw_flush = {0};
|
|
|
|
lv_area_t flush_area = {0, 0, info.width - 1, info.height - 1 };
|
2022-01-05 14:38:20 +08:00
|
|
|
|
2022-12-29 15:15:13 +08:00
|
|
|
//rt_kprintf("[nu_flush %d %08x] %dx%d %d %d\n", lv_area_get_size(area), color_p, area_w, area_h, area->x1, area->y1 );
|
|
|
|
|
2022-06-03 10:01:15 +08:00
|
|
|
blend_flush.blend_area = area;
|
|
|
|
blend_flush.src_buf = color_p;
|
|
|
|
blend_flush.mask_buf = NULL;
|
|
|
|
blend_flush.opa = LV_OPA_MAX;
|
|
|
|
blend_flush.blend_mode = LV_BLEND_MODE_NORMAL;
|
2022-01-05 14:38:20 +08:00
|
|
|
|
2022-06-03 10:01:15 +08:00
|
|
|
draw_flush.buf = info.framebuffer;
|
|
|
|
draw_flush.clip_area = &flush_area;
|
|
|
|
draw_flush.buf_area = &flush_area;
|
2022-01-05 14:38:20 +08:00
|
|
|
|
2022-06-03 10:01:15 +08:00
|
|
|
lv_draw_n9h30_ge2d_blend(&draw_flush, (const lv_draw_sw_blend_dsc_t *)&blend_flush);
|
2021-12-17 17:20:33 +08:00
|
|
|
|
2022-01-16 18:43:27 +08:00
|
|
|
if (!u32FirstFlush)
|
|
|
|
{
|
|
|
|
/* Enable backlight at first flushing. */
|
|
|
|
rt_device_control(lcd_device, RTGRAPHIC_CTRL_POWERON, RT_NULL);
|
|
|
|
u32FirstFlush = 1;
|
|
|
|
}
|
|
|
|
|
2021-12-28 13:37:04 +08:00
|
|
|
lv_disp_flush_ready(disp_drv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nu_perf_monitor(struct _lv_disp_drv_t *disp_drv, uint32_t time, uint32_t px)
|
2021-12-17 17:20:33 +08:00
|
|
|
{
|
2022-12-29 15:15:13 +08:00
|
|
|
LOG_I("Elapsed: %dms, Pixel: %d, Bytes:%d, %d%\n", time, px, px * sizeof(lv_color_t), px * 100 / disp_drv->draw_buf->size);
|
2021-12-17 17:20:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void lv_port_disp_init(void)
|
|
|
|
{
|
|
|
|
rt_err_t result;
|
2022-01-05 14:38:20 +08:00
|
|
|
void *buf1 = RT_NULL;
|
|
|
|
void *buf2 = RT_NULL;
|
2021-12-28 13:37:04 +08:00
|
|
|
uint32_t u32FBSize;
|
2021-12-17 17:20:33 +08:00
|
|
|
|
2022-12-29 15:15:13 +08:00
|
|
|
lcd_device = rt_device_find(NU_PKG_LVGL_RENDERING_LAYER);
|
|
|
|
if (lcd_device == RT_NULL)
|
2021-12-17 17:20:33 +08:00
|
|
|
{
|
|
|
|
LOG_E("error!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-29 15:15:13 +08:00
|
|
|
if (!LV_VERSION_CHECK(8, 3, 0))
|
|
|
|
{
|
|
|
|
LV_USE_GPU_N9H30_GE2D = 0;
|
|
|
|
}
|
|
|
|
LOG_I("LVGL: %s drawing using 2DGE", LV_USE_GPU_N9H30_GE2D ? "Enabled" : "Disabled");
|
|
|
|
|
2021-12-17 17:20:33 +08:00
|
|
|
/* get framebuffer address */
|
|
|
|
result = rt_device_control(lcd_device, RTGRAPHIC_CTRL_GET_INFO, &info);
|
|
|
|
if (result != RT_EOK)
|
|
|
|
{
|
|
|
|
LOG_E("error!");
|
|
|
|
/* get device information failed */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-01-16 18:43:27 +08:00
|
|
|
/* Disable backlight at startup. */
|
|
|
|
rt_device_control(lcd_device, RTGRAPHIC_CTRL_POWEROFF, RT_NULL);
|
|
|
|
|
2021-12-17 17:20:33 +08:00
|
|
|
RT_ASSERT(info.bits_per_pixel == 8 || info.bits_per_pixel == 16 ||
|
|
|
|
info.bits_per_pixel == 24 || info.bits_per_pixel == 32);
|
|
|
|
|
2021-12-28 13:37:04 +08:00
|
|
|
lv_disp_drv_init(&disp_drv); /*Basic initialization*/
|
|
|
|
|
|
|
|
/*Set the resolution of the display*/
|
|
|
|
disp_drv.hor_res = info.width;
|
|
|
|
disp_drv.ver_res = info.height;
|
|
|
|
u32FBSize = info.height * info.width * (info.bits_per_pixel / 8);
|
|
|
|
|
2022-06-03 10:01:15 +08:00
|
|
|
#if (LV_USE_ANTI_TEARING==1)
|
2022-01-05 14:38:20 +08:00
|
|
|
disp_drv.full_refresh = 1;
|
|
|
|
#endif
|
2022-12-29 15:15:13 +08:00
|
|
|
LOG_I("LVGL: %s anti-tearing", disp_drv.full_refresh ? "Enabled" : "Disabled");
|
2022-01-05 14:38:20 +08:00
|
|
|
|
2022-06-03 10:01:15 +08:00
|
|
|
if (disp_drv.full_refresh)
|
2021-12-28 13:37:04 +08:00
|
|
|
{
|
2022-06-03 10:01:15 +08:00
|
|
|
buf1 = (void *)((uint32_t)info.framebuffer & ~BIT31); // Use Cacheable VRAM
|
2022-01-05 14:38:20 +08:00
|
|
|
buf2 = (void *)((uint32_t)buf1 + u32FBSize);
|
|
|
|
buf3_next = (void *)((uint32_t)buf2 + u32FBSize);
|
2022-12-29 15:15:13 +08:00
|
|
|
LOG_I("LVGL: Use triple screen-sized buffers(full_refresh) - buf1@%08x, buf2@%08x, buf3_next@%08x", buf1, buf2, buf3_next);
|
2021-12-28 13:37:04 +08:00
|
|
|
|
2022-06-03 10:01:15 +08:00
|
|
|
disp_drv.flush_cb = nu_flush_full_refresh;
|
2021-12-28 13:37:04 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-12-29 15:15:13 +08:00
|
|
|
buf1 = (void *)(((uint32_t)info.framebuffer & ~BIT31) + u32FBSize); // Use Cacheable VRAM
|
2022-01-05 14:38:20 +08:00
|
|
|
buf2 = (void *)((uint32_t)buf1 + u32FBSize);
|
2022-12-29 15:15:13 +08:00
|
|
|
LOG_I("LVGL: Use two screen-sized buffers - buf1@%08x, buf2@%08x", buf1, buf2);
|
2021-12-28 13:37:04 +08:00
|
|
|
rt_device_control(lcd_device, RTGRAPHIC_CTRL_PAN_DISPLAY, info.framebuffer);
|
|
|
|
|
|
|
|
disp_drv.flush_cb = nu_flush;
|
|
|
|
}
|
2021-12-17 17:20:33 +08:00
|
|
|
|
|
|
|
/*Initialize `disp_buf` with the buffer(s).*/
|
2022-01-05 14:38:20 +08:00
|
|
|
lv_disp_draw_buf_init(&disp_buf, buf1, buf2, info.width * info.height);
|
2021-12-17 17:20:33 +08:00
|
|
|
|
|
|
|
result = rt_device_open(lcd_device, 0);
|
|
|
|
if (result != RT_EOK)
|
|
|
|
{
|
|
|
|
LOG_E("error!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Set a display buffer*/
|
|
|
|
disp_drv.draw_buf = &disp_buf;
|
|
|
|
|
2022-12-29 15:15:13 +08:00
|
|
|
if (LV_USE_GPU_N9H30_GE2D)
|
|
|
|
{
|
|
|
|
disp_drv.draw_ctx_init = lv_draw_n9h30_ge2d_ctx_init;
|
|
|
|
disp_drv.draw_ctx_deinit = lv_draw_n9h30_ge2d_ctx_init;
|
|
|
|
disp_drv.draw_ctx_size = sizeof(lv_draw_n9h30_ge2d_ctx_t);
|
|
|
|
}
|
2022-06-03 10:01:15 +08:00
|
|
|
|
2021-12-28 13:37:04 +08:00
|
|
|
/*Called after every refresh cycle to tell the rendering and flushing time + the number of flushed pixels*/
|
|
|
|
//disp_drv.monitor_cb = nu_perf_monitor;
|
2021-12-17 17:20:33 +08:00
|
|
|
|
|
|
|
/*Finally register the driver*/
|
|
|
|
lv_disp_drv_register(&disp_drv);
|
|
|
|
}
|