RT-Thread ART-PI 学习笔记:轻量化GUI框架LVGL的使用和配置

前言

本文记录RT-Thread官方开发板ART-PI配置和使用LVGL图形库的过程

旨在以ART-PI学习LVGL,但是在配置的过程中遇到不少问题,ART-PI对LVGL的适配并没有TOUCHGFX那么好,还存在不少问题,其中一些还有待解决

以这篇博客作为记录配置和使用过程,之后有时间会完善这篇博客

参考资料

https://club.rt-thread.org/ask/article/2464.html

https://blog.csdn.net/weixin_37127273/article/details/110134225

https://www.jianshu.com/p/e01bf5b628bc

实验步骤

image-20210813111840289 image-20210813112836674 image-20210813113945181 image-20210813114505991 image-20210813114524630 image-20210813114849205 image-20210813115623593 image-20210813120135440 image-20210813142506705 image-20210813142621201

image-20210813144052366

https://github.com/RT-Thread-Studio/sdk-bsp-stm32h750-realthread-artpi/blob/master/documents/board/ART-Pi_HW_V1.5/ART-Pi_SCH_V1.5_Release.pdf

image-20210813145319027

image-20210813145336358

image-20210813150213630

image-20210813150253189

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "drv_common.h"
#define GT9147_IRQ_PIN GET_PIN(G,12)
#define GT9147_RST_PIN GET_PIN(D,3)

int rt_hw_gt9147_port(void)
{
struct rt_touch_config config;
rt_uint8_t rst;

rst = GT9147_RST_PIN;
config.dev_name = "i2c1";
config.irq_pin.pin = GT9147_IRQ_PIN;
config.irq_pin.mode = PIN_MODE_INPUT_PULLDOWN;
config.user_data = &rst;

rt_hw_gt9147_init("gt", &config);

return 0;
}
INIT_DEVICE_EXPORT(rt_hw_gt9147_port);

image-20210813150415372

1
2
3
4
5
6
void touch_init(void)
{
gt9147_sample("gt",800,480);
}

INIT_APP_EXPORT(touch_init);

image-20210813151036707

image-20210813151635140

别忘了加头文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "littlevgl2rtt.h"

#define TOUCH_LCD_WIDTH 800
#define TOUCH_LCD_HEIGHT 480

static void gt9147_entry(void *parameter)
{
uint16_t x;
uint16_t y;

rt_device_control(dev, RT_TOUCH_CTRL_GET_INFO, &info);

read_data = (struct rt_touch_data *)rt_malloc(sizeof(struct rt_touch_data) * info.point_num);

while (1)
{
rt_sem_take(gt9147_sem, RT_WAITING_FOREVER);

if (rt_device_read(dev, 0, read_data, info.point_num) == info.point_num)
{
for (rt_uint8_t i = 0; i < info.point_num; i++)
{
x = TOUCH_LCD_WIDTH-(uint16_t)read_data[i].x_coordinate;
y = TOUCH_LCD_HEIGHT-(uint16_t)read_data[i].y_coordinate;
littlevgl2rtt_send_input_event(x,y,read_data[i].event);
if (read_data[i].event == RT_TOUCH_EVENT_DOWN || read_data[i].event == RT_TOUCH_EVENT_MOVE)
{
// rt_kprintf("%d %d %d %d %d\n", read_data[i].track_id,
// read_data[i].x_coordinate,
// read_data[i].y_coordinate,
// read_data[i].timestamp,
// read_data[i].width);
rt_kprintf("(%d,%d)\n",x,y);
}
}
}
rt_device_control(dev, RT_TOUCH_CTRL_ENABLE_INT, RT_NULL);
}
}

image-20210813152856907

下面是启用DMA2D提高LVGL的屏幕刷新率,但是最后出现白屏的现象不知道为什么,有待解决

image-20210813163527495

image-20210813172902373

image-20210813173029874

image-20210813173400190

image-20210813173601592

image-20210813173623234

image-20210813173640673

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/**
* @brief DMA2D MSP Initialization
* This function configures the hardware resources used in this example
* @param hdma2d: DMA2D handle pointer
* @retval None
*/
void HAL_DMA2D_MspInit(DMA2D_HandleTypeDef* hdma2d)
{
if(hdma2d->Instance==DMA2D)
{
/* USER CODE BEGIN DMA2D_MspInit 0 */

/* USER CODE END DMA2D_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_DMA2D_CLK_ENABLE();
/* DMA2D interrupt Init */
HAL_NVIC_SetPriority(DMA2D_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(DMA2D_IRQn);
/* USER CODE BEGIN DMA2D_MspInit 1 */

/* USER CODE END DMA2D_MspInit 1 */
}

}

/**
* @brief DMA2D MSP De-Initialization
* This function freeze the hardware resources used in this example
* @param hdma2d: DMA2D handle pointer
* @retval None
*/
void HAL_DMA2D_MspDeInit(DMA2D_HandleTypeDef* hdma2d)
{
if(hdma2d->Instance==DMA2D)
{
/* USER CODE BEGIN DMA2D_MspDeInit 0 */

/* USER CODE END DMA2D_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_DMA2D_CLK_DISABLE();

/* DMA2D interrupt DeInit */
HAL_NVIC_DisableIRQ(DMA2D_IRQn);
/* USER CODE BEGIN DMA2D_MspDeInit 1 */

/* USER CODE END DMA2D_MspDeInit 1 */
}

}

image-20210813190103577

image-20210813190324367

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
DMA2D_HandleTypeDef hdma2d;

static void MX_DMA2D_Init(void)
{

/* USER CODE BEGIN DMA2D_Init 0 */

/* USER CODE END DMA2D_Init 0 */

/* USER CODE BEGIN DMA2D_Init 1 */

/* USER CODE END DMA2D_Init 1 */
hdma2d.Instance = DMA2D;
hdma2d.Init.Mode = DMA2D_M2M;
hdma2d.Init.ColorMode = DMA2D_OUTPUT_RGB565;
hdma2d.Init.OutputOffset = 0;

hdma2d.LayerCfg[1].InputOffset = 0;
hdma2d.LayerCfg[1].InputColorMode = DMA2D_INPUT_RGB565;
hdma2d.LayerCfg[1].AlphaMode = DMA2D_NO_MODIF_ALPHA;
hdma2d.LayerCfg[1].InputAlpha = 0;
hdma2d.LayerCfg[1].AlphaInverted = DMA2D_REGULAR_ALPHA;
hdma2d.LayerCfg[1].RedBlueSwap = DMA2D_RB_REGULAR;
hdma2d.LayerCfg[1].ChromaSubSampling = DMA2D_NO_CSS;
if (HAL_DMA2D_Init(&hdma2d) != HAL_OK)
{
Error_Handler();
}
if (HAL_DMA2D_ConfigLayer(&hdma2d, 1) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN DMA2D_Init 2 */

/* USER CODE END DMA2D_Init 2 */
}

image-20210813190435208

drv_lcd_hw_init()

littlevgl2rtt_init

image-20210813192314323

1
2
3
4
5
6
lv_color_t *buf1 = rt_malloc(sizeof(lv_color_t)*LV_HOR_RES_MAX*LV_VER_RES_MAX);
rt_memset(buf1, 0, sizeof(lv_color_t)*LV_HOR_RES_MAX*LV_VER_RES_MAX);

lv_color_t *buf2 = rt_malloc(sizeof(lv_color_t)*LV_HOR_RES_MAX*LV_VER_RES_MAX);
rt_memset(buf2, 0, sizeof(lv_color_t)*LV_HOR_RES_MAX*LV_VER_RES_MAX);

image-20210813192519216

``

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2021 张竞豪的小岛 All Rights Reserved.

UV : | PV :