Skip to content

Commit 524ae34

Browse files
authored
新增gd32470z-lckfb配套LCD驱动 (#10311)
* 新增gd32470z-lckfb配套LCD驱动 * 1.使用RTT的编程规范修改注释 2.readme文件新增注意事项以及原作者信息 * Add maintainer info for gd32470z-lckfb-lcd
1 parent 5153f38 commit 524ae34

File tree

13 files changed

+2009
-1
lines changed

13 files changed

+2009
-1
lines changed

MAINTAINERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,6 @@ tag: workflow
7575
path: .github
7676
owners: supper thomas(supperthomas)<[email protected]>, Bingru Zhang(Rbb666)<[email protected]>, Yuqiang Wang(kurisaW)<[email protected]>
7777

78+
tag: gd32470z-lckfb-lcd
79+
path: bsp/gd32/arm/gd32470z-lckfb/board/ports
80+
owners: Wu Ying Xiang(godmial)<[email protected]>

bsp/gd32/arm/gd32470z-lckfb/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ GD32470Z-LCKFB梁山派是立创开发板推出的一款GD32F470系列的开发
5151
| GPIO | 支持 | PA0, PA1... ---> PIN: 0, 1...113 |
5252
| UART | 支持 | UART0 - UART7 |
5353
| **扩展模块** | **支持情况** | **备注** |
54-
| 暂无 | 暂不支持 | 暂不支持 |
54+
| LCD+触摸屏 | 支持 | 暂不支持中文显示(因 Keil5 编码限制),使用方法请查看bsp\gd32\arm\gd32470z-lckfb\board\ports\README.md |
5555

5656
## 使用说明
5757

bsp/gd32/arm/gd32470z-lckfb/SConstruct

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@ objs.extend(SConscript(os.path.join(libraries_path_prefix, gd32_library, 'SConsc
5656
# include drivers
5757
objs.extend(SConscript(os.path.join(libraries_path_prefix, 'gd32_drivers', 'SConscript')))
5858

59+
# include lcd and drivers
60+
objs.extend(SConscript(os.path.join(RTT_ROOT, 'bsp', 'gd32', 'arm', 'gd32470z-lckfb', 'board', 'ports', 'SConscript')))
61+
5962
# make a building
6063
DoBuilding(TARGET, objs)

bsp/gd32/arm/gd32470z-lckfb/board/Kconfig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,37 @@ endmenu
433433

434434
menu "Board extended module Drivers"
435435

436+
menuconfig BSP_USING_LCD
437+
bool "Enable LCD"
438+
select RT_USING_LCD
439+
default n
440+
if BSP_USING_LCD
441+
442+
config BSP_USING_TLI
443+
bool "Enable TLI"
444+
default y
445+
446+
config BSP_USING_SDRAM
447+
bool "Enable SDRAM"
448+
select RT_USING_SDRAM
449+
default y
450+
451+
config BSP_USING_TOUCH
452+
bool "Enable TOUCH"
453+
select RT_USING_TOUCH
454+
default n
455+
456+
config BSP_USING_GPU
457+
bool "Enable GPU"
458+
select RT_USING_GPU
459+
default y
460+
461+
config BSP_USING_DRAW_PANEL_EXAMPLE
462+
bool "Enable DRAW PANEL EXAMPLE"
463+
select RT_USING_DRAW_PANEL_EXAMPLE
464+
default n
465+
endif
466+
436467
endmenu
437468

438469
endmenu
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#### 1. 简介
2+
3+
用于 GD32F470 立创开发板配套 RGB LCD 屏幕的驱动,支持触摸。
4+
5+
> **原作者:LCKFB**
6+
> 本驱动最初由 LCKFB 开发,由 godmial 移植到本BSP。
7+
8+
#### 2. 在 ENV 中的开启
9+
ps:建议全部开启
10+
```
11+
Hardware Drivers Config --->
12+
Board extended module Drivers --->
13+
Enable LCD --->
14+
- [*]Enable TLI
15+
- [*]Enable SDRAM
16+
- [*]Enable TOUCH
17+
- [*]Enable GPU
18+
- [*]Enable DRAW PANEL EXAMPLE
19+
```
20+
21+
#### 3. 注意事项
22+
23+
1. 如果屏幕出现刷新抖动,触摸屏出现连点的情况,可以尝试在 `libraries\GD32F4xx_Firmware_Library\CMSIS\GD\GD32F4xx\Source\system_gd32f4xx.c` 将时钟值修改为
24+
`#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000)`
25+
然后重新编译即可
26+
27+
2. 由于代码格式审查原因,本驱动未包含中文显示函数。但可直接移植官方源码中的中文显示函数进行使用。
28+
29+
3. 为避免 `scons` 命令编译不通过,代码使用了如下代码段以适配不同编译器:
30+
```
31+
#if defined(__CC_ARM) || defined(__ARMCC_VERSION)
32+
// Keil MDK
33+
uint16_t ltdc_lcd_framebuf0[800][480] __attribute__((at(LCD_FRAME_BUF_ADDR)));
34+
#elif defined(__GNUC__)
35+
// GCC (RT-Thread)
36+
uint16_t ltdc_lcd_framebuf0[10][10]; // 此行为避免 scons 编译错误而添加
37+
#endif
38+
39+
40+
41+
#### 4. 联系方式
42+
43+
- 维护:godmial
44+
- 主页:<https://github.com/godmial>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Import('RTT_ROOT')
2+
Import('rtconfig')
3+
from building import *
4+
5+
cwd = GetCurrentDir()
6+
7+
# add the general drivers.
8+
src = Split("""
9+
""")
10+
11+
# add lcd drivers.
12+
if GetDepend('BSP_USING_LCD'):
13+
src += ['drv_lcd.c']
14+
15+
if GetDepend('BSP_USING_TOUCH'):
16+
src += ['drv_touch.c']
17+
18+
if GetDepend('BSP_USING_DRAW_PANEL_EXAMPLE'):
19+
src += ['draw_panel.c']
20+
21+
path = [cwd]
22+
23+
group = DefineGroup('Applications', src, depend = [''], CPPPATH = path)
24+
25+
Return('group')
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
* Copyright (c) 2006-2025, RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-05-23 godmial Refactor to conform to RT-Thread coding style.
9+
*/
10+
11+
#include <board.h>
12+
#include <rthw.h>
13+
#include <rtthread.h>
14+
#include "drv_lcd.h"
15+
#include "drv_touch.h"
16+
17+
#define COLOR_MAX 14
18+
19+
/* Maximum magnification of pixels */
20+
#define PIXEL_SIZE_MAX 20
21+
22+
typedef struct button_struct
23+
{
24+
uint16_t x;
25+
uint16_t y;
26+
uint16_t w;
27+
uint16_t h;
28+
uint16_t color;
29+
uint16_t value;
30+
} widget_object_t;
31+
32+
uint16_t color_buf[COLOR_MAX] = {GRAYBLUE, BLACK, BLUE, BRED, GRED, GBLUE, RED, MAGENTA, GREEN, YELLOW, CYAN, BROWN, BRRED, GRAY};
33+
widget_object_t button_clear, button_color, button_pixel, button_eraser;
34+
35+
36+
/**
37+
* @brief Initialize a widget button with given properties.
38+
*
39+
* @param obj Pointer to the widget object.
40+
* @param x X coordinate of the top-left corner.
41+
* @param y Y coordinate of the top-left corner.
42+
* @param w Width of the widget.
43+
* @param h Height of the widget.
44+
* @param color Color value of the widget.
45+
* @param value Initial value of the widget.
46+
*
47+
* @return None.
48+
*/
49+
void widget_object_init(widget_object_t *obj, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, uint16_t value)
50+
{
51+
obj->x = x;
52+
obj->y = y;
53+
obj->h = h;
54+
obj->w = w;
55+
obj->color = color;
56+
obj->value = value;
57+
}
58+
59+
60+
/**
61+
* @brief Initialize and display the user interface.
62+
*
63+
* This function draws the control buttons for clear, color,
64+
* pixel size, and eraser on the screen.
65+
*
66+
* @return None.
67+
*/
68+
void ui_init(void)
69+
{
70+
char temp_buf[20] = {0};
71+
72+
tli_show_button(button_clear.x, button_clear.y, button_clear.w, button_clear.h, 12, button_clear.color);
73+
tli_show_string(button_clear.x + 20, button_clear.y + 20, WHITE, button_clear.color, 2, "clear", 0);
74+
75+
tli_show_button(button_color.x, button_color.y, button_color.w, button_color.h, 12, button_color.color);
76+
tli_show_string(button_color.x + 20, button_color.y + 20, WHITE, button_color.color, 2, "color", 0);
77+
78+
tli_show_button(button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, 12, button_pixel.color);
79+
if (button_pixel.value == 0)
80+
{
81+
tli_show_string(button_pixel.x + 20, button_pixel.y + 20, WHITE, button_pixel.color, 2, "pixel", 0);
82+
button_pixel.value = 1;
83+
}
84+
else
85+
{
86+
sprintf(temp_buf, "%d", button_pixel.value);
87+
tli_show_string(button_pixel.x + (button_pixel.w / 2) - (strlen(temp_buf) / 2 * 16), button_pixel.y + 20, WHITE, button_pixel.color, 2, (uint8_t *)temp_buf, 0);
88+
}
89+
90+
tli_show_button(button_eraser.x, button_eraser.y, button_eraser.w, button_eraser.h, 12, button_eraser.color);
91+
tli_show_string(button_eraser.x + (button_eraser.w / 2) - (strlen("eraser") / 2 * 16), button_eraser.y + 20, WHITE, button_eraser.color, 2, "eraser", 0);
92+
}
93+
94+
/**
95+
* @brief Main routine to test the drawing panel with touch interaction.
96+
*
97+
* Initializes LCD and touch interface, sets up buttons and handles user input
98+
* to draw or erase on the screen based on touch events.
99+
*
100+
* @return Always returns 0.
101+
*/
102+
int draw_panel_test(void)
103+
{
104+
int touch_state = 0;
105+
char color_num = 0;
106+
char pixel_size = 0;
107+
108+
lcd_disp_config();
109+
FT5206_Init();
110+
tli_draw_rectangle(0, 0, 800, 480, WHITE, 1);
111+
112+
widget_object_init(&button_clear, 800 - 130, 480 - 80, 120, 70, BLUE, 0);
113+
widget_object_init(&button_color, 10, 480 - 80, 120, 70, BLUE, 0);
114+
widget_object_init(&button_pixel, 400 - 60, 480 - 80, 120, 70, BLUE, pixel_size);
115+
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, 0);
116+
117+
ui_init();
118+
119+
while (1)
120+
{
121+
touch_state = FT5206_Scan(0);
122+
if (touch_state == 1)
123+
{
124+
if (tp_dev.x[0] >= button_color.x && tp_dev.x[0] <= (button_color.x + button_color.w))
125+
{
126+
if (tp_dev.y[0] >= button_color.y && tp_dev.y[0] <= (button_color.y + button_color.h))
127+
{
128+
letgo_scan(0, button_color.x, button_color.y, (button_color.x + button_color.w), (button_color.y + button_color.h));
129+
color_num = (color_num + 1) % COLOR_MAX;
130+
widget_object_init(&button_color, button_color.x, button_color.y, button_color.w, button_color.h, color_buf[color_num], 0);
131+
ui_init();
132+
}
133+
}
134+
if (tp_dev.x[0] >= button_clear.x && tp_dev.x[0] <= (button_clear.x + button_clear.w))
135+
{
136+
if (tp_dev.y[0] >= button_clear.y && tp_dev.y[0] <= (button_clear.y + button_clear.h))
137+
{
138+
letgo_scan(0, button_clear.x, button_clear.y, (button_clear.x + button_clear.w), (button_clear.y + button_clear.h));
139+
tli_draw_rectangle(0, 0, 800, 480, WHITE, 1);
140+
ui_init();
141+
}
142+
}
143+
if (tp_dev.x[0] >= button_pixel.x && tp_dev.x[0] <= (button_pixel.x + button_pixel.w))
144+
{
145+
if (tp_dev.y[0] >= button_pixel.y && tp_dev.y[0] <= (button_pixel.y + button_pixel.h))
146+
{
147+
letgo_scan(0, button_pixel.x, button_pixel.y, (button_pixel.x + button_pixel.w), (button_pixel.y + button_pixel.h));
148+
pixel_size++;
149+
if (pixel_size > PIXEL_SIZE_MAX) pixel_size = 1;
150+
widget_object_init(&button_pixel, button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, button_pixel.color, pixel_size);
151+
ui_init();
152+
}
153+
}
154+
155+
if (tp_dev.x[0] >= button_eraser.x && tp_dev.x[0] <= (button_eraser.x + button_eraser.w))
156+
{
157+
if (tp_dev.y[0] >= button_eraser.y && tp_dev.y[0] <= (button_eraser.y + button_eraser.h))
158+
{
159+
letgo_scan(0, button_eraser.x, button_eraser.y, (button_eraser.x + button_eraser.w), (button_eraser.y + button_eraser.h));
160+
button_eraser.value = !button_eraser.value;
161+
if (button_eraser.value)
162+
{
163+
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLACK, button_eraser.value);
164+
}
165+
else
166+
{
167+
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, button_eraser.value);
168+
}
169+
170+
ui_init();
171+
}
172+
}
173+
174+
175+
if (!button_eraser.value)
176+
{
177+
tli_point_enlarge(tp_dev.x[0], tp_dev.y[0], color_buf[color_num], button_pixel.value);
178+
}
179+
else
180+
{
181+
tli_point_enlarge(tp_dev.x[0], tp_dev.y[0], WHITE, button_pixel.value);
182+
}
183+
}
184+
}
185+
}
186+
187+
INIT_COMPONENT_EXPORT(draw_panel_test);

0 commit comments

Comments
 (0)