Skip to content

Commit 36674b5

Browse files
committed
新增gd32470z-lckfb配套LCD驱动
1 parent d64ce33 commit 36674b5

File tree

12 files changed

+1903
-1
lines changed

12 files changed

+1903
-1
lines changed

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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#### 1.简介
2+
3+
用于GD32F470立创开发板配套RGB LCD屏幕的驱动,支持触摸。
4+
#### 2.在 ENV 中的开启
5+
ps:建议全部开启
6+
```
7+
Hardware Drivers Config --->
8+
Board extended module Drivers --->
9+
Enable LCD --->
10+
- [*]Enable TLI
11+
- [*]Enable SDRAM
12+
- [*]Enable TOUCH
13+
- [*]Enable GPU
14+
- [*]Enable DRAW PANEL EXAMPLE
15+
```
16+
#### 3.注意事项
17+
1.如果屏幕出现刷新抖动,触摸屏出现连点的情况,可以尝试在 `libraries\GD32F4xx_Firmware_Library\CMSIS\GD\GD32F4xx\Source\system_gd32f4xx.c`将时钟值修改为
18+
`#define __SYSTEM_CLOCK_240M_PLL_25M_HXTAL (uint32_t)(240000000)`然后重新编译即可
19+
20+
#### 4.联系方式
21+
22+
- 维护:godmial
23+
- 主页:<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: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#include <board.h>
2+
#include <rthw.h>
3+
#include <rtthread.h>
4+
#include "drv_lcd.h"
5+
#include "drv_touch.h"
6+
7+
#define COLOR_MAX 14
8+
9+
//像素最大放大倍数
10+
#define PIXEL_SIZE_MAX 20
11+
12+
typedef struct button_struct
13+
{
14+
uint16_t x;
15+
uint16_t y;
16+
uint16_t w;
17+
uint16_t h;
18+
uint16_t color;
19+
uint16_t value;
20+
} _widget_object_struct;
21+
22+
uint16_t color_buf[COLOR_MAX] = {GRAYBLUE, BLACK, BLUE, BRED, GRED, GBLUE, RED, MAGENTA, GREEN, YELLOW, CYAN, BROWN, BRRED, GRAY};
23+
_widget_object_struct button_clear, button_color, button_pixel, button_eraser;
24+
25+
26+
/**********************************************************
27+
* 函 数 名 称:widget_object_init
28+
* 函 数 功 能:控件对象初始化
29+
* 传 入 参 数:obj:要初始化的控件
30+
* xywh:控件的(x,y)起点坐标 w宽h高
31+
* color:控件颜色
32+
* value:控件值
33+
* 函 数 返 回:无
34+
* 作 者:LCKFB
35+
* 备 注:无
36+
**********************************************************/
37+
void widget_object_init(_widget_object_struct *obj, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t color, uint16_t value)
38+
{
39+
obj->x = x;
40+
obj->y = y;
41+
obj->h = h;
42+
obj->w = w;
43+
obj->color = color;
44+
obj->value = value;
45+
}
46+
47+
48+
/**********************************************************
49+
* 函 数 名 称:ui_init
50+
* 函 数 功 能:UI界面初始化
51+
* 传 入 参 数:无
52+
* 函 数 返 回:无
53+
* 作 者:LCKFB
54+
* 备 注:无
55+
**********************************************************/
56+
void ui_init(void)
57+
{
58+
char temp_buf[20] = {0};
59+
60+
//绘制[清除]按钮
61+
//绘制一个圆角按钮
62+
tli_show_button(button_clear.x, button_clear.y, button_clear.w, button_clear.h, 12, button_clear.color);
63+
//绘制圆角按钮的文本
64+
tli_show_string(button_clear.x + 20, button_clear.y + 20, WHITE, button_clear.color, 2, "clear", 0);
65+
66+
//绘制[颜色]按钮
67+
//绘制一个圆角按钮
68+
tli_show_button(button_color.x, button_color.y, button_color.w, button_color.h, 12, button_color.color);
69+
//绘制圆角按钮的文本
70+
tli_show_string(button_color.x + 20, button_color.y + 20, WHITE, button_color.color, 2, "color", 0);
71+
72+
//绘制[像素]按钮
73+
//绘制一个圆角按钮
74+
tli_show_button(button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, 12, button_pixel.color);
75+
if (button_pixel.value == 0)
76+
{
77+
//绘制圆角按钮的文本
78+
tli_show_string(button_pixel.x + 20, button_pixel.y + 20, WHITE, button_pixel.color, 2, "pixel", 0);
79+
button_pixel.value = 1;
80+
}
81+
else
82+
{
83+
//绘制居中显示的字符串
84+
sprintf(temp_buf, "%d", button_pixel.value);
85+
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);
86+
}
87+
88+
//绘制[擦除]按钮
89+
//绘制一个圆角按钮
90+
tli_show_button(button_eraser.x, button_eraser.y, button_eraser.w, button_eraser.h, 12, button_eraser.color);
91+
//绘制圆角按钮的文本
92+
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);
93+
}
94+
95+
int draw_panel_test(void)
96+
{
97+
int touch_state = 0;
98+
char color_num = 0;
99+
char pixel_size = 0;
100+
101+
// 屏幕初始化
102+
lcd_disp_config();
103+
// 触摸初始化
104+
FT5206_Init();
105+
//全屏清屏
106+
tli_draw_Rectangle(0, 0, 800, 480, WHITE, 1);
107+
108+
109+
//初始化[清除]按钮的xywh
110+
widget_object_init(&button_clear, 800 - 130, 480 - 80, 120, 70, BLUE, 0);
111+
//初始化[颜色]按钮的xywh
112+
widget_object_init(&button_color, 10, 480 - 80, 120, 70, BLUE, 0);
113+
//初始化[像素]按钮的xywh
114+
widget_object_init(&button_pixel, 400 - 60, 480 - 80, 120, 70, BLUE, pixel_size);
115+
//初始化[橡皮擦]按钮的xywh
116+
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, 0);
117+
118+
//UI显示
119+
ui_init();
120+
121+
while (1)
122+
{
123+
//触摸扫描
124+
touch_state = FT5206_Scan(0);
125+
//如果屏幕被触摸
126+
if (touch_state == 1)
127+
{
128+
//[颜色]按钮被按下
129+
if (tp_dev.x[0] >= button_color.x && tp_dev.x[0] <= (button_color.x + button_color.w))
130+
{
131+
if (tp_dev.y[0] >= button_color.y && tp_dev.y[0] <= (button_color.y + button_color.h))
132+
{
133+
//判断是否松手
134+
letgo_scan(0, button_color.x, button_color.y, (button_color.x + button_color.w), (button_color.y + button_color.h));
135+
//改变颜色
136+
color_num = (color_num + 1) % COLOR_MAX;
137+
//重新设置[颜色]按钮的背景色
138+
widget_object_init(&button_color, button_color.x, button_color.y, button_color.w, button_color.h, color_buf[color_num], 0);
139+
//UI重新显示
140+
ui_init();
141+
}
142+
}
143+
//[清除]按钮被按下
144+
if (tp_dev.x[0] >= button_clear.x && tp_dev.x[0] <= (button_clear.x + button_clear.w))
145+
{
146+
if (tp_dev.y[0] >= button_clear.y && tp_dev.y[0] <= (button_clear.y + button_clear.h))
147+
{
148+
//判断是否松手
149+
letgo_scan(0, button_clear.x, button_clear.y, (button_clear.x + button_clear.w), (button_clear.y + button_clear.h));
150+
//清屏为背景色
151+
tli_draw_Rectangle(0, 0, 800, 480, WHITE, 1);
152+
//UI重新显示
153+
ui_init();
154+
}
155+
}
156+
//[像素]按钮被按下
157+
if (tp_dev.x[0] >= button_pixel.x && tp_dev.x[0] <= (button_pixel.x + button_pixel.w))
158+
{
159+
if (tp_dev.y[0] >= button_pixel.y && tp_dev.y[0] <= (button_pixel.y + button_pixel.h))
160+
{
161+
//判断是否松手
162+
letgo_scan(0, button_pixel.x, button_pixel.y, (button_pixel.x + button_pixel.w), (button_pixel.y + button_pixel.h));
163+
//像素放大倍数自增
164+
pixel_size++;
165+
//如果像素放大倍数大于最大倍数
166+
if (pixel_size > PIXEL_SIZE_MAX) pixel_size = 1;
167+
//重新设置[颜色]按钮的背景色
168+
widget_object_init(&button_pixel, button_pixel.x, button_pixel.y, button_pixel.w, button_pixel.h, button_pixel.color, pixel_size);
169+
//UI重新显示
170+
ui_init();
171+
}
172+
}
173+
174+
//[擦除]按钮被按下
175+
if (tp_dev.x[0] >= button_eraser.x && tp_dev.x[0] <= (button_eraser.x + button_eraser.w))
176+
{
177+
if (tp_dev.y[0] >= button_eraser.y && tp_dev.y[0] <= (button_eraser.y + button_eraser.h))
178+
{
179+
//判断是否松手
180+
letgo_scan(0, button_eraser.x, button_eraser.y, (button_eraser.x + button_eraser.w), (button_eraser.y + button_eraser.h));
181+
//修改擦除按钮的状态
182+
button_eraser.value = !button_eraser.value;
183+
//如果是擦除状态
184+
if (button_eraser.value)
185+
{
186+
//初始化[橡皮擦]按钮的xywh颜色修改为黑色
187+
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLACK, button_eraser.value);
188+
}
189+
else
190+
{
191+
//初始化[橡皮擦]按钮的xywh颜色修改为蓝色
192+
widget_object_init(&button_eraser, 800 - 130 - 130, 480 - 80, 120, 70, BLUE, button_eraser.value);
193+
}
194+
//UI重新显示
195+
ui_init();
196+
}
197+
}
198+
199+
//如果不是擦除状态
200+
if (!button_eraser.value)
201+
{
202+
//绘制触摸点
203+
//根据[颜色]按钮的背景色设置触摸点的颜色
204+
point_enlargement(tp_dev.x[0], tp_dev.y[0], color_buf[color_num], button_pixel.value);
205+
}
206+
else
207+
{
208+
//擦除
209+
point_enlargement(tp_dev.x[0], tp_dev.y[0], WHITE, button_pixel.value);
210+
}
211+
}
212+
}
213+
}
214+
// MSH_CMD_EXPORT(draw_panel_test, draw panel test)
215+
INIT_COMPONENT_EXPORT(draw_panel_test);

0 commit comments

Comments
 (0)