2021-10-26 18:42:35 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2021-10-18 Meco Man The first version
|
2021-12-24 11:01:53 +08:00
|
|
|
* 2021-12-24 Rb Refresh using dma2d
|
2021-10-26 18:42:35 +08:00
|
|
|
*/
|
|
|
|
#include <lvgl.h>
|
|
|
|
#include <lcd_port.h>
|
|
|
|
|
2021-11-11 13:32:48 +08:00
|
|
|
//#define DRV_DEBUG
|
2021-12-06 22:33:04 +08:00
|
|
|
#define LOG_TAG "LVGL.port.disp"
|
2021-11-11 13:32:48 +08:00
|
|
|
#include <drv_log.h>
|
|
|
|
|
2021-10-26 18:42:35 +08:00
|
|
|
/*A static or global variable to store the buffers*/
|
|
|
|
static lv_disp_draw_buf_t disp_buf;
|
|
|
|
|
2021-12-06 22:33:04 +08:00
|
|
|
static rt_device_t lcd_device = RT_NULL;
|
2021-10-26 18:42:35 +08:00
|
|
|
static struct rt_device_graphic_info info;
|
|
|
|
|
|
|
|
static lv_disp_drv_t disp_drv; /*Descriptor of a display driver*/
|
|
|
|
|
2021-12-24 11:01:53 +08:00
|
|
|
#define DISP_BUF_SIZE (LV_HOR_RES_MAX * LV_VER_RES_MAX / 4)
|
2021-11-11 13:32:48 +08:00
|
|
|
|
2021-12-24 11:01:53 +08:00
|
|
|
static lv_disp_drv_t g_disp_drv;
|
|
|
|
extern LTDC_HandleTypeDef hltdc;
|
|
|
|
volatile rt_bool_t g_gpu_state = RT_FALSE;
|
2021-11-11 14:44:42 +08:00
|
|
|
|
2021-12-24 11:01:53 +08:00
|
|
|
static void lvgl_dma_config(void)
|
2021-10-26 18:42:35 +08:00
|
|
|
{
|
2021-12-24 11:01:53 +08:00
|
|
|
HAL_NVIC_SetPriority(DMA2D_IRQn, 0, 0);
|
|
|
|
HAL_NVIC_EnableIRQ(DMA2D_IRQn);
|
|
|
|
__HAL_RCC_DMA2D_CLK_ENABLE();
|
2021-10-26 18:42:35 +08:00
|
|
|
}
|
|
|
|
|
2021-12-24 11:01:53 +08:00
|
|
|
static void lcd_fb_flush(lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p)
|
2021-10-26 18:42:35 +08:00
|
|
|
{
|
2021-12-24 11:01:53 +08:00
|
|
|
uint32_t OffLineSrc = LV_HOR_RES_MAX - (area->x2 - area->x1 + 1);
|
|
|
|
uint32_t addr = (uint32_t) hltdc.LayerCfg[0].FBStartAdress + 2 * (LV_HOR_RES_MAX * area->y1 + area->x1);
|
2021-11-11 14:44:42 +08:00
|
|
|
|
2021-12-24 11:01:53 +08:00
|
|
|
DMA2D->CR = 0x00000000UL | (1 << 9);
|
|
|
|
DMA2D->FGMAR = (uint32_t) (uint16_t*) (color_p);
|
|
|
|
DMA2D->OMAR = (uint32_t) addr;
|
2021-11-11 14:44:42 +08:00
|
|
|
|
2021-12-24 11:01:53 +08:00
|
|
|
DMA2D->FGOR = 0;
|
|
|
|
DMA2D->OOR = OffLineSrc;
|
2021-10-26 18:42:35 +08:00
|
|
|
|
2021-12-24 11:01:53 +08:00
|
|
|
DMA2D->FGPFCCR = DMA2D_OUTPUT_RGB565;
|
|
|
|
DMA2D->OPFCCR = DMA2D_OUTPUT_RGB565;
|
2021-10-26 18:42:35 +08:00
|
|
|
|
2021-12-24 11:01:53 +08:00
|
|
|
DMA2D->NLR = (area->y2 - area->y1 + 1) | ((area->x2 - area->x1 + 1) << 16);
|
|
|
|
DMA2D->CR |= DMA2D_IT_TC | DMA2D_IT_TE | DMA2D_IT_CE;
|
|
|
|
DMA2D->CR |= DMA2D_CR_START;
|
2021-10-26 18:42:35 +08:00
|
|
|
|
2021-12-24 11:01:53 +08:00
|
|
|
g_gpu_state = RT_TRUE;
|
2021-11-11 13:32:48 +08:00
|
|
|
}
|
2021-10-26 18:42:35 +08:00
|
|
|
|
2021-12-24 11:01:53 +08:00
|
|
|
void DMA2D_IRQHandler(void)
|
2021-11-11 13:32:48 +08:00
|
|
|
{
|
2021-12-24 11:01:53 +08:00
|
|
|
rt_interrupt_enter();
|
|
|
|
|
|
|
|
if ((DMA2D->ISR & DMA2D_FLAG_TC) != 0U)
|
2021-10-26 18:42:35 +08:00
|
|
|
{
|
2021-12-24 11:01:53 +08:00
|
|
|
if ((DMA2D->CR & DMA2D_IT_TC) != 0U)
|
|
|
|
{
|
|
|
|
|
|
|
|
DMA2D->CR &= ~DMA2D_IT_TC;
|
|
|
|
DMA2D->IFCR = DMA2D_FLAG_TC;
|
|
|
|
|
|
|
|
if (g_gpu_state == RT_TRUE)
|
|
|
|
{
|
|
|
|
g_gpu_state = RT_FALSE;
|
|
|
|
lv_disp_flush_ready(&g_disp_drv);
|
|
|
|
}
|
|
|
|
}
|
2021-10-26 18:42:35 +08:00
|
|
|
}
|
2021-12-24 11:01:53 +08:00
|
|
|
|
|
|
|
rt_interrupt_leave();
|
2021-10-26 18:42:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void lv_port_disp_init(void)
|
|
|
|
{
|
|
|
|
rt_err_t result;
|
2021-12-24 11:01:53 +08:00
|
|
|
static lv_color_t lv_disp_buf1[DISP_BUF_SIZE] = {0};
|
2021-10-26 18:42:35 +08:00
|
|
|
|
|
|
|
lcd_device = rt_device_find("lcd");
|
2021-12-24 11:01:53 +08:00
|
|
|
|
2021-10-26 18:42:35 +08:00
|
|
|
if (lcd_device == 0)
|
|
|
|
{
|
2021-12-24 11:01:53 +08:00
|
|
|
LOG_E("lcd_device error!");
|
2021-10-26 18:42:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-12-24 11:01:53 +08:00
|
|
|
|
2021-10-26 18:42:35 +08:00
|
|
|
result = rt_device_open(lcd_device, 0);
|
2021-12-24 11:01:53 +08:00
|
|
|
|
2021-10-26 18:42:35 +08:00
|
|
|
if (result != RT_EOK)
|
|
|
|
{
|
2021-11-11 13:32:48 +08:00
|
|
|
LOG_E("error!");
|
2021-10-26 18:42:35 +08:00
|
|
|
return;
|
|
|
|
}
|
2021-11-11 13:32:48 +08:00
|
|
|
|
2021-10-26 18:42:35 +08:00
|
|
|
/* get framebuffer address */
|
|
|
|
result = rt_device_control(lcd_device, RTGRAPHIC_CTRL_GET_INFO, &info);
|
2021-12-24 11:01:53 +08:00
|
|
|
|
2021-10-26 18:42:35 +08:00
|
|
|
if (result != RT_EOK)
|
|
|
|
{
|
2021-11-11 13:32:48 +08:00
|
|
|
LOG_E("error!");
|
2021-10-26 18:42:35 +08:00
|
|
|
/* get device information failed */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-11 13:32:48 +08:00
|
|
|
RT_ASSERT (info.bits_per_pixel == 8 || info.bits_per_pixel == 16 ||
|
2021-12-24 11:01:53 +08:00
|
|
|
info.bits_per_pixel == 24 || info.bits_per_pixel == 32);
|
2021-10-26 18:42:35 +08:00
|
|
|
|
2021-11-11 14:44:42 +08:00
|
|
|
lvgl_dma_config();
|
2021-11-11 13:32:48 +08:00
|
|
|
|
|
|
|
/*Initialize `disp_buf` with the buffer(s).*/
|
2021-12-24 11:01:53 +08:00
|
|
|
lv_disp_draw_buf_init(&disp_buf, lv_disp_buf1, RT_NULL, DISP_BUF_SIZE);
|
2021-10-26 18:42:35 +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;
|
|
|
|
|
|
|
|
/*Set a display buffer*/
|
|
|
|
disp_drv.draw_buf = &disp_buf;
|
|
|
|
|
|
|
|
/*Used to copy the buffer's content to the display*/
|
|
|
|
disp_drv.flush_cb = lcd_fb_flush;
|
|
|
|
|
|
|
|
/*Finally register the driver*/
|
|
|
|
lv_disp_drv_register(&disp_drv);
|
2021-12-24 11:01:53 +08:00
|
|
|
|
|
|
|
g_disp_drv = disp_drv;
|
2021-10-26 18:42:35 +08:00
|
|
|
}
|